From cc76e1af4c4c2ae9dae789dd09d210696ebab97d Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Wed, 29 Jan 2020 09:33:34 +0000 Subject: FOP-2907: Missing bounding box on repeated image for PDF/UA git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1873290 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/fop/render/pdf/PDFPainter.java | 2 +- .../apache/fop/render/pdf/PDFPainterTestCase.java | 42 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java index 1ab1a8a9e..985e587cb 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java @@ -168,6 +168,7 @@ public class PDFPainter extends AbstractIFPainter { public void drawImage(String uri, Rectangle rect) throws IFException { PDFXObject xobject = getDocumentHandler().getPDFDocument().getXObject(uri); + addStructTreeBBox(rect); if (xobject != null) { if (accessEnabled) { PDFStructElem structElem = (PDFStructElem) getContext().getStructureTreeElement(); @@ -177,7 +178,6 @@ public class PDFPainter extends AbstractIFPainter { placeImage(rect, xobject); } } else { - addStructTreeBBox(rect); drawImageUsingURI(uri, rect); if (!getDocumentHandler().getPDFDocument().isLinearizationEnabled()) { flushPDFDoc(); diff --git a/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java index 04509398b..1c9c685f6 100644 --- a/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java @@ -24,9 +24,12 @@ import java.awt.Dimension; import java.awt.Rectangle; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.IOException; +import java.util.Locale; import javax.xml.transform.stream.StreamResult; +import org.junit.Assert; import org.junit.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -47,9 +50,13 @@ import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontTriplet; import org.apache.fop.fonts.MultiByteFont; import org.apache.fop.pdf.PDFDocument; +import org.apache.fop.pdf.PDFPage; import org.apache.fop.pdf.PDFProfile; +import org.apache.fop.pdf.PDFResources; import org.apache.fop.pdf.PDFStructElem; import org.apache.fop.pdf.PDFTextUtil; +import org.apache.fop.pdf.PDFUAMode; +import org.apache.fop.pdf.StandardStructureTypes; import org.apache.fop.render.RenderingContext; import org.apache.fop.render.intermediate.IFContext; import org.apache.fop.render.intermediate.IFException; @@ -218,4 +225,39 @@ public class PDFPainterTestCase { return (Integer) invocation.getArguments()[0]; } } + + @Test + public void testPDFUAImage() throws IFException, IOException { + FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI()); + foUserAgent = fopFactory.newFOUserAgent(); + foUserAgent.setAccessibility(true); + IFContext ifContext = new IFContext(foUserAgent); + pdfDocumentHandler = new PDFDocumentHandler(ifContext); + pdfDocumentHandler.getStructureTreeEventHandler(); + pdfDocumentHandler.setResult(new StreamResult(new ByteArrayOutputStream())); + pdfDocumentHandler.startDocument(); + pdfDocumentHandler.startPage(0, "", "", new Dimension()); + PDFDocument doc = pdfDocumentHandler.getPDFDocument(); + doc.getProfile().setPDFUAMode(PDFUAMode.PDFUA_1); + doc.getInfo().setTitle("a"); + PDFLogicalStructureHandler structureHandler = new PDFLogicalStructureHandler(doc); + structureHandler.startPage(new PDFPage(new PDFResources(doc), 0, + new Rectangle(), new Rectangle(), new Rectangle(), new Rectangle())); + PDFPainter pdfPainter = new PDFPainter(pdfDocumentHandler, structureHandler); + ifContext.setLanguage(Locale.US); + drawImage(doc, pdfPainter, ifContext); + String output = drawImage(doc, pdfPainter, ifContext); + Assert.assertTrue(output, output.contains("/BBox [0 0 0 0]")); + } + + private String drawImage(PDFDocument doc, PDFPainter pdfPainter, IFContext ifContext) + throws IOException, IFException { + PDFStructElem structElem = new PDFStructElem(doc.getRoot(), StandardStructureTypes.InlineLevelStructure.NOTE); + structElem.setDocument(doc); + ifContext.setStructureTreeElement(structElem); + pdfPainter.drawImage("test/resources/images/cmyk.jpg", new Rectangle()); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + structElem.output(bos); + return bos.toString(); + } } -- cgit v1.2.3