xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r611278 [3/5] - in /xmlgraphics/fop/trunk: ./ examples/mathml/resources/META-INF/services/ examples/mathml/src/org/apache/fop/mathml/ examples/plan/resources/META-INF/services/ examples/plan/src/org/apache/fop/plan/ lib/ src/java/META-INF/s...
Date Fri, 11 Jan 2008 19:51:11 GMT
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java?rev=611278&r1=611277&r2=611278&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java Fri Jan 11 11:50:53 2008
@@ -20,10 +20,13 @@
 package org.apache.fop.render.afp;
 
 import java.awt.Color;
+import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
+import java.awt.image.RenderedImage;
+import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
@@ -32,7 +35,22 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.ByteArrayOutputStream;
+
+import org.apache.xmlgraphics.image.codec.tiff.TIFFImage;
+import org.apache.xmlgraphics.image.loader.ImageException;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
+import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
+import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
+import org.apache.xmlgraphics.image.loader.util.ImageUtil;
+import org.apache.xmlgraphics.ps.ImageEncodingHelper;
+
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.area.Block;
@@ -49,6 +67,7 @@
 import org.apache.fop.area.inline.SpaceArea;
 import org.apache.fop.area.inline.TextArea;
 import org.apache.fop.area.inline.WordArea;
+import org.apache.fop.datatypes.URISpecification;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.extensions.ExtensionAttachment;
 import org.apache.fop.fonts.FontInfo;
@@ -56,10 +75,6 @@
 import org.apache.fop.fonts.base14.Courier;
 import org.apache.fop.fonts.base14.Helvetica;
 import org.apache.fop.fonts.base14.TimesRoman;
-import org.apache.fop.image.FopImage;
-import org.apache.fop.image.ImageFactory;
-import org.apache.fop.image.TIFFImage;
-import org.apache.fop.image.XMLImage;
 import org.apache.fop.render.AbstractPathOrientedRenderer;
 import org.apache.fop.render.Graphics2DAdapter;
 import org.apache.fop.render.RendererContext;
@@ -74,7 +89,6 @@
 import org.apache.fop.render.afp.modca.AFPDataStream;
 import org.apache.fop.render.afp.modca.ImageObject;
 import org.apache.fop.render.afp.modca.PageObject;
-import org.w3c.dom.Document;
 
 /**
  * This is an implementation of a FOP Renderer that renders areas to AFP.
@@ -735,20 +749,117 @@
         return context;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public void drawImage(String url, Rectangle2D pos, Map foreignAttributes) {
+    private static final ImageFlavor[] FLAVORS = new ImageFlavor[]
+                                                     {ImageFlavor.RAW_CCITTFAX,
+                                                      ImageFlavor.GRAPHICS2D,
+                                                      ImageFlavor.BUFFERED_IMAGE, 
+                                                      ImageFlavor.RENDERED_IMAGE,
+                                                      ImageFlavor.XML_DOM};
+
+    /** {@inheritDoc} */
+    public void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) {
+        uri = URISpecification.getURL(uri);
+        Rectangle posInt = new Rectangle(
+                (int)pos.getX(),
+                (int)pos.getY(),
+                (int)pos.getWidth(),
+                (int)pos.getHeight());
+        Point origin = new Point(currentIPPosition, currentBPPosition);
+        int x = origin.x + posInt.x;
+        int y = origin.y + posInt.y;
+
         String name = null;
         if (pageSegmentsMap != null) {
-            name = (String) pageSegmentsMap.get(url);
+            name = (String) pageSegmentsMap.get(uri);
         }
         if (name != null) {
-            int x = mpts2units(pos.getX() + currentIPPosition);
-            int y = mpts2units(pos.getY() + currentBPPosition);
-            afpDataStream.createIncludePageSegment(name, x, y);
+            afpDataStream.createIncludePageSegment(name, mpts2units(x), mpts2units(y));
         } else {
-            url = ImageFactory.getURL(url);
+            ImageManager manager = getUserAgent().getFactory().getImageManager();
+            ImageInfo info = null;
+            try {
+                ImageSessionContext sessionContext = getUserAgent().getImageSessionContext();
+                info = manager.getImageInfo(uri, sessionContext);
+                
+                //Only now fully load/prepare the image
+                Map hints = ImageUtil.getDefaultHints(sessionContext);
+                org.apache.xmlgraphics.image.loader.Image img = manager.getImage(
+                        info, FLAVORS, hints, sessionContext);
+                
+                //...and process the image
+                if (img instanceof ImageGraphics2D) {
+                    ImageGraphics2D imageG2D = (ImageGraphics2D)img;
+                    RendererContext context = createRendererContext(
+                            posInt.x, posInt.y,
+                            posInt.width, posInt.height, foreignAttributes);
+                    getGraphics2DAdapter().paintImage(imageG2D.getGraphics2DImagePainter(),
+                            context,
+                            origin.x + posInt.x, origin.y + posInt.y,
+                            posInt.width, posInt.height);
+                } else if (img instanceof ImageRendered) {
+                    ImageRendered imgRend = (ImageRendered)img;
+                    RenderedImage ri = imgRend.getRenderedImage();
+                    
+                    drawBufferedImage(ri, getResolution(),
+                            posInt.x + currentIPPosition,
+                            posInt.y + currentBPPosition,
+                            posInt.width,
+                            posInt.height);
+                } else if (img instanceof ImageRawCCITTFax) {
+                    ImageRawCCITTFax ccitt = (ImageRawCCITTFax)img;
+                    int afpx = mpts2units(posInt.x + currentIPPosition);
+                    int afpy = mpts2units(posInt.y + currentBPPosition);
+                    int afpw = mpts2units(posInt.getWidth());
+                    int afph = mpts2units(posInt.getHeight());
+                    int afpres = getResolution();
+                    ImageObject io = afpDataStream.getImageObject(afpx, afpy, afpw, afph,
+                            afpres, afpres);
+                    io.setImageParameters(
+                            (int) (ccitt.getSize().getDpiHorizontal() * 10),
+                            (int) (ccitt.getSize().getDpiVertical() * 10),
+                            ccitt.getSize().getWidthPx(),
+                            ccitt.getSize().getHeightPx());
+                    int compression = ccitt.getCompression();
+                    switch (compression) {
+                    case TIFFImage.COMP_FAX_G3_1D :
+                        io.setImageEncoding((byte) 0x80);
+                        break;
+                    case TIFFImage.COMP_FAX_G3_2D :
+                        io.setImageEncoding((byte) 0x81);
+                        break;
+                    case TIFFImage.COMP_FAX_G4_2D :
+                        io.setImageEncoding((byte) 0x82);
+                        break;
+                    default:
+                        throw new IllegalStateException(
+                                "Invalid compression scheme: " + compression);
+                    }
+                    InputStream in = ccitt.createInputStream();
+                    try {
+                        byte[] buf = IOUtils.toByteArray(in);
+                        io.setImageData(buf);
+                    } finally {
+                        IOUtils.closeQuietly(in);
+                    }
+                } else if (img instanceof ImageXMLDOM) {
+                    ImageXMLDOM imgXML = (ImageXMLDOM)img;
+                    renderDocument(imgXML.getDocument(), imgXML.getRootNamespace(),
+                            pos, foreignAttributes);
+                } else {
+                    throw new UnsupportedOperationException("Unsupported image type: " + img);
+                }
+
+            } catch (ImageException ie) {
+                log.error("Error while processing image: "
+                        + (info != null ? info.toString() : uri), ie);
+            } catch (FileNotFoundException fe) {
+                log.error(fe.getMessage());
+            } catch (IOException ioe) {
+                log.error("I/O error while processing image: "
+                        + (info != null ? info.toString() : uri), ioe);
+            }
+            
+            /*
             ImageFactory fact = userAgent.getFactory().getImageFactory();
             FopImage fopimage = fact.getImage(url, userAgent);
             if (fopimage == null) {
@@ -768,6 +879,7 @@
                 renderDocument(doc, ns, pos, foreignAttributes);
             } else if (MimeConstants.MIME_EPS.equals(mime)) {
                 log.warn("EPS images are not supported by this renderer");
+                */
                 /*
                  * } else if (MimeConstants.MIME_JPEG.equals(mime)) { if
                  * (!fopimage.load(FopImage.ORIGINAL_DATA)) { return; }
@@ -785,7 +897,7 @@
                  * io.setImageIDESize((byte)fopimage.getBitsPerPixel());
                  * io.setImageEncoding((byte)0x83);
                  * io.setImageData(fopimage.getRessourceBytes());
-                 */
+                 *//*
             } else if (MimeConstants.MIME_TIFF.equals(mime)
                     && fopimage instanceof TIFFImage) {
                 TIFFImage tiffImage = (TIFFImage) fopimage;
@@ -852,43 +964,30 @@
                     convertToGrayScaleImage(io, fopimage.getBitmaps(), fopimage
                             .getWidth(), fopimage.getHeight(), this.bitsPerPixel);
                 }
-            }
+            }*/
         }
     }
 
     /**
-     * Writes a BufferedImage to an OutputStream as raw sRGB bitmaps.
+     * Writes a RenderedImage to an OutputStream as raw sRGB bitmaps.
      * 
-     * @param img
-     *            the BufferedImage
+     * @param image
+     *            the RenderedImage
      * @param out
      *            the OutputStream
      * @throws IOException
      *             In case of an I/O error.
      */
