From 86fb9989a551ff40a4c0512f550e4ece355939a1 Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Fri, 4 Dec 2015 12:18:50 +0000 Subject: FOP-2548: Support Barcode4J page number git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1717946 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/render/bitmap/AbstractBitmapDocumentHandler.java | 2 +- .../fop/render/intermediate/AbstractIFPainter.java | 2 +- .../org/apache/fop/render/intermediate/IFContext.java | 9 +++++++++ .../org/apache/fop/render/intermediate/IFParser.java | 1 + .../org/apache/fop/render/intermediate/IFRenderer.java | 1 + src/java/org/apache/fop/render/java2d/Java2DPainter.java | 16 +++++++++++++--- .../org/apache/fop/render/pcl/PCLDocumentHandler.java | 2 +- 7 files changed, 27 insertions(+), 6 deletions(-) (limited to 'src/java') diff --git a/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java b/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java index 374fa5833..0c8b4bc0e 100644 --- a/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java +++ b/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java @@ -273,7 +273,7 @@ public abstract class AbstractBitmapDocumentHandler extends AbstractBinaryWritin } graphics2D.scale(scale / 1000f, scale / 1000f); - return new Java2DPainter(graphics2D, getContext(), getFontInfo()); + return new Java2DPainter(graphics2D, getContext(), getFontInfo(), this); } /** diff --git a/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java b/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java index 2c04a0714..929d786ea 100644 --- a/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java +++ b/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java @@ -188,7 +188,7 @@ public abstract class AbstractIFPainter implements if (conversionMode != null) { hints.put(ImageHandlerUtil.CONVERSION_MODE, conversionMode); } - + hints.put("page-number", documentHandler.getContext().getPageNumber()); return hints; } diff --git a/src/java/org/apache/fop/render/intermediate/IFContext.java b/src/java/org/apache/fop/render/intermediate/IFContext.java index 7464e26e0..0edb94c4b 100644 --- a/src/java/org/apache/fop/render/intermediate/IFContext.java +++ b/src/java/org/apache/fop/render/intermediate/IFContext.java @@ -57,6 +57,8 @@ public class IFContext { private int pageIndex = -1; + private int pageNumber = -1; + /** * Main constructor. * @param ua the user agent @@ -234,4 +236,11 @@ public class IFContext { return this.pageIndex; } + public int getPageNumber() { + return pageNumber; + } + + public void setPageNumber(int pageNumber) { + this.pageNumber = pageNumber; + } } diff --git a/src/java/org/apache/fop/render/intermediate/IFParser.java b/src/java/org/apache/fop/render/intermediate/IFParser.java index 3d0bfd32f..235e051f9 100644 --- a/src/java/org/apache/fop/render/intermediate/IFParser.java +++ b/src/java/org/apache/fop/render/intermediate/IFParser.java @@ -523,6 +523,7 @@ public class IFParser implements IFConstants { establishForeignAttributes(foreignAttributes); documentHandler.startPage(index, name, pageMasterName, new Dimension(width, height)); + documentHandler.getContext().setPageNumber(Integer.parseInt(name)); resetForeignAttributes(); } diff --git a/src/java/org/apache/fop/render/intermediate/IFRenderer.java b/src/java/org/apache/fop/render/intermediate/IFRenderer.java index e0843ef74..f2eae9ae1 100644 --- a/src/java/org/apache/fop/render/intermediate/IFRenderer.java +++ b/src/java/org/apache/fop/render/intermediate/IFRenderer.java @@ -573,6 +573,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer { establishForeignAttributes(page.getForeignAttributes()); documentHandler.getContext().setPageIndex(page.getPageIndex()); + documentHandler.getContext().setPageNumber(page.getPageNumber()); documentHandler.startPage(page.getPageIndex(), page.getPageNumberString(), page.getSimplePageMasterName(), dim); resetForeignAttributes(); diff --git a/src/java/org/apache/fop/render/java2d/Java2DPainter.java b/src/java/org/apache/fop/render/java2d/Java2DPainter.java index 328d1a4f8..06f67e75b 100644 --- a/src/java/org/apache/fop/render/java2d/Java2DPainter.java +++ b/src/java/org/apache/fop/render/java2d/Java2DPainter.java @@ -41,6 +41,7 @@ import org.apache.fop.render.intermediate.AbstractIFPainter; import org.apache.fop.render.intermediate.BorderPainter; import org.apache.fop.render.intermediate.GraphicsPainter; import org.apache.fop.render.intermediate.IFContext; +import org.apache.fop.render.intermediate.IFDocumentHandler; import org.apache.fop.render.intermediate.IFException; import org.apache.fop.render.intermediate.IFState; import org.apache.fop.traits.BorderProps; @@ -51,7 +52,7 @@ import org.apache.fop.util.CharUtilities; * {@link org.apache.fop.render.intermediate.IFPainter} implementation that paints on a Graphics2D * instance. */ -public class Java2DPainter extends AbstractIFPainter { +public class Java2DPainter extends AbstractIFPainter { /** the IF context */ protected IFContext ifContext; @@ -74,7 +75,11 @@ public class Java2DPainter extends AbstractIFPainter { * @param fontInfo the font information */ public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo) { - this(g2d, context, fontInfo, null); + this(g2d, context, fontInfo, new Java2DDocumentHandler()); + } + + public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo, IFDocumentHandler documentHandler) { + this(g2d, context, fontInfo, null, documentHandler); } /** @@ -86,7 +91,12 @@ public class Java2DPainter extends AbstractIFPainter { * @param state the IF state object */ public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo, IFState state) { - super(new Java2DDocumentHandler()); + this(g2d, context, fontInfo, state, new Java2DDocumentHandler()); + } + + public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo, IFState state, + IFDocumentHandler documentHandler) { + super(documentHandler); this.ifContext = context; if (state != null) { this.state = state.push(); diff --git a/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java b/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java index 4d0efd8ed..1991295bd 100644 --- a/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java +++ b/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java @@ -251,7 +251,7 @@ public class PCLDocumentHandler extends AbstractBinaryWritingIFDocumentHandler graphics2D.scale(scale / 1000f, scale / 1000f); graphics2D.translate(-printArea.x, -printArea.y); - return new Java2DPainter(graphics2D, getContext(), getFontInfo()); + return new Java2DPainter(graphics2D, getContext(), getFontInfo(), this); } private BufferedImage createBufferedImage(int bitmapWidth, int bitmapHeight) { -- cgit v1.2.3