]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Configuration option in the Java2D-based renderers that allows to disable the default...
authorJeremias Maerki <jeremias@apache.org>
Sun, 10 Sep 2006 16:39:56 +0000 (16:39 +0000)
committerJeremias Maerki <jeremias@apache.org>
Sun, 10 Sep 2006 16:39:56 +0000 (16:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@441965 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/trunk/output.xml
src/foschema/fop-configuration.xsd
src/java/org/apache/fop/render/bitmap/TIFFRenderer.java
src/java/org/apache/fop/render/java2d/Java2DRenderer.java
status.xml

index a0a53324f1a69e87ab2fd2ac8cf512167060566f..a783899175ed571a664b231bbfd514be979bdcd4 100644 (file)
@@ -633,6 +633,22 @@ out = proc.getOutputStream();]]></source>
     page. The quality of the bitmap depends on the target resolution setting 
     on the FOUserAgent.
   </p>
+    <section id="bitmap-configuration">
+      <title>Configuration</title>
+      <p>
+        The TIFF and PNG renderer configuration currently allows the following settings:
+      </p>
+<source><![CDATA[<renderer mime="image/png">
+  <transparent-page-background>true</transparent-page-background>
+  <fonts><!-- described elsewhere --></fonts>
+</renderer>]]></source>
+      <p>
+        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.
+      </p>
+    </section>
 </section>
 <section id="txt">
   <title>TXT</title>
index f1e792858873ad90d4ca4b28165ce9406cd649b1..d2f0799de22ce3b20367b202c8eb9178dca9f5a2 100644 (file)
             </xsd:simpleType>
           </xsd:element>
         </xsd:sequence>
+        <xsd:sequence>
+          <xsd:annotation>
+            <xsd:documentation>The elements in this sequence apply only to the PNG renderer,
+          MIME type image/png.</xsd:documentation>
+          </xsd:annotation>
+          <xsd:element name="transparent-page-background" type="xsd:boolean" default="false" minOccurs="0"/>
+        </xsd:sequence>
         <xsd:sequence>
           <xsd:annotation>
             <xsd:documentation>The elements in this sequence apply only to the text renderer,
index 428ed6cccee39a2fbc55179610c316a60ab8d90f..d6016a1ec74f963282898b2c320d04692cf997a6 100644 (file)
@@ -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);
index 6a8e34187b4baefec662892b27e0e6ec142d500a..bd88345a4a3fed7b3ceda553fda7baba00152cd0 100644 (file)
@@ -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);
index cdf6f68c30c9aa6cb98d2dcbd5e115ccb79839b4..3e5bb48c266f6caf8325f65aabaac876fd3248e3 100644 (file)
 
   <changes>
     <release version="FOP Trunk">
+      <action context="Code" dev="JM" type="add">
+        Configuration option in the Java2D-based renderers that allows to disable the default
+        white background in order to produce bitmap output with transparency.
+      </action>
       <action context="Code" dev="AD" type="fix" fixes-bug="39414">
         Split up FOText instances larger than 32K characters to avoid 
         integer overflow during layout.