Commit ed7f3d5eab7872f2932939d442545924f12bd39d

Authored by m-holger
1 parent 8f455ffa

Rename `FormField` class to `FormNode` for to reflect that node can also be widgets

- Update class name and references in `FormField.hh` and `QPDFFormFieldObjectHelper.cc`.
- Enhance comments to align with PDF specification, providing clearer descriptions of class functionality and attributes.
libqpdf/QPDFFormFieldObjectHelper.cc
@@ -16,15 +16,15 @@ @@ -16,15 +16,15 @@
16 16
17 using namespace qpdf; 17 using namespace qpdf;
18 18
19 -using FormField = qpdf::impl::FormField; 19 +using FormNode = qpdf::impl::FormNode;
20 20
21 -const QPDFObjectHandle FormField::null_oh; 21 +const QPDFObjectHandle FormNode::null_oh;
22 22
23 -class QPDFFormFieldObjectHelper::Members: public FormField 23 +class QPDFFormFieldObjectHelper::Members: public FormNode
24 { 24 {
25 public: 25 public:
26 Members(QPDFObjectHandle const& oh) : 26 Members(QPDFObjectHandle const& oh) :
27 - FormField(oh) 27 + FormNode(oh)
28 { 28 {
29 } 29 }
30 }; 30 };
@@ -59,8 +59,8 @@ QPDFFormFieldObjectHelper::getTopLevelField(bool* is_different) @@ -59,8 +59,8 @@ QPDFFormFieldObjectHelper::getTopLevelField(bool* is_different)
59 return Null::if_null(m->root_field(is_different).oh()); 59 return Null::if_null(m->root_field(is_different).oh());
60 } 60 }
61 61
62 -FormField  
63 -FormField::root_field(bool* is_different) 62 +FormNode
  63 +FormNode::root_field(bool* is_different)
