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 16  
17 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 25 public:
26 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 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 65 if (is_different) {
66 66 *is_different = false;
... ... @@ -87,7 +87,7 @@ QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name)
87 87 }
88 88  
89 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 92 if (!obj) {
93 93 return null_oh;
... ... @@ -111,7 +111,7 @@ QPDFFormFieldObjectHelper::getInheritableFieldValueAsString(std::string const& n
111 111 }
112 112  
113 113 std::string
114   -FormField::inheritable_string(std::string const& name) const
  114 +FormNode::inheritable_string(std::string const& name) const
115 115 {
116 116 if (auto fv = inheritable_value<String>(name)) {
117 117 return fv.utf8_value();
... ... @@ -144,7 +144,7 @@ QPDFFormFieldObjectHelper::getFullyQualifiedName()
144 144 }
145 145  
146 146 std::string
147   -FormField::fully_qualified_name() const
  147 +FormNode::fully_qualified_name() const
148 148 {
149 149 std::string result;
150 150 auto node = *this;
... ... @@ -169,7 +169,7 @@ QPDFFormFieldObjectHelper::getPartialName()
169 169 }
170 170  
171 171 std::string
172   -FormField::partial_name() const
  172 +FormNode::partial_name() const
173 173 {
174 174 if (auto pn = T()) {
175 175 return pn.utf8_value();
... ... @@ -184,7 +184,7 @@ QPDFFormFieldObjectHelper::getAlternativeName()
184 184 }
185 185  
186 186 std::string
187   -FormField::alternative_name() const
  187 +FormNode::alternative_name() const
188 188 {
189 189 if (auto an = TU()) {
190 190 return an.utf8_value();
... ... @@ -199,7 +199,7 @@ QPDFFormFieldObjectHelper::getMappingName()
199 199 }
200 200  
201 201 std::string
202   -FormField::mapping_name() const
  202 +FormNode::mapping_name() const
203 203 {
204 204 if (auto mn = TM()) {
205 205 return mn.utf8_value();
... ... @@ -220,7 +220,7 @@ QPDFFormFieldObjectHelper::getValueAsString()
220 220 }
221 221  
222 222 std::string
223   -FormField::value() const
  223 +FormNode::value() const
224 224 {
225 225 return inheritable_string("/V");
226 226 }
... ... @@ -238,7 +238,7 @@ QPDFFormFieldObjectHelper::getDefaultValueAsString()
238 238 }
239 239  
240 240 std::string
241   -FormField::default_value() const
  241 +FormNode::default_value() const
242 242 {
243 243 return inheritable_string("/DV");
244 244 }
... ... @@ -250,7 +250,7 @@ QPDFFormFieldObjectHelper::getDefaultResources()
250 250 }
251 251  
252 252 QPDFObjectHandle
253   -FormField::getDefaultResources()
  253 +FormNode::getDefaultResources()
254 254 {
255 255 return from_AcroForm("/DR");
256 256 }
... ... @@ -262,7 +262,7 @@ QPDFFormFieldObjectHelper::getDefaultAppearance()
262 262 }
263 263  
264 264 std::string
265   -FormField::default_appearance() const
  265 +FormNode::default_appearance() const
266 266 {
267 267 if (auto DA = inheritable_value<String>("/DA")) {
268 268 return DA.utf8_value();
... ... @@ -280,7 +280,7 @@ QPDFFormFieldObjectHelper::getQuadding()
280 280 }
281 281  
282 282 int
283   -FormField::getQuadding()
  283 +FormNode::getQuadding()
284 284 {
285 285 auto fv = inheritable_value<QPDFObjectHandle>("/Q");
286 286 bool looked_in_acroform = false;
... ... @@ -302,7 +302,7 @@ QPDFFormFieldObjectHelper::getFlags()
302 302 }
303 303  
304 304 int
305   -FormField::getFlags()
  305 +FormNode::getFlags()
306 306 {
307 307 auto f = inheritable_value<QPDFObjectHandle>("/Ff");
308 308 return f.isInteger() ? f.getIntValueAsInt() : 0;
... ... @@ -315,7 +315,7 @@ QPDFFormFieldObjectHelper::isText()
315 315 }
316 316  
317 317 bool
318   -FormField::isText()
  318 +FormNode::isText()
319 319 {
320 320 return FT() == "/Tx";
321 321 }
... ... @@ -327,7 +327,7 @@ QPDFFormFieldObjectHelper::isCheckbox()
327 327 }
328 328  
329 329 bool
330   -FormField::isCheckbox()
  330 +FormNode::isCheckbox()
331 331 {
332 332 return FT() == "/Btn" && (getFlags() & (ff_btn_radio | ff_btn_pushbutton)) == 0;
333 333 }
... ... @@ -339,7 +339,7 @@ QPDFFormFieldObjectHelper::isChecked()
339 339 }
340 340  
341 341 bool
342   -FormField::isChecked()
  342 +FormNode::isChecked()
343 343 {
344 344 return isCheckbox() && V<Name>() != "/Off";
345 345 }
... ... @@ -351,7 +351,7 @@ QPDFFormFieldObjectHelper::isRadioButton()
351 351 }
352 352  
353 353 bool
354   -FormField::isRadioButton()
  354 +FormNode::isRadioButton()
355 355 {
356 356 return FT() == "/Btn" && (getFlags() & ff_btn_radio) == ff_btn_radio;
357 357 }
... ... @@ -363,7 +363,7 @@ QPDFFormFieldObjectHelper::isPushbutton()
363 363 }
364 364  
365 365 bool
366   -FormField::isPushbutton()
  366 +FormNode::isPushbutton()
