diff --git a/libqpdf/QPDFFormFieldObjectHelper.cc b/libqpdf/QPDFFormFieldObjectHelper.cc index eb8fe1a..1ca0e63 100644 --- a/libqpdf/QPDFFormFieldObjectHelper.cc +++ b/libqpdf/QPDFFormFieldObjectHelper.cc @@ -510,19 +510,18 @@ FormNode::setRadioButtonValue(QPDFObjectHandle name) return; } } - - QPDFObjectHandle kids = oh().getKey("/Kids"); - if (!(isRadioButton() && parent.null() && kids.isArray())) { + auto kids = Kids(); + if (!(isRadioButton() && parent.null() && kids)) { warn("don't know how to set the value of this field as a radio button"); return; } setFieldAttribute("/V", name); - for (auto const& kid: kids.as_array()) { - QPDFObjectHandle AP = kid.getKey("/AP"); + for (FormNode kid: kids) { + QPDFObjectHandle AP = kid["/AP"]; QPDFObjectHandle annot; if (AP.null()) { // The widget may be below. If there is more than one, just find the first one. - for (auto const& grandkid: kid.getKey("/Kids").as_array()) { + for (auto const& grandkid: kid.Kids()) { AP = grandkid.getKey("/AP"); if (!AP.null()) { annot = grandkid; @@ -553,11 +552,9 @@ FormNode::setCheckBoxValue(bool value) if (AP.null()) { // The widget may be below. If there is more than one, just // find the first one. - QPDFObjectHandle kids = oh().getKey("/Kids"); - for (auto const& kid: oh().getKey("/Kids").as_array(qpdf::strict)) { + for (auto const& kid: Kids()) { AP = kid.getKey("/AP"); if (!AP.null()) { - QTC::TC("qpdf", "QPDFFormFieldObjectHelper checkbox kid widget"); annot = kid; break; } diff --git a/libqpdf/qpdf/AcroForm.hh b/libqpdf/qpdf/AcroForm.hh index 98728cd..468965f 100644 --- a/libqpdf/qpdf/AcroForm.hh +++ b/libqpdf/qpdf/AcroForm.hh @@ -356,6 +356,20 @@ namespace qpdf::impl { } + /// @brief Retrieves the /Kids array. + /// + /// This method returns the /Kids entry, which is an array of the immediate descendants of + /// this node. It is only present if the node is a form field rather than a pure widget + /// annotation. + /// + /// @return An `Array` object containing the /Kids elements. If the /Kids entry + /// does not exist or is not a valid array, the returned `Array` will be invalid. + Array + Kids() const + { + return {get("/Kids")}; + } + /// Retrieves the /Parent form field of the current field. /// /// This function accesses the parent field in the hierarchical structure of form fields, if diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index 6c58745..d39cb08 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -193,7 +193,6 @@ QPDFPageDocumentHelper non-widget annotation 0 QPDFObjectHandle replace with copy 0 QPDFAnnotationObjectHelper forbidden flags 0 QPDFAnnotationObjectHelper missing required flags 0 -QPDFFormFieldObjectHelper checkbox kid widget 0 QPDFFormFieldObjectHelper set checkbox AS 0 QPDFObjectHandle broken checkbox 0 QPDFFormFieldObjectHelper list not found 0