Sfoglia il codice sorgente

FOP-3092: PDF/UA NPE when using external pdf

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1903941 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-2_8
Simon Steiner 1 anno fa
parent
commit
142ae43d63

+ 7
- 8
fop-core/src/main/java/org/apache/fop/pdf/PDFStructElem.java Vedi File

*/ */
public class PDFStructElem extends StructureHierarchyMember public class PDFStructElem extends StructureHierarchyMember
implements StructureTreeElement, CompressedObject, Serializable { 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 static final long serialVersionUID = -3055241807589202532L;
private StructureType structureType; private StructureType structureType;
put("Alt", "No alternate text specified"); put("Alt", "No alternate text specified");
} else if (kids != null) { } else if (kids != null) {
for (PDFObject kid : kids) { 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; structureType = StandardStructureTypes.Grouping.DIV;
put("S", StandardStructureTypes.Grouping.DIV.getName());
put("S", structureType.getName());
break; break;
} }
} }
return super.output(stream); 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());
} }


/** /**

+ 20
- 8
fop-core/src/test/java/org/apache/fop/accessibility/fo/PDFUAWarningTestCase.java Vedi File



public class PDFUAWarningTestCase { 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 @Test
public void nestedTableWarningTestCase() throws IOException { public void nestedTableWarningTestCase() throws IOException {
Assert.assertEquals("Div", block.getStructureType().toString()); 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 [<< >>] >>");
} }
} }

Loading…
Annulla
Salva