Commit 2ac099bd39d135566764029377ee8be137ab6c16

Authored by m-holger
1 parent 66e41e3e

Refactor `AcroForm::traverseField` to improve field handling logic: streamline c…

…hecks, replace manual key access with `FormNode` methods, and enhance maintainability.
libqpdf/QPDFAcroFormDocumentHelper.cc
@@ -432,7 +432,11 @@ AcroForm::traverseField(QPDFObjectHandle field, QPDFObjectHandle const& parent, @@ -432,7 +432,11 @@ AcroForm::traverseField(QPDFObjectHandle field, QPDFObjectHandle const& parent,
432 annotation_to_field_[og] = QPDFFormFieldObjectHelper(our_field); 432 annotation_to_field_[og] = QPDFFormFieldObjectHelper(our_field);
433 } 433 }
434 434
435 - if (is_field && depth != 0 && field["/Parent"] != parent) { 435 + if (!is_field) {
  436 + return true;
  437 + }
  438 +
  439 + if (depth != 0 && field["/Parent"] != parent) {
436 for (auto const& kid: Array(field["/Parent"]["/Kids"])) { 440 for (auto const& kid: Array(field["/Parent"]["/Kids"])) {
437 if (kid == field) { 441 if (kid == field) {
438 field.warn("while traversing /AcroForm found field with two parents"); 442 field.warn("while traversing /AcroForm found field with two parents");
@@ -449,14 +453,13 @@ AcroForm::traverseField(QPDFObjectHandle field, QPDFObjectHandle const& parent, @@ -449,14 +453,13 @@ AcroForm::traverseField(QPDFObjectHandle field, QPDFObjectHandle const& parent,
449 field.replaceKey("/Parent", parent); 453 field.replaceKey("/Parent", parent);
450 } 454 }
451 455
452 - if (is_field && field.hasKey("/T")) {  
453 - QPDFFormFieldObjectHelper foh(field);  
454 - std::string name = foh.getFullyQualifiedName(); 456 + if (node.T()) {
455 auto old = fields_.find(og); 457 auto old = fields_.find(og);
456 if (old != fields_.end() && !old->second.name.empty()) { 458 if (old != fields_.end() && !old->second.name.empty()) {
457 // We might be updating after a name change, so remove any old information 459 // We might be updating after a name change, so remove any old information
458 name_to_fields_[old->second.name].erase(og); 460 name_to_fields_[old->second.name].erase(og);
459 } 461 }
  462 + std::string name = node.fully_qualified_name();
460 fields_[og].name = name; 463 fields_[og].name = name;
461 name_to_fields_[name].insert(og); 464 name_to_fields_[name].insert(og);
462 } 465 }