aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2012-11-19 18:53:11 +0000
committerVincent Hennebert <vhennebert@apache.org>2012-11-19 18:53:11 +0000
commit638ea00309ef225858fdc2b5ab2889e1236d783d (patch)
tree2d10d41ef1459a40e0a3ee644e08a21a412dd823 /src
parentff6508e118c14d1e8eb270a559d147e85bf0418f (diff)
downloadxmlgraphics-fop-638ea00309ef225858fdc2b5ab2889e1236d783d.tar.gz
xmlgraphics-fop-638ea00309ef225858fdc2b5ab2889e1236d783d.zip
Bugzilla #54169: Split the parent tree (the number tree corresponding to the ParentTree entry in the structure tree root) to avoid reaching the internal limits of Acrobat Pro, that would otherwise split it at the wrong place when saving the document.
Patch submitted by Robert Meyer git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1411352 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/fop/pdf/PDFNumberTreeNode.java28
-rw-r--r--src/java/org/apache/fop/pdf/PDFPageLabels.java14
-rw-r--r--src/java/org/apache/fop/pdf/PDFParentTree.java46
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java4
4 files changed, 61 insertions, 31 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFNumberTreeNode.java b/src/java/org/apache/fop/pdf/PDFNumberTreeNode.java
index 72fbcd1c6..599530439 100644
--- a/src/java/org/apache/fop/pdf/PDFNumberTreeNode.java
+++ b/src/java/org/apache/fop/pdf/PDFNumberTreeNode.java
@@ -49,7 +49,7 @@ public class PDFNumberTreeNode extends PDFDictionary {
* @return the Kids array
*/
public PDFArray getKids() {
- return (PDFArray)get(KIDS);
+ return (PDFArray) get(KIDS);
}
/**
@@ -65,7 +65,12 @@ public class PDFNumberTreeNode extends PDFDictionary {
* @return the Nums array
*/
public PDFNumsArray getNums() {
- return (PDFNumsArray)get(NUMS);
+ PDFNumsArray nums = (PDFNumsArray) get(NUMS);
+ if (nums == null) {
+ nums = new PDFNumsArray(this);
+ setNums(nums);
+ }
+ return nums;
}
/**
@@ -83,7 +88,7 @@ public class PDFNumberTreeNode extends PDFDictionary {
*/
public Integer getLowerLimit() {
PDFArray limits = prepareLimitsArray();
- return (Integer)limits.get(0);
+ return (Integer) limits.get(0);
}
/**
@@ -101,12 +106,25 @@ public class PDFNumberTreeNode extends PDFDictionary {
*/
public Integer getUpperLimit() {
PDFArray limits = prepareLimitsArray();
- return (Integer)limits.get(1);
+ return (Integer) limits.get(1);
+ }
+
+ /**
+ * Adds a number and object to the nums array and increases the
+ * upper limit should it be required.
+ * @param num The unique number identifying the object in the array
+ * @param object The object being added
+ */
+ protected void addToNums(int num, Object object) {
+ getNums().put(num, object);
+ if (getUpperLimit() < num) {
+ setUpperLimit(num);
+ }
}
private PDFArray prepareLimitsArray() {
- PDFArray limits = (PDFArray)get(LIMITS);
+ PDFArray limits = (PDFArray) get(LIMITS);
if (limits == null) {
limits = new PDFArray(this, new Object[2]);
put(LIMITS, limits);
diff --git a/src/java/org/apache/fop/pdf/PDFPageLabels.java b/src/java/org/apache/fop/pdf/PDFPageLabels.java
index e95c97a25..e7b90ec4e 100644
--- a/src/java/org/apache/fop/pdf/PDFPageLabels.java
+++ b/src/java/org/apache/fop/pdf/PDFPageLabels.java
@@ -57,20 +57,6 @@ public class PDFPageLabels extends PDFNumberTreeNode {
}
/**
- * Returns the Nums object
- * @return the Nums object (an empty PDFNumsArray for the "/Nums" entry is created
- * if it doesn't exist)
- */
- public PDFNumsArray getNums() {
- PDFNumsArray nums = super.getNums();
- if (nums == null) {
- nums = new PDFNumsArray(this);
- setNums(nums);
- }
- return nums;
- }
-
- /**
* Adds a new entry, if necessary, to the /PageLabels dictionary.
* @param index the page index (0 for page 1)
* @param pageLabel the page number as a string
diff --git a/src/java/org/apache/fop/pdf/PDFParentTree.java b/src/java/org/apache/fop/pdf/PDFParentTree.java
index 7876bbc0c..e03545568 100644
--- a/src/java/org/apache/fop/pdf/PDFParentTree.java
+++ b/src/java/org/apache/fop/pdf/PDFParentTree.java
@@ -24,18 +24,44 @@ package org.apache.fop.pdf;
*/
public class PDFParentTree extends PDFNumberTreeNode {
+ private static final int MAX_NUMS_ARRAY_SIZE = 50;
+
+ public PDFParentTree() {
+ put("Kids", new PDFArray());
+ }
+
+ @Override
+ public void addToNums(int num, Object object) {
+ int arrayIndex = num / MAX_NUMS_ARRAY_SIZE;
+ setNumOfKidsArrays(arrayIndex + 1);
+ insertItemToNumsArray(arrayIndex, num, object);
+ }
+
+ private void setNumOfKidsArrays(int numKids) {
+ for (int i = getKids().length(); i < numKids; i++) {
+ PDFNumberTreeNode newArray = new PDFNumberTreeNode();
+ newArray.setNums(new PDFNumsArray(newArray));
+ newArray.setLowerLimit(i * MAX_NUMS_ARRAY_SIZE);
+ newArray.setUpperLimit(i * MAX_NUMS_ARRAY_SIZE);
+ addKid(newArray);
+ }
+ }
+
/**
- * Returns the number tree corresponding to this parent tree.
- *
- * @return the number tree
+ * Registers a child object and adds it to the Kids array.
+ * @param kid The child PDF object to be added
*/
- public PDFNumsArray getNums() {
- PDFNumsArray nums = super.getNums();
- if (nums == null) {
- nums = new PDFNumsArray(this);
- setNums(nums);
- }
- return nums;
+ private void addKid(PDFObject kid) {
+ assert getDocument() != null;
+ getDocument().assignObjectNumber(kid);
+ getDocument().addTrailerObject(kid);
+ ((PDFArray) get("Kids")).add(kid);
+ }
+
+ private void insertItemToNumsArray(int array, int num, Object object) {
+ assert getKids().get(array) instanceof PDFNumberTreeNode;
+ PDFNumberTreeNode numsArray = (PDFNumberTreeNode) getKids().get(array);
+ numsArray.addToNums(num, object);
}
}
diff --git a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java
index ee00d2401..c532a05a4 100644
--- a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java
+++ b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java
@@ -124,7 +124,7 @@ class PDFLogicalStructureHandler {
// being output to the PDF.
// This should really be handled by PDFNumsArray
pdfDoc.registerObject(pageParentTreeArray);
- parentTree.getNums().put(currentPage.getStructParents(), pageParentTreeArray);
+ parentTree.addToNums(currentPage.getStructParents(), pageParentTreeArray);
}
private MarkedContentInfo addToParentTree(PDFStructElem structureTreeElement) {
@@ -198,7 +198,7 @@ class PDFLogicalStructureHandler {
contentItem.put("Type", OBJR);
contentItem.put("Pg", this.currentPage);
contentItem.put("Obj", link);
- parentTree.getNums().put(structParent, structureTreeElement);
+ parentTree.addToNums(structParent, structureTreeElement);
structureTreeElement.addKid(contentItem);
}