svn commit: r1903941 - in /xmlgraphics/fop/trunk/fop-core/src: main/java/org/apache/fop/pdf/PDFStructElem.java test/java/org/apache/fop/accessibility/fo/PDFUAWarningTestCase.java

[email protected] Fri, 09 Sep 2022 14:52:08 -0000
Newsgroups gmane.text.xml.fop.cvs
Message-ID <[email protected]>
Author: ssteiner
Date: Fri Sep  9 14:52:08 2022
New Revision: 1903941

URL: http://svn.apache.org/viewvc?rev=1903941&view=rev
Log:
FOP-3092: PDF/UA NPE when using external pdf

Modified:
    xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/pdf/PDFStructElem.java
    xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/accessibility/fo/PDFUAWarningTestCase.java

Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/pdf/PDFStructElem.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/pdf/PDFStructElem.java?rev=1903941&r1=1903940&r2=1903941&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/pdf/PDFStructElem.java (original)
+++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/pdf/PDFStructElem.java Fri Sep  9 14:52:08 2022
@@ -37,6 +37,8 @@ import org.apache.fop.util.LanguageTags;
  */
 public class PDFStructElem extends StructureHierarchyMember
         implements StructureTreeElement, CompressedObject, Serializable {
+    private static final List<StructureType> BLSE = Arrays.asList(StandardStructureTypes.Table.TABLE,
+            StandardStructureTypes.List.L, StandardStructureTypes.Paragraphlike.P);
 
     private static final long serialVersionUID = -3055241807589202532L;
     private StructureType structureType;
@@ -253,12 +255,9 @@ public class PDFStructElem extends Struc
                 put("Alt", "No alternate text specified");
             } else if (kids != null) {
                 for (PDFObject kid : kids) {
-                    if (kid instanceof PDFStructElem
-                            && !(kid instanceof Placeholder)
-                            && structureType.toString().equals("P")
-                            && isBSLE(((PDFStructElem) kid).getStructureType().toString())) {
+                    if (kid instanceof PDFStructElem && isBSLE(((PDFStructElem) kid))) {
                         structureType = StandardStructureTypes.Grouping.DIV;
-                        put("S", StandardStructureTypes.Grouping.DIV.getName());
+                        put("S", structureType.getName());
                         break;
                     }
                 }
@@ -267,9 +266,9 @@ public class PDFStructElem extends Struc
         return super.output(stream);
     }
 
-    private boolean isBSLE(String type) {
-        String[] blseValues = {"Table", "L", "P"};
-        return Arrays.asList(blseValues).contains(type);
+    private boolean isBSLE(PDFStructElem kid) {
+        boolean pType = !(kid instanceof Placeholder) && structureType == StandardStructureTypes.Paragraphlike.P;
+        return pType && BLSE.contains(kid.getStructureType());
     }
 
     /**

Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/accessibility/fo/PDFUAWarningTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/accessibility/fo/PDFUAWarningTestCase.java?rev=1903941&r1=1903940&r2=1903941&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/accessibility/fo/PDFUAWarningTestCase.java (original)
+++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/accessibility/fo/PDFUAWarningTestCase.java Fri Sep  9 14:52:08 2022
@@ -37,7 +37,16 @@ import org.apache.fop.render.pdf.PDFStru
 
 public class PDFUAWarningTestCase {
 
-    PDFFactory pdfFactory;
+    private PDFFactory pdfFactory;
+
+    @Before
+    public void setUp() {
+        PDFParentTree tree = new  PDFParentTree();
+        PDFDocument doc = new PDFDocument("");
+        doc.makeStructTreeRoot(tree);
+        doc.getProfile().setPDFUAMode(PDFUAMode.PDFUA_1);
+        pdfFactory = new PDFFactory(doc);
+    }
 
     @Test
     public void nestedTableWarningTestCase() throws IOException {
@@ -50,12 +59,15 @@ public class PDFUAWarningTestCase {
         Assert.assertEquals("Div", block.getStructureType().toString());
     }
 
-    @Before
-    public void setUp() {
-        PDFParentTree tree = new  PDFParentTree();
-        PDFDocument doc = new PDFDocument("");
-        doc.makeStructTreeRoot(tree);
-        doc.getProfile().setPDFUAMode(PDFUAMode.PDFUA_1);
-        pdfFactory = new PDFFactory(doc);
+    @Test
+    public void testNoStructureType() throws IOException {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        PDFStructElem structElem = new PDFStructElem();
+        structElem.setDocument(pdfFactory.getDocument());
+        PDFStructElem structElem2 = new PDFStructElem();
+        structElem2.setDocument(pdfFactory.getDocument());
+        structElem.addKid(structElem2);
+        structElem.output(bos);
+        Assert.assertEquals(bos.toString(), "<< /K [<< >>] >>");
     }
 }