Commit 66e41e3e2ed725d312db5fdad92c42023dec6fd4
1 parent
bc28f7db
Fix `field` method in `FormNode`: the previous heuristic incorrectly treated the…
… presence of a `/Parent` attribute as evidence that the node a form fields; however, it is also a (sometimes required) attribute of a pure widget annotation.
Showing
2 changed files
with
9 additions
and
9 deletions
libqpdf/QPDFAcroFormDocumentHelper.cc
| ... | ... | @@ -413,7 +413,7 @@ AcroForm::traverseField(QPDFObjectHandle field, QPDFObjectHandle const& parent, |
| 413 | 413 | // be there to be inherited by annotations below it. |
| 414 | 414 | |
| 415 | 415 | FormNode node = field; |
| 416 | - const bool is_field = depth == 0 || node.field(); | |
| 416 | + const bool is_field = node.field(); | |
| 417 | 417 | const bool is_annotation = node.widget(); |
| 418 | 418 | |
| 419 | 419 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper field found", (depth == 0) ? 0 : 1); | ... | ... |
libqpdf/qpdf/AcroForm.hh
| ... | ... | @@ -644,19 +644,19 @@ namespace qpdf::impl |
| 644 | 644 | /// no value is found. |
| 645 | 645 | std::string default_appearance() const; |
| 646 | 646 | |
| 647 | - /// @brief Determines whether the form node represents a field (does not apply to root | |
| 648 | - /// fields). | |
| 647 | + /// @brief Determines if the current node represents a valid form field node. | |
| 649 | 648 | /// |
| 650 | - /// This method checks if the current node represents a field by examining two conditions: | |
| 651 | - /// 1. The presence of children nodes (via the `/Kids` array). | |
| 652 | - /// 2. Whether it contains the `/Parent` key. | |
| 649 | + /// This function evaluates whether the current node is valid by combining | |
| 650 | + /// checks for the node's partial name (/T attribute), its immediate descendants | |
| 651 | + /// (/Kids array), and its field type (/FT attribute). It ensures that at least | |
| 652 | + /// one of these properties exists or returns a valid value. | |
| 653 | 653 | /// |
| 654 | - /// @return `true` if the node represents a field (either has children or contains a | |
| 655 | - /// `/Parent` key), otherwise `false`. | |
| 654 | + /// @return true if the form node contains a valid /T attribute, /Kids array, | |
| 655 | + /// or /FT attribute; otherwise, false. | |
| 656 | 656 | bool |
| 657 | 657 | field() const |
| 658 | 658 | { |
| 659 | - return Kids() || contains("/Parent"); | |
| 659 | + return T() || Kids() || FT(); | |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | /// @brief Determines if the form node represents a widget annotation. | ... | ... |