From 619b777c5655aefc6a02953a9f706daaa5a6d638 Mon Sep 17 00:00:00 2001 From: moschece Date: Thu, 9 Mar 2023 10:51:26 +0100 Subject: [PATCH] :bug: Link newly created accessubility object to existing one while fixing ancestor tree --- .../openhtmltopdf/pdfboxout/PdfBoxAccessibilityHelper.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxAccessibilityHelper.java b/openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxAccessibilityHelper.java index 0258e9cbd..31b91d7a5 100644 --- a/openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxAccessibilityHelper.java +++ b/openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxAccessibilityHelper.java @@ -913,7 +913,9 @@ private COSDictionary createMarkedContentDictionary() { private void ensureAncestorTree(AbstractTreeItem child, Box parent) { // Walk up the ancestor tree making sure they all have accessibility objects. + boolean newAccessibilityObjectCreated=false; while (parent != null && parent.getAccessibilityObject() == null) { + newAccessibilityObjectCreated=true; AbstractStructualElement parentItem = createStructureItem(null, parent); parent.setAccessiblityObject(parentItem); @@ -923,6 +925,11 @@ private void ensureAncestorTree(AbstractTreeItem child, Box parent) { child = parentItem; parent = parent.getParent(); } + if(newAccessibilityObjectCreated) { + AbstractStructualElement alreadyExistingAccessibilityObject = (AbstractStructualElement) parent.getAccessibilityObject(); + child.parent = alreadyExistingAccessibilityObject; + alreadyExistingAccessibilityObject.addChild(child); + } } private AbstractStructualElement createStructureItem(StructureType type, Box box) {