xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r820637 - in /xmlgraphics/fop/trunk/src: java/META-INF/services/ java/org/apache/fop/render/bitmap/ sandbox/org/apache/fop/render/svg/
Date Thu, 01 Oct 2009 12:56:26 GMT
Author: jeremias
Date: Thu Oct  1 12:56:26 2009
New Revision: 820637

URL: http://svn.apache.org/viewvc?rev=820637&view=rev
Log:
Added a DocumentHandler implementation for PNG output including multi-file output support.

Added:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java
      - copied, changed from r820575, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/BitmapRendererConfigurator.java
      - copied, changed from r820575, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGDocumentHandler.java  
(with props)
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGDocumentHandlerMaker.java
      - copied, changed from r820575, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java
Modified:
    xmlgraphics/fop/trunk/src/java/META-INF/services/org.apache.fop.render.intermediate.IFDocumentHandler
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/BitmapRenderingSettings.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/MultiFileRenderingUtil.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java
    xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandler.java

Modified: xmlgraphics/fop/trunk/src/java/META-INF/services/org.apache.fop.render.intermediate.IFDocumentHandler
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/META-INF/services/org.apache.fop.render.intermediate.IFDocumentHandler?rev=820637&r1=820636&r2=820637&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/META-INF/services/org.apache.fop.render.intermediate.IFDocumentHandler
(original)
+++ xmlgraphics/fop/trunk/src/java/META-INF/services/org.apache.fop.render.intermediate.IFDocumentHandler
Thu Oct  1 12:56:26 2009
@@ -1,6 +1,7 @@
 org.apache.fop.render.pdf.PDFDocumentHandlerMaker
 org.apache.fop.render.pcl.PCLDocumentHandlerMaker
 org.apache.fop.render.bitmap.TIFFDocumentHandlerMaker
+org.apache.fop.render.bitmap.PNGDocumentHandlerMaker
 org.apache.fop.render.ps.PSDocumentHandlerMaker
 org.apache.fop.render.afp.AFPDocumentHandlerMaker
 org.apache.fop.render.intermediate.IFSerializerMaker
\ No newline at end of file

