Subject: [PATCH 17/20] Dupplicate static content structures for each pages Linking the content of each static-content region on multiple pages into one structure tree generates not useable results: static-content: AB => AAAAAA BBBBBBB --- .../fop/render/pdf/PDFLogicalStructureHandler.java | 43 +++++++++++--------- 1 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java index 79b7cfb..debf3c7 100644 --- a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java +++ b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java @@ -59,6 +59,8 @@ class PDFLogicalStructureHandler { * Map of references to the corresponding structure elements. */ private Map structTreeMap = new HashMap(); + private Map structStaticTreeMap = new HashMap(); + private List staticRegions; private final PDFParentTree parentTree = new PDFParentTree(); @@ -136,32 +138,22 @@ class PDFLogicalStructureHandler { structElemPart.setLanguage(language); } currentPageSequence = structElemPart; + staticRegions = new ArrayList(); for (int i = 0, n = structureTree.getLength(); i < n; i++) { - StructureElement node = structureTree.getChild(i); - assert node.getName().equals("flow") - || node.getName().equals("static-content"); - PDFStructElem structElemSect = pdfDoc.getFactory().makeStructureElement( - FOToPDFRoleMap.mapFormattingObject(node.getName(), structElemPart), - structElemPart); - structElemPart.addKid(structElemSect); - for (int j = 0, m = node.getLength(); j < m; j++) { - processNode(node.getChild(j), structElemSect, true); - } + if (structureTree.getChild(i).getName().equals("static-content")) + staticRegions.add(structureTree.getChild(i)); + else + processNode(structureTree.getChild(i), currentPageSequence, false); } } - private void processNode(StructureElement node, PDFStructElem parent, boolean addKid) { + private void processNode(StructureElement node, PDFStructElem parent, boolean isStatic) { String ptr = node.getPtr(); assert ptr != null; PDFStructElem structElem = pdfDoc.getFactory().makeStructureElement( FOToPDFRoleMap.mapFormattingObject(node, parent, eventBroadcaster), parent); - // TODO necessary? If a page-sequence is empty (e.g., contains a single - // empty fo:block), should the block still be added to the structure - // tree? This is not being done for descendant empty elements... - if (addKid) { - parent.addKid(structElem); - } + String nodeName = node.getName(); if (nodeName.equals("external-graphic") || nodeName.equals("instream-foreign-object")) { String altTextNode = node.getAltText(); @@ -171,9 +163,14 @@ class PDFLogicalStructureHandler { structElem.put("Alt", "No alternate text specified"); } } - structTreeMap.put(ptr, structElem); + + if (isStatic) + structStaticTreeMap.put(ptr, structElem); + else + structTreeMap.put(ptr, structElem); + for (int i = 0, n = node.getLength(); i < n; i++) { - processNode(node.getChild(i), structElem, false); + processNode(node.getChild(i), structElem, isStatic); } } @@ -190,6 +187,10 @@ class PDFLogicalStructureHandler { currentPage = page; currentPage.setStructParents(getNextParentTreeKey()); pageParentTreeArray = new PDFArray(); + + structStaticTreeMap = new HashMap(); + for(int i = 0;i< staticRegions.size(); i++) + processNode((StructureElement)staticRegions.get(i), currentPageSequence, true); } /** @@ -221,6 +222,8 @@ class PDFLogicalStructureHandler { private MarkedContentInfo addToParentTree(String structurePointer) { PDFStructElem parent = (PDFStructElem) structTreeMap.get(structurePointer); + if (parent == null) + parent = (PDFStructElem) structStaticTreeMap.get(structurePointer); if (parent == null) { return ARTIFACT; } else { @@ -308,6 +311,8 @@ class PDFLogicalStructureHandler { contentItem.put("Pg", this.currentPage); contentItem.put("Obj", link); PDFStructElem parent = (PDFStructElem) structTreeMap.get(structurePointer); + if (parent == null) + parent = (PDFStructElem) structStaticTreeMap.get(structurePointer); parent.addKid(contentItem); } -- 1.6.4.2