diff --git a/libqpdf/QPDFFormFieldObjectHelper.cc b/libqpdf/QPDFFormFieldObjectHelper.cc index a7cd52f..7d92c2a 100644 --- a/libqpdf/QPDFFormFieldObjectHelper.cc +++ b/libqpdf/QPDFFormFieldObjectHelper.cc @@ -270,21 +270,17 @@ FormField::getDefaultResources() std::string QPDFFormFieldObjectHelper::getDefaultAppearance() { - return m->getDefaultAppearance(); + return m->default_appearance(); } std::string -FormField::getDefaultAppearance() +FormField::default_appearance() const { - auto value = inheritable_value("/DA"); - bool looked_in_acroform = false; - if (!value.isString()) { - value = from_AcroForm("/DA"); - looked_in_acroform = true; + if (auto DA = inheritable_value("/DA")) { + return DA.utf8_value(); } - if (value.isString()) { - QTC::TC("qpdf", "QPDFFormFieldObjectHelper DA present", looked_in_acroform ? 0 : 1); - return value.getUTF8Value(); + if (String DA = from_AcroForm("/DA")) { + return DA.utf8_value(); } return {}; } @@ -939,7 +935,7 @@ FormField::generateTextAppearance(QPDFAnnotationObjectHelper& aoh) return; } QPDFObjectHandle::Rectangle bbox = bbox_obj.getArrayAsRectangle(); - std::string DA = getDefaultAppearance(); + std::string DA = default_appearance(); std::string V = getValueAsString(); std::vector opt; if (isChoice() && (getFlags() & ff_ch_combo) == 0) { diff --git a/libqpdf/qpdf/FormField.hh b/libqpdf/qpdf/FormField.hh index 9dba5a6..c1361c3 100644 --- a/libqpdf/qpdf/FormField.hh +++ b/libqpdf/qpdf/FormField.hh @@ -200,11 +200,18 @@ namespace qpdf::impl // is not a string, the empty string will be silently returned. std::string getDefaultValueAsString(); - // Return the default appearance string, taking inheritance from the field tree into - // account. Returns the empty string if the default appearance string is not available - // (because it's erroneously absent or because this is not a variable text field). If not - // found in the field hierarchy, look in /AcroForm. - std::string getDefaultAppearance(); + /// @brief Returns the default appearance string for the form field, considering inheritance + /// from the field tree hierarchy and the document's /AcroForm dictionary. + /// + /// This method retrieves the field's /DA (default appearance) attribute. If the attribute + /// is not directly available, it checks the parent fields in the hierarchy for an inherited + /// value. If no value is found in the field hierarchy, it attempts to retrieve the /DA + /// attribute from the document's /AcroForm dictionary. The method returns an empty string + /// if no default appearance string is available or applicable. + /// + /// @return A string representing the default appearance, or an empty string if + /// no value is found. + std::string default_appearance() const; // Return the default resource dictionary for the field. This comes not from the field but // from the document-level /AcroForm dictionary. While several PDF generates put a /DR key diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index 66407cd..6c58745 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -175,7 +175,6 @@ QPDFObjectHandle numeric non-numeric 0 QPDFObjectHandle erase array bounds 0 qpdf-c called qpdf_check_pdf 0 QPDFFormFieldObjectHelper Q present 1 -QPDFFormFieldObjectHelper DA present 1 QPDFAcroFormDocumentHelper field found 1 QPDFAcroFormDocumentHelper annotation found 1 QPDFJob automatically set keep files open 1