Copied: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java
(from r820575, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java?p2=xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java&p1=xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java&r1=820575&r2=820637&rev=820637&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java
Thu Oct  1 12:56:26 2009
@@ -24,7 +24,9 @@
 import java.awt.RenderingHints;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
+import java.io.OutputStream;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -33,7 +35,6 @@
 import org.apache.xmlgraphics.image.writer.MultiImageWriter;
 
 import org.apache.fop.apps.FopFactoryConfigurator;
-import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
 import org.apache.fop.render.intermediate.IFContext;
@@ -44,17 +45,19 @@
 import org.apache.fop.render.java2d.Java2DUtil;
 
 /**
- * {@code IFDocumentHandler} implementation that produces PCL 5.
+ * Abstract {@code IFDocumentHandler} implementation for producing bitmap images.
  */
-public class TIFFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
-            implements TIFFConstants {
+public abstract class AbstractBitmapDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
{
 
     /** logging instance */
-    private static Log log = LogFactory.getLog(TIFFDocumentHandler.class);
+    private static Log log = LogFactory.getLog(AbstractBitmapDocumentHandler.class);
 
     private ImageWriter imageWriter;
     private MultiImageWriter multiImageWriter;
 
+    /** Helper class for generating multiple files */
+    private MultiFileRenderingUtil multiFileUtil;
+
     private int pageCount;
     private Dimension currentPageDimensions;
     private BufferedImage currentImage;
@@ -66,7 +69,7 @@
     /**
      * Default constructor.
      */
-    public TIFFDocumentHandler() {
+    public AbstractBitmapDocumentHandler() {
     }
 
     /** {@inheritDoc} */
@@ -75,9 +78,13 @@
     }
 
     /** {@inheritDoc} */
-    public String getMimeType() {
-        return MimeConstants.MIME_TIFF;
-    }
+    public abstract String getMimeType();
+
+    /**
+     * Returns the default file extension for the supported image type.
+     * @return the default file extension (ex. "png")
+     */
+    public abstract String getDefaultExtension();
 
     /** {@inheritDoc} */
     public void setContext(IFContext context) {
@@ -89,9 +96,7 @@
     }
 
     /** {@inheritDoc} */
-    public IFDocumentHandlerConfigurator getConfigurator() {
-        return new TIFFRendererConfigurator(getUserAgent());
-    }
+    public abstract IFDocumentHandlerConfigurator getConfigurator();
 
     /**
      * Returns the settings for bitmap rendering.
@@ -123,6 +128,9 @@
             }
             if (this.imageWriter.supportsMultiImageWriter()) {
                 this.multiImageWriter = this.imageWriter.createMultiImageWriter(outputStream);
+            } else {
+                this.multiFileUtil = new MultiFileRenderingUtil(getDefaultExtension(),
+                        getUserAgent().getOutputFile());
             }
             this.pageCount = 0;
         } catch (IOException e) {
@@ -228,15 +236,24 @@
                     this.imageWriter.writeImage(
                             this.currentImage, this.outputStream,
                             getSettings().getWriterParams());
-                    break;
-                case 2:
-                    BitmapRendererEventProducer eventProducer
-                        = BitmapRendererEventProducer.Provider.get(
-                                getUserAgent().getEventBroadcaster());
-                    eventProducer.stoppingAfterFirstPageNoFilename(this);
+                    IOUtils.closeQuietly(this.outputStream);
+                    this.outputStream = null;
                     break;
                 default:
-                    //ignore
+                    OutputStream out = this.multiFileUtil.createOutputStream(this.pageCount
- 1);
+                    if (out == null) {
+                        BitmapRendererEventProducer eventProducer
+                            = BitmapRendererEventProducer.Provider.get(
+                                    getUserAgent().getEventBroadcaster());
+                        eventProducer.stoppingAfterFirstPageNoFilename(this);
+                    }
+                    try {
+                        this.imageWriter.writeImage(
+                                this.currentImage, out,
+                                getSettings().getWriterParams());
+                    } finally {
+                        IOUtils.closeQuietly(out);
+                    }
                 }
             } else {
                 this.multiImageWriter.writeImage(this.currentImage,
@@ -255,12 +272,8 @@
 
     /** {@inheritDoc} */
     public void handleExtensionObject(Object extension) throws IFException {
-        if (false) {
-            //TODO Handle extensions
-        } else {
-            log.debug("Don't know how to handle extension object. Ignoring: "
+        log.debug("Don't know how to handle extension object. Ignoring: "
                     + extension + " (" + extension.getClass().getName() + ")");
-        }
     }
 
 }

Copied: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/BitmapRendererConfigurator.java
(from r820575, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/BitmapRendererConfigurator.java?p2=xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/BitmapRendererConfigurator.java&p1=xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java&r1=820575&r2=820637&rev=820637&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/BitmapRendererConfigurator.java
Thu Oct  1 12:56:26 2009
@@ -35,7 +35,6 @@
 import org.apache.fop.fonts.FontManager;
 import org.apache.fop.fonts.FontResolver;
 import org.apache.fop.render.DefaultFontResolver;
-import org.apache.fop.render.Renderer;
 import org.apache.fop.render.intermediate.IFDocumentHandler;
 import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
 import org.apache.fop.render.java2d.Base14FontCollection;
@@ -47,72 +46,29 @@
 import org.apache.fop.util.ColorUtil;
 
 /**
- * TIFF Renderer configurator
+ * Configurator for bitmap output.
  */
-public class TIFFRendererConfigurator extends Java2DRendererConfigurator
+public class BitmapRendererConfigurator extends Java2DRendererConfigurator
             implements IFDocumentHandlerConfigurator {
 
     /**
      * Default constructor
      * @param userAgent user agent
      */
-    public TIFFRendererConfigurator(FOUserAgent userAgent) {
+    public BitmapRendererConfigurator(FOUserAgent userAgent) {
         super(userAgent);
     }
 
-    /**
-     * Configure the TIFF renderer. Get the configuration to be used for
-     * compression
-     * @param renderer tiff renderer
-     * @throws FOPException fop exception
-     * {@inheritDoc}
-     */
-    public void configure(Renderer renderer) throws FOPException {
-        Configuration cfg = super.getRendererConfig(renderer);
-        if (cfg != null) {
-            TIFFRenderer tiffRenderer = (TIFFRenderer)renderer;
-            //set compression
-            String name = cfg.getChild("compression").getValue(TIFFConstants.COMPRESSION_PACKBITS);
-            //Some compression formats need a special image format:
-            tiffRenderer.setBufferedImageType(getBufferedImageTypeFor(name));
-            if (!"NONE".equalsIgnoreCase(name)) {
-                tiffRenderer.getWriterParams().setCompressionMethod(name);
-            }
-            if (log.isInfoEnabled()) {
-                log.info("TIFF compression set to " + name);
-            }
-        }
-        super.configure(renderer);
-    }
-
-    private int getBufferedImageTypeFor(String compressionName) {
-        if (compressionName.equalsIgnoreCase(TIFFConstants.COMPRESSION_CCITT_T6)) {
-            return BufferedImage.TYPE_BYTE_BINARY;
-        } else if (compressionName.equalsIgnoreCase(TIFFConstants.COMPRESSION_CCITT_T4))
{
-            return BufferedImage.TYPE_BYTE_BINARY;
-        } else {
-            return BufferedImage.TYPE_INT_ARGB;
-        }
-    }
-
     // ---=== IFDocumentHandler configuration ===---
 
     /** {@inheritDoc} */
     public void configure(IFDocumentHandler documentHandler) throws FOPException {
+        super.configure(documentHandler);
         Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
         if (cfg != null) {
-            TIFFDocumentHandler tiffHandler = (TIFFDocumentHandler)documentHandler;
-            BitmapRenderingSettings settings = tiffHandler.getSettings();
-            //set compression
-            String name = cfg.getChild("compression").getValue(TIFFConstants.COMPRESSION_PACKBITS);
-            //Some compression formats need a special image format:
-            settings.setBufferedImageType(getBufferedImageTypeFor(name));
-            if (!"NONE".equalsIgnoreCase(name)) {
-                settings.getWriterParams().setCompressionMethod(name);
-            }
-            if (log.isInfoEnabled()) {
-                log.info("TIFF compression set to " + name);
-            }
+            AbstractBitmapDocumentHandler bitmapHandler
+                = (AbstractBitmapDocumentHandler)documentHandler;
+            BitmapRenderingSettings settings = bitmapHandler.getSettings();
 
             boolean transparent = cfg.getChild(
                     Java2DRenderer.JAVA2D_TRANSPARENT_PAGE_BACKGROUND).getValueAsBoolean(
@@ -183,5 +139,4 @@
         documentHandler.setFontInfo(fontInfo);
     }
 
-
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/BitmapRenderingSettings.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/BitmapRenderingSettings.java?rev=820637&r1=820636&r2=820637&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/BitmapRenderingSettings.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/BitmapRenderingSettings.java
Thu Oct  1 12:56:26 2009
@@ -47,7 +47,6 @@
      */
     public BitmapRenderingSettings() {
         writerParams = new ImageWriterParams();
-        writerParams.setCompressionMethod(COMPRESSION_PACKBITS);
     }
 
     /**

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/MultiFileRenderingUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/MultiFileRenderingUtil.java?rev=820637&r1=820636&r2=820637&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/MultiFileRenderingUtil.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/MultiFileRenderingUtil.java
Thu Oct  1 12:56:26 2009
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
 package org.apache.fop.render.bitmap;
 
 import java.io.BufferedOutputStream;
@@ -61,6 +80,12 @@
         }
     }
 
+    /**
+     * Creates a new {@link OutputStream} for the given page number.
+     * @param pageNumber the page number (zero-based)
+     * @return the output stream for the page
+     * @throws IOException if there's an I/O error while setting up the output stream
+     */
     public OutputStream createOutputStream(int pageNumber) throws IOException {
         if (filePrefix == null) {
             return null;

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGDocumentHandler.java?rev=820637&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGDocumentHandler.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGDocumentHandler.java Thu
Oct  1 12:56:26 2009
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.bitmap;
+
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
+
+/**
+ * {@code IFDocumentHandler} implementation that produces PNG files.
+ */
+public class PNGDocumentHandler extends AbstractBitmapDocumentHandler {
+
+    /** {@inheritDoc} */
+    public String getMimeType() {
+        return MimeConstants.MIME_PNG;
+    }
+
+    /** {@inheritDoc} */
+    public String getDefaultExtension() {
+        return "png";
+    }
+
+    /** {@inheritDoc} */
+    public IFDocumentHandlerConfigurator getConfigurator() {
+        return new BitmapRendererConfigurator(getUserAgent());
+    }
+
+}

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGDocumentHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGDocumentHandler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGDocumentHandlerMaker.java
(from r820575, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGDocumentHandlerMaker.java?p2=xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGDocumentHandlerMaker.java&p1=xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java&r1=820575&r2=820637&rev=820637&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGDocumentHandlerMaker.java
Thu Oct  1 12:56:26 2009
@@ -26,15 +26,15 @@
 import org.apache.fop.render.intermediate.IFDocumentHandler;
 
 /**
- * Document handler factory for TIFF output.
+ * Document handler factory for PNG output.
  */
-public class TIFFDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker {
+public class PNGDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker {
 
-    private static final String[] MIMES = new String[] {MimeConstants.MIME_TIFF};
+    private static final String[] MIMES = new String[] {MimeConstants.MIME_PNG};
 
     /** {@inheritDoc} */
     public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {
-        TIFFDocumentHandler handler = new TIFFDocumentHandler();
+        PNGDocumentHandler handler = new PNGDocumentHandler();
         handler.setContext(new IFContext(ua));
         return handler;
     }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java?rev=820637&r1=820636&r2=820637&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java Thu
Oct  1 12:56:26 2009
@@ -19,60 +19,13 @@
 
 package org.apache.fop.render.bitmap;
 
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.xmlgraphics.image.writer.ImageWriter;
-import org.apache.xmlgraphics.image.writer.ImageWriterRegistry;
-import org.apache.xmlgraphics.image.writer.MultiImageWriter;
-
-import org.apache.fop.apps.FopFactoryConfigurator;
 import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
-import org.apache.fop.render.intermediate.IFContext;
 import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
-import org.apache.fop.render.intermediate.IFException;
-import org.apache.fop.render.intermediate.IFPainter;
-import org.apache.fop.render.java2d.Java2DPainter;
-import org.apache.fop.render.java2d.Java2DUtil;
 
 /**
- * {@code IFDocumentHandler} implementation that produces PCL 5.
+ * {@code IFDocumentHandler} implementation that produces TIFF files.
  */
-public class TIFFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
-            implements TIFFConstants {
-
-    /** logging instance */
-    private static Log log = LogFactory.getLog(TIFFDocumentHandler.class);
-
-    private ImageWriter imageWriter;
-    private MultiImageWriter multiImageWriter;
-
-    private int pageCount;
-    private Dimension currentPageDimensions;
-    private BufferedImage currentImage;
-
-    private BitmapRenderingSettings bitmapSettings = new BitmapRenderingSettings();
-
-    private double scaleFactor = 1.0;
-
-    /**
-     * Default constructor.
-     */
-    public TIFFDocumentHandler() {
-    }
-
-    /** {@inheritDoc} */
-    public boolean supportsPagesOutOfOrder() {
-        return false;
-    }
+public class TIFFDocumentHandler extends AbstractBitmapDocumentHandler {
 
     /** {@inheritDoc} */
     public String getMimeType() {
@@ -80,12 +33,8 @@
     }
 
     /** {@inheritDoc} */
-    public void setContext(IFContext context) {
-        super.setContext(context);
-
-        //Set target resolution
-        int dpi = Math.round(context.getUserAgent().getTargetResolution());
-        getSettings().getWriterParams().setResolution(dpi);
+    public String getDefaultExtension() {
+        return "tif";
     }
 
     /** {@inheritDoc} */
@@ -93,174 +42,4 @@
         return new TIFFRendererConfigurator(getUserAgent());
     }
 
-    /**
-     * Returns the settings for bitmap rendering.
-     * @return the settings object
-     */
-    public BitmapRenderingSettings getSettings() {
-        return this.bitmapSettings;
-    }
-
-    /** {@inheritDoc} */
-    public void setDefaultFontInfo(FontInfo fontInfo) {
-        FontInfo fi = Java2DUtil.buildDefaultJava2DBasedFontInfo(fontInfo, getUserAgent());
-        setFontInfo(fi);
-    }
-
-    //----------------------------------------------------------------------------------------------
-
-    /** {@inheritDoc} */
-    public void startDocument() throws IFException {
-        super.startDocument();
-        try {
-            // Creates writer
-            this.imageWriter = ImageWriterRegistry.getInstance().getWriterFor(getMimeType());
-            if (this.imageWriter == null) {
-                BitmapRendererEventProducer eventProducer
-                    = BitmapRendererEventProducer.Provider.get(
-                            getUserAgent().getEventBroadcaster());
-                eventProducer.noImageWriterFound(this, getMimeType());
-            }
-            if (this.imageWriter.supportsMultiImageWriter()) {
-                this.multiImageWriter = this.imageWriter.createMultiImageWriter(outputStream);
-            }
-            this.pageCount = 0;
-        } catch (IOException e) {
-            throw new IFException("I/O error in startDocument()", e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    public void endDocumentHeader() throws IFException {
-    }
-
-    /** {@inheritDoc} */
-    public void endDocument() throws IFException {
-        try {
-            if (this.multiImageWriter != null) {
-                this.multiImageWriter.close();
-            }
-            this.multiImageWriter = null;
-            this.imageWriter = null;
-        } catch (IOException ioe) {
-            throw new IFException("I/O error in endDocument()", ioe);
-        }
-        super.endDocument();
-    }
-
-    /** {@inheritDoc} */
-    public void startPageSequence(String id) throws IFException {
-        //nop
-    }
-
-    /** {@inheritDoc} */
-    public void endPageSequence() throws IFException {
-        //nop
-    }
-
-    /** {@inheritDoc} */
-    public void startPage(int index, String name, String pageMasterName, Dimension size)
-                throws IFException {
-        this.pageCount++;
-        this.currentPageDimensions = new Dimension(size);
-    }
-
-    /** {@inheritDoc} */
-    public IFPainter startPageContent() throws IFException {
-        double scale = scaleFactor
-            * (25.4f / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION)
-                / getUserAgent().getTargetPixelUnitToMillimeter();
-        int bitmapWidth = (int) ((this.currentPageDimensions.width * scale / 1000f) + 0.5f);
-        int bitmapHeight = (int) ((this.currentPageDimensions.height * scale / 1000f) + 0.5f);
-        this.currentImage = createBufferedImage(bitmapWidth, bitmapHeight);
-        Graphics2D graphics2D = this.currentImage.createGraphics();
-        // draw page background
-        if (!getSettings().hasTransparentPageBackground()) {
-            graphics2D.setBackground(getSettings().getPageBackgroundColor());
-            graphics2D.setPaint(getSettings().getPageBackgroundColor());
-            graphics2D.fillRect(0, 0, bitmapWidth, bitmapHeight);
-        }
-
-        graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
-                RenderingHints.VALUE_FRACTIONALMETRICS_ON);
-        if (getSettings().isAntiAliasingEnabled()
-                && this.currentImage.getColorModel().getPixelSize() > 1) {
-            graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-                    RenderingHints.VALUE_ANTIALIAS_ON);
-            graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
-                    RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
-        } else {
-            graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-                    RenderingHints.VALUE_ANTIALIAS_OFF);
-            graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
-                    RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
-        }
-        if (getSettings().isQualityRenderingEnabled()) {
-            graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING,
-                    RenderingHints.VALUE_RENDER_QUALITY);
-        } else {
-            graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING,
-                    RenderingHints.VALUE_RENDER_SPEED);
-        }
-        graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
-                RenderingHints.VALUE_STROKE_PURE);
-        graphics2D.scale(scale / 1000f, scale / 1000f);
-
-        return new Java2DPainter(graphics2D, getContext(), getFontInfo());
-    }
-
-    /**
-     * Creates a new BufferedImage.
-     * @param bitmapWidth the desired width in pixels
-     * @param bitmapHeight the desired height in pixels
-     * @return the new BufferedImage instance
-     */
-    protected BufferedImage createBufferedImage(int bitmapWidth, int bitmapHeight) {
-        return new BufferedImage(bitmapWidth, bitmapHeight, getSettings().getBufferedImageType());
-    }
-
-    /** {@inheritDoc} */
-    public void endPageContent() throws IFException {
-        try {
-            if (this.multiImageWriter == null) {
-                switch (this.pageCount) {
-                case 1:
-                    this.imageWriter.writeImage(
-                            this.currentImage, this.outputStream,
-                            getSettings().getWriterParams());
-                    break;
-                case 2:
-                    BitmapRendererEventProducer eventProducer
-                        = BitmapRendererEventProducer.Provider.get(
-                                getUserAgent().getEventBroadcaster());
-                    eventProducer.stoppingAfterFirstPageNoFilename(this);
-                    break;
-                default:
-                    //ignore
-                }
-            } else {
-                this.multiImageWriter.writeImage(this.currentImage,
-                        getSettings().getWriterParams());
-            }
-            this.currentImage = null;
-        } catch (IOException ioe) {
-            throw new IFException("I/O error while encoding BufferedImage", ioe);
-        }
-    }
-
-    /** {@inheritDoc} */
-    public void endPage() throws IFException {
-        this.currentPageDimensions = null;
-    }
-
-    /** {@inheritDoc} */
-    public void handleExtensionObject(Object extension) throws IFException {
-        if (false) {
-            //TODO Handle extensions
-        } else {
-            log.debug("Don't know how to handle extension object. Ignoring: "
-                    + extension + " (" + extension.getClass().getName() + ")");
-        }
-    }
-
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java?rev=820637&r1=820636&r2=820637&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java
Thu Oct  1 12:56:26 2009
@@ -19,38 +19,19 @@
 
 package org.apache.fop.render.bitmap;
 
-import java.awt.Color;
-import java.awt.Graphics2D;
 import java.awt.image.BufferedImage;
-import java.util.List;
 
 import org.apache.avalon.framework.configuration.Configuration;
 
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.fonts.FontCollection;
-import org.apache.fop.fonts.FontEventAdapter;
-import org.apache.fop.fonts.FontEventListener;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontManager;
-import org.apache.fop.fonts.FontResolver;
-import org.apache.fop.render.DefaultFontResolver;
 import org.apache.fop.render.Renderer;
 import org.apache.fop.render.intermediate.IFDocumentHandler;
-import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
-import org.apache.fop.render.java2d.Base14FontCollection;
-import org.apache.fop.render.java2d.ConfiguredFontCollection;
-import org.apache.fop.render.java2d.InstalledFontCollection;
-import org.apache.fop.render.java2d.Java2DFontMetrics;
-import org.apache.fop.render.java2d.Java2DRenderer;
-import org.apache.fop.render.java2d.Java2DRendererConfigurator;
-import org.apache.fop.util.ColorUtil;
 
 /**
  * TIFF Renderer configurator
  */
-public class TIFFRendererConfigurator extends Java2DRendererConfigurator
-            implements IFDocumentHandlerConfigurator {
+public class TIFFRendererConfigurator extends BitmapRendererConfigurator {
 
     /**
      * Default constructor
@@ -85,6 +66,12 @@
         super.configure(renderer);
     }
 
+    /**
+     * Determines the type value for the BufferedImage to be produced for rendering
+     * the bitmap image.
+     * @param compressionName the compression name
+     * @return a value from the {@link BufferedImage}.TYPE_* constants
+     */
     private int getBufferedImageTypeFor(String compressionName) {
         if (compressionName.equalsIgnoreCase(TIFFConstants.COMPRESSION_CCITT_T6)) {
             return BufferedImage.TYPE_BYTE_BINARY;
@@ -99,6 +86,7 @@
 
     /** {@inheritDoc} */
     public void configure(IFDocumentHandler documentHandler) throws FOPException {
+        super.configure(documentHandler);
         Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
         if (cfg != null) {
             TIFFDocumentHandler tiffHandler = (TIFFDocumentHandler)documentHandler;
@@ -113,75 +101,7 @@
             if (log.isInfoEnabled()) {
                 log.info("TIFF compression set to " + name);
             }
-
-            boolean transparent = cfg.getChild(
-                    Java2DRenderer.JAVA2D_TRANSPARENT_PAGE_BACKGROUND).getValueAsBoolean(
-                            settings.hasTransparentPageBackground());
-            if (transparent) {
-                settings.setPageBackgroundColor(null);
-            } else {
-                String background = cfg.getChild("background-color").getValue(null);
-                if (background != null) {
-                    settings.setPageBackgroundColor(
-                            ColorUtil.parseColorString(this.userAgent, background));
-                } else {
-                    settings.setPageBackgroundColor(Color.WHITE);
-                }
-            }
-
-            boolean antiAliasing = cfg.getChild("anti-aliasing").getValueAsBoolean(
-                    settings.isAntiAliasingEnabled());
-            settings.setAntiAliasing(antiAliasing);
-
-            String optimization = cfg.getChild("rendering").getValue(null);
-            if ("quality".equalsIgnoreCase(optimization)) {
-                settings.setQualityRendering(true);
-            } else if ("speed".equalsIgnoreCase(optimization)) {
-                settings.setQualityRendering(false);
-            }
-
-            String color = cfg.getChild("color-mode").getValue(null);
-            if (color != null) {
-                if ("rgba".equalsIgnoreCase(color)) {
-                    settings.setBufferedImageType(BufferedImage.TYPE_INT_ARGB);
-                } else if ("rgb".equalsIgnoreCase(color)) {
-                    settings.setBufferedImageType(BufferedImage.TYPE_INT_RGB);
-                } else if ("gray".equalsIgnoreCase(color)) {
-                    settings.setBufferedImageType(BufferedImage.TYPE_BYTE_GRAY);
-                } else if ("binary".equalsIgnoreCase(color)) {
-                    settings.setBufferedImageType(BufferedImage.TYPE_BYTE_BINARY);
-                } else {
-                    throw new FOPException("Invalid value for color-mode: " + color);
-                }
-            }
         }
     }
 
-    /** {@inheritDoc} */
-    public void setupFontInfo(IFDocumentHandler documentHandler, FontInfo fontInfo)
-            throws FOPException {
-        FontManager fontManager = userAgent.getFactory().getFontManager();
-
-        Graphics2D graphics2D = Java2DFontMetrics.createFontMetricsGraphics2D();
-
-        List fontCollections = new java.util.ArrayList();
-        fontCollections.add(new Base14FontCollection(graphics2D));
-        fontCollections.add(new InstalledFontCollection(graphics2D));
-
-        Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
-        if (cfg != null) {
-            FontResolver fontResolver = new DefaultFontResolver(userAgent);
-            FontEventListener listener = new FontEventAdapter(
-                    userAgent.getEventBroadcaster());
-            List fontList = buildFontList(cfg, fontResolver, listener);
-            fontCollections.add(new ConfiguredFontCollection(fontResolver, fontList));
-        }
-
-        fontManager.setup(fontInfo,
-                (FontCollection[])fontCollections.toArray(
-                        new FontCollection[fontCollections.size()]));
-        documentHandler.setFontInfo(fontInfo);
-    }
-
-
 }

Modified: xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandler.java?rev=820637&r1=820636&r2=820637&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandler.java (original)
+++ xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandler.java Thu
Oct  1 12:56:26 2009
@@ -45,6 +45,7 @@
 
 import org.apache.commons.io.IOUtils;
 
+import org.apache.fop.render.bitmap.BitmapRendererEventProducer;
 import org.apache.fop.render.bitmap.MultiFileRenderingUtil;
 import org.apache.fop.render.intermediate.DelegatingFragmentContentHandler;
 import org.apache.fop.render.intermediate.IFException;
@@ -209,9 +210,10 @@
             } else {
                 out = this.multiFileUtil.createOutputStream(index);
                 if (out == null) {
-                    //TODO Convert to event
-                    throw new IFException(
-                            "No filename information available. Stopping after first page.",
null);
+                    BitmapRendererEventProducer eventProducer
+                        = BitmapRendererEventProducer.Provider.get(
+                                getUserAgent().getEventBroadcaster());
+                    eventProducer.stoppingAfterFirstPageNoFilename(this);
                 }
             }
         } catch (IOException ioe) {



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message