xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r682757 [1/2] - in /xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src: java/META-INF/services/ java/org/apache/fop/render/ java/org/apache/fop/render/intermediate/ java/org/apache/fop/render/pdf/ java/org/apache/fop/svg/ sandbox/META-INF/...
Date Tue, 05 Aug 2008 15:31:02 GMT
Author: jeremias
Date: Tue Aug  5 08:31:00 2008
New Revision: 682757

URL: http://svn.apache.org/viewvc?rev=682757&view=rev
Log:
First steps at unified image handling as proposed on http://wiki.apache.org/xmlgraphics-fop/ImageSupport/ImageHandler. This shall serve as a preview to motivate early feedback if anyone is interested.
Basic external-graphic support now available for PDF and SVG painters (for PDF: RenderedImage, SVG, JPEG, CCITT and Java2D, for SVG: embedded SVG and RFC2397 data URLs containing PNG and JPEG images)
Change to IFPainter: added support for foreign attributes for the "image" tag.
PDFContentGenerator introduced to hold the most important objects for PDF generation (unification for renderer and painter).
Re-routed most image handling through the new image handling code (not fully done, yet, some code duplication remains).

Added:
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.render.ImageHandler
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.render.intermediate.IFPainter
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractImageHandlerGraphics2D.java   (contents, props changed)
      - copied, changed from r680381, xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractRenderingContext.java   (contents, props changed)
      - copied, changed from r680381, xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererContext.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandler.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandlerRegistry.java   (contents, props changed)
      - copied, changed from r680381, xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RenderingContext.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFRenderingContext.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/META-INF/services/org.apache.fop.render.ImageHandler
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/EmbeddedSVGImageHandler.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGDataUrlImageHandler.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGRenderingContext.java   (with props)
Modified:
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageAdapter.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererContext.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFConstants.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFParser.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRenderedImage.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFPainter.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFPainterMaker.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFRenderer.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/svg/PDFGraphics2D.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGConstants.java

Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.render.ImageHandler
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.render.ImageHandler?rev=682757&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.render.ImageHandler (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.render.ImageHandler Tue Aug  5 08:31:00 2008
@@ -0,0 +1,4 @@
+org.apache.fop.render.pdf.PDFImageHandlerGraphics2D
+org.apache.fop.render.pdf.PDFImageHandlerRenderedImage
+org.apache.fop.render.pdf.PDFImageHandlerRawJPEG
+org.apache.fop.render.pdf.PDFImageHandlerRawCCITTFax

Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.render.intermediate.IFPainter
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.render.intermediate.IFPainter?rev=682757&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.render.intermediate.IFPainter (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.render.intermediate.IFPainter Tue Aug  5 08:31:00 2008
@@ -0,0 +1 @@
+org.apache.fop.render.pdf.PDFPainterMaker
\ No newline at end of file

Copied: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractImageHandlerGraphics2D.java (from r680381, xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractImageHandlerGraphics2D.java?p2=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractImageHandlerGraphics2D.java&p1=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java&r1=680381&r2=682757&rev=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractImageHandlerGraphics2D.java Tue Aug  5 08:31:00 2008
@@ -20,6 +20,7 @@
 package org.apache.fop.render;
 
 import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.Graphics2D;
 import java.awt.Point;
 import java.awt.RenderingHints;
@@ -32,20 +33,20 @@
 import java.awt.image.DataBuffer;
 import java.awt.image.Raster;
 import java.awt.image.WritableRaster;
-import java.io.IOException;
 
-import org.apache.fop.render.RendererContext.RendererContextWrapper;
 import org.apache.fop.util.UnitConv;
 
 /**
- * Abstract base class for Graphics2DAdapter implementations.
+ * Abstract base class for ImageHandler implementations that process Java2D images through
+ * the Graphics2DImagePainter interface.
  */
-public abstract class AbstractGraphics2DAdapter implements Graphics2DAdapter {
+public abstract class AbstractImageHandlerGraphics2D implements ImageHandler {
 
     /**
      * Paints the image to a BufferedImage and returns that.
      * @param painter the painter which will paint the actual image
      * @param context the renderer context for the current renderer
+     * @param targetDimension the target dimensions of the image to be converted to a bitmap
      * @param resolution the requested bitmap resolution
      * @param gray true if the generated image should be in grayscales
      * @param withAlpha true if an alpha channel should be created
@@ -53,9 +54,10 @@
      */
     protected BufferedImage paintToBufferedImage(
             org.apache.xmlgraphics.java2d.Graphics2DImagePainter painter,
-             RendererContextWrapper context, int resolution, boolean gray, boolean withAlpha) {
-        int bmw = (int)Math.ceil(UnitConv.mpt2px(context.getWidth(), resolution));
-        int bmh = (int)Math.ceil(UnitConv.mpt2px(context.getHeight(), resolution));
+            Dimension targetDimension,
+            int resolution, boolean gray, boolean withAlpha) {
+        int bmw = (int)Math.ceil(UnitConv.mpt2px(targetDimension.getWidth(), resolution));
+        int bmh = (int)Math.ceil(UnitConv.mpt2px(targetDimension.getHeight(), resolution));
         BufferedImage bi;
         if (gray) {
             if (withAlpha) {
@@ -88,13 +90,13 @@
             g2d.drawLine(0, off, bmw, off);
             g2d.drawLine(0, bmh - off, bmw, bmh - off);
             */
-            double sx = (double)bmw / context.getWidth();
-            double sy = (double)bmh / context.getHeight();
+            double sx = (double)bmw / targetDimension.getWidth();
+            double sy = (double)bmh / targetDimension.getHeight();
             g2d.scale(sx, sy);
 
             //Paint the image on the BufferedImage
             Rectangle2D area = new Rectangle2D.Double(
-                    0.0, 0.0, context.getWidth(), context.getHeight());
+                    0.0, 0.0, targetDimension.getWidth(), targetDimension.getHeight());
             painter.paint(g2d, area);
         } finally {
             g2d.dispose();
@@ -126,22 +128,14 @@
 
     /**
      * Sets rendering hints on the Graphics2D created for painting to a BufferedImage. Subclasses
-     * can modify the settings to customize the behaviour.
+     * can modify the settings to customize the behavior.
      * @param g2d the Graphics2D instance
      */
     protected void setRenderingHintsForBufferedImage(Graphics2D g2d) {
         g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-            RenderingHints.VALUE_ANTIALIAS_OFF);
+            RenderingHints.VALUE_ANTIALIAS_ON);
         g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
-            RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
-    }
-
-    /** {@inheritDoc} */
-    public void paintImage(Graphics2DImagePainter painter,
-            RendererContext context,
-            int x, int y, int width, int height) throws IOException {
-        paintImage((org.apache.xmlgraphics.java2d.Graphics2DImagePainter)painter,
-                context, x, y, width, height);
+            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
     }
 
 }

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractImageHandlerGraphics2D.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractImageHandlerGraphics2D.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractImageHandlerGraphics2D.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Aug  5 08:31:00 2008
@@ -0,0 +1 @@
+/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java:603620-680380

Copied: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractRenderingContext.java (from r680381, xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererContext.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractRenderingContext.java?p2=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractRenderingContext.java&p1=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererContext.java&r1=680381&r2=682757&rev=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererContext.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractRenderingContext.java Tue Aug  5 08:31:00 2008
@@ -19,58 +19,21 @@
 
 package org.apache.fop.render;
 
-//Java
-import java.util.Map;
-
-//FOP
 import org.apache.fop.apps.FOUserAgent;
 
 /**
- * The Render Context for external handlers. This provides a rendering context
- * so that external handlers can get information to be able to render to the
- * render target.
+ * Abstract base class for RenderingContext implementations.
  */
-public class RendererContext {
+public abstract class AbstractRenderingContext implements RenderingContext {
 
-    private String mime;
-    private AbstractRenderer renderer;
     private FOUserAgent userAgent;
-    private Map props = new java.util.HashMap();
-
-    /**
-     * Contructor for this class. It takes a MIME type as parameter.
-     *
-     * @param renderer The current renderer
-     * @param m  The MIME type of the output that's generated.
-     */
-    public RendererContext(AbstractRenderer renderer, String m) {
-        this.renderer = renderer;
-        this.mime = m;
-    }
-
-    /**
-     * @return Returns the renderer.
-     */
-    public AbstractRenderer getRenderer() {
-        return renderer;
-    }
 
     /**
-     * Returns the MIME type associated with this RendererContext.
-     *
-     * @return   The MIME type (ex. application/pdf)
+     * Main constructor.
+     * @param userAgent the user agent
      */
-    public String getMimeType() {
-        return mime;
-    }
-
-    /**
-     * Sets the user agent.
-     *
-     * @param ua  The user agent
-     */
-    public void setUserAgent(FOUserAgent ua) {
-        userAgent = ua;
+    public AbstractRenderingContext(FOUserAgent userAgent) {
+        this.userAgent = userAgent;
     }
 
     /**
@@ -82,83 +45,5 @@
         return userAgent;
     }
 
-    /**
-     * Sets a property on the RendererContext.
-     *
-     * @param name  The key of the property
-     * @param val   The value of the property
-     */
-    public void setProperty(String name, Object val) {
-        props.put(name, val);
-    }
-
-    /**
-     * Returns a property from the RendererContext.
-     *
-     * @param prop  The key of the property to return.
-     * @return      The requested value, <code>null</code> if it doesn't exist.
-     */
-    public Object getProperty(String prop) {
-        return props.get(prop);
-    }
-
-    /**
-     * Wrap the render context to allow easier access to its values.
-     *
-     * @param context the renderer context
-     * @return the generic renderer context wrapper
-     */
-    public static RendererContextWrapper wrapRendererContext(RendererContext context) {
-        RendererContextWrapper wrapper = new RendererContextWrapper(context);
-        return wrapper;
-    }
-
-    /**
-     * Base class for a wrapper around RendererContext to access its properties in a type-safe,
-     * renderer-specific way.
-     */
-    public static class RendererContextWrapper {
-
-        /** The wrapped RendererContext */
-        protected RendererContext context;
-
-        /**
-         * Main constructor
-         * @param context the RendererContent instance
-         */
-        public RendererContextWrapper(RendererContext context) {
-            this.context = context;
-        }
-
-        /** @return the user agent */
-        public FOUserAgent getUserAgent() {
-            return context.getUserAgent();
-        }
-
-        /** @return the currentXPosition */
-        public int getCurrentXPosition() {
-            return ((Integer)context.getProperty(RendererContextConstants.XPOS)).intValue();
-        }
-
-        /** @return the currentYPosition */
-        public int getCurrentYPosition() {
-            return ((Integer)context.getProperty(RendererContextConstants.YPOS)).intValue();
-        }
-
-        /** @return the width of the image */
-        public int getWidth() {
-            return ((Integer)context.getProperty(RendererContextConstants.WIDTH)).intValue();
-        }
-
-        /** @return the height of the image */
-        public int getHeight() {
-            return ((Integer)context.getProperty(RendererContextConstants.HEIGHT)).intValue();
-        }
-
-        /** @return the foreign attributes */
-        public Map getForeignAttributes() {
-            return (Map)context.getProperty(RendererContextConstants.FOREIGN_ATTRIBUTES);
-        }
-    }
 }
 

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractRenderingContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractRenderingContext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/AbstractRenderingContext.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Aug  5 08:31:00 2008
@@ -0,0 +1 @@
+/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererContext.java:603620-680380

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageAdapter.java?rev=682757&r1=682756&r2=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageAdapter.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageAdapter.java Tue Aug  5 08:31:00 2008
@@ -34,10 +34,10 @@
      * Paints an image at the given position.
      * @param image the image which will be painted
      * @param context the renderer context for the current renderer
-     * @param x X position of the image
-     * @param y Y position of the image
-     * @param width width of the image
-     * @param height height of the image
+     * @param x X position of the image (in millipoints)
+     * @param y Y position of the image (in millipoints)
+     * @param width width of the image (in millipoints)
+     * @param height height of the image (in millipoints)
      * @throws IOException In case of an I/O error while writing the output format
      */
     void paintImage(RenderedImage image,

Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandler.java?rev=682757&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandler.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandler.java Tue Aug  5 08:31:00 2008
@@ -0,0 +1,78 @@
+/*
+ * 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;
+
+import java.awt.Rectangle;
+import java.io.IOException;
+
+import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+
+/**
+ * This interface is used for handling all sorts of image types for PDF output.
+ */
+public interface ImageHandler {
+
+    /**
+     * Returns the priority for this image handler. A lower value means higher priority. This
+     * information is used to build the ordered/prioritized list of supported ImageFlavors.
+     * The built-in handlers use priorities between 100 and 999.
+     * @return a positive integer (>0) indicating the priority
+     */
+    int getPriority();
+
+    /**
+     * Returns the {@link ImageFlavor}s supported by this instance
+     * @return the supported image flavors
+     */
+    ImageFlavor[] getSupportedImageFlavors();
+
+    /**
+     * Indicates whether the image handler is compatible with the indicated target represented
+     * by the rendering context object and with the image to be processed. The image is also
+     * passed as a parameter because a handler might not support every subtype of image that is
+     * presented. For example: in the case of {@code ImageXMLDOM}, the image might carry an SVG
+     * or some other XML format. One handler might only handle SVG but no other XML format.
+     * @param targetContext the target rendering context
+     * @param image the image to be processed (or null if only to check based on the rendering
+     *              context)
+     * @return true if this handler is compatible with the target rendering context
+     */
+    boolean isCompatible(RenderingContext targetContext, Image image);
+
+    /**
+     * Returns the {@link Image} subclass supported by this instance.
+     * @return the Image type
+     */
+    Class getSupportedImageClass();
+
+    /**
+     * Handles the given {@link Image} instance painting it at the indicated position in the
+     * output format being generated.
+     * @param context the rendering context
+     * @param image the image to be handled
+     * @param pos the position and scaling of the image relative to the origin point of the
+     *          current viewport (in millipoints)
+     * @throws IOException if an I/O error occurs
+     */
+    void handleImage(RenderingContext context, Image image,
+            Rectangle pos) throws IOException;
+
+}

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandlerRegistry.java (from r680381, xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandlerRegistry.java?p2=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandlerRegistry.java&p1=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java&r1=680381&r2=682757&rev=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandlerRegistry.java Tue Aug  5 08:31:00 2008
@@ -17,7 +17,7 @@
 
 /* $Id$ */
 
-package org.apache.fop.render.pdf;
+package org.apache.fop.render;
 
 import java.util.Comparator;
 import java.util.Iterator;
@@ -33,37 +33,34 @@
 import org.apache.xmlgraphics.util.Service;
 
 /**
- * This class holds references to various image handlers used by the PDF renderer. It also
+ * This class holds references to various image handlers. It also
  * supports automatic discovery of additional handlers available through
  * the class path.
  */
-public class PDFImageHandlerRegistry {
+public class ImageHandlerRegistry {
 
     /** the logger */
-    private static Log log = LogFactory.getLog(PDFImageHandlerRegistry.class);
+    private static Log log = LogFactory.getLog(ImageHandlerRegistry.class);
 
     private static final Comparator HANDLER_COMPARATOR = new Comparator() {
         public int compare(Object o1, Object o2) {
-            PDFImageHandler h1 = (PDFImageHandler)o1;
-            PDFImageHandler h2 = (PDFImageHandler)o2;
+            ImageHandler h1 = (ImageHandler)o1;
+            ImageHandler h2 = (ImageHandler)o2;
             return h1.getPriority() - h2.getPriority();
         }
     };
 
-    /** Map containing PDF image handlers for various MIME types */
+    /** Map containing image handlers for various {@code Image} subclasses. */
     private Map handlers = new java.util.HashMap();
     /** List containing the same handlers as above but ordered by priority */
     private List handlerList = new java.util.LinkedList();
 
-    /** Sorted Set of registered handlers */
-    private ImageFlavor[] supportedFlavors = new ImageFlavor[0];
     private int handlerRegistrations;
-    private int lastSync;
 
     /**
      * Default constructor.
      */
-    public PDFImageHandlerRegistry() {
+    public ImageHandlerRegistry() {
         discoverHandlers();
     }
 
@@ -73,8 +70,8 @@
      */
     public void addHandler(String classname) {
         try {
-            PDFImageHandler handlerInstance
-                = (PDFImageHandler)Class.forName(classname).newInstance();
+            ImageHandler handlerInstance
+                = (ImageHandler)Class.forName(classname).newInstance();
             addHandler(handlerInstance);
         } catch (ClassNotFoundException e) {
             throw new IllegalArgumentException("Could not find "
@@ -88,22 +85,23 @@
         } catch (ClassCastException e) {
             throw new IllegalArgumentException(classname
                                                + " is not an "
-                                               + PDFImageHandler.class.getName());
+                                               + ImageHandler.class.getName());
         }
     }
 
     /**
      * Add an image handler. The handler itself is inspected to find out what it supports.
-     * @param handler the PDFImageHandler instance
+     * @param handler the ImageHandler instance
      */
-    public synchronized void addHandler(PDFImageHandler handler) {
+    public synchronized void addHandler(ImageHandler handler) {
         Class imageClass = handler.getSupportedImageClass();
+        //List
         this.handlers.put(imageClass, handler);
 
-        //Sorted insert
+        //Sorted insert (sort by priority)
         ListIterator iter = this.handlerList.listIterator();
         while (iter.hasNext()) {
-            PDFImageHandler h = (PDFImageHandler)iter.next();
+            ImageHandler h = (ImageHandler)iter.next();
             if (HANDLER_COMPARATOR.compare(handler, h) < 0) {
                 iter.previous();
                 break;
@@ -114,73 +112,63 @@
     }
 
     /**
-     * Returns an PDFImageHandler which handles an specific image type given the MIME type
+     * Returns an {@code ImageHandler} which handles an specific image type given the MIME type
      * of the image.
-     * @param img the Image to be handled
-     * @return the PDFImageHandler responsible for handling the image or null if none is available
+     * @param targetContext the target rendering context that is used for identifying compatibility
+     * @param image the Image to be handled
+     * @return the image handler responsible for handling the image or null if none is available
      */
-    public PDFImageHandler getHandler(Image img) {
-        return getHandler(img.getClass());
-    }
-
-    /**
-     * Returns an PDFImageHandler which handles an specific image type given the MIME type
-     * of the image.
-     * @param imageClass the Image subclass for which to get a handler
-     * @return the PDFImageHandler responsible for handling the image or null if none is available
-     */
-    protected synchronized PDFImageHandler getHandler(Class imageClass) {
-        PDFImageHandler handler = null;
-        Class cl = imageClass;
-        while (cl != null) {
-            handler = (PDFImageHandler)handlers.get(cl);
-            if (handler != null) {
-                break;
+    public ImageHandler getHandler(RenderingContext targetContext, Image image) {
+        ListIterator iter = this.handlerList.listIterator();
+        while (iter.hasNext()) {
+            ImageHandler h = (ImageHandler)iter.next();
+            if (h.isCompatible(targetContext, image)) {
+                //Return the first handler in the prioritized list that is compatible
+                return h;
             }
-            cl = cl.getSuperclass();
         }
-        return handler;
+        return null;
     }
 
     /**
-     * Returns the ordered array of supported image flavors.
+     * Returns the ordered array of supported image flavors. The array needs to be ordered by
+     * priority so the image loader framework can return the preferred image type.
      * @return the array of image flavors
      */
-    public synchronized ImageFlavor[] getSupportedFlavors() {
-        if (this.lastSync != this.handlerRegistrations) {
-            //Extract all ImageFlavors into a single array
-            List flavors = new java.util.ArrayList();
-            Iterator iter = this.handlerList.iterator();
-            while (iter.hasNext()) {
-                ImageFlavor[] f = ((PDFImageHandler)iter.next()).getSupportedImageFlavors();
+    public synchronized ImageFlavor[] getSupportedFlavors(RenderingContext context) {
+        //Extract all ImageFlavors into a single array
+        List flavors = new java.util.ArrayList();
+        Iterator iter = this.handlerList.iterator();
+        while (iter.hasNext()) {
+            ImageHandler handler = (ImageHandler)iter.next();
+            if (handler.isCompatible(context, null)) {
+                ImageFlavor[] f = handler.getSupportedImageFlavors();
                 for (int i = 0; i < f.length; i++) {
                     flavors.add(f[i]);
                 }
             }
-            this.supportedFlavors = (ImageFlavor[])flavors.toArray(new ImageFlavor[flavors.size()]);
-            this.lastSync = this.handlerRegistrations;
         }
-        return this.supportedFlavors;
+        return (ImageFlavor[])flavors.toArray(new ImageFlavor[flavors.size()]);
     }
 
     /**
-     * Discovers PDFImageHandler implementations through the classpath and dynamically
+     * Discovers ImageHandler implementations through the classpath and dynamically
      * registers them.
      */
     private void discoverHandlers() {
         // add mappings from available services
-        Iterator providers = Service.providers(PDFImageHandler.class);
+        Iterator providers = Service.providers(ImageHandler.class);
         if (providers != null) {
             while (providers.hasNext()) {
-                PDFImageHandler handler = (PDFImageHandler)providers.next();
+                ImageHandler handler = (ImageHandler)providers.next();
                 try {
                     if (log.isDebugEnabled()) {
-                        log.debug("Dynamically adding PDFImageHandler: "
+                        log.debug("Dynamically adding ImageHandler: "
                                 + handler.getClass().getName());
                     }
                     addHandler(handler);
                 } catch (IllegalArgumentException e) {
-                    log.error("Error while adding PDFImageHandler", e);
+                    log.error("Error while adding ImageHandler", e);
                 }
 
             }

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandlerRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandlerRegistry.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ImageHandlerRegistry.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Aug  5 08:31:00 2008
@@ -0,0 +1 @@
+/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java:603620-680380

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererContext.java?rev=682757&r1=682756&r2=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererContext.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererContext.java Tue Aug  5 08:31:00 2008
@@ -22,7 +22,6 @@
 //Java
 import java.util.Map;
 
-//FOP
 import org.apache.fop.apps.FOUserAgent;
 
 /**
@@ -30,7 +29,7 @@
  * so that external handlers can get information to be able to render to the
  * render target.
  */
-public class RendererContext {
+public class RendererContext implements RenderingContext {
 
     private String mime;
     private AbstractRenderer renderer;

Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RenderingContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RenderingContext.java?rev=682757&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RenderingContext.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RenderingContext.java Tue Aug  5 08:31:00 2008
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+import org.apache.fop.apps.FOUserAgent;
+
+/**
+ * Implementations of this interface provide context information needed by supporting classes
+ * during specific tasks (like image rendering).
+ */
+public interface RenderingContext {
+
+    /**
+     * Returns the MIME type associated with the current output format.
+     * @return the MIME type (ex. application/pdf)
+     */
+    String getMimeType();
+
+    /**
+     * Returns the user agent. The user agent is used to access configuration and other information
+     * for the rendering process.
+     * @return the user agent
+     */
+    FOUserAgent getUserAgent();
+
+}

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RenderingContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RenderingContext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java?rev=682757&r1=682756&r2=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java Tue Aug  5 08:31:00 2008
@@ -24,6 +24,7 @@
 import java.awt.geom.AffineTransform;
 
 import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.render.ImageHandlerRegistry;
 
 /**
  * Abstract base class for IFPainter implementations.
@@ -32,6 +33,9 @@
 
     private FOUserAgent userAgent;
 
+    /** Image handler registry */
+    protected ImageHandlerRegistry imageHandlerRegistry = new ImageHandlerRegistry();
+
     /**
      * Default constructor.
      */
@@ -40,6 +44,9 @@
 
     /** {@inheritDoc} */
     public void setUserAgent(FOUserAgent ua) {
+        if (this.userAgent != null) {
+            throw new IllegalStateException("The user agent was already set");
+        }
         this.userAgent = ua;
     }
 

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java?rev=682757&r1=682756&r2=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java Tue Aug  5 08:31:00 2008
@@ -35,6 +35,8 @@
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
 
+import org.apache.xmlgraphics.util.QName;
+
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.util.DecimalFormatCache;
 
@@ -219,6 +221,17 @@
     }
 
     /**
+     * Adds an attribute to a given {@code AttributesImpl} instance.
+     * @param atts the attributes collection
+     * @param attribute the attribute to add
+     * @param value the attribute's CDATA value
+     */
+    protected void addAttribute(AttributesImpl atts, QName attribute, String value) {
+        atts.addAttribute(attribute.getNamespaceURI(),
+                attribute.getLocalName(), attribute.getQName(), CDATA, value);
+    }
+
+    /**
      * Converts an array of integer coordinates into a space-separated string.
      * @param coordinates the coordinates
      * @return the space-separated array of coordinates

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFConstants.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFConstants.java?rev=682757&r1=682756&r2=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFConstants.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFConstants.java Tue Aug  5 08:31:00 2008
@@ -19,6 +19,8 @@
 
 package org.apache.fop.render.intermediate;
 
+import org.apache.xmlgraphics.util.QName;
+
 import org.apache.fop.apps.MimeConstants;
 
 /**
@@ -39,6 +41,8 @@
     String XLINK_PREFIX = "xlink";
     /** XML namespace for XLink */
     String XLINK_NAMESPACE = "http://www.w3.org/1999/xlink";
+    /** xlink:href attribute */
+    QName XLINK_HREF = new QName(XLINK_NAMESPACE, XLINK_PREFIX, "href");
 
     String EL_DOCUMENT = "document";
     String EL_HEADER = "header";
@@ -49,4 +53,5 @@
     String EL_PAGE_CONTENT = "content";
     String EL_VIEWPORT = "viewport";
     String EL_GROUP = "g";
+    String EL_IMAGE = "image";
 }

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java?rev=682757&r1=682756&r2=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java Tue Aug  5 08:31:00 2008
@@ -24,6 +24,7 @@
 import java.awt.Paint;
 import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
+import java.util.Map;
 
 import javax.xml.transform.Result;
 
@@ -257,7 +258,7 @@
      * @throws IFException if an error occurs while handling this event
      */
     void drawRect(Rectangle rect, Paint fill, Color stroke) throws IFException;
-    void drawImage(String uri, Rectangle rect) throws IFException; //external images
+    void drawImage(String uri, Rectangle rect, Map foreignAttributes) throws IFException; //external images
     void startImage(Rectangle rect) throws IFException; //followed by a SAX stream (SVG etc.)
     void endImage() throws IFException;
     //etc. etc.

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFParser.java?rev=682757&r1=682756&r2=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFParser.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFParser.java Tue Aug  5 08:31:00 2008
@@ -135,6 +135,7 @@
             elementHandlers.put("font", new FontHandler());
             elementHandlers.put("text", new TextHandler());
             elementHandlers.put("rect", new RectHandler());
+            elementHandlers.put(EL_IMAGE, new ImageHandler());
         }
 
 
@@ -459,6 +460,24 @@
 
         }
 
+        private class ImageHandler extends AbstractElementHandler {
+
+            public void endElement() throws IFException {
+                int x = Integer.parseInt(lastAttributes.getValue("x"));
+                int y = Integer.parseInt(lastAttributes.getValue("y"));
+                int width = Integer.parseInt(lastAttributes.getValue("width"));
+                int height = Integer.parseInt(lastAttributes.getValue("height"));
+                String uri = lastAttributes.getValue(
+                        XLINK_HREF.getNamespaceURI(), XLINK_HREF.getLocalName());
+                Map foreignAttributes = null; //TODO Implement me!
+                painter.drawImage(uri, new Rectangle(x, y, width, height), foreignAttributes);
+            }
+
+            public boolean ignoreCharacters() {
+                return false;
+            }
+        }
+
 
         // ====================================================================
 

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java?rev=682757&r1=682756&r2=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java Tue Aug  5 08:31:00 2008
@@ -62,6 +62,7 @@
 import org.apache.fop.area.inline.TextArea;
 import org.apache.fop.area.inline.Viewport;
 import org.apache.fop.area.inline.WordArea;
+import org.apache.fop.datatypes.URISpecification;
 import org.apache.fop.fo.extensions.ExtensionAttachment;
 import org.apache.fop.fo.extensions.xmp.XMPMetadata;
 import org.apache.fop.fonts.Font;
@@ -168,8 +169,8 @@
                 }
                 if (this.painter == null) {
                     this.painter = new IFSerializer();
+                    this.painter.setUserAgent(getUserAgent());
                 }
-                this.painter.setUserAgent(getUserAgent());
                 this.painter.setFontInfo(fontInfo);
                 this.painter.setResult(result);
             }
@@ -695,15 +696,22 @@
 
     /** {@inheritDoc} */
     public void renderImage(Image image, Rectangle2D pos) {
-        if (log.isDebugEnabled()) {
-            log.debug("renderImage() image=" + image + ", pos=" + pos);
-        }
-        super.renderImage(image, pos);
+        drawImage(image.getURL(), pos, image.getForeignAttributes());
     }
 
-    protected void drawImage(String url, Rectangle2D pos, Map foreignAttributes) {
-        // TODO Auto-generated method stub
-        log.warn("drawImage() NYI");
+    /** {@inheritDoc} */
+    protected void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) {
+        Rectangle posInt = new Rectangle(
+                currentIPPosition + (int)pos.getX(),
+                currentBPPosition + (int)pos.getY(),
+                (int)pos.getWidth(),
+                (int)pos.getHeight());
+        uri = URISpecification.getURL(uri);
+        try {
+            painter.drawImage(uri, posInt, foreignAttributes);
+        } catch (IFException ife) {
+            handleIFException(ife);
+        }
     }
 
     protected void clip() {

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java?rev=682757&r1=682756&r2=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java Tue Aug  5 08:31:00 2008
@@ -24,10 +24,13 @@
 import java.awt.Paint;
 import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
+import java.util.Iterator;
+import java.util.Map;
 
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
 
+import org.apache.xmlgraphics.util.QName;
 import org.apache.xmlgraphics.util.XMLizable;
 
 import org.apache.fop.util.ColorUtil;
@@ -275,9 +278,25 @@
     }
 
     /** {@inheritDoc} */
-    public void drawImage(String uri, Rectangle rect) throws IFException {
-        // TODO Auto-generated method stub
-
+    public void drawImage(String uri, Rectangle rect, Map foreignAttributes) throws IFException {
+        try {
+            AttributesImpl atts = new AttributesImpl();
+            addAttribute(atts, XLINK_HREF, uri);
+            atts.addAttribute("", "x", "x", CDATA, Integer.toString(rect.x));
+            atts.addAttribute("", "y", "y", CDATA, Integer.toString(rect.y));
+            atts.addAttribute("", "width", "width", CDATA, Integer.toString(rect.width));
+            atts.addAttribute("", "height", "height", CDATA, Integer.toString(rect.height));
+            if (foreignAttributes != null) {
+                Iterator iter = foreignAttributes.entrySet().iterator();
+                while (iter.hasNext()) {
+                    Map.Entry entry = (Map.Entry)iter.next();
+                    addAttribute(atts, (QName)entry.getKey(), entry.getValue().toString());
+                }
+            }
+            element(EL_IMAGE, atts);
+        } catch (SAXException e) {
+            throw new IFException("SAX error in startGroup()", e);
+        }
     }
 
     /** {@inheritDoc} */

Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java?rev=682757&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java Tue Aug  5 08:31:00 2008
@@ -0,0 +1,327 @@
+/*
+ * 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.pdf;
+
+import java.awt.Color;
+import java.awt.geom.AffineTransform;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.fop.pdf.PDFColor;
+import org.apache.fop.pdf.PDFDocument;
+import org.apache.fop.pdf.PDFFilterList;
+import org.apache.fop.pdf.PDFNumber;
+import org.apache.fop.pdf.PDFResourceContext;
+import org.apache.fop.pdf.PDFState;
+import org.apache.fop.pdf.PDFStream;
+import org.apache.fop.pdf.PDFTextUtil;
+import org.apache.fop.pdf.PDFXObject;
+
+/**
+ * Generator class encapsulating all object references and state necessary to generate a
+ * PDF content stream.
+ */
+public class PDFContentGenerator {
+
+    /** Controls whether comments are written to the PDF stream. */
+    protected static final boolean WRITE_COMMENTS = true;
+
+    private PDFDocument document;
+    private OutputStream outputStream;
+    private PDFResourceContext resourceContext;
+
+    /** the current stream to add PDF commands to */
+    private PDFStream currentStream;
+
+    /** drawing state */
+    protected PDFState currentState = null;
+    /** Text generation utility holding the current font status */
+    protected PDFTextUtil textutil;
+
+
+    /**
+     * Main constructor. Creates a new PDF stream and additional helper classes for text painting
+     * and state management.
+     * @param document the PDF document
+     * @param out the output stream the PDF document is generated to
+     * @param resourceContext the resource context
+     */
+    public PDFContentGenerator(PDFDocument document, OutputStream out,
+            PDFResourceContext resourceContext) {
+        this.document = document;
+        this.outputStream = out;
+        this.resourceContext = resourceContext;
+        this.currentStream = document.getFactory()
+                .makeStream(PDFFilterList.CONTENT_FILTER, false);
+        this.textutil = new PDFTextUtil() {
+            protected void write(String code) {
+                currentStream.add(code);
+            }
+        };
+
+        this.currentState = new PDFState();
+    }
+
+    /**
+     * Returns the applicable resource context for the generator.
+     * @return the resource context
+     */
+    public PDFDocument getDocument() {
+        return this.document;
+    }
+
+    /**
+     * Returns the output stream the PDF document is written to.
+     * @return the output stream
+     */
+    public OutputStream getOutputStream() {
+        return this.outputStream;
+    }
+
+    /**
+     * Returns the applicable resource context for the generator.
+     * @return the resource context
+     */
+    public PDFResourceContext getResourceContext() {
+        return this.resourceContext;
+    }
+
+    /**
+     * Returns the {@code PDFStream} associated with this instance.
+     * @return the PDF stream
+     */
+    public PDFStream getStream() {
+        return this.currentStream;
+    }
+
+    /**
+     * Returns the {@code PDFState} associated with this instance.
+     * @return the PDF state
+     */
+    public PDFState getState() {
+        return this.currentState;
+    }
+
+    /**
+     * Returns the {@code PDFTextUtil} associated with this instance.
+     * @return the text utility
+     */
+    public PDFTextUtil getTextUtil() {
+        return this.textutil;
+    }
+
+    /**
+     * Flushes all queued PDF objects ready to be written to the output stream.
+     * @throws IOException if an error occurs while flushing the PDF objects
+     */
+    public void flushPDFDoc() throws IOException {
+        this.document.output(this.outputStream);
+    }
+
+    /**
+     * Writes out a comment.
+     * @param text text for the comment
+     */
+    protected void comment(String text) {
+        if (WRITE_COMMENTS) {
+            currentStream.add("% " + text + "\n");
+        }
+    }
+
+    /** {@inheritDoc} */
+    protected void saveGraphicsState() {
+        endTextObject();
+        currentState.push();
+        currentStream.add("q\n");
+    }
+
+    /**
+     * Restored the graphics state valid before the previous {@code #saveGraphicsState()}.
+     * @param popState true if the state should also be popped, false if only the PDF command
+     *           should be issued
+     */
+    protected void restoreGraphicsState(boolean popState) {
+        endTextObject();
+        currentStream.add("Q\n");
+        if (popState) {
+            currentState.pop();
+        }
+    }
+
+    /** {@inheritDoc} */
+    protected void restoreGraphicsState() {
+        restoreGraphicsState(true);
+    }
+
+    /** Indicates the beginning of a text object. */
+    protected void beginTextObject() {
+        if (!textutil.isInTextObject()) {
+            textutil.beginTextObject();
+        }
+    }
+
+    /** Indicates the end of a text object. */
+    protected void endTextObject() {
+        if (textutil.isInTextObject()) {
+            textutil.endTextObject();
+        }
+    }
+
+    /**
+     * Concatenates the given transformation matrix with the current one.
+     * @param transform the transformation matrix (in points)
+     */
+    public void concatenate(AffineTransform transform) {
+        concatenate(transform, false);
+    }
+
+    /**
+     * Concatenates the given transformation matrix with the current one.
+     * @param transform the transformation matrix
+     * @param convertMillipoints true if the coordinates are in millipoints and need to be
+     *          converted to points
+     */
+    public void concatenate(AffineTransform transform, boolean convertMillipoints) {
+        if (!transform.isIdentity()) {
+            currentState.concatenate(transform);
+            currentStream.add(CTMHelper.toPDFString(transform, convertMillipoints) + " cm\n");
+        }
+    }
+
+    /**
+     * Adds content to the stream.
+     * @param content the PDF content
+     */
+    public void add(String content) {
+        currentStream.add(content);
+    }
+
+    /**
+     * Formats a float value (normally coordinates in points) as Strings.
+     * @param value the value
+     * @return the formatted value
+     */
+    protected static String format(float value) {
+        return PDFNumber.doubleOut(value);
+    }
+
+    /**
+     * Sets the current line width in points.
+     * @param width line width in points
+     */
+    public void updateLineWidth(float width) {
+        if (currentState.setLineWidth(width)) {
+            //Only write if value has changed WRT the current line width
+            currentStream.add(format(width) + " w\n");
+        }
+    }
+
+    /**
+     * Establishes a new foreground or fill color. In contrast to updateColor
+     * this method does not check the PDFState for optimization possibilities.
+     * @param col the color to apply
+     * @param fill true to set the fill color, false for the foreground color
+     * @param pdf StringBuffer to write the PDF code to
+     *//*
+    public void setColor(Color col, boolean fill, StringBuffer pdf) {
+        assert pdf != null;
+    }*/
+
+    /**
+     * Establishes a new foreground or fill color.
+     * @param col the color to apply
+     * @param fill true to set the fill color, false for the foreground color
+     * @param stream the PDFStream to write the PDF code to
+     */
+    public void setColor(Color col, boolean fill, PDFStream stream) {
+        assert stream != null;
+        PDFColor color = new PDFColor(this.document, col);
+        stream.add(color.getColorSpaceOut(fill));
+    }
+
+    /**
+     * Establishes a new foreground or fill color.
+     * @param col the color to apply
+     * @param fill true to set the fill color, false for the foreground color
+     */
+    public void setColor(Color col, boolean fill) {
+        setColor(col, fill, getStream());
+    }
+
+    /**
+     * Establishes a new foreground or fill color. In contrast to updateColor
+     * this method does not check the PDFState for optimization possibilities.
+     * @param col the color to apply
+     * @param fill true to set the fill color, false for the foreground color
+     * @param pdf StringBuffer to write the PDF code to, if null, the code is
+     *     written to the current stream.
+     */
+    protected void setColor(Color col, boolean fill, StringBuffer pdf) {
+        if (pdf != null) {
+            PDFColor color = new PDFColor(this.document, col);
+            pdf.append(color.getColorSpaceOut(fill));
+        } else {
+            setColor(col, fill, this.currentStream);
+        }
+    }
+
+    /**
+     * Establishes a new foreground or fill color.
+     * @param col the color to apply (null skips this operation)
+     * @param fill true to set the fill color, false for the foreground color
+     * @param pdf StringBuffer to write the PDF code to, if null, the code is
+     *     written to the current stream.
+     */
+    public void updateColor(Color col, boolean fill, StringBuffer pdf) {
+        if (col == null) {
+            return;
+        }
+        boolean update = false;
+        if (fill) {
+            update = getState().setBackColor(col);
+        } else {
+            update = getState().setColor(col);
+        }
+
+        if (update) {
+            setColor(col, fill, pdf);
+        }
+    }
+
+    /**
+     * Places a previously registered image at a certain place on the page.
+     * @param x X coordinate
+     * @param y Y coordinate
+     * @param w width for image
+     * @param h height for image
+     * @param xobj the image XObject
+     */
+    public void placeImage(float x, float y, float w, float h, PDFXObject xobj) {
+        saveGraphicsState();
+        add(format(w) + " 0 0 "
+                          + format(-h) + " "
+                          + format(x) + " "
+                          + format(y + h)
+                          + " cm\n" + xobj.getName() + " Do\n");
+        restoreGraphicsState();
+    }
+
+
+}

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java?rev=682757&r1=682756&r2=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java Tue Aug  5 08:31:00 2008
@@ -55,6 +55,7 @@
             RendererContext context,
             int x, int y, int width, int height) throws IOException {
 
+        PDFContentGenerator generator = renderer.getGenerator();
         PDFSVGHandler.PDFInfo pdfInfo = PDFSVGHandler.getPDFInfo(context);
         float fwidth = width / 1000f;
         float fheight = height / 1000f;
@@ -69,16 +70,17 @@
         float sx = fwidth / (float)imw;
         float sy = fheight / (float)imh;
 
-        renderer.saveGraphicsState();
-        renderer.setColor(Color.black, false, null);
-        renderer.setColor(Color.black, true, null);
+        generator.comment("G2D start");
+        generator.saveGraphicsState();
+        generator.updateColor(Color.black, false, null);
+        generator.updateColor(Color.black, true, null);
 
         //TODO Clip to the image area.
 
         // transform so that the coordinates (0,0) is from the top left
         // and positive is down and to the right. (0,0) is where the
         // viewBox puts it.
-        renderer.currentStream.add(sx + " 0 0 " + sy + " " + fx + " "
+        generator.add(sx + " 0 0 " + sy + " " + fx + " "
                           + fy + " cm\n");
 
 
@@ -95,8 +97,8 @@
 
         AffineTransform transform = new AffineTransform();
         transform.translate(fx, fy);
-        pdfInfo.pdfState.concatenate(transform);
-        graphics.setPDFState(pdfInfo.pdfState);
+        generator.getState().concatenate(transform);
+        graphics.setPDFState(generator.getState());
         graphics.setOutputStream(pdfInfo.outputStream);
 
         if (pdfInfo.paintAsBitmap) {
@@ -113,9 +115,9 @@
             painter.paint(graphics, area);
         }
 
-        pdfInfo.currentStream.add(graphics.getString());
-        renderer.restoreGraphicsState();
-        pdfInfo.pdfState.pop();
+        generator.add(graphics.getString());
+        generator.restoreGraphicsState();
+        generator.comment("G2D end");
     }
 
     /** {@inheritDoc} */

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java?rev=682757&r1=682756&r2=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java Tue Aug  5 08:31:00 2008
@@ -19,8 +19,12 @@
 
 package org.apache.fop.render.pdf;
 
+import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.Point;
 import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 
 import org.apache.xmlgraphics.image.loader.Image;
@@ -28,12 +32,16 @@
 import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
 
 import org.apache.fop.pdf.PDFXObject;
+import org.apache.fop.render.AbstractImageHandlerGraphics2D;
 import org.apache.fop.render.RendererContext;
+import org.apache.fop.render.RenderingContext;
+import org.apache.fop.svg.PDFGraphics2D;
 
 /**
  * PDFImageHandler implementation which handles Graphics2D images.
  */
-public class PDFImageHandlerGraphics2D implements PDFImageHandler {
+public class PDFImageHandlerGraphics2D extends AbstractImageHandlerGraphics2D
+                implements PDFImageHandler {
 
     private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
         ImageFlavor.GRAPHICS2D,
@@ -44,13 +52,74 @@
             Point origin, Rectangle pos)
             throws IOException {
         PDFRenderer renderer = (PDFRenderer)context.getRenderer();
+        /*
         ImageGraphics2D imageG2D = (ImageGraphics2D)image;
         renderer.getGraphics2DAdapter().paintImage(imageG2D.getGraphics2DImagePainter(),
                 context, origin.x + pos.x, origin.y + pos.y, pos.width, pos.height);
+                */
+        PDFRenderingContext pdfContext = new PDFRenderingContext(
+                context.getUserAgent(),
+                renderer.getGenerator(),
+                renderer.currentPage,
+                renderer.getFontInfo());
+        Rectangle effPos = new Rectangle(origin.x + pos.x, origin.y + pos.y, pos.width, pos.height);
+        handleImage(pdfContext, image, effPos);
         return null;
     }
 
     /** {@inheritDoc} */
+    public void handleImage(RenderingContext context, Image image, Rectangle pos)
+                throws IOException {
+        PDFRenderingContext pdfContext = (PDFRenderingContext)context;
+        PDFContentGenerator generator = pdfContext.getGenerator();
+        ImageGraphics2D imageG2D = (ImageGraphics2D)image;
+        float fwidth = pos.width / 1000f;
+        float fheight = pos.height / 1000f;
+        float fx = pos.x / 1000f;
+        float fy = pos.y / 1000f;
+
+        // get the 'width' and 'height' attributes of the SVG document
+        Dimension dim = image.getInfo().getSize().getDimensionMpt();
+        float imw = (float)dim.getWidth() / 1000f;
+        float imh = (float)dim.getHeight() / 1000f;
+
+        float sx = fwidth / (float)imw;
+        float sy = fheight / (float)imh;
+
+        generator.comment("G2D start");
+        generator.saveGraphicsState();
+        generator.updateColor(Color.black, false, null);
+        generator.updateColor(Color.black, true, null);
+
+        //TODO Clip to the image area.
+
+        // transform so that the coordinates (0,0) is from the top left
+        // and positive is down and to the right. (0,0) is where the
+        // viewBox puts it.
+        generator.add(sx + " 0 0 " + sy + " " + fx + " " + fy + " cm\n");
+
+        final boolean textAsShapes = false;
+        PDFGraphics2D graphics = new PDFGraphics2D(textAsShapes,
+                pdfContext.getFontInfo(), generator.getDocument(),
+                generator.getResourceContext(), pdfContext.getPage().referencePDF(),
+                "", 0.0f);
+        graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
+
+        AffineTransform transform = new AffineTransform();
+        transform.translate(fx, fy);
+        generator.getState().concatenate(transform);
+        graphics.setPDFState(generator.getState());
+        graphics.setOutputStream(generator.getOutputStream());
+
+        Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
+        imageG2D.getGraphics2DImagePainter().paint(graphics, area);
+
+        generator.add(graphics.getString());
+        generator.restoreGraphicsState();
+        generator.comment("G2D end");
+    }
+
+    /** {@inheritDoc} */
     public int getPriority() {
         return 200;
     }
@@ -65,4 +134,10 @@
         return FLAVORS;
     }
 
+    /** {@inheritDoc} */
+    public boolean isCompatible(RenderingContext targetContext, Image image) {
+        return (image == null || image instanceof ImageGraphics2D)
+                && targetContext instanceof PDFRenderingContext;
+    }
+
 }

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java?rev=682757&r1=682756&r2=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java Tue Aug  5 08:31:00 2008
@@ -31,12 +31,15 @@
 import org.apache.fop.pdf.PDFImage;
 import org.apache.fop.pdf.PDFResourceContext;
 import org.apache.fop.pdf.PDFXObject;
+import org.apache.fop.render.ImageHandler;
 import org.apache.fop.render.RendererContext;
+import org.apache.fop.render.RenderingContext;
 
 /**
- * PDFImageHandler implementation which handles CCITT encoded images (CCITT fax group 3/4).
+ * Image handler implementation which handles CCITT encoded images (CCITT fax group 3/4)
+ * for PDF output.
  */
-public class PDFImageHandlerRawCCITTFax implements PDFImageHandler {
+public class PDFImageHandlerRawCCITTFax implements PDFImageHandler, ImageHandler {
 
     private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
         ImageFlavor.RAW_CCITTFAX,
@@ -66,6 +69,24 @@
     }
 
     /** {@inheritDoc} */
+    public void handleImage(RenderingContext context, Image image, Rectangle pos)
+                throws IOException {
+        PDFRenderingContext pdfContext = (PDFRenderingContext)context;
+        PDFContentGenerator generator = pdfContext.getGenerator();
+        ImageRawCCITTFax ccitt = (ImageRawCCITTFax)image;
+
+        PDFImage pdfimage = new ImageRawCCITTFaxAdapter(ccitt, image.getInfo().getOriginalURI());
+        PDFXObject xobj = generator.getDocument().addImage(
+                generator.getResourceContext(), pdfimage);
+
+        float x = (float)pos.getX() / 1000f;
+        float y = (float)pos.getY() / 1000f;
+        float w = (float)pos.getWidth() / 1000f;
+        float h = (float)pos.getHeight() / 1000f;
+        generator.placeImage(x, y, w, h, xobj);
+    }
+
+    /** {@inheritDoc} */
     public int getPriority() {
         return 100;
     }
@@ -80,4 +101,10 @@
         return FLAVORS;
     }
 
+    /** {@inheritDoc} */
+    public boolean isCompatible(RenderingContext targetContext, Image image) {
+        return (image == null || image instanceof ImageRawCCITTFax)
+                && targetContext instanceof PDFRenderingContext;
+    }
+
 }

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java?rev=682757&r1=682756&r2=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java Tue Aug  5 08:31:00 2008
@@ -31,12 +31,14 @@
 import org.apache.fop.pdf.PDFImage;
 import org.apache.fop.pdf.PDFResourceContext;
 import org.apache.fop.pdf.PDFXObject;
+import org.apache.fop.render.ImageHandler;
 import org.apache.fop.render.RendererContext;
+import org.apache.fop.render.RenderingContext;
 
 /**
- * PDFImageHandler implementation which handles raw JPEG images.
+ * Image handler implementation which handles raw JPEG images for PDF output.
  */
-public class PDFImageHandlerRawJPEG implements PDFImageHandler {
+public class PDFImageHandlerRawJPEG implements PDFImageHandler, ImageHandler {
 
     private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
         ImageFlavor.RAW_JPEG,
@@ -66,6 +68,24 @@
     }
 
     /** {@inheritDoc} */
+    public void handleImage(RenderingContext context, Image image, Rectangle pos)
+                throws IOException {
+        PDFRenderingContext pdfContext = (PDFRenderingContext)context;
+        PDFContentGenerator generator = pdfContext.getGenerator();
+        ImageRawJPEG imageJPEG = (ImageRawJPEG)image;
+
+        PDFImage pdfimage = new ImageRawJPEGAdapter(imageJPEG, image.getInfo().getOriginalURI());
+        PDFXObject xobj = generator.getDocument().addImage(
+                generator.getResourceContext(), pdfimage);
+
+        float x = (float)pos.getX() / 1000f;
+        float y = (float)pos.getY() / 1000f;
+        float w = (float)pos.getWidth() / 1000f;
+        float h = (float)pos.getHeight() / 1000f;
+        generator.placeImage(x, y, w, h, xobj);
+    }
+
+    /** {@inheritDoc} */
     public int getPriority() {
         return 100;
     }
@@ -80,4 +100,10 @@
         return FLAVORS;
     }
 
+    /** {@inheritDoc} */
+    public boolean isCompatible(RenderingContext targetContext, Image image) {
+        return (image == null || image instanceof ImageRawJPEG)
+                && targetContext instanceof PDFRenderingContext;
+    }
+
 }

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRenderedImage.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRenderedImage.java?rev=682757&r1=682756&r2=682757&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRenderedImage.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRenderedImage.java Tue Aug  5 08:31:00 2008
@@ -31,12 +31,14 @@
 import org.apache.fop.pdf.PDFImage;
 import org.apache.fop.pdf.PDFResourceContext;
 import org.apache.fop.pdf.PDFXObject;
+import org.apache.fop.render.ImageHandler;
 import org.apache.fop.render.RendererContext;
+import org.apache.fop.render.RenderingContext;
 
 /**
- * PDFImageHandler implementation which handles RenderedImage instances.
+ * Image handler implementation which handles RenderedImage instances for PDF output.
  */
-public class PDFImageHandlerRenderedImage implements PDFImageHandler {
+public class PDFImageHandlerRenderedImage implements PDFImageHandler, ImageHandler {
 
     private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
         ImageFlavor.BUFFERED_IMAGE,
@@ -67,6 +69,24 @@
     }
 
     /** {@inheritDoc} */
+    public void handleImage(RenderingContext context, Image image, Rectangle pos)
+                throws IOException {
+        PDFRenderingContext pdfContext = (PDFRenderingContext)context;
+        PDFContentGenerator generator = pdfContext.getGenerator();
+        ImageRendered imageRend = (ImageRendered)image;
+
+        PDFImage pdfimage = new ImageRenderedAdapter(imageRend, image.getInfo().getOriginalURI());
+        PDFXObject xobj = generator.getDocument().addImage(
+                generator.getResourceContext(), pdfimage);
+
+        float x = (float)pos.getX() / 1000f;
+        float y = (float)pos.getY() / 1000f;
+        float w = (float)pos.getWidth() / 1000f;
+        float h = (float)pos.getHeight() / 1000f;
+        generator.placeImage(x, y, w, h, xobj);
+    }
+
+    /** {@inheritDoc} */
     public int getPriority() {
         return 300;
     }
@@ -81,4 +101,10 @@
         return FLAVORS;
     }
 
+    /** {@inheritDoc} */
+    public boolean isCompatible(RenderingContext targetContext, Image image) {
+        return (image == null || image instanceof ImageRendered)
+                && targetContext instanceof PDFRenderingContext;
+    }
+
 }



---------------------------------------------------------------------
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