Commit 2fe9086adeb80b642503cc6e6df6983722f48ffd
1 parent
31c7b097
Introduce `FormNode::Kids()` method and replace manual `/Kids` processing with method calls
Showing
3 changed files
with
20 additions
and
10 deletions
libqpdf/QPDFFormFieldObjectHelper.cc
| ... | ... | @@ -510,19 +510,18 @@ FormNode::setRadioButtonValue(QPDFObjectHandle name) |
| 510 | 510 | return; |
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | - | |
| 514 | - QPDFObjectHandle kids = oh().getKey("/Kids"); | |
| 515 | - if (!(isRadioButton() && parent.null() && kids.isArray())) { | |
| 513 | + auto kids = Kids(); | |
| 514 | + if (!(isRadioButton() && parent.null() && kids)) { | |
| 516 | 515 | warn("don't know how to set the value of this field as a radio button"); |
| 517 | 516 | return; |
| 518 | 517 | } |
| 519 | 518 | setFieldAttribute("/V", name); |
| 520 | - for (auto const& kid: kids.as_array()) { | |
| 521 | - QPDFObjectHandle AP = kid.getKey("/AP"); | |
| 519 | + for (FormNode kid: kids) { | |
| 520 | + QPDFObjectHandle AP = kid["/AP"]; | |
| 522 | 521 | QPDFObjectHandle annot; |
| 523 | 522 | if (AP.null()) { |
| 524 | 523 | // The widget may be below. If there is more than one, just find the first one. |
| 525 | - for (auto const& grandkid: kid.getKey("/Kids").as_array()) { | |
| 524 | + for (auto const& grandkid: kid.Kids()) { | |
| 526 | 525 | AP = grandkid.getKey("/AP"); |
| 527 | 526 | if (!AP.null()) { |
| 528 | 527 | annot = grandkid; |
| ... | ... | @@ -553,11 +552,9 @@ FormNode::setCheckBoxValue(bool value) |
| 553 | 552 | if (AP.null()) { |
| 554 | 553 | // The widget may be below. If there is more than one, just |
| 555 | 554 | // find the first one. |
| 556 | - QPDFObjectHandle kids = oh().getKey("/Kids"); | |
| 557 | - for (auto const& kid: oh().getKey("/Kids").as_array(qpdf::strict)) { | |
| 555 | + for (auto const& kid: Kids()) { | |
| 558 | 556 | AP = kid.getKey("/AP"); |
| 559 | 557 | if (!AP.null()) { |
| 560 | - QTC::TC("qpdf", "QPDFFormFieldObjectHelper checkbox kid widget"); | |
| 561 | 558 | annot = kid; |
| 562 | 559 | break; |
| 563 | 560 | } | ... | ... |
libqpdf/qpdf/AcroForm.hh
| ... | ... | @@ -356,6 +356,20 @@ namespace qpdf::impl |
| 356 | 356 | { |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | + /// @brief Retrieves the /Kids array. | |
| 360 | + /// | |
| 361 | + /// This method returns the /Kids entry, which is an array of the immediate descendants of | |
| 362 | + /// this node. It is only present if the node is a form field rather than a pure widget | |
| 363 | + /// annotation. | |
| 364 | + /// | |
| 365 | + /// @return An `Array` object containing the /Kids elements. If the /Kids entry | |
| 366 | + /// does not exist or is not a valid array, the returned `Array` will be invalid. | |
| 367 | + Array | |
| 368 | + Kids() const | |
| 369 | + { | |
| 370 | + return {get("/Kids")}; | |
| 371 | + } | |
| 372 | + | |
| 359 | 373 | /// Retrieves the /Parent form field of the current field. |
| 360 | 374 | /// |
| 361 | 375 | /// This function accesses the parent field in the hierarchical structure of form fields, if | ... | ... |
qpdf/qpdf.testcov
| ... | ... | @@ -193,7 +193,6 @@ QPDFPageDocumentHelper non-widget annotation 0 |
| 193 | 193 | QPDFObjectHandle replace with copy 0 |
| 194 | 194 | QPDFAnnotationObjectHelper forbidden flags 0 |
| 195 | 195 | QPDFAnnotationObjectHelper missing required flags 0 |
| 196 | -QPDFFormFieldObjectHelper checkbox kid widget 0 | |
| 197 | 196 | QPDFFormFieldObjectHelper set checkbox AS 0 |
| 198 | 197 | QPDFObjectHandle broken checkbox 0 |
| 199 | 198 | QPDFFormFieldObjectHelper list not found 0 | ... | ... |