Commit ce110b439335ec9985b645bbe89e1814c7a03e8d
1 parent
44032bfd
Refactor `FormField`: replace `getDefaultAppearance` with `default_appearance`, …
…streamline logic, update references, and improve method documentation.
Showing
3 changed files
with
19 additions
and
17 deletions
libqpdf/QPDFFormFieldObjectHelper.cc
| @@ -270,21 +270,17 @@ FormField::getDefaultResources() | @@ -270,21 +270,17 @@ FormField::getDefaultResources() | ||
| 270 | std::string | 270 | std::string |
| 271 | QPDFFormFieldObjectHelper::getDefaultAppearance() | 271 | QPDFFormFieldObjectHelper::getDefaultAppearance() |
| 272 | { | 272 | { |
| 273 | - return m->getDefaultAppearance(); | 273 | + return m->default_appearance(); |
| 274 | } | 274 | } |
| 275 | 275 | ||
| 276 | std::string | 276 | std::string |
| 277 | -FormField::getDefaultAppearance() | 277 | +FormField::default_appearance() const |
| 278 | { | 278 | { |
| 279 | - auto value = inheritable_value<QPDFObjectHandle>("/DA"); | ||
| 280 | - bool looked_in_acroform = false; | ||
| 281 | - if (!value.isString()) { | ||
| 282 | - value = from_AcroForm("/DA"); | ||
| 283 | - looked_in_acroform = true; | 279 | + if (auto DA = inheritable_value<String>("/DA")) { |
| 280 | + return DA.utf8_value(); | ||
| 284 | } | 281 | } |
| 285 | - if (value.isString()) { | ||
| 286 | - QTC::TC("qpdf", "QPDFFormFieldObjectHelper DA present", looked_in_acroform ? 0 : 1); | ||
| 287 | - return value.getUTF8Value(); | 282 | + if (String DA = from_AcroForm("/DA")) { |
| 283 | + return DA.utf8_value(); | ||
| 288 | } | 284 | } |
| 289 | return {}; | 285 | return {}; |
| 290 | } | 286 | } |
| @@ -939,7 +935,7 @@ FormField::generateTextAppearance(QPDFAnnotationObjectHelper& aoh) | @@ -939,7 +935,7 @@ FormField::generateTextAppearance(QPDFAnnotationObjectHelper& aoh) | ||
| 939 | return; | 935 | return; |
| 940 | } | 936 | } |
| 941 | QPDFObjectHandle::Rectangle bbox = bbox_obj.getArrayAsRectangle(); | 937 | QPDFObjectHandle::Rectangle bbox = bbox_obj.getArrayAsRectangle(); |
| 942 | - std::string DA = getDefaultAppearance(); | 938 | + std::string DA = default_appearance(); |
| 943 | std::string V = getValueAsString(); | 939 | std::string V = getValueAsString(); |
| 944 | std::vector<std::string> opt; | 940 | std::vector<std::string> opt; |
| 945 | if (isChoice() && (getFlags() & ff_ch_combo) == 0) { | 941 | if (isChoice() && (getFlags() & ff_ch_combo) == 0) { |
libqpdf/qpdf/FormField.hh
| @@ -200,11 +200,18 @@ namespace qpdf::impl | @@ -200,11 +200,18 @@ namespace qpdf::impl | ||
| 200 | // is not a string, the empty string will be silently returned. | 200 | // is not a string, the empty string will be silently returned. |
| 201 | std::string getDefaultValueAsString(); | 201 | std::string getDefaultValueAsString(); |
| 202 | 202 | ||
| 203 | - // Return the default appearance string, taking inheritance from the field tree into | ||
| 204 | - // account. Returns the empty string if the default appearance string is not available | ||
| 205 | - // (because it's erroneously absent or because this is not a variable text field). If not | ||
| 206 | - // found in the field hierarchy, look in /AcroForm. | ||
| 207 | - std::string getDefaultAppearance(); | 203 | + /// @brief Returns the default appearance string for the form field, considering inheritance |
| 204 | + /// from the field tree hierarchy and the document's /AcroForm dictionary. | ||
| 205 | + /// | ||
| 206 | + /// This method retrieves the field's /DA (default appearance) attribute. If the attribute | ||
| 207 | + /// is not directly available, it checks the parent fields in the hierarchy for an inherited | ||
| 208 | + /// value. If no value is found in the field hierarchy, it attempts to retrieve the /DA | ||
| 209 | + /// attribute from the document's /AcroForm dictionary. The method returns an empty string | ||
| 210 | + /// if no default appearance string is available or applicable. | ||
| 211 | + /// | ||
| 212 | + /// @return A string representing the default appearance, or an empty string if | ||
| 213 | + /// no value is found. | ||
| 214 | + std::string default_appearance() const; | ||
| 208 | 215 | ||
| 209 | // Return the default resource dictionary for the field. This comes not from the field but | 216 | // Return the default resource dictionary for the field. This comes not from the field but |
| 210 | // from the document-level /AcroForm dictionary. While several PDF generates put a /DR key | 217 | // from the document-level /AcroForm dictionary. While several PDF generates put a /DR key |
qpdf/qpdf.testcov
| @@ -175,7 +175,6 @@ QPDFObjectHandle numeric non-numeric 0 | @@ -175,7 +175,6 @@ QPDFObjectHandle numeric non-numeric 0 | ||
| 175 | QPDFObjectHandle erase array bounds 0 | 175 | QPDFObjectHandle erase array bounds 0 |
| 176 | qpdf-c called qpdf_check_pdf 0 | 176 | qpdf-c called qpdf_check_pdf 0 |
| 177 | QPDFFormFieldObjectHelper Q present 1 | 177 | QPDFFormFieldObjectHelper Q present 1 |
| 178 | -QPDFFormFieldObjectHelper DA present 1 | ||
| 179 | QPDFAcroFormDocumentHelper field found 1 | 178 | QPDFAcroFormDocumentHelper field found 1 |
| 180 | QPDFAcroFormDocumentHelper annotation found 1 | 179 | QPDFAcroFormDocumentHelper annotation found 1 |
| 181 | QPDFJob automatically set keep files open 1 | 180 | QPDFJob automatically set keep files open 1 |