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,13 +122,7 @@ FormField::inheritable_string(std::string const& name) const | ||
| 122 | std::string | 122 | std::string |
| 123 | QPDFFormFieldObjectHelper::getInheritableFieldValueAsName(std::string const& name) | 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 | return fv; | 126 | return fv; |
| 133 | } | 127 | } |
| 134 | return {}; | 128 | return {}; |
| @@ -137,13 +131,10 @@ FormField::getInheritableFieldValueAsName(std::string const& name) | @@ -137,13 +131,10 @@ FormField::getInheritableFieldValueAsName(std::string const& name) | ||
| 137 | std::string | 131 | std::string |
| 138 | QPDFFormFieldObjectHelper::getFieldType() | 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 | std::string | 140 | std::string |
| @@ -346,7 +337,7 @@ QPDFFormFieldObjectHelper::isText() | @@ -346,7 +337,7 @@ QPDFFormFieldObjectHelper::isText() | ||
| 346 | bool | 337 | bool |
| 347 | FormField::isText() | 338 | FormField::isText() |
| 348 | { | 339 | { |
| 349 | - return getFieldType() == "/Tx"; | 340 | + return FT() == "/Tx"; |
| 350 | } | 341 | } |
| 351 | 342 | ||
| 352 | bool | 343 | bool |
| @@ -358,7 +349,7 @@ QPDFFormFieldObjectHelper::isCheckbox() | @@ -358,7 +349,7 @@ QPDFFormFieldObjectHelper::isCheckbox() | ||
| 358 | bool | 349 | bool |
| 359 | FormField::isCheckbox() | 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 | bool | 355 | bool |
| @@ -382,7 +373,7 @@ QPDFFormFieldObjectHelper::isRadioButton() | @@ -382,7 +373,7 @@ QPDFFormFieldObjectHelper::isRadioButton() | ||
| 382 | bool | 373 | bool |
| 383 | FormField::isRadioButton() | 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 | bool | 379 | bool |
| @@ -394,7 +385,7 @@ QPDFFormFieldObjectHelper::isPushbutton() | @@ -394,7 +385,7 @@ QPDFFormFieldObjectHelper::isPushbutton() | ||
| 394 | bool | 385 | bool |
| 395 | FormField::isPushbutton() | 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 | bool | 391 | bool |
| @@ -406,7 +397,7 @@ QPDFFormFieldObjectHelper::isChoice() | @@ -406,7 +397,7 @@ QPDFFormFieldObjectHelper::isChoice() | ||
| 406 | bool | 397 | bool |
| 407 | FormField::isChoice() | 398 | FormField::isChoice() |
| 408 | { | 399 | { |
| 409 | - return getFieldType() == "/Ch"; | 400 | + return FT() == "/Ch"; |
| 410 | } | 401 | } |
| 411 | 402 | ||
| 412 | std::vector<std::string> | 403 | std::vector<std::string> |
| @@ -469,7 +460,7 @@ void | @@ -469,7 +460,7 @@ void | ||
| 469 | FormField::setV(QPDFObjectHandle value, bool need_appearances) | 460 | FormField::setV(QPDFObjectHandle value, bool need_appearances) |
| 470 | { | 461 | { |
| 471 | Name name = value; | 462 | Name name = value; |
| 472 | - if (getFieldType() == "/Btn") { | 463 | + if (FT() == "/Btn") { |
| 473 | if (isCheckbox()) { | 464 | if (isCheckbox()) { |
| 474 | if (!name) { | 465 | if (!name) { |
| 475 | warn("ignoring attempt to set a checkbox field to a value whose type is not name"); | 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,10 +623,9 @@ QPDFFormFieldObjectHelper::generateAppearance(QPDFAnnotationObjectHelper& aoh) | ||
| 632 | void | 623 | void |
| 633 | FormField::generateAppearance(QPDFAnnotationObjectHelper& aoh) | 624 | FormField::generateAppearance(QPDFAnnotationObjectHelper& aoh) |
| 634 | { | 625 | { |
| 635 | - std::string ft = getFieldType(); | ||
| 636 | // Ignore field types we don't know how to generate appearances for. Button fields don't really | 626 | // Ignore field types we don't know how to generate appearances for. Button fields don't really |
| 637 | // need them -- see code in QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded. | 627 | // need them -- see code in QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded. |
| 638 | - if ((ft == "/Tx") || (ft == "/Ch")) { | 628 | + if (FT() == "/Tx" || FT() == "/Ch") { |
| 639 | generateTextAppearance(aoh); | 629 | generateTextAppearance(aoh); |
| 640 | } | 630 | } |
| 641 | } | 631 | } |
libqpdf/qpdf/FormField.hh
| @@ -104,12 +104,16 @@ namespace qpdf::impl | @@ -104,12 +104,16 @@ namespace qpdf::impl | ||
| 104 | /// value does not exist or is not of String type. | 104 | /// value does not exist or is not of String type. |
| 105 | std::string inheritable_string(std::string const& name) const; | 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 | std::string getFullyQualifiedName(); | 118 | std::string getFullyQualifiedName(); |
| 115 | 119 |