diff options
author | Jeremias Maerki <jeremias@apache.org> | 2006-09-10 16:39:56 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2006-09-10 16:39:56 +0000 |
commit | d6c34646cbeb93d305a72a2bd913ce73182b8881 (patch) | |
tree | 64de4c5cc90814e34788d4298f631586ed3467a9 /src/java/org/apache | |
parent | 4bc66553af06005331b55f3ecd108f307b82cd30 (diff) | |
download | xmlgraphics-fop-d6c34646cbeb93d305a72a2bd913ce73182b8881.tar.gz xmlgraphics-fop-d6c34646cbeb93d305a72a2bd913ce73182b8881.zip |
Configuration option in the Java2D-based renderers that allows to disable the default white background in order to produce bitmap output with transparency.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@441965 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r-- | src/java/org/apache/fop/render/bitmap/TIFFRenderer.java | 6 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/java2d/Java2DRenderer.java | 33 |
2 files changed, 36 insertions, 3 deletions
diff --git a/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java b/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java index 428ed6ccc..d6016a1ec 100644 --- a/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java +++ b/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java @@ -34,13 +34,16 @@ import java.util.Iterator; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; + +import org.apache.commons.logging.Log; + import org.apache.xmlgraphics.image.GraphicsUtil; import org.apache.xmlgraphics.image.codec.tiff.TIFFEncodeParam; import org.apache.xmlgraphics.image.codec.tiff.TIFFField; import org.apache.xmlgraphics.image.codec.tiff.TIFFImageDecoder; import org.apache.xmlgraphics.image.codec.tiff.TIFFImageEncoder; import org.apache.xmlgraphics.image.rendered.FormatRed; -import org.apache.commons.logging.Log; + import org.apache.fop.apps.FOPException; import org.apache.fop.apps.MimeConstants; import org.apache.fop.render.java2d.Java2DRenderer; @@ -94,6 +97,7 @@ public class TIFFRenderer extends Java2DRenderer { * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration) */ public void configure(Configuration cfg) throws ConfigurationException { + super.configure(cfg); //TODO Support output of monochrome bitmaps (fax-style) int comp = cfg.getChild("compression").getAttributeAsInteger("value", 1); diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java index 6a8e34187..bd88345a4 100644 --- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java +++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java @@ -53,6 +53,8 @@ import java.util.Stack; import org.w3c.dom.Document; +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.area.CTM; @@ -71,6 +73,7 @@ import org.apache.fop.fonts.Typeface; import org.apache.fop.image.FopImage; import org.apache.fop.image.ImageFactory; import org.apache.fop.image.XMLImage; +import org.apache.fop.pdf.PDFAMode; import org.apache.fop.render.AbstractPathOrientedRenderer; import org.apache.fop.render.Graphics2DAdapter; import org.apache.fop.render.RendererContext; @@ -103,6 +106,9 @@ import org.apache.fop.util.CharUtilities; */ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implements Printable { + /** Rendering Options key for the controlling the transparent page background option. */ + public static final String JAVA2D_TRANSPARENT_PAGE_BACKGROUND = "transparent-page-background"; + /** The scale factor for the image size, values: ]0 ; 1] */ protected double scaleFactor = 1; @@ -127,6 +133,9 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem /** true if qualityRendering is set */ protected boolean qualityRendering = true; + /** false: paints a non-transparent white background, true: for a transparent background */ + protected boolean transparentPageBackground = false; + /** The current state, holds a Graphics2D and its context */ protected Java2DGraphicsState state; @@ -142,11 +151,29 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem } /** + * @see org.apache.fop.render.AbstractRenderer#configure( + * org.apache.avalon.framework.configuration.Configuration) + */ + public void configure(Configuration cfg) throws ConfigurationException { + super.configure(cfg); + + String s = cfg.getChild(JAVA2D_TRANSPARENT_PAGE_BACKGROUND, true).getValue(null); + if (s != null) { + this.transparentPageBackground = "true".equalsIgnoreCase(s); + } + } + + /** * @see org.apache.fop.render.Renderer#setUserAgent(org.apache.fop.apps.FOUserAgent) */ public void setUserAgent(FOUserAgent foUserAgent) { super.setUserAgent(foUserAgent); userAgent.setRendererOverride(this); // for document regeneration + + String s = (String)userAgent.getRendererOptions().get(JAVA2D_TRANSPARENT_PAGE_BACKGROUND); + if (s != null) { + this.transparentPageBackground = "true".equalsIgnoreCase(s); + } } /** @return the FOUserAgent */ @@ -311,8 +338,10 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem graphics.setTransform(at); // draw page frame - graphics.setColor(Color.white); - graphics.fillRect(0, 0, pageWidth, pageHeight); + if (!transparentPageBackground) { + graphics.setColor(Color.white); + graphics.fillRect(0, 0, pageWidth, pageHeight); + } graphics.setColor(Color.black); graphics.drawRect(-1, -1, pageWidth + 2, pageHeight + 2); graphics.drawLine(pageWidth + 2, 0, pageWidth + 2, pageHeight + 2); |