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