Commit bdcc697af348928a01dd2892f472a82f2c8c3027

Authored by m-holger
1 parent 9f58e96b

Refactor `QPDFFormFieldObjectHelper`: streamline name handling using `Name` clas…

…s for improved clarity and consistency.
libqpdf/QPDFFormFieldObjectHelper.cc
... ... @@ -10,6 +10,8 @@
10 10 #include <qpdf/QUtil.hh>
11 11 #include <cstdlib>
12 12  
  13 +using namespace qpdf;
  14 +
13 15 QPDFFormFieldObjectHelper::QPDFFormFieldObjectHelper(QPDFObjectHandle oh) :
14 16 QPDFObjectHelper(oh),
15 17 m(new Members())
... ... @@ -98,9 +100,8 @@ QPDFFormFieldObjectHelper::getInheritableFieldValueAsString(std::string const&amp; n
98 100 std::string
99 101 QPDFFormFieldObjectHelper::getInheritableFieldValueAsName(std::string const& name)
100 102 {
101   - auto fv = getInheritableFieldValue(name);
102   - if (fv.isName()) {
103   - return fv.getName();
  103 + if (Name fv = getInheritableFieldValue(name)) {
  104 + return fv;
104 105 }
105 106 return {};
106 107 }
... ... @@ -245,7 +246,7 @@ QPDFFormFieldObjectHelper::isCheckbox()
245 246 bool
246 247 QPDFFormFieldObjectHelper::isChecked()
247 248 {
248   - return isCheckbox() && getValue().isName() && getValue().getName() != "/Off";
  249 + return isCheckbox() && Name(getValue()) != "/Off";
249 250 }
250 251  
251 252 bool
... ... @@ -301,25 +302,25 @@ QPDFFormFieldObjectHelper::setFieldAttribute(std::string const&amp; key, std::string
301 302 void
302 303 QPDFFormFieldObjectHelper::setV(QPDFObjectHandle value, bool need_appearances)
303 304 {
  305 + Name name = value;
304 306 if (getFieldType() == "/Btn") {
305 307 if (isCheckbox()) {
306   - if (!value.isName()) {
  308 + if (!name) {
307 309 warn("ignoring attempt to set a checkbox field to a value whose type is not name");
308 310 return;
309 311 }
310   - std::string name = value.getName();
311 312 // Accept any value other than /Off to mean checked. Files have been seen that use
312 313 // /1 or other values.
313 314 setCheckBoxValue(name != "/Off");
314 315 return;
315 316 }
316 317 if (isRadioButton()) {
317   - if (!value.isName()) {
  318 + if (!name) {
318 319 warn(
319 320 "ignoring attempt to set a radio button field to an object that is not a name");
320 321 return;
321 322 }
322   - setRadioButtonValue(value);
  323 + setRadioButtonValue(name);
323 324 return;
324 325 }
325 326 if (isPushbutton()) {
... ...