Commit 94a0e76b6951f0cb1e844ebe2ad0bcd32b162f1b
1 parent
1367ea75
Refactor `FormField`: replace `getFieldType` and `getInheritableFieldValueAsName…
…` with `FT` method, streamline logic, and update related references for clarity and consistency.
Showing
2 changed files
with
22 additions
and
28 deletions
libqpdf/QPDFFormFieldObjectHelper.cc
| ... | ... | @@ -122,13 +122,7 @@ FormField::inheritable_string(std::string const& name) const |
| 122 | 122 | std::string |
| 123 | 123 | QPDFFormFieldObjectHelper::getInheritableFieldValueAsName(std::string const& name) |
| 124 | 124 | { |
| 125 | - return m->getInheritableFieldValueAsName(name); | |
| 126 | -} | |
| 127 | - | |
| 128 | -std::string | |
| 129 | -FormField::getInheritableFieldValueAsName(std::string const& name) | |
| 130 | -{ | |
| 131 | - if (auto fv = inheritable_value<Name>(name)) { | |
| 125 | + if (auto fv = m->inheritable_value<Name>(name)) { | |
| 132 | 126 | return fv; |
| 133 | 127 | } |
| 134 | 128 | return {}; |
| ... | ... | @@ -137,13 +131,10 @@ FormField::getInheritableFieldValueAsName(std::string const& name) |
| 137 | 131 | std::string |
| 138 | 132 | QPDFFormFieldObjectHelper::getFieldType() |
| 139 | 133 | { |
| 140 | - return m->getFieldType(); | |
| 141 | -} | |
| 142 | - | |
| 143 | -std::string | |
| 144 | -FormField::getFieldType() | |
| 145 | -{ | |
| 146 | - return getInheritableFieldValueAsName("/FT"); | |
| 134 | + if (auto ft = m->FT()) { | |
| 135 | + return ft; | |
| 136 | + } | |
| 137 | + return {}; | |
| 147 | 138 | } |
| 148 | 139 | |
| 149 | 140 | std::string |
| ... | ... | @@ -346,7 +337,7 @@ QPDFFormFieldObjectHelper::isText() |
| 346 | 337 | bool |
| 347 | 338 | FormField::isText() |
| 348 | 339 | { |
| 349 | - return getFieldType() == "/Tx"; | |
| 340 | + return FT() == "/Tx"; | |
| 350 | 341 | } |
| 351 | 342 | |
| 352 | 343 | bool |
| ... | ... | @@ -358,7 +349,7 @@ QPDFFormFieldObjectHelper::isCheckbox() |
| 358 | 349 | bool |
| 359 | 350 | FormField::isCheckbox() |
| 360 | 351 | { |
| 361 | - return getFieldType() == "/Btn" && (getFlags() & (ff_btn_radio | ff_btn_pushbutton)) == 0; | |
| 352 | + return FT() == "/Btn" && (getFlags() & (ff_btn_radio | ff_btn_pushbutton)) == 0; | |
| 362 | 353 | } |
| 363 | 354 | |
| 364 | 355 | bool |
| ... | ... | @@ -382,7 +373,7 @@ QPDFFormFieldObjectHelper::isRadioButton() |
| 382 | 373 | bool |
| 383 | 374 | FormField::isRadioButton() |
| 384 | 375 | { |
| 385 | - return getFieldType() == "/Btn" && (getFlags() & ff_btn_radio) == ff_btn_radio; | |
| 376 | + return FT() == "/Btn" && (getFlags() & ff_btn_radio) == ff_btn_radio; | |
| 386 | 377 | } |
| 387 | 378 | |
| 388 | 379 | bool |
| ... | ... | @@ -394,7 +385,7 @@ QPDFFormFieldObjectHelper::isPushbutton() |
| 394 | 385 | bool |
| 395 | 386 | FormField::isPushbutton() |
| 396 | 387 | { |
| 397 | - return getFieldType() == "/Btn" && (getFlags() & ff_btn_pushbutton) == ff_btn_pushbutton; | |
| 388 | + return FT() == "/Btn" && (getFlags() & ff_btn_pushbutton) == ff_btn_pushbutton; | |
| 398 | 389 | } |
| 399 | 390 | |
| 400 | 391 | bool |
| ... | ... | @@ -406,7 +397,7 @@ QPDFFormFieldObjectHelper::isChoice() |
| 406 | 397 | bool |
| 407 | 398 | FormField::isChoice() |
| 408 | 399 | { |
| 409 | - return getFieldType() == "/Ch"; | |
| 400 | + return FT() == "/Ch"; | |
| 410 | 401 | } |
| 411 | 402 | |
| 412 | 403 | std::vector<std::string> |
| ... | ... | @@ -469,7 +460,7 @@ void |
| 469 | 460 | FormField::setV(QPDFObjectHandle value, bool need_appearances) |
| 470 | 461 | { |
| 471 | 462 | Name name = value; |
| 472 | - if (getFieldType() == "/Btn") { | |
| 463 | + if (FT() == "/Btn") { | |
| 473 | 464 | if (isCheckbox()) { |
| 474 | 465 | if (!name) { |
| 475 | 466 | warn("ignoring attempt to set a checkbox field to a value whose type is not name"); |
| ... | ... | @@ -632,10 +623,9 @@ QPDFFormFieldObjectHelper::generateAppearance(QPDFAnnotationObjectHelper& aoh) |
| 632 | 623 | void |
| 633 | 624 | FormField::generateAppearance(QPDFAnnotationObjectHelper& aoh) |
| 634 | 625 | { |
| 635 | - std::string ft = getFieldType(); | |
| 636 | 626 | // Ignore field types we don't know how to generate appearances for. Button fields don't really |
| 637 | 627 | // need them -- see code in QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded. |
| 638 | - if ((ft == "/Tx") || (ft == "/Ch")) { | |
| 628 | + if (FT() == "/Tx" || FT() == "/Ch") { | |
| 639 | 629 | generateTextAppearance(aoh); |
| 640 | 630 | } |
| 641 | 631 | } | ... | ... |
libqpdf/qpdf/FormField.hh
| ... | ... | @@ -104,12 +104,16 @@ namespace qpdf::impl |
| 104 | 104 | /// value does not exist or is not of String type. |
| 105 | 105 | std::string inheritable_string(std::string const& name) const; |
| 106 | 106 | |
| 107 | - // Get an inherited field value of type name as a string representing the name. If it is not | |
| 108 | - // a name, silently return the empty string. | |
| 109 | - std::string getInheritableFieldValueAsName(std::string const& name); | |
| 110 | - | |
| 111 | - // Returns the value of /FT if present, otherwise returns the empty string. | |
| 112 | - std::string getFieldType(); | |
| 107 | + /// @brief Retrieves the field type (/FT attribute). | |
| 108 | + /// @param inherit If set to `true`, the function will attempt to retrieve the value by | |
| 109 | + /// inheritance from the parent hierarchy of the form field. Defaults to `true`. | |
| 110 | + /// @return Returns the field type if found; otherwise, returns a default-constructed | |
| 111 | + /// `Name`. | |
| 112 | + Name | |
| 113 | + FT(bool inherit = true) const | |
| 114 | + { | |
| 115 | + return inheritable_value<Name>("/FT"); | |
| 116 | + } | |
| 113 | 117 | |
| 114 | 118 | std::string getFullyQualifiedName(); |
| 115 | 119 | ... | ... |