You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ss...@apache.org on 2017/01/23 11:49:59 UTC

svn commit: r1779911 - in /xmlgraphics/fop-pdf-images/trunk: build.xml src/java/org/apache/fop/render/pdf/pdfbox/PageParentTreeFinder.java test/java/org/apache/fop/render/pdf/PageParentTreeFinderTestCase.java

Author: ssteiner
Date: Mon Jan 23 11:49:58 2017
New Revision: 1779911

URL: http://svn.apache.org/viewvc?rev=1779911&view=rev
Log:
FOP-2682: ClassCastException in PageParentTreeFinder

Modified:
    xmlgraphics/fop-pdf-images/trunk/build.xml
    xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PageParentTreeFinder.java
    xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PageParentTreeFinderTestCase.java

Modified: xmlgraphics/fop-pdf-images/trunk/build.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/build.xml?rev=1779911&r1=1779910&r2=1779911&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/build.xml (original)
+++ xmlgraphics/fop-pdf-images/trunk/build.xml Mon Jan 23 11:49:58 2017
@@ -448,6 +448,7 @@
       <class location="${build.unit.tests.dir}"/>
       <auxClasspath>
         <path refid="libs-build-classpath"/>
+        <path refid="libs-build-tools-classpath"/>
         <path>
           <fileset dir="${ant.library.dir}">
             <include name="ant.jar"/>
@@ -458,4 +459,22 @@
     </findbugs>
     <fail if="findbugs.warnings"/>
   </target>
+  
+  <target name="jar-sources" description="Generates a jar file with all the sources">
+    <tstamp>
+      <format property="ts" pattern="yyyyMMdd-HHmmss-z"/>
+    </tstamp>
+    <patternset id="java-only">
+      <include name="**/*.java"/>
+    </patternset>
+    <jar jarfile="${build.dir}/${name}-${version}-sources.jar">
+      <fileset dir="${src.java.dir}">
+        <patternset refid="java-only"/>
+      </fileset>
+      <fileset dir="${basedir}">
+        <include name="LICENSE"/>
+        <include name="NOTICE"/>
+      </fileset>
+    </jar>
+  </target>  
 </project>

Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PageParentTreeFinder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PageParentTreeFinder.java?rev=1779911&r1=1779910&r2=1779911&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PageParentTreeFinder.java (original)
+++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PageParentTreeFinder.java Mon Jan 23 11:49:58 2017
@@ -35,7 +35,7 @@ import org.apache.pdfbox.pdmodel.graphic
 
 public class PageParentTreeFinder {
 
-    PDPage srcPage;
+    private PDPage srcPage;
     public PageParentTreeFinder(PDPage srcPage) {
         this.srcPage = srcPage;
     }
@@ -57,7 +57,7 @@ public class PageParentTreeFinder {
         Iterable<COSName> mapXObject = srcPage.getResources().getXObjectNames();
         for (COSName n : mapXObject) {
             PDXObject t = srcPage.getResources().getXObject(n);
-            COSDictionary xObjectDict = (COSDictionary)t.getCOSObject();
+            COSDictionary xObjectDict = t.getCOSObject();
             position = xObjectDict.getInt(COSName.STRUCT_PARENTS);
             if (position != -1) {
                 return position;
@@ -77,11 +77,13 @@ public class PageParentTreeFinder {
             parentTree = (COSArray) numberTreeNodeDict.getDictionaryObject(COSName.KIDS);
             traverseKids(parentTree, position, nums);
         }
+        if (nums.isEmpty()) {
+            return new COSArray();
+        }
         return nums.get(0);
     }
 
     private void traverseKids(COSBase kids, int position, List<COSArray> numList) {
-        COSArray pageParentTree;
         if (!numList.isEmpty()) {
             return;
         }
@@ -95,7 +97,6 @@ public class PageParentTreeFinder {
             COSObject kidCOSObj = (COSObject) kids;
             if (kidCOSObj.getDictionaryObject(COSName.NUMS) == null) {
                 traverseKids(kidCOSObj.getDictionaryObject(COSName.KIDS), position, numList);
-
             } else {
                 if (kidCOSObj.getDictionaryObject(COSName.LIMITS) != null) {
                     COSArray kidCOSArray = (COSArray) kidCOSObj.getDictionaryObject(COSName.LIMITS);
@@ -103,8 +104,7 @@ public class PageParentTreeFinder {
                     int upperLimit = ((COSInteger) kidCOSArray.get(1)).intValue();
                     if (lowerLimit <= position && position <= upperLimit) {
                         COSArray nums = (COSArray) kidCOSObj.getDictionaryObject(COSName.NUMS);
-                        pageParentTree = (COSArray) nums.getObject(((position - lowerLimit) * 2) + 1);
-                        numList.add(pageParentTree);
+                        numList.add(extractMarkedContentParents(nums, position));
                     }
                 } else {
                     COSArray nums = (COSArray) kidCOSObj.getDictionaryObject(COSName.NUMS);

Modified: xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PageParentTreeFinderTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PageParentTreeFinderTestCase.java?rev=1779911&r1=1779910&r2=1779911&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PageParentTreeFinderTestCase.java (original)
+++ xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PageParentTreeFinderTestCase.java Mon Jan 23 11:49:58 2017
@@ -31,6 +31,7 @@ import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDResources;
+import org.apache.pdfbox.pdmodel.common.PDNumberTreeNode;
 
 import org.apache.fop.render.pdf.pdfbox.PageParentTreeFinder;
 
@@ -62,6 +63,7 @@ public class PageParentTreeFinderTestCas
         test = secondKid.getInt("MCID");
         expected = 1;
         Assert.assertEquals(test, expected);
+        doc.close();
     }
 
     @Test
@@ -75,4 +77,18 @@ public class PageParentTreeFinderTestCas
         int test = parentTree.size();
         Assert.assertEquals(test, 0);
     }
+
+    @Test
+    public void testTraverseKids() throws IOException {
+        PDDocument doc = PDDocument.load(new File(LINK));
+        PDNumberTreeNode srcNumberTreeNode = doc.getDocumentCatalog().getStructureTreeRoot().getParentTree();
+        COSArray parentTree = (COSArray) srcNumberTreeNode.getCOSObject().getDictionaryObject(COSName.KIDS);
+        COSObject kidCOSObj = (COSObject) parentTree.get(0);
+        COSArray nums = (COSArray) kidCOSObj.getDictionaryObject(COSName.NUMS);
+        nums.add(0, COSInteger.get(9));
+        nums.add(1, new COSDictionary());
+        COSArray numList = new PageParentTreeFinder(doc.getPage(0)).getPageParentTreeArray(doc);
+        Assert.assertEquals(numList.size(), 3);
+        doc.close();
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org