Commit 2fe9086adeb80b642503cc6e6df6983722f48ffd

Authored by m-holger
1 parent 31c7b097

Introduce `FormNode::Kids()` method and replace manual `/Kids` processing with method calls

libqpdf/QPDFFormFieldObjectHelper.cc
@@ -510,19 +510,18 @@ FormNode::setRadioButtonValue(QPDFObjectHandle name) @@ -510,19 +510,18 @@ FormNode::setRadioButtonValue(QPDFObjectHandle name)
510 return; 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 warn("don't know how to set the value of this field as a radio button"); 515 warn("don't know how to set the value of this field as a radio button");
517 return; 516 return;
518 } 517 }
519 setFieldAttribute("/V", name); 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 QPDFObjectHandle annot; 521 QPDFObjectHandle annot;
523 if (AP.null()) { 522 if (AP.null()) {
524 // The widget may be below. If there is more than one, just find the first one. 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 AP = grandkid.getKey("/AP"); 525 AP = grandkid.getKey("/AP");
527 if (!AP.null()) { 526 if (!AP.null()) {
528 annot = grandkid; 527 annot = grandkid;
@@ -553,11 +552,9 @@ FormNode::setCheckBoxValue(bool value) @@ -553,11 +552,9 @@ FormNode::setCheckBoxValue(bool value)
553 if (AP.null()) { 552 if (AP.null()) {
554 // The widget may be below. If there is more than one, just 553 // The widget may be below. If there is more than one, just
555 // find the first one. 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 AP = kid.getKey("/AP"); 556 AP = kid.getKey("/AP");
559 if (!AP.null()) { 557 if (!AP.null()) {
560 - QTC::TC("qpdf", "QPDFFormFieldObjectHelper checkbox kid widget");  
561 annot = kid; 558 annot = kid;
562 break; 559 break;
563 } 560 }
libqpdf/qpdf/AcroForm.hh
@@ -356,6 +356,20 @@ namespace qpdf::impl @@ -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 /// Retrieves the /Parent form field of the current field. 373 /// Retrieves the /Parent form field of the current field.
360 /// 374 ///
361 /// This function accesses the parent field in the hierarchical structure of form fields, if 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,7 +193,6 @@ QPDFPageDocumentHelper non-widget annotation 0
193 QPDFObjectHandle replace with copy 0 193 QPDFObjectHandle replace with copy 0
194 QPDFAnnotationObjectHelper forbidden flags 0 194 QPDFAnnotationObjectHelper forbidden flags 0
195 QPDFAnnotationObjectHelper missing required flags 0 195 QPDFAnnotationObjectHelper missing required flags 0
196 -QPDFFormFieldObjectHelper checkbox kid widget 0  
197 QPDFFormFieldObjectHelper set checkbox AS 0 196 QPDFFormFieldObjectHelper set checkbox AS 0
198 QPDFObjectHandle broken checkbox 0 197 QPDFObjectHandle broken checkbox 0
199 QPDFFormFieldObjectHelper list not found 0 198 QPDFFormFieldObjectHelper list not found 0