64 { 64 {
65 if (is_different) { 65 if (is_different) {
66 *is_different = false; 66 *is_different = false;
@@ -87,7 +87,7 @@ QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name) @@ -87,7 +87,7 @@ QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name)
87 } 87 }
88 88
89 QPDFObjectHandle const& 89 QPDFObjectHandle const&
90 -FormField::inherited(std::string const& name, bool acroform) const 90 +FormNode::inherited(std::string const& name, bool acroform) const
91 { 91 {
92 if (!obj) { 92 if (!obj) {
93 return null_oh; 93 return null_oh;
@@ -111,7 +111,7 @@ QPDFFormFieldObjectHelper::getInheritableFieldValueAsString(std::string const& n @@ -111,7 +111,7 @@ QPDFFormFieldObjectHelper::getInheritableFieldValueAsString(std::string const& n
111 } 111 }
112 112
113 std::string 113 std::string
114 -FormField::inheritable_string(std::string const& name) const 114 +FormNode::inheritable_string(std::string const& name) const
115 { 115 {
116 if (auto fv = inheritable_value<String>(name)) { 116 if (auto fv = inheritable_value<String>(name)) {
117 return fv.utf8_value(); 117 return fv.utf8_value();
@@ -144,7 +144,7 @@ QPDFFormFieldObjectHelper::getFullyQualifiedName() @@ -144,7 +144,7 @@ QPDFFormFieldObjectHelper::getFullyQualifiedName()
144 } 144 }
145 145
146 std::string 146 std::string
147 -FormField::fully_qualified_name() const 147 +FormNode::fully_qualified_name() const
148 { 148 {
149 std::string result; 149 std::string result;
150 auto node = *this; 150 auto node = *this;
@@ -169,7 +169,7 @@ QPDFFormFieldObjectHelper::getPartialName() @@ -169,7 +169,7 @@ QPDFFormFieldObjectHelper::getPartialName()
169 } 169 }
170 170
171 std::string 171 std::string
172 -FormField::partial_name() const 172 +FormNode::partial_name() const
173 { 173 {
174 if (auto pn = T()) { 174 if (auto pn = T()) {
175 return pn.utf8_value(); 175 return pn.utf8_value();
@@ -184,7 +184,7 @@ QPDFFormFieldObjectHelper::getAlternativeName() @@ -184,7 +184,7 @@ QPDFFormFieldObjectHelper::getAlternativeName()
184 } 184 }
185 185
186 std::string 186 std::string
187 -FormField::alternative_name() const 187 +FormNode::alternative_name() const
188 { 188 {
189 if (auto an = TU()) { 189 if (auto an = TU()) {
190 return an.utf8_value(); 190 return an.utf8_value();
@@ -199,7 +199,7 @@ QPDFFormFieldObjectHelper::getMappingName() @@ -199,7 +199,7 @@ QPDFFormFieldObjectHelper::getMappingName()
199 } 199 }
200 200
201 std::string 201 std::string
202 -FormField::mapping_name() const 202 +FormNode::mapping_name() const
203 { 203 {
204 if (auto mn = TM()) { 204 if (auto mn = TM()) {
205 return mn.utf8_value(); 205 return mn.utf8_value();
@@ -220,7 +220,7 @@ QPDFFormFieldObjectHelper::getValueAsString() @@ -220,7 +220,7 @@ QPDFFormFieldObjectHelper::getValueAsString()
220 } 220 }
221 221
222 std::string 222 std::string
223 -FormField::value() const 223 +FormNode::value() const
224 { 224 {
225 return inheritable_string("/V"); 225 return inheritable_string("/V");
226 } 226 }
@@ -238,7 +238,7 @@ QPDFFormFieldObjectHelper::getDefaultValueAsString() @@ -238,7 +238,7 @@ QPDFFormFieldObjectHelper::getDefaultValueAsString()
238 } 238 }
239 239
240 std::string 240 std::string
241 -FormField::default_value() const 241 +FormNode::default_value() const
242 { 242 {
243 return inheritable_string("/DV"); 243 return inheritable_string("/DV");
244 } 244 }
@@ -250,7 +250,7 @@ QPDFFormFieldObjectHelper::getDefaultResources() @@ -250,7 +250,7 @@ QPDFFormFieldObjectHelper::getDefaultResources()
250 } 250 }
251 251
252 QPDFObjectHandle 252 QPDFObjectHandle
253 -FormField::getDefaultResources() 253 +FormNode::getDefaultResources()
254 { 254 {
255 return from_AcroForm("/DR"); 255 return from_AcroForm("/DR");
256 } 256 }
@@ -262,7 +262,7 @@ QPDFFormFieldObjectHelper::getDefaultAppearance() @@ -262,7 +262,7 @@ QPDFFormFieldObjectHelper::getDefaultAppearance()
262 } 262 }
263 263
264 std::string 264 std::string
265 -FormField::default_appearance() const 265 +FormNode::default_appearance() const
266 { 266 {
267 if (auto DA = inheritable_value<String>("/DA")) { 267 if (auto DA = inheritable_value<String>("/DA")) {
268 return DA.utf8_value(); 268 return DA.utf8_value();
@@ -280,7 +280,7 @@ QPDFFormFieldObjectHelper::getQuadding() @@ -280,7 +280,7 @@ QPDFFormFieldObjectHelper::getQuadding()
280 } 280 }
281 281
282 int 282 int
283 -FormField::getQuadding() 283 +FormNode::getQuadding()
284 { 284 {
285 auto fv = inheritable_value<QPDFObjectHandle>("/Q"); 285 auto fv = inheritable_value<QPDFObjectHandle>("/Q");
286 bool looked_in_acroform = false; 286 bool looked_in_acroform = false;
@@ -302,7 +302,7 @@ QPDFFormFieldObjectHelper::getFlags() @@ -302,7 +302,7 @@ QPDFFormFieldObjectHelper::getFlags()
302 } 302 }
303 303
304 int 304 int
305 -FormField::getFlags() 305 +FormNode::getFlags()
306 { 306 {
307 auto f = inheritable_value<QPDFObjectHandle>("/Ff"); 307 auto f = inheritable_value<QPDFObjectHandle>("/Ff");
308 return f.isInteger() ? f.getIntValueAsInt() : 0; 308 return f.isInteger() ? f.getIntValueAsInt() : 0;
@@ -315,7 +315,7 @@ QPDFFormFieldObjectHelper::isText() @@ -315,7 +315,7 @@ QPDFFormFieldObjectHelper::isText()
315 } 315 }
316 316
317 bool 317 bool
318 -FormField::isText() 318 +FormNode::isText()
319 { 319 {
320 return FT() == "/Tx"; 320 return FT() == "/Tx";
321 } 321 }
@@ -327,7 +327,7 @@ QPDFFormFieldObjectHelper::isCheckbox() @@ -327,7 +327,7 @@ QPDFFormFieldObjectHelper::isCheckbox()
327 } 327 }
328 328
329 bool 329 bool
330 -FormField::isCheckbox() 330 +FormNode::isCheckbox()
331 { 331 {
332 return FT() == "/Btn" && (getFlags() & (ff_btn_radio | ff_btn_pushbutton)) == 0; 332 return FT() == "/Btn" && (getFlags() & (ff_btn_radio | ff_btn_pushbutton)) == 0;
333 } 333 }
@@ -339,7 +339,7 @@ QPDFFormFieldObjectHelper::isChecked() @@ -339,7 +339,7 @@ QPDFFormFieldObjectHelper::isChecked()
339 } 339 }
340 340
341 bool 341 bool
342 -FormField::isChecked() 342 +FormNode::isChecked()
343 { 343 {
344 return isCheckbox() && V<Name>() != "/Off"; 344 return isCheckbox() && V<Name>() != "/Off";
345 } 345 }
@@ -351,7 +351,7 @@ QPDFFormFieldObjectHelper::isRadioButton() @@ -351,7 +351,7 @@ QPDFFormFieldObjectHelper::isRadioButton()
351 } 351 }
352 352
353 bool 353 bool
354 -FormField::isRadioButton() 354 +FormNode::isRadioButton()
355 { 355 {
356 return FT() == "/Btn" && (getFlags() & ff_btn_radio) == ff_btn_radio; 356 return FT() == "/Btn" && (getFlags() & ff_btn_radio) == ff_btn_radio;
357 } 357 }
@@ -363,7 +363,7 @@ QPDFFormFieldObjectHelper::isPushbutton() @@ -363,7 +363,7 @@ QPDFFormFieldObjectHelper::isPushbutton()
363 } 363 }
364 364
365 bool 365 bool
366 -FormField::isPushbutton() 366 +FormNode::isPushbutton()
367 { 367 {
368 return FT() == "/Btn" && (getFlags() & ff_btn_pushbutton) == ff_btn_pushbutton; 368 return FT() == "/Btn" && (getFlags() & ff_btn_pushbutton) == ff_btn_pushbutton;
369 } 369 }
@@ -375,7 +375,7 @@ QPDFFormFieldObjectHelper::isChoice() @@ -375,7 +375,7 @@ QPDFFormFieldObjectHelper::isChoice()
375 } 375 }
376 376
377 bool 377 bool
378 -FormField::isChoice() 378 +FormNode::isChoice()
379 { 379 {
380 return FT() == "/Ch"; 380 return FT() == "/Ch";
381 } 381 }
@@ -387,7 +387,7 @@ QPDFFormFieldObjectHelper::getChoices() @@ -387,7 +387,7 @@ QPDFFormFieldObjectHelper::getChoices()
387 } 387 }
388 388
389 std::vector<std::string> 389 std::vector<std::string>
390 -FormField::getChoices() 390 +FormNode::getChoices()
391 { 391 {
392 if (!isChoice()) { 392 if (!isChoice()) {
393 return {}; 393 return {};
@@ -413,7 +413,7 @@ QPDFFormFieldObjectHelper::setFieldAttribute(std::string const&amp; key, QPDFObjectH @@ -413,7 +413,7 @@ QPDFFormFieldObjectHelper::setFieldAttribute(std::string const&amp; key, QPDFObjectH
413 } 413 }
414 414
415 void 415 void
416 -FormField::setFieldAttribute(std::string const& key, QPDFObjectHandle value) 416 +FormNode::setFieldAttribute(std::string const& key, QPDFObjectHandle value)
417 { 417 {
418 oh().replaceKey(key, value); 418 oh().replaceKey(key, value);
419 } 419 }
@@ -425,7 +425,7 @@ QPDFFormFieldObjectHelper::setFieldAttribute(std::string const&amp; key, std::string @@ -425,7 +425,7 @@ QPDFFormFieldObjectHelper::setFieldAttribute(std::string const&amp; key, std::string
425 } 425 }
426 426
427 void 427 void
428 -FormField::setFieldAttribute(std::string const& key, std::string const& utf8_value) 428 +FormNode::setFieldAttribute(std::string const& key, std::string const& utf8_value)
429 { 429 {
430 oh().replaceKey(key, QPDFObjectHandle::newUnicodeString(utf8_value)); 430 oh().replaceKey(key, QPDFObjectHandle::newUnicodeString(utf8_value));
431 } 431 }
@@ -437,7 +437,7 @@ QPDFFormFieldObjectHelper::setV(QPDFObjectHandle value, bool need_appearances) @@ -437,7 +437,7 @@ QPDFFormFieldObjectHelper::setV(QPDFObjectHandle value, bool need_appearances)
437 } 437 }
438 438
439 void 439 void
440 -FormField::setV(QPDFObjectHandle value, bool need_appearances) 440 +FormNode::setV(QPDFObjectHandle value, bool need_appearances)
441 { 441 {
442 Name name = value; 442 Name name = value;
443 if (FT() == "/Btn") { 443 if (FT() == "/Btn") {
@@ -485,13 +485,13 @@ QPDFFormFieldObjectHelper::setV(std::string const&amp; utf8_value, bool need_appeara @@ -485,13 +485,13 @@ QPDFFormFieldObjectHelper::setV(std::string const&amp; utf8_value, bool need_appeara
485 } 485 }
486 486
487 void 487 void
488 -FormField::setV(std::string const& utf8_value, bool need_appearances) 488 +FormNode::setV(std::string const& utf8_value, bool need_appearances)
489 { 489 {
490 setV(QPDFObjectHandle::newUnicodeString(utf8_value), need_appearances); 490 setV(QPDFObjectHandle::newUnicodeString(utf8_value), need_appearances);
491 } 491 }
492 492
493 void 493 void
494 -FormField::setRadioButtonValue(QPDFObjectHandle name) 494 +FormNode::setRadioButtonValue(QPDFObjectHandle name)
495 { 495 {
496 // Set the value of a radio button field. This has the following specific behavior: 496 // Set the value of a radio button field. This has the following specific behavior:
497 // * If this is a radio button field that has a parent that is also a radio button field and has 497 // * If this is a radio button field that has a parent that is also a radio button field and has
@@ -503,7 +503,7 @@ FormField::setRadioButtonValue(QPDFObjectHandle name) @@ -503,7 +503,7 @@ FormField::setRadioButtonValue(QPDFObjectHandle name)
503 // Note that we never turn on /NeedAppearances when setting a radio button field. 503 // Note that we never turn on /NeedAppearances when setting a radio button field.
504 QPDFObjectHandle parent = oh().getKey("/Parent"); 504 QPDFObjectHandle parent = oh().getKey("/Parent");
505 if (parent.isDictionary() && parent.getKey("/Parent").null()) { 505 if (parent.isDictionary() && parent.getKey("/Parent").null()) {
506 - FormField ph(parent); 506 + FormNode ph(parent);
507 if (ph.isRadioButton()) { 507 if (ph.isRadioButton()) {
508 // This is most likely one of the individual buttons. Try calling on the parent. 508 // This is most likely one of the individual buttons. Try calling on the parent.
509 ph.setRadioButtonValue(name); 509 ph.setRadioButtonValue(name);
@@ -546,7 +546,7 @@ FormField::setRadioButtonValue(QPDFObjectHandle name) @@ -546,7 +546,7 @@ FormField::setRadioButtonValue(QPDFObjectHandle name)
546 } 546 }
547 547
548 void 548 void
549 -FormField::setCheckBoxValue(bool value) 549 +FormNode::setCheckBoxValue(bool value)
550 { 550 {
551 QPDFObjectHandle AP = oh().getKey("/AP"); 551 QPDFObjectHandle AP = oh().getKey("/AP");
552 QPDFObjectHandle annot; 552 QPDFObjectHandle annot;
@@ -601,7 +601,7 @@ QPDFFormFieldObjectHelper::generateAppearance(QPDFAnnotationObjectHelper&amp; aoh) @@ -601,7 +601,7 @@ QPDFFormFieldObjectHelper::generateAppearance(QPDFAnnotationObjectHelper&amp; aoh)
601 } 601 }
602 602
603 void 603 void
604 -FormField::generateAppearance(QPDFAnnotationObjectHelper& aoh) 604 +FormNode::generateAppearance(QPDFAnnotationObjectHelper& aoh)
605 { 605 {
606 // Ignore field types we don't know how to generate appearances for. Button fields don't really 606 // Ignore field types we don't know how to generate appearances for. Button fields don't really
607 // need them -- see code in QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded. 607 // need them -- see code in QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded.
@@ -877,7 +877,7 @@ namespace @@ -877,7 +877,7 @@ namespace
877 } // namespace 877 } // namespace
878 878
879 QPDFObjectHandle 879 QPDFObjectHandle
880 -FormField::getFontFromResource(QPDFObjectHandle resources, std::string const& name) 880 +FormNode::getFontFromResource(QPDFObjectHandle resources, std::string const& name)
881 { 881 {
882 QPDFObjectHandle result; 882 QPDFObjectHandle result;
883 if (resources.isDictionary() && resources.getKey("/Font").isDictionary() && 883 if (resources.isDictionary() && resources.getKey("/Font").isDictionary() &&
@@ -888,7 +888,7 @@ FormField::getFontFromResource(QPDFObjectHandle resources, std::string const&amp; na @@ -888,7 +888,7 @@ FormField::getFontFromResource(QPDFObjectHandle resources, std::string const&amp; na
888 } 888 }
889 889
890 void 890 void
891 -FormField::generateTextAppearance(QPDFAnnotationObjectHelper& aoh) 891 +FormNode::generateTextAppearance(QPDFAnnotationObjectHelper& aoh)
892 { 892 {
893 QPDFObjectHandle AS = aoh.getAppearanceStream("/N"); 893 QPDFObjectHandle AS = aoh.getAppearanceStream("/N");
894 if (AS.null()) { 894 if (AS.null()) {
libqpdf/qpdf/FormField.hh
@@ -10,24 +10,30 @@ class QPDFAnnotationObjectHelper; @@ -10,24 +10,30 @@ class QPDFAnnotationObjectHelper;
10 10
11 namespace qpdf::impl 11 namespace qpdf::impl
12 { 12 {
13 - // This object helper helps with form fields for interactive forms. Please see comments in  
14 - // QPDFAcroFormDocumentHelper.hh for additional details.  
15 - class FormField: public qpdf::BaseDictionary 13 + /// @class FormNode
  14 + /// @brief Represents a node in the interactive forms tree of a PDF document.
  15 + ///
  16 + /// This class models nodes that may be either form field dictionaries or widget annotation
  17 + /// dictionaries, as defined in the PDF specification (sections 12.7 and 12.5.6.19).
  18 + ///
  19 + /// For a detailed description of the attributes that this class can expose, refer to the
  20 + /// corresponding tables in the PDF 2.0 (Table 226) or PDF 1.7 (Table 220) specifications.
  21 + class FormNode: public qpdf::BaseDictionary
16 { 22 {
17 public: 23 public:
18 - FormField() = default;  
19 - FormField(FormField const&) = default;  
20 - FormField& operator=(FormField const&) = default;  
21 - FormField(FormField&&) = default;  
22 - FormField& operator=(FormField&&) = default;  
23 - ~FormField() = default;  
24 -  
25 - FormField(QPDFObjectHandle const& oh) : 24 + FormNode() = default;
  25 + FormNode(FormNode const&) = default;
  26 + FormNode& operator=(FormNode const&) = default;
  27 + FormNode(FormNode&&) = default;
  28 + FormNode& operator=(FormNode&&) = default;
  29 + ~FormNode() = default;
  30 +
  31 + FormNode(QPDFObjectHandle const& oh) :
26 BaseDictionary(oh) 32 BaseDictionary(oh)
27 { 33 {
28 } 34 }
29 35
30 - FormField(QPDFObjectHandle&& oh) : 36 + FormNode(QPDFObjectHandle&& oh) :
31 BaseDictionary(std::move(oh)) 37 BaseDictionary(std::move(oh))
32 { 38 {
33 } 39 }
@@ -38,9 +44,9 @@ namespace qpdf::impl @@ -38,9 +44,9 @@ namespace qpdf::impl
38 /// it exists. The parent is determined based on the /Parent attribute in the field 44 /// it exists. The parent is determined based on the /Parent attribute in the field
39 /// dictionary. 45 /// dictionary.
40 /// 46 ///
41 - /// @return A FormField object representing the parent field. If the current field has no  
42 - /// parent, an empty FormField object is returned.  
43 - FormField 47 + /// @return A FormNode object representing the parent field. If the current field has no
  48 + /// parent, an empty FormNode object is returned.
  49 + FormNode
44 Parent() 50 Parent()
45 { 51 {
46 return {get("/Parent")}; 52 return {get("/Parent")};
@@ -58,7 +64,7 @@ namespace qpdf::impl @@ -58,7 +64,7 @@ namespace qpdf::impl
58 /// false. 64 /// false.
59 /// 65 ///
60 /// @return The top-level field in the form field hierarchy. 66 /// @return The top-level field in the form field hierarchy.
61 - FormField root_field(bool* is_different = nullptr); 67 + FormNode root_field(bool* is_different = nullptr);
62 68
63 /// @brief Retrieves the inherited value of the specified attribute. 69 /// @brief Retrieves the inherited value of the specified attribute.
64 /// 70 ///