From d6c34646cbeb93d305a72a2bd913ce73182b8881 Mon Sep 17 00:00:00 2001
From: Jeremias Maerki
Date: Sun, 10 Sep 2006 16:39:56 +0000
Subject: [PATCH] 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
---
.../content/xdocs/trunk/output.xml | 16 +++++++++
src/foschema/fop-configuration.xsd | 7 ++++
.../fop/render/bitmap/TIFFRenderer.java | 6 +++-
.../fop/render/java2d/Java2DRenderer.java | 33 +++++++++++++++++--
status.xml | 4 +++
5 files changed, 63 insertions(+), 3 deletions(-)
diff --git a/src/documentation/content/xdocs/trunk/output.xml b/src/documentation/content/xdocs/trunk/output.xml
index a0a53324f..a78389917 100644
--- a/src/documentation/content/xdocs/trunk/output.xml
+++ b/src/documentation/content/xdocs/trunk/output.xml
@@ -633,6 +633,22 @@ out = proc.getOutputStream();]]>
page. The quality of the bitmap depends on the target resolution setting
on the FOUserAgent.
+
+ Configuration
+
+ The TIFF and PNG renderer configuration currently allows the following settings:
+
+
+
+ The default value for the "transparent-page-background" setting is "false" which
+ paints an opaque, white background for the whole image. If you set this to true,
+ no such background will be painted and you will get a transparent image if
+ an alpha channel is available in the output format.
+
+ TXT
diff --git a/src/foschema/fop-configuration.xsd b/src/foschema/fop-configuration.xsd
index f1e792858..d2f0799de 100644
--- a/src/foschema/fop-configuration.xsd
+++ b/src/foschema/fop-configuration.xsd
@@ -150,6 +150,13 @@
+
+
+ The elements in this sequence apply only to the PNG renderer,
+ MIME type image/png.
+
+
+ The elements in this sequence apply only to the text renderer,
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;
@@ -141,12 +150,30 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
public Java2DRenderer() {
}
+ /**
+ * @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);
diff --git a/status.xml b/status.xml
index cdf6f68c3..3e5bb48c2 100644
--- a/status.xml
+++ b/status.xml
@@ -28,6 +28,10 @@
+
+ Configuration option in the Java2D-based renderers that allows to disable the default
+ white background in order to produce bitmap output with transparency.
+
Split up FOText instances larger than 32K characters to avoid
integer overflow during layout.
--
2.39.5