367 367 {
368 368 return FT() == "/Btn" && (getFlags() & ff_btn_pushbutton) == ff_btn_pushbutton;
369 369 }
... ... @@ -375,7 +375,7 @@ QPDFFormFieldObjectHelper::isChoice()
375 375 }
376 376  
377 377 bool
378   -FormField::isChoice()
  378 +FormNode::isChoice()
379 379 {
380 380 return FT() == "/Ch";
381 381 }
... ... @@ -387,7 +387,7 @@ QPDFFormFieldObjectHelper::getChoices()
387 387 }
388 388  
389 389 std::vector<std::string>
390   -FormField::getChoices()
  390 +FormNode::getChoices()
391 391 {
392 392 if (!isChoice()) {
393 393 return {};
... ... @@ -413,7 +413,7 @@ QPDFFormFieldObjectHelper::setFieldAttribute(std::string const&amp; key, QPDFObjectH
413 413 }
414 414  
415 415 void
416   -FormField::setFieldAttribute(std::string const& key, QPDFObjectHandle value)
  416 +FormNode::setFieldAttribute(std::string const& key, QPDFObjectHandle value)
417 417 {
418 418 oh().replaceKey(key, value);
419 419 }
... ... @@ -425,7 +425,7 @@ QPDFFormFieldObjectHelper::setFieldAttribute(std::string const&amp; key, std::string
425 425 }
426 426  
427 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 430 oh().replaceKey(key, QPDFObjectHandle::newUnicodeString(utf8_value));
431 431 }
... ... @@ -437,7 +437,7 @@ QPDFFormFieldObjectHelper::setV(QPDFObjectHandle value, bool need_appearances)
437 437 }
438 438  
439 439 void
440   -FormField::setV(QPDFObjectHandle value, bool need_appearances)
  440 +FormNode::setV(QPDFObjectHandle value, bool need_appearances)
441 441 {
442 442 Name name = value;
443 443 if (FT() == "/Btn") {
... ... @@ -485,13 +485,13 @@ QPDFFormFieldObjectHelper::setV(std::string const&amp; utf8_value, bool need_appeara
485 485 }
486 486  
487 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 490 setV(QPDFObjectHandle::newUnicodeString(utf8_value), need_appearances);
491 491 }
492 492  
493 493 void
494   -FormField::setRadioButtonValue(QPDFObjectHandle name)
  494 +FormNode::setRadioButtonValue(QPDFObjectHandle name)
495 495 {
496 496 // Set the value of a radio button field. This has the following specific behavior:
497 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 503 // Note that we never turn on /NeedAppearances when setting a radio button field.
504 504 QPDFObjectHandle parent = oh().getKey("/Parent");
505 505 if (parent.isDictionary() && parent.getKey("/Parent").null()) {
506   - FormField ph(parent);
  506 + FormNode ph(parent);
507 507 if (ph.isRadioButton()) {
508 508 // This is most likely one of the individual buttons. Try calling on the parent.
509 509 ph.setRadioButtonValue(name);
... ... @@ -546,7 +546,7 @@ FormField::setRadioButtonValue(QPDFObjectHandle name)
546 546 }
547 547  
548 548 void
549   -FormField::setCheckBoxValue(bool value)
  549 +FormNode::setCheckBoxValue(bool value)
550 550 {
551 551 QPDFObjectHandle AP = oh().getKey("/AP");
552 552 QPDFObjectHandle annot;
... ... @@ -601,7 +601,7 @@ QPDFFormFieldObjectHelper::generateAppearance(QPDFAnnotationObjectHelper&amp; aoh)
601 601 }
602 602  
603 603 void
604   -FormField::generateAppearance(QPDFAnnotationObjectHelper& aoh)
  604 +FormNode::generateAppearance(QPDFAnnotationObjectHelper& aoh)
605 605 {
606 606 // Ignore field types we don't know how to generate appearances for. Button fields don't really
607 607 // need them -- see code in QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded.
... ... @@ -877,7 +877,7 @@ namespace
877 877 } // namespace
878 878  
879 879 QPDFObjectHandle
880   -FormField::getFontFromResource(QPDFObjectHandle resources, std::string const& name)
  880 +FormNode::getFontFromResource(QPDFObjectHandle resources, std::string const& name)
881 881 {
882 882 QPDFObjectHandle result;
883 883 if (resources.isDictionary() && resources.getKey("/Font").isDictionary() &&
... ... @@ -888,7 +888,7 @@ FormField::getFontFromResource(QPDFObjectHandle resources, std::string const&amp; na
888 888 }
889 889  
890 890 void
891   -FormField::generateTextAppearance(QPDFAnnotationObjectHelper& aoh)
  891 +FormNode::generateTextAppearance(QPDFAnnotationObjectHelper& aoh)
892 892 {
893 893 QPDFObjectHandle AS = aoh.getAppearanceStream("/N");
894 894 if (AS.null()) {
... ...
libqpdf/qpdf/FormField.hh
... ... @@ -10,24 +10,30 @@ class QPDFAnnotationObjectHelper;
10 10  
11 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 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 32 BaseDictionary(oh)
27 33 {
28 34 }
29 35  
30   - FormField(QPDFObjectHandle&& oh) :
  36 + FormNode(QPDFObjectHandle&& oh) :
31 37 BaseDictionary(std::move(oh))
32 38 {
33 39 }
... ... @@ -38,9 +44,9 @@ namespace qpdf::impl
38 44 /// it exists. The parent is determined based on the /Parent attribute in the field
39 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 50 Parent()
45 51 {
46 52 return {get("/Parent")};
... ... @@ -58,7 +64,7 @@ namespace qpdf::impl
58 64 /// false.
59 65 ///
60 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 69 /// @brief Retrieves the inherited value of the specified attribute.
64 70 ///
... ...