aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2020-01-29 09:33:34 +0000
committerSimon Steiner <ssteiner@apache.org>2020-01-29 09:33:34 +0000
commitcc76e1af4c4c2ae9dae789dd09d210696ebab97d (patch)
treeb8accfcb89d2e491e5f8fb2401a4598c3df0f97c
parentda0f28174020cf8b8606ea01c7b09c51155eb830 (diff)
downloadxmlgraphics-fop-cc76e1af4c4c2ae9dae789dd09d210696ebab97d.tar.gz
xmlgraphics-fop-cc76e1af4c4c2ae9dae789dd09d210696ebab97d.zip
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
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java2
-rw-r--r--fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java42
2 files changed, 43 insertions, 1 deletions
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<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();
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();
+ }
}