-    public static void writeImage(BufferedImage img, OutputStream out)
+    public static void writeImage(RenderedImage image, OutputStream out)
             throws IOException {
-        int w = img.getWidth();
-        int h = img.getHeight();
-        int[] tmpMap = img.getRGB(0, 0, w, h, null, 0, w);
-        for (int i = 0; i < h; i++) {
-            for (int j = 0; j < w; j++) {
-                int p = tmpMap[i * w + j];
-                int r = (p >> 16) & 0xFF;
-                int g = (p >> 8) & 0xFF;
-                int b = (p) & 0xFF;
-                out.write((byte) (r & 0xFF));
-                out.write((byte) (g & 0xFF));
-                out.write((byte) (b & 0xFF));
-            }
-        }
+        ImageEncodingHelper.encodeRenderedImageAsRGB(image, out);
     }
 
     /**
      * Draws a BufferedImage to AFP.
      * 
-     * @param bi
-     *            the BufferedImage
+     * @param image
+     *            the RenderedImage
      * @param imageResolution
      *            the resolution of the BufferedImage
      * @param x
@@ -900,7 +999,7 @@
      * @param h
      *            the height of the viewport (in mpt)
      */
-    public void drawBufferedImage(BufferedImage bi, int imageResolution, int x,
+    public void drawBufferedImage(RenderedImage image, int imageResolution, int x,
             int y, int w, int h) {
         int afpx = mpts2units(x);
         int afpy = mpts2units(y);
@@ -910,21 +1009,24 @@
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
         try {
             // Serialize image
-            writeImage(bi, baout);
+            //TODO Eventually, this should be changed not to buffer as this increases the
+            //memory consumption (see PostScript output)
+            writeImage(image, baout);
             byte[] buf = baout.toByteArray();
 
             // Generate image
             ImageObject io = afpDataStream.getImageObject(afpx, afpy, afpw,
                     afph, afpres, afpres);
             io.setImageParameters(imageResolution, imageResolution,
-                    bi.getWidth(), bi.getHeight());
+                    image.getWidth(), image.getHeight());
             if (colorImages) {
                 io.setImageIDESize((byte)24);
                 io.setImageData(buf);
             } else {
                 // TODO Teach it how to handle grayscale BufferedImages directly
                 // because this is pretty inefficient
-                convertToGrayScaleImage(io, buf, bi.getWidth(), bi.getHeight(), this.bitsPerPixel);
+                convertToGrayScaleImage(io, buf,
+                        image.getWidth(), image.getHeight(), this.bitsPerPixel);
             }
         } catch (IOException ioe) {
             log.error("Error while serializing bitmap: " + ioe.getMessage(),

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DGraphics2DAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DGraphics2DAdapter.java?rev=611278&r1=611277&r2=611278&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DGraphics2DAdapter.java Fri Jan 11 11:50:53 2008
@@ -21,12 +21,14 @@
 
 import java.awt.Color;
 import java.awt.Dimension;
+import java.awt.Graphics2D;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+
 import org.apache.fop.render.Graphics2DAdapter;
-import org.apache.fop.render.Graphics2DImagePainter;
 import org.apache.fop.render.RendererContext;
 
 /**
@@ -34,16 +36,6 @@
  */
 public class Java2DGraphics2DAdapter implements Graphics2DAdapter {
 
-    private Java2DGraphicsState state;
-
-    /**
-     * Main constructor
-     * @param state the state tracker for this rendering run
-     */
-    public Java2DGraphics2DAdapter(Java2DGraphicsState state) {
-        this.state = state;
-    }
-    
     /** {@inheritDoc} */
     public void paintImage(Graphics2DImagePainter painter,
             RendererContext context,
@@ -63,26 +55,28 @@
         float sy = fheight / (float)imh;
 
         Java2DRenderer renderer = (Java2DRenderer)context.getRenderer();
-        renderer.saveGraphicsState();
-        state.getGraph().setColor(Color.black);
-        state.getGraph().setBackground(Color.black);
+        Java2DGraphicsState state = renderer.state;
+        
+        //Create copy and paint on that
+        Graphics2D g2d = (Graphics2D)state.getGraph().create();
+        g2d.setColor(Color.black);
+        g2d.setBackground(Color.black);
         
         //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.
-        state.getGraph().translate(fx, fy);
+        g2d.translate(fx, fy);
         AffineTransform at = AffineTransform.getScaleInstance(sx, sy);
         if (!at.isIdentity()) {
-            state.getGraph().transform(at);
+            g2d.transform(at);
         }
 
         Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
-        painter.paint(state.getGraph(), area);
+        painter.paint(g2d, area);
 
-        renderer.restoreGraphicsState();
-    
+        g2d.dispose();
     }
 
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DRenderer.java?rev=611278&r1=611277&r2=611278&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DRenderer.java Fri Jan 11 11:50:53 2008
@@ -25,7 +25,6 @@
 import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.RenderingHints;
-import java.awt.color.ColorSpace;
 import java.awt.font.GlyphVector;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.GeneralPath;
@@ -33,14 +32,6 @@
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
-import java.awt.image.ColorModel;
-import java.awt.image.ComponentColorModel;
-import java.awt.image.DataBuffer;
-import java.awt.image.DataBufferByte;
-import java.awt.image.PixelInterleavedSampleModel;
-import java.awt.image.Raster;
-import java.awt.image.SampleModel;
-import java.awt.image.WritableRaster;
 import java.awt.print.PageFormat;
 import java.awt.print.Printable;
 import java.awt.print.PrinterException;
@@ -51,7 +42,15 @@
 import java.util.Map;
 import java.util.Stack;
 
-import org.w3c.dom.Document;
+import org.apache.xmlgraphics.image.loader.ImageException;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
+import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
+import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
+import org.apache.xmlgraphics.image.loader.util.ImageUtil;
 
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
@@ -65,13 +64,11 @@
 import org.apache.fop.area.inline.SpaceArea;
 import org.apache.fop.area.inline.TextArea;
 import org.apache.fop.area.inline.WordArea;
+import org.apache.fop.datatypes.URISpecification;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.Typeface;
-import org.apache.fop.image.FopImage;
-import org.apache.fop.image.ImageFactory;
-import org.apache.fop.image.XMLImage;
 import org.apache.fop.render.AbstractPathOrientedRenderer;
 import org.apache.fop.render.Graphics2DAdapter;
 import org.apache.fop.render.RendererContext;
@@ -184,7 +181,7 @@
 
     /** {@inheritDoc} */
     public Graphics2DAdapter getGraphics2DAdapter() {
-        return new Java2DGraphics2DAdapter(state);
+        return new Java2DGraphics2DAdapter();
     }
 
     /**
@@ -884,76 +881,58 @@
     /**
      * {@inheritDoc}
      */
-    protected void drawImage(String url, Rectangle2D pos, Map foreignAttributes) {
+    protected void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) {
 
         int x = currentIPPosition + (int)Math.round(pos.getX());
         int y = currentBPPosition + (int)Math.round(pos.getY());
-        url = ImageFactory.getURL(url);
-
-        ImageFactory fact = userAgent.getFactory().getImageFactory();
-        FopImage fopimage = fact.getImage(url, userAgent);
-
-        if (fopimage == null) {
-            return;
-        }
-        if (!fopimage.load(FopImage.DIMENSIONS)) {
-            return;
-        }
-        int w = fopimage.getWidth();
-        int h = fopimage.getHeight();
-        String mime = fopimage.getMimeType();
-        if ("text/xml".equals(mime)) {
-            if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
-                return;
-            }
-            Document doc = ((XMLImage) fopimage).getDocument();
-            String ns = ((XMLImage) fopimage).getNameSpace();
-            renderDocument(doc, ns, pos, foreignAttributes);
-
-        } else if ("image/svg+xml".equals(mime)) {
-            if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
-                return;
-            }
-            Document doc = ((XMLImage) fopimage).getDocument();
-            String ns = ((XMLImage) fopimage).getNameSpace();
-
-            renderDocument(doc, ns, pos, foreignAttributes);
-        } else if ("image/eps".equals(mime)) {
-            log.warn("EPS images are not supported by this renderer");
-        } else {
-            if (!fopimage.load(FopImage.BITMAP)) {
-                log.warn("Loading of bitmap failed: " + url);
-                return;
+        uri = URISpecification.getURL(uri);
+        
+        ImageManager manager = getUserAgent().getFactory().getImageManager();
+        ImageInfo info = null;
+        try {
+            ImageSessionContext sessionContext = getUserAgent().getImageSessionContext();
+            info = manager.getImageInfo(uri, sessionContext);
+            final ImageFlavor[] flavors = new ImageFlavor[]
+                {ImageFlavor.GRAPHICS2D,
+                    ImageFlavor.BUFFERED_IMAGE, 
+                    ImageFlavor.RENDERED_IMAGE, 
+                    ImageFlavor.XML_DOM};
+            Map hints = ImageUtil.getDefaultHints(sessionContext);
+            org.apache.xmlgraphics.image.loader.Image img = manager.getImage(
+                    info, flavors, hints, sessionContext);
+            if (img instanceof ImageGraphics2D) {
+                ImageGraphics2D imageG2D = (ImageGraphics2D)img;
+                int width = (int)pos.getWidth();
+                int height = (int)pos.getHeight();
+                RendererContext context = createRendererContext(
+                        x, y, width, height, foreignAttributes);
+                getGraphics2DAdapter().paintImage(imageG2D.getGraphics2DImagePainter(),
+                        context, x, y, width, height);
+            } else if (img instanceof ImageRendered) {
+                ImageRendered imgRend = (ImageRendered)img;
+                AffineTransform at = new AffineTransform();
+                at.translate(x / 1000f, y / 1000f);
+                double sx = pos.getWidth() / info.getSize().getWidthMpt();
+                double sy = pos.getHeight() / info.getSize().getHeightMpt();
+                sx *= userAgent.getSourceResolution() / info.getSize().getDpiHorizontal();
+                sy *= userAgent.getSourceResolution() / info.getSize().getDpiVertical();
+                at.scale(sx, sy);
+                state.getGraph().drawRenderedImage(imgRend.getRenderedImage(), at);
+            } else if (img instanceof ImageXMLDOM) {
+                ImageXMLDOM imgXML = (ImageXMLDOM)img;
+                renderDocument(imgXML.getDocument(), imgXML.getRootNamespace(),
+                        pos, foreignAttributes);
             }
-
-            byte[] raw = fopimage.getBitmaps();
-
-            // TODO Hardcoded color and sample models, FIX ME!
-            ColorModel cm = new ComponentColorModel(
-                    ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), 
-                    new int[] {8, 8, 8},
-                    false, false,
-                    ColorModel.OPAQUE, DataBuffer.TYPE_BYTE);
-            SampleModel sampleModel = new PixelInterleavedSampleModel(
-                    DataBuffer.TYPE_BYTE, w, h, 3, w * 3, new int[] {0, 1, 2});
-            DataBuffer dbuf = new DataBufferByte(raw, w * h * 3);
-
-            WritableRaster raster = Raster.createWritableRaster(sampleModel,
-                    dbuf, null);
-
-            java.awt.Image awtImage;
-            // Combine the color model and raster into a buffered image
-            awtImage = new BufferedImage(cm, raster, false, null);
-
-            state.getGraph().drawImage(awtImage, 
-                    (int)(x / 1000f), (int)(y / 1000f), 
-                    (int)(pos.getWidth() / 1000f), (int)(pos.getHeight() / 1000f), null);
+        } catch (ImageException ie) {
+            log.error("Error while processing image: "
+                    + (info != null ? info.toString() : uri), ie);
+        } catch (IOException ioe) {
+            log.error("I/O error while processing image: "
+                    + (info != null ? info.toString() : uri), ioe);
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     protected RendererContext createRendererContext(int x, int y, int width, int height, 
             Map foreignAttributes) {
         RendererContext context = super.createRendererContext(
@@ -962,9 +941,7 @@
         return context;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public int print(Graphics g, PageFormat pageFormat, int pageIndex)
             throws PrinterException {
         if (pageIndex >= getNumberOfPages()) {
@@ -1004,6 +981,10 @@
         //not necessary in Java2D
     }
 
+    /**
+     * Controls the page background.
+     * @param transparentPageBackground true if the background should be transparent
+     */
     public void setTransparentPageBackground(boolean transparentPageBackground) {
         this.transparentPageBackground = transparentPageBackground;
     }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java?rev=611278&r1=611277&r2=611278&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java Fri Jan 11 11:50:53 2008
@@ -28,11 +28,13 @@
 import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.java2d.GraphicContext;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+
 import org.apache.fop.render.AbstractGraphics2DAdapter;
-import org.apache.fop.render.Graphics2DImagePainter;
 import org.apache.fop.render.RendererContext;
 import org.apache.fop.util.UnitConv;
-import org.apache.xmlgraphics.java2d.GraphicContext;
 
 /**
  * Graphics2DAdapter implementation for PCL and HP GL/2.
@@ -110,7 +112,8 @@
         if (!painted) {
             //Fallback solution: Paint to a BufferedImage
             int resolution = (int)Math.round(context.getUserAgent().getTargetResolution());
-            BufferedImage bi = paintToBufferedImage(painter, pclContext, resolution, true, false);
+            BufferedImage bi = paintToBufferedImage(painter, pclContext,
+                    resolution, !pclContext.isColorCanvas(), false);
 
             pcl.setCursorPos(x, y);
             gen.paintBitmap(bi, new Dimension(width, height), pclContext.isSourceTransparency());

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLRenderer.java?rev=611278&r1=611277&r2=611278&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLRenderer.java Fri Jan 11 11:50:53 2008
@@ -24,24 +24,17 @@
 import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Graphics2D;
+import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.RenderingHints;
-import java.awt.color.ColorSpace;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.GeneralPath;
 import java.awt.geom.Line2D;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
-import java.awt.image.ColorModel;
-import java.awt.image.ComponentColorModel;
-import java.awt.image.DataBuffer;
-import java.awt.image.DataBufferByte;
-import java.awt.image.PixelInterleavedSampleModel;
-import java.awt.image.Raster;
 import java.awt.image.RenderedImage;
-import java.awt.image.SampleModel;
-import java.awt.image.WritableRaster;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.List;
@@ -52,7 +45,19 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.image.loader.ImageException;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+import org.apache.xmlgraphics.image.loader.ImageSize;
+import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
+import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
+import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
+import org.apache.xmlgraphics.image.loader.util.ImageUtil;
 import org.apache.xmlgraphics.java2d.GraphicContext;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
 
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.MimeConstants;
@@ -70,16 +75,12 @@
 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.ExtensionElementMapping;
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontMetrics;
-import org.apache.fop.image.EPSImage;
-import org.apache.fop.image.FopImage;
-import org.apache.fop.image.ImageFactory;
-import org.apache.fop.image.XMLImage;
 import org.apache.fop.render.Graphics2DAdapter;
-import org.apache.fop.render.Graphics2DImagePainter;
 import org.apache.fop.render.PrintRenderer;
 import org.apache.fop.render.RendererContext;
 import org.apache.fop.render.RendererContextConstants;
@@ -135,6 +136,13 @@
     private boolean allTextAsBitmaps = false;
 
     /**
+     * Controls whether an RGB canvas is used when converting Java2D graphics to bitmaps.
+     * This can be used to work around problems with Apache Batik, for example, but setting
+     * this to true will increase memory consumption.
+     */
+    private boolean useColorCanvas = false;
+    
+    /**
      * Controls whether the generation of PJL commands gets disabled. 
      */
     private boolean disabledPJL = false;
@@ -991,87 +999,88 @@
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
+    protected RendererContext createRendererContext(int x, int y, int width, int height, 
+            Map foreignAttributes) {
+        RendererContext context = super.createRendererContext(
+                x, y, width, height, foreignAttributes);
+        context.setProperty(PCLRendererContextConstants.PCL_COLOR_CANVAS,
+                Boolean.valueOf(this.useColorCanvas));
+        return context;
+    }
+
+    /** {@inheritDoc} */
     public void renderImage(Image image, Rectangle2D pos) {
         drawImage(image.getURL(), pos, image.getForeignAttributes());
     }
 
+    private static final ImageFlavor[] FLAVORS = new ImageFlavor[]
+                                             {ImageFlavor.GRAPHICS2D,
+                                              ImageFlavor.BUFFERED_IMAGE, 
+                                              ImageFlavor.RENDERED_IMAGE,
+                                              ImageFlavor.XML_DOM};
     /**
      * Draw an image at the indicated location.
-     * @param url the URI/URL of the image
+     * @param uri the URI/URL of the image
      * @param pos the position of the image
      * @param foreignAttributes an optional Map with foreign attributes, may be null
      */
-    protected void drawImage(String url, Rectangle2D pos, Map foreignAttributes) {
-        url = ImageFactory.getURL(url);
-        ImageFactory fact = userAgent.getFactory().getImageFactory();
-        FopImage fopimage = fact.getImage(url, userAgent);
-        if (fopimage == null) {
-            return;
-        }
-        if (!fopimage.load(FopImage.DIMENSIONS)) {
-            return;
-        }
-        String mime = fopimage.getMimeType();
-        if ("text/xml".equals(mime)) {
-            if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
-                return;
-            }
-            Document doc = ((XMLImage) fopimage).getDocument();
-            String ns = ((XMLImage) fopimage).getNameSpace();
-
-            renderDocument(doc, ns, pos, foreignAttributes);
-        } else if ("image/svg+xml".equals(mime)) {
-            if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
-                return;
-            }
-            Document doc = ((XMLImage) fopimage).getDocument();
-            String ns = ((XMLImage) fopimage).getNameSpace();
-
-            renderDocument(doc, ns, pos, foreignAttributes);
-        } else if (fopimage instanceof EPSImage) {
-            log.warn("EPS images are not supported by this renderer");
-        } else {
-            if (!fopimage.load(FopImage.BITMAP)) {
-                log.error("Bitmap image could not be processed: " + fopimage);
-                return;
-            }
-            byte[] imgmap = fopimage.getBitmaps();
+    protected void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) {
+        uri = URISpecification.getURL(uri);
+        Rectangle posInt = new Rectangle(
+                (int)pos.getX(),
+                (int)pos.getY(),
+                (int)pos.getWidth(),
+                (int)pos.getHeight());
+        Point origin = new Point(currentIPPosition, currentBPPosition);
+        int x = origin.x + posInt.x;
+        int y = origin.y + posInt.y;
+        
+        ImageManager manager = getUserAgent().getFactory().getImageManager();
+        ImageInfo info = null;
+        try {
+            ImageSessionContext sessionContext = getUserAgent().getImageSessionContext();
+            info = manager.getImageInfo(uri, sessionContext);
             
-            ColorModel cm = new ComponentColorModel(
-                    ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), 
-                    new int[] {8, 8, 8},
-                    false, false,
-                    ColorModel.OPAQUE, DataBuffer.TYPE_BYTE);
-            int imgw = fopimage.getWidth();
-            int imgh = fopimage.getHeight();
-            SampleModel sampleModel = new PixelInterleavedSampleModel(
-                    DataBuffer.TYPE_BYTE, imgw, imgh, 3, imgw * 3, new int[] {0, 1, 2});
-            DataBuffer dbuf = new DataBufferByte(imgmap, imgw * imgh * 3);
-
-            WritableRaster raster = Raster.createWritableRaster(sampleModel,
-                    dbuf, null);
-
-            // Combine the color model and raster into a buffered image
-            RenderedImage img = new BufferedImage(cm, raster, false, null);
-
-            try {
-                setCursorPos(this.currentIPPosition + (int)pos.getX(),
-                        this.currentBPPosition + (int)pos.getY());
-                gen.paintBitmap(img, 
-                        new Dimension((int)pos.getWidth(), (int)pos.getHeight()), 
+            //Only now fully load/prepare the image
+            Map hints = ImageUtil.getDefaultHints(sessionContext);
+            org.apache.xmlgraphics.image.loader.Image img = manager.getImage(
+                    info, FLAVORS, hints, sessionContext);
+            
+            //...and process the image
+            if (img instanceof ImageGraphics2D) {
+                ImageGraphics2D imageG2D = (ImageGraphics2D)img;
+                RendererContext context = createRendererContext(
+                        posInt.x, posInt.y,
+                        posInt.width, posInt.height, foreignAttributes);
+                getGraphics2DAdapter().paintImage(imageG2D.getGraphics2DImagePainter(),
+                        context, x, y, posInt.width, posInt.height);
+            } else if (img instanceof ImageRendered) {
+                ImageRendered imgRend = (ImageRendered)img;
+                RenderedImage ri = imgRend.getRenderedImage();
+                setCursorPos(x, y);
+                gen.paintBitmap(ri, 
+                        new Dimension(posInt.width, posInt.height), 
                         false);
-            } catch (IOException ioe) {
-                handleIOTrouble(ioe);
+            } else if (img instanceof ImageXMLDOM) {
+                ImageXMLDOM imgXML = (ImageXMLDOM)img;
+                renderDocument(imgXML.getDocument(), imgXML.getRootNamespace(),
+                        pos, foreignAttributes);
+            } else {
+                throw new UnsupportedOperationException("Unsupported image type: " + img);
             }
+
+        } catch (ImageException ie) {
+            log.error("Error while processing image: "
+                    + (info != null ? info.toString() : uri), ie);
+        } catch (FileNotFoundException fe) {
+            log.error(fe.getMessage());
+        } catch (IOException ioe) {
+            handleIOTrouble(ioe);
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public void renderForeignObject(ForeignObject fo, Rectangle2D pos) {
         Document doc = fo.getDocument();
         String ns = fo.getNameSpace();
@@ -1153,52 +1162,45 @@
             }
     
             // background image
-            if (back.getFopImage() != null) {
-                FopImage fopimage = back.getFopImage();
-                if (fopimage != null && fopimage.load(FopImage.DIMENSIONS)) {
-                    saveGraphicsState();
-                    clipRect(sx, sy, paddRectWidth, paddRectHeight);
-                    int horzCount = (int) ((paddRectWidth * 1000 / fopimage
-                            .getIntrinsicWidth()) + 1.0f);
-                    int vertCount = (int) ((paddRectHeight * 1000 / fopimage
-                            .getIntrinsicHeight()) + 1.0f);
-                    if (back.getRepeat() == EN_NOREPEAT) {
-                        horzCount = 1;
-                        vertCount = 1;
-                    } else if (back.getRepeat() == EN_REPEATX) {
-                        vertCount = 1;
-                    } else if (back.getRepeat() == EN_REPEATY) {
-                        horzCount = 1;
-                    }
-                    // change from points to millipoints
-                    sx *= 1000;
-                    sy *= 1000;
-                    if (horzCount == 1) {
-                        sx += back.getHoriz();
-                    }
-                    if (vertCount == 1) {
-                        sy += back.getVertical();
-                    }
-                    for (int x = 0; x < horzCount; x++) {
-                        for (int y = 0; y < vertCount; y++) {
-                            // place once
-                            Rectangle2D pos;
-                            // Image positions are relative to the currentIP/BP
-                            pos = new Rectangle2D.Float(
-                                    sx - currentIPPosition 
-                                        + (x * fopimage.getIntrinsicWidth()),
-                                    sy - currentBPPosition
-                                        + (y * fopimage.getIntrinsicHeight()),
-                                    fopimage.getIntrinsicWidth(),
-                                    fopimage.getIntrinsicHeight());
-                            drawImage(back.getURL(), pos, null);
-                        }
+            if (back.getImageInfo() != null) {
+                ImageSize imageSize = back.getImageInfo().getSize(); 
+                saveGraphicsState();
+                clipRect(sx, sy, paddRectWidth, paddRectHeight);
+                int horzCount = (int) ((paddRectWidth * 1000 / imageSize.getWidthMpt()) + 1.0f);
+                int vertCount = (int) ((paddRectHeight * 1000 / imageSize.getHeightMpt()) + 1.0f);
+                if (back.getRepeat() == EN_NOREPEAT) {
+                    horzCount = 1;
+                    vertCount = 1;
+                } else if (back.getRepeat() == EN_REPEATX) {
+                    vertCount = 1;
+                } else if (back.getRepeat() == EN_REPEATY) {
+                    horzCount = 1;
+                }
+                // change from points to millipoints
+                sx *= 1000;
+                sy *= 1000;
+                if (horzCount == 1) {
+                    sx += back.getHoriz();
+                }
+                if (vertCount == 1) {
+                    sy += back.getVertical();
+                }
+                for (int x = 0; x < horzCount; x++) {
+                    for (int y = 0; y < vertCount; y++) {
+                        // place once
+                        Rectangle2D pos;
+                        // Image positions are relative to the currentIP/BP
+                        pos = new Rectangle2D.Float(
+                                sx - currentIPPosition 
+                                    + (x * imageSize.getWidthMpt()),
+                                sy - currentBPPosition
+                                    + (y * imageSize.getHeightMpt()),
+                                imageSize.getWidthMpt(),
+                                imageSize.getHeightMpt());
+                        drawImage(back.getURL(), pos, null);
                     }
-                    restoreGraphicsState();
-                } else {
-                    log.warn(
-                            "Can't find background image: " + back.getURL());
                 }
+                restoreGraphicsState();
             }
         }
         
@@ -1508,6 +1510,11 @@
         }
     }
 
+    /**
+     * Controls whether all text should be generated as bitmaps or only text for which there's
+     * no native font.
+     * @param allTextAsBitmaps true if all text should be painted as bitmaps
+     */
     public void setAllTextAsBitmaps(boolean allTextAsBitmaps) {
         this.allTextAsBitmaps = allTextAsBitmaps;
     }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLRendererContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLRendererContext.java?rev=611278&r1=611277&r2=611278&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLRendererContext.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLRendererContext.java Fri Jan 11 11:50:53 2008
@@ -62,11 +62,28 @@
              && "true".equalsIgnoreCase((String)getForeignAttributes().get(qName));
     }
 
+    /**
+     * Indicates whether the background should not be erased prior to painting.
+     * @return true if the background shouldn't be erased
+     */
     public boolean isSourceTransparency() {
         QName qName = new QName(ExtensionElementMapping.URI, null, "source-transparency");
         return getForeignAttributes() != null 
              && "true".equalsIgnoreCase((String)getForeignAttributes().get(qName));
     }
     
+    /**
+     * Indicates whether an RGB canvas should be used rather than one with grayscales.
+     * This can be used to work around limitations of Apache Batik if you get error while
+     * processing SVG graphics. Note, however, that RGB mode will use more memory.
+     * @return true if an EGB canvas should be used
+     */
+    public boolean isColorCanvas() {
+        QName qName = new QName(ExtensionElementMapping.URI, null, "color-canvas");
+        Boolean prop = (Boolean)context.getProperty(PCLRendererContextConstants.PCL_COLOR_CANVAS);
+        return Boolean.TRUE.equals(prop) 
+            || (getForeignAttributes() != null 
+                    && "true".equalsIgnoreCase((String)getForeignAttributes().get(qName)));
+    }
 
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLSVGHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLSVGHandler.java?rev=611278&r1=611277&r2=611278&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLSVGHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLSVGHandler.java Fri Jan 11 11:50:53 2008
@@ -22,6 +22,7 @@
 // FOP
 import org.apache.fop.render.AbstractGenericSVGHandler;
 import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererContext;
 
 /**
  * PCL XML handler for SVG. Uses Apache Batik for SVG processing.
@@ -34,6 +35,13 @@
     /** {@inheritDoc} */
     public boolean supportsRenderer(Renderer renderer) {
         return (renderer instanceof PCLRenderer);
+    }
+    
+    /** {@inheritDoc} */
+    protected void updateRendererContext(RendererContext context) {
+        //Work around a problem in Batik: Gradients cannot be done in ColorSpace.CS_GRAY
+        context.setProperty(PCLRendererContextConstants.PCL_COLOR_CANVAS,
+                Boolean.TRUE);
     }
     
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java?rev=611278&r1=611277&r2=611278&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java Fri Jan 11 11:50:53 2008
@@ -28,8 +28,9 @@
 import java.awt.image.BufferedImage;
 import java.io.IOException;
 
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+
 import org.apache.fop.render.AbstractGraphics2DAdapter;
-import org.apache.fop.render.Graphics2DImagePainter;
 import org.apache.fop.render.RendererContext;
 import org.apache.fop.render.RendererContext.RendererContextWrapper;
 import org.apache.fop.svg.PDFGraphics2D;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFImageHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFImageHandler.java?rev=611278&r1=611277&r2=611278&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFImageHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFImageHandler.java Fri Jan 11 11:50:53 2008
@@ -19,11 +19,15 @@
 
 package org.apache.fop.render.pdf;
 
+import java.awt.Point;
+import java.awt.Rectangle;
 import java.io.IOException;
 
-import org.apache.fop.image.FopImage;
-import org.apache.fop.pdf.PDFDocument;
+import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+
 import org.apache.fop.pdf.PDFXObject;
+import org.apache.fop.render.RendererContext;
 
 /**
  * This interface is used for handling all sorts of image type for PDF output.
@@ -31,20 +35,38 @@
 public interface PDFImageHandler {
 
     /**
-     * Returns the MIME type supported by this instance.
-     * @return the MIME type
+     * 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 for
+     * the PDF renderer. 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();
+    
+    /**
+     * Returns the {@link Image} subclass supported by this instance.
+     * @return the Image type
      */
-    String getSupportedMimeType();
+    Class getSupportedImageClass();
     
     /**
-     * Generates the PDF objects for the given FopImage instance and returns
-     * the resulting XObject.
+     * Generates the PDF objects for the given {@link Image} instance. If the handler generates
+     * an XObject, it shall return it or otherwise return null. A generated XObject shall be
+     * placed in the current viewport according to the two parameters "origin" and "pos".
+     * @param context the PDF renderer context
      * @param image the image to be handled
-     * @param uri the URI of the image
-     * @param pdfDoc the target PDF document
-     * @return the generated XObject
+     * @param origin the current position in the current viewport (in millipoints)
+     * @param pos the position and scaling of the image relative to the origin point
+     *                  (in millipoints)
+     * @return the generated XObject or null if no XObject was generated
      * @throws IOException if an I/O error occurs
      */
-    PDFXObject generateImage(FopImage image, String uri, PDFDocument pdfDoc) throws IOException;
+    PDFXObject generateImage(RendererContext context, Image image, 
+            Point origin, Rectangle pos) throws IOException;
     
 }

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

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java?rev=611278&r1=611277&r2=611278&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java Fri Jan 11 11:50:53 2008
@@ -19,11 +19,17 @@
 
 package org.apache.fop.render.pdf;
 
+import java.util.Comparator;
 import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
 import org.apache.xmlgraphics.util.Service;
 
 /**
@@ -36,8 +42,23 @@
     /** the logger */
     private static Log log = LogFactory.getLog(PDFImageHandlerRegistry.class);
     
+    private static final Comparator HANDLER_COMPARATOR = new Comparator() {
+        public int compare(Object o1, Object o2) {
+            PDFImageHandler h1 = (PDFImageHandler)o1;
+            PDFImageHandler h2 = (PDFImageHandler)o2;
+            return h1.getPriority() - h2.getPriority();
+        }
+    };
+
     /** Map containing PDF image handlers for various MIME types */
     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.
@@ -75,24 +96,73 @@
      * Add an image handler. The handler itself is inspected to find out what it supports.
      * @param handler the PDFImageHandler instance
      */
-    public void addHandler(PDFImageHandler handler) {
-        String mime = handler.getSupportedMimeType();
-        handlers.put(mime, handler);
+    public synchronized void addHandler(PDFImageHandler handler) {
+        Class imageClass = handler.getSupportedImageClass();
+        this.handlers.put(imageClass, handler);
+        
+        //Sorted insert
+        ListIterator iter = this.handlerList.listIterator();
+        while (iter.hasNext()) {
+            PDFImageHandler h = (PDFImageHandler)iter.next();
+            if (HANDLER_COMPARATOR.compare(handler, h) < 0) {
+                iter.previous();
+                break;
+            }
+        }
+        iter.add(handler);
+        this.handlerRegistrations++;
     }
     
     /**
      * Returns an PDFImageHandler which handles an specific image type given the MIME type
      * of the image.
-     * @param mime the requested MIME type
+     * @param img the Image to be handled
      * @return the PDFImageHandler responsible for handling the image or null if none is available
      */
-    public PDFImageHandler getHandler(String mime) {
-        PDFImageHandler handler;
+    public PDFImageHandler getHandler(Image img) {
+        return getHandler(img.getClass());
+    }
 
-        handler = (PDFImageHandler)handlers.get(mime);
+    /**
+     * 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;
+            }
+            cl = cl.getSuperclass();
+        }
         return handler;
     }
 
+    /**
+     * Returns the ordered array of supported image flavors. 
+     * @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();
+                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;
+    }
+    
     /**
      * Discovers PDFImageHandler implementations through the classpath and dynamically
      * registers them.

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

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java?rev=611278&r1=611277&r2=611278&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java Fri Jan 11 11:50:53 2008
@@ -21,6 +21,8 @@
 
 // Java
 import java.awt.Color;
+import java.awt.Point;
+import java.awt.Rectangle;
 import java.awt.color.ColorSpace;
 import java.awt.color.ICC_Profile;
 import java.awt.geom.AffineTransform;
@@ -37,11 +39,13 @@
 import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
 
-import org.w3c.dom.Document;
-
 import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.output.CountingOutputStream;
 
+import org.apache.xmlgraphics.image.loader.ImageException;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+import org.apache.xmlgraphics.image.loader.util.ImageUtil;
 import org.apache.xmlgraphics.xmp.Metadata;
 import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter;
 import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema;
@@ -68,14 +72,12 @@
 import org.apache.fop.area.inline.SpaceArea;
 import org.apache.fop.area.inline.TextArea;
 import org.apache.fop.area.inline.WordArea;
+import org.apache.fop.datatypes.URISpecification;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.extensions.ExtensionAttachment;
 import org.apache.fop.fo.extensions.xmp.XMPMetadata;
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.Typeface;
-import org.apache.fop.image.FopImage;
-import org.apache.fop.image.ImageFactory;
-import org.apache.fop.image.XMLImage;
 import org.apache.fop.pdf.PDFAMode;
 import org.apache.fop.pdf.PDFAction;
 import org.apache.fop.pdf.PDFAnnotList;
@@ -1661,29 +1663,44 @@
         }
     }
 
-    /**
-     * {@inheritDoc} 
-     */
+    /** {@inheritDoc} */
     public void renderImage(Image image, Rectangle2D pos) {
         endTextObject();
         String url = image.getURL();
-        putImage(url, pos);
+        putImage(url, pos, image.getForeignAttributes());
     }
 
     /** {@inheritDoc} */
     protected void drawImage(String url, Rectangle2D pos, Map foreignAttributes) {
         endTextObject();
-        putImage(url, pos);
+        putImage(url, pos, foreignAttributes);
+    }
+    
+    /**
+     * Adds a PDF XObject (a bitmap or form) to the PDF that will later be referenced.
+     * @param uri URL of the bitmap
+     * @param pos Position of the bitmap
+     * @deprecated Use {@link @putImage(String, Rectangle2D, Map)} instead.
+     */
+    protected void putImage(String uri, Rectangle2D pos) {
+        putImage(uri, pos, null);
     }
     
     /**
      * Adds a PDF XObject (a bitmap or form) to the PDF that will later be referenced.
-     * @param url URL of the bitmap
+     * @param uri URL of the bitmap
      * @param pos Position of the bitmap
+     * @param foreignAttributes foreign attributes associated with the image
      */
-    protected void putImage(String url, Rectangle2D pos) {
-        url = ImageFactory.getURL(url);
-        PDFXObject xobject = pdfDoc.getXObject(url);
+    protected void putImage(String uri, Rectangle2D pos, Map foreignAttributes) {
+        Rectangle posInt = new Rectangle(
+                (int)pos.getX(),
+                (int)pos.getY(),
+                (int)pos.getWidth(),
+                (int)pos.getHeight());
+
+        uri = URISpecification.getURL(uri);
+        PDFXObject xobject = pdfDoc.getXObject(uri);
         if (xobject != null) {
             float w = (float) pos.getWidth() / 1000f;
             float h = (float) pos.getHeight() / 1000f;
@@ -1691,79 +1708,47 @@
                        (float)pos.getY() / 1000f, w, h, xobject);
             return;
         }
+        Point origin = new Point(currentIPPosition, currentBPPosition);
+        int x = origin.x + posInt.x;
+        int y = origin.y + posInt.y;
 
-        ImageFactory fact = userAgent.getFactory().getImageFactory();
-        FopImage fopimage = fact.getImage(url, userAgent);
-        if (fopimage == null) {
-            return;
-        }
-        if (!fopimage.load(FopImage.DIMENSIONS)) {
-            return;
-        }
-        String mime = fopimage.getMimeType();
-        
-        //First check for a dynamically registered handler
-        PDFImageHandler handler = imageHandlerRegistry.getHandler(mime);
-        if (handler != null) {
-            PDFXObject xobj;
-            try {
-                xobj = handler.generateImage(fopimage, url, pdfDoc);
-            } catch (IOException ioe) {
-                log.error("I/O error while handling " + mime + " image", ioe);
-                return;
-            }
-            fact.releaseImage(url, userAgent);
+        ImageManager manager = getUserAgent().getFactory().getImageManager();
+        ImageInfo info = null;
+        try {
+            ImageSessionContext sessionContext = getUserAgent().getImageSessionContext();
+            info = manager.getImageInfo(uri, sessionContext);
             
-            float w = (float)pos.getWidth() / 1000f;
-            float h = (float)pos.getHeight() / 1000f;
-            placeImage((float) pos.getX() / 1000,
-                       (float) pos.getY() / 1000, w, h, xobj);
-        } else if ("text/xml".equals(mime)) {
-            if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
-                return;
-            }
-            Document doc = ((XMLImage) fopimage).getDocument();
-            String ns = ((XMLImage) fopimage).getNameSpace();
-
-            renderDocument(doc, ns, pos, null);
-        } else if ("image/svg+xml".equals(mime)) {
-            if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
-                return;
-            }
-            Document doc = ((XMLImage) fopimage).getDocument();
-            String ns = ((XMLImage) fopimage).getNameSpace();
-
-            renderDocument(doc, ns, pos, null);
-        } else if ("image/eps".equals(mime)) {
-            FopPDFImage pdfimage = new FopPDFImage(fopimage, url);
-            PDFXObject xobj = pdfDoc.addImage(currentContext, pdfimage);
-            fact.releaseImage(url, userAgent);
             
-            float w = (float)pos.getWidth() / 1000f;
-            float h = (float)pos.getHeight() / 1000f;
-            placeImage((float) pos.getX() / 1000,
-                       (float) pos.getY() / 1000, w, h, xobj);
-        } else if ("image/jpeg".equals(mime) || "image/tiff".equals(mime)) {
-            FopPDFImage pdfimage = new FopPDFImage(fopimage, url);
-            PDFXObject xobj = pdfDoc.addImage(currentContext, pdfimage);
-            fact.releaseImage(url, userAgent);
-
-            float w = (float)pos.getWidth() / 1000f;
-            float h = (float)pos.getHeight() / 1000f;
-            placeImage((float) pos.getX() / 1000,
-                       (float) pos.getY() / 1000, w, h, xobj);
-        } else {
-            if (!fopimage.load(FopImage.BITMAP)) {
-                return;
-            }
-            FopPDFImage pdfimage = new FopPDFImage(fopimage, url);
-            PDFXObject xobj = pdfDoc.addImage(currentContext, pdfimage);
-            fact.releaseImage(url, userAgent);
-
-            float w = (float) pos.getWidth() / 1000f;
-            float h = (float) pos.getHeight() / 1000f;
-            placeImage((float) pos.getX() / 1000f,
-                       (float) pos.getY() / 1000f, w, h, xobj);
+            
+            Map hints = ImageUtil.getDefaultHints(sessionContext);
+            org.apache.xmlgraphics.image.loader.Image img = manager.getImage(
+                        info, imageHandlerRegistry.getSupportedFlavors(), hints, sessionContext);
+            
+            //First check for a dynamically registered handler
+            PDFImageHandler handler = imageHandlerRegistry.getHandler(img.getClass());
+            if (handler != null) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Using PDFImageHandler: " + handler.getClass().getName());
+                }
+                try {
+                    RendererContext context = createRendererContext(
+                            x, y, posInt.width, posInt.height, foreignAttributes);
+                    handler.generateImage(context, img, origin, posInt);
+                } catch (IOException ioe) {
+                    log.error("I/O error while handling image: " + info, ioe);
+                    return;
+                }
+            } else {
+                throw new UnsupportedOperationException(
+                        "No PDFImageHandler available for image: "
+                            + info + " (" + img.getClass().getName() + ")");
+            }
+        } catch (ImageException ie) {
+            log.error("Error while processing image: "
+                    + (info != null ? info.toString() : uri), ie);
+        } catch (IOException ioe) {
+            log.error("I/O error while processing image: "
+                    + (info != null ? info.toString() : uri), ioe);
         }
 
         // output new data
@@ -1782,7 +1767,7 @@
      * @param h height for image
      * @param xobj the image XObject
      */
-    protected void placeImage(float x, float y, float w, float h, PDFXObject xobj) {
+    public void placeImage(float x, float y, float w, float h, PDFXObject xobj) {
         saveGraphicsState();
         currentStream.add(format(w) + " 0 0 "
                           + format(-h) + " "
@@ -1792,10 +1777,7 @@
         restoreGraphicsState();
     }
 
-    /**
-     * {@inheritDoc}
-     *          int, int, int, int, java.util.Map)
-     */
+    /** {@inheritDoc} */
     protected RendererContext createRendererContext(int x, int y, int width, int height, 
             Map foreignAttributes) {
         RendererContext context = super.createRendererContext(

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java?rev=611278&r1=611277&r2=611278&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java Fri Jan 11 11:50:53 2008
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-/* $Id: $ */
+/* $Id$ */
 
 package org.apache.fop.render.pdf;
 

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

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java?rev=611278&r1=611277&r2=611278&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java Fri Jan 11 11:50:53 2008
@@ -19,42 +19,40 @@
 
 package org.apache.fop.render.pdf;
 
+import java.awt.Color;
+import java.awt.geom.AffineTransform;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Map;
-import java.awt.Color;
-import java.awt.geom.AffineTransform;
 
 import org.w3c.dom.Document;
 
-import org.apache.fop.render.AbstractGenericSVGHandler;
-import org.apache.fop.render.Renderer;
-import org.apache.fop.render.RendererContext;
-import org.apache.fop.render.RendererContextConstants;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.batik.bridge.BridgeContext;
+import org.apache.batik.bridge.GVTBuilder;
+import org.apache.batik.dom.svg.SVGDOMImplementation;
+import org.apache.batik.gvt.GraphicsNode;
+import org.apache.batik.util.SVGConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.fo.extensions.ExtensionElementMapping;
+import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.pdf.PDFDocument;
 import org.apache.fop.pdf.PDFPage;
+import org.apache.fop.pdf.PDFResourceContext;
 import org.apache.fop.pdf.PDFState;
 import org.apache.fop.pdf.PDFStream;
-import org.apache.fop.pdf.PDFResourceContext;
+import org.apache.fop.render.AbstractGenericSVGHandler;
+import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererContext;
+import org.apache.fop.render.RendererContextConstants;
 import org.apache.fop.svg.PDFAElementBridge;
 import org.apache.fop.svg.PDFBridgeContext;
 import org.apache.fop.svg.PDFGraphics2D;
 import org.apache.fop.svg.SVGUserAgent;
 import org.apache.fop.util.QName;
-import org.apache.fop.fo.extensions.ExtensionElementMapping;
-import org.apache.fop.fonts.FontInfo;
-
-// Commons-Logging
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.avalon.framework.configuration.Configuration;
-
-import org.apache.batik.bridge.GVTBuilder;
-import org.apache.batik.bridge.BridgeContext;
-import org.apache.batik.dom.svg.SVGDOMImplementation;
-import org.apache.batik.gvt.GraphicsNode;
-import org.apache.batik.util.SVGConstants;
 
 /**
  * PDF XML handler for SVG (uses Apache Batik).
@@ -154,10 +152,15 @@
         int xOffset = pdfInfo.currentXPosition;
         int yOffset = pdfInfo.currentYPosition;
 
-        final float deviceResolution = context.getUserAgent().getTargetResolution();
+        FOUserAgent userAgent = context.getUserAgent(); 
+        log.debug("Generating SVG at " 
+                + userAgent.getTargetResolution()
+                + "dpi.");
+        final float deviceResolution = userAgent.getTargetResolution();
+        log.debug("Generating SVG at " + deviceResolution + "dpi.");
         log.debug("Generating SVG at " + deviceResolution + "dpi.");
         
-        final float uaResolution = context.getUserAgent().getSourceResolution();
+        final float uaResolution = userAgent.getSourceResolution();
         SVGUserAgent ua = new SVGUserAgent(25.4f / uaResolution, new AffineTransform());
 
         //Scale for higher resolution on-the-fly images from Batik
@@ -176,6 +179,8 @@
         
         BridgeContext ctx = new PDFBridgeContext(ua, 
                 (strokeText ? null : pdfInfo.fi),
+                userAgent.getFactory().getImageManager(),
+                userAgent.getImageSessionContext(),
                 new AffineTransform());
         
         GraphicsNode root;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java?rev=611278&r1=611277&r2=611278&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java Fri Jan 11 11:50:53 2008
@@ -24,33 +24,43 @@
 import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 
-import org.apache.fop.render.Graphics2DAdapter;
-import org.apache.fop.render.Graphics2DImagePainter;
-import org.apache.fop.render.RendererContext;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
 import org.apache.xmlgraphics.java2d.ps.PSGraphics2D;
 import org.apache.xmlgraphics.ps.PSGenerator;
 
+import org.apache.fop.render.Graphics2DAdapter;
+import org.apache.fop.render.RendererContext;
+
 /**
  * Graphics2DAdapter implementation for PostScript.
  */
 public class PSGraphics2DAdapter implements Graphics2DAdapter {
 
-    private PSRenderer renderer;
+    private PSGenerator gen;
+    private boolean clip = true;
 
     /**
      * Main constructor
      * @param renderer the Renderer instance to which this instance belongs
      */
     public PSGraphics2DAdapter(PSRenderer renderer) {
-        this.renderer = renderer;
+        this(renderer.gen, true);
+    }
+    
+    /**
+     * Constructor for use without a PSRenderer instance.
+     * @param gen the PostScript generator
+     * @param clip true if the image should be clipped
+     */
+    public PSGraphics2DAdapter(PSGenerator gen, boolean clip) {
+        this.gen = gen;
+        this.clip = clip;
     }
     
     /** {@inheritDoc} */
     public void paintImage(Graphics2DImagePainter painter, 
             RendererContext context,
             int x, int y, int width, int height) throws IOException {
-        PSGenerator gen = renderer.gen;
-        
         float fwidth = width / 1000f;
         float fheight = height / 1000f;
         float fx = x / 1000f;
@@ -66,10 +76,12 @@
 
         gen.commentln("%FOPBeginGraphics2D");
         gen.saveGraphicsState();
-        // Clip to the image area.
-        gen.writeln("newpath");
-        gen.defineRect(fx, fy, fwidth, fheight);
-        gen.writeln("clip");
+        if (clip) {
+            // Clip to the image area.
+            gen.writeln("newpath");
+            gen.defineRect(fx, fy, fwidth, fheight);
+            gen.writeln("clip");
+        }
         
         // 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

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSImageUtils.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSImageUtils.java?rev=611278&r1=611277&r2=611278&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSImageUtils.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSImageUtils.java Fri Jan 11 11:50:53 2008
@@ -19,20 +19,15 @@
  
 package org.apache.fop.render.ps;
 
-import java.awt.Dimension;
-import java.awt.geom.Rectangle2D;
-import java.io.IOException;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.xmlgraphics.ps.PSGenerator;
+
 import org.apache.fop.image.EPSImage;
 import org.apache.fop.image.FopImage;
-import org.apache.fop.image.JpegImage;
-import org.apache.xmlgraphics.ps.PSGenerator;
-import org.apache.xmlgraphics.ps.PSResource;
 
 /**
- * Utility code for rendering images in PostScript. 
+ * Utility code for rendering images in PostScript.
  */
 public class PSImageUtils extends org.apache.xmlgraphics.ps.PSImageUtils {
 
@@ -40,93 +35,6 @@
     protected static Log log = LogFactory.getLog(PSImageUtils.class);
 
     /**
-     * Renders a bitmap image to PostScript.
-     * @param img image to render
-     * @param x x position
-     * @param y y position
-     * @param w width
-     * @param h height
-     * @param gen PS generator
-     * @throws IOException In case of an I/O problem while rendering the image
-     */
-    public static void renderBitmapImage(FopImage img, 
-                float x, float y, float w, float h, PSGenerator gen)
-                    throws IOException {
-        boolean isJPEG = (img instanceof JpegImage && (gen.getPSLevel() >= 3));
-        byte[] imgmap = convertImageToRawBitmapArray(img, isJPEG);
-        if (imgmap == null) {
-            gen.commentln("%Image data is not available: " + img);
-            return; //Image cannot be converted 
-        }
-        
-        String imgDescription = img.getMimeType() + " " + img.getOriginalURI();
-        Dimension imgDim = new Dimension(img.getWidth(), img.getHeight());
-        Rectangle2D targetRect = new Rectangle2D.Double(x, y, w, h);
-        writeImage(imgmap, imgDim, imgDescription, targetRect, isJPEG, 
-                img.getColorSpace(), gen);
-    }
-
-    /**
-     * Renders a bitmap image (as form) to PostScript.
-     * @param img image to render
-     * @param form the form resource
-     * @param x x position
-     * @param y y position
-     * @param w width
-     * @param h height
-     * @param gen PS generator
-     * @throws IOException In case of an I/O problem while rendering the image
-     */
-    public static void renderForm(FopImage img, PSResource form, 
-                float x, float y, float w, float h, PSGenerator gen)
-                    throws IOException {
-        Rectangle2D targetRect = new Rectangle2D.Double(x, y, w, h);
-        paintForm(form, targetRect, gen);
-    }
-    
-    /**
-     * Generates a form resource for a FopImage in PostScript.
-     * @param img image to render
-     * @param form the form resource
-     * @param gen PS generator
-     * @throws IOException In case of an I/O problem while rendering the image
-     */
-    public static void generateFormResourceForImage(FopImage img, PSResource form,
-                PSGenerator gen) throws IOException {
-        boolean isJPEG = (img instanceof JpegImage && (gen.getPSLevel() >= 3));
-        byte[] imgmap = convertImageToRawBitmapArray(img, isJPEG);
-        if (imgmap == null) {
-            gen.commentln("%Image data is not available: " + img);
-            return; //Image cannot be converted 
-        }
-        
-        String imgDescription = img.getMimeType() + " " + img.getOriginalURI();
-        Dimension imgDim = new Dimension(img.getWidth(), img.getHeight());
-        writeReusableImage(imgmap, imgDim, form.getName(), imgDescription, isJPEG, 
-                img.getColorSpace(), gen);
-    }
-
-    private static byte[] convertImageToRawBitmapArray(FopImage img, boolean allowUndecodedJPEG)
-                throws IOException {
-        if (img instanceof JpegImage && allowUndecodedJPEG) {
-            if (!img.load(FopImage.ORIGINAL_DATA)) {
-                return null;
-            }
-        } else {
-            if (!img.load(FopImage.BITMAP)) {
-                return null;
-            }
-        }
-        byte[] imgmap;
-        if (img.getBitmapsSize() > 0) {
-            imgmap = img.getBitmaps();
-        } else {
-            imgmap = img.getRessourceBytes();
-        }
-        return imgmap;
-    }
-
-    /**
      * Renders an EPS image to PostScript.
      * @param img EPS image to render
      * @param x x position
@@ -134,6 +42,8 @@
      * @param w width
      * @param h height
      * @param gen PS generator
+     * @deprecated Use {@link #renderEPS(java.io.InputStream, String, java.awt.geom.Rectangle2D,
+     *          java.awt.geom.Rectangle2D, PSGenerator)} instead
      */
     public static void renderEPS(EPSImage img, 
             float x, float y, float w, float h,



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