diff options
author | Simon Steiner <ssteiner@apache.org> | 2021-10-12 14:33:18 +0000 |
---|---|---|
committer | Simon Steiner <ssteiner@apache.org> | 2021-10-12 14:33:18 +0000 |
commit | 8346c10d0890f33dbb9b7bc43a68a32534729f1d (patch) | |
tree | 2b355d67df1cd23fb34c097e01d5ee91afc4557f /fop-core | |
parent | 8be0a4a4dc922d2c8a08728d08bb697dd35442bd (diff) | |
download | xmlgraphics-fop-8346c10d0890f33dbb9b7bc43a68a32534729f1d.tar.gz xmlgraphics-fop-8346c10d0890f33dbb9b7bc43a68a32534729f1d.zip |
FOP-2928: PDFDocumentGraphics2D does not clear content on nextPage()
Thanks to J Frank
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1894166 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core')
-rw-r--r-- | fop-core/src/main/java/org/apache/fop/svg/PDFDocumentGraphics2D.java | 1 | ||||
-rw-r--r-- | fop-core/src/test/java/org/apache/fop/pdf/PDFDocumentGraphics2DTestCase.java | 32 |
2 files changed, 32 insertions, 1 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/svg/PDFDocumentGraphics2D.java b/fop-core/src/main/java/org/apache/fop/svg/PDFDocumentGraphics2D.java index 6bc19db44..0e49cc40c 100644 --- a/fop-core/src/main/java/org/apache/fop/svg/PDFDocumentGraphics2D.java +++ b/fop-core/src/main/java/org/apache/fop/svg/PDFDocumentGraphics2D.java @@ -286,6 +286,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D { this.pdfDoc.addObject(annots); } this.pdfDoc.addObject(pdfContext.getCurrentPage()); + currentStream = null; pdfContext.clearCurrentPage(); } diff --git a/fop-core/src/test/java/org/apache/fop/pdf/PDFDocumentGraphics2DTestCase.java b/fop-core/src/test/java/org/apache/fop/pdf/PDFDocumentGraphics2DTestCase.java index fd6d8b94b..1678d32d2 100644 --- a/fop-core/src/test/java/org/apache/fop/pdf/PDFDocumentGraphics2DTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/pdf/PDFDocumentGraphics2DTestCase.java @@ -27,9 +27,12 @@ import java.awt.Graphics2D; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.xmlgraphics.java2d.GraphicContext; import org.apache.xmlgraphics.util.UnitConv; import org.apache.fop.svg.PDFDocumentGraphics2D; @@ -48,7 +51,7 @@ public class PDFDocumentGraphics2DTestCase { public void smokeTest() throws Exception { ByteArrayOutputStream baout = new ByteArrayOutputStream(); PDFDocumentGraphics2D g2d = new PDFDocumentGraphics2D(false); - g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); + g2d.setGraphicContext(new GraphicContext()); //Set up the document size Dimension pageSize = new Dimension( @@ -90,4 +93,31 @@ public class PDFDocumentGraphics2DTestCase { pdfString.substring(pdfString.length() - 6), "%%EOF\n"); } + @Test + public void checkContentNotRepeatedAcrossPage() throws Exception { + ByteArrayOutputStream baout = new ByteArrayOutputStream(); + PDFDocumentGraphics2D gPDF = new PDFDocumentGraphics2D(false); + Dimension pageSize = new Dimension( + (int) Math.ceil(UnitConv.mm2pt(210)), + (int) Math.ceil(UnitConv.mm2pt(297))); //page size A4 (in pt) + gPDF.setupDocument(baout, pageSize.width, pageSize.height); + gPDF.setupDefaultFontInfo(); + gPDF.setGraphicContext(new GraphicContext()); + for (int i = 0; i < 4; i++) { + gPDF.drawString("PageOUTPUT " + i, getInch(1), getInch(1 + i * 0.2)); + assertTrue(gPDF.getString().contains("PageOUTPUT " + i)); + if (i > 1) { + int previousValue = i - 1; + assertFalse(gPDF.getString().contains("PageOUTPUT " + previousValue)); + } + gPDF.nextPage(); + } + gPDF.finish(); + } + + private int getInch(double p) { + final int point = 72; + final int dpiScale = 4; + return (int) (p * point * dpiScale); + } } |