]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2907: Missing bounding box on repeated image for PDF/UA
authorSimon Steiner <ssteiner@apache.org>
Wed, 29 Jan 2020 09:33:34 +0000 (09:33 +0000)
committerSimon Steiner <ssteiner@apache.org>
Wed, 29 Jan 2020 09:33:34 +0000 (09:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1873290 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java
fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java

index 1ab1a8a9edc5c9708e688da5b611e224a8f27787..985e587cbb7367cef72e9505fd95c0785a10d362 100644 (file)
@@ -168,6 +168,7 @@ public class PDFPainter extends AbstractIFPainter<PDFDocumentHandler> {
     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<PDFDocumentHandler> {
                 placeImage(rect, xobject);
             }
         } else {
-            addStructTreeBBox(rect);
             drawImageUsingURI(uri, rect);
             if (!getDocumentHandler().getPDFDocument().isLinearizationEnabled()) {
                 flushPDFDoc();
index 04509398b9d3eff6824f6cfb6126b4ba19e372be..1c9c685f6826872af2cd12b42517aa04b5cc256d 100644 (file)
@@ -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();
+    }
 }