xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r603632 - in /xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop: render/pdf/PDFSVGHandler.java svg/PDFBridgeContext.java svg/PDFGraphics2D.java svg/PDFImageElementBridge.java svg/PDFTranscoder.java
Date Wed, 12 Dec 2007 14:52:12 GMT
Author: jeremias
Date: Wed Dec 12 06:52:09 2007
New Revision: 603632

URL: http://svn.apache.org/viewvc?rev=603632&view=rev
Log:
Switch to new image package for PDF/SVG support.

Modified:
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFBridgeContext.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFGraphics2D.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFImageElementBridge.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFTranscoder.java

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java?rev=603632&r1=603631&r2=603632&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
(original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
Wed Dec 12 06:52:09 2007
@@ -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,12 +152,13 @@
         int xOffset = pdfInfo.currentXPosition;
         int yOffset = pdfInfo.currentYPosition;
 
+        FOUserAgent userAgent = context.getUserAgent(); 
         log.debug("Generating SVG at " 
-                + context.getUserAgent().getTargetResolution()
+                + userAgent.getTargetResolution()
                 + "dpi.");
-        final float deviceResolution = context.getUserAgent().getTargetResolution();
+        final float deviceResolution = userAgent.getTargetResolution();
         
-        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
@@ -178,6 +177,8 @@
         
         BridgeContext ctx = new PDFBridgeContext(ua, 
                 (strokeText ? null : pdfInfo.fi),
+                userAgent.getFactory().getImageManager(),
+                userAgent.getImageSessionContext(),
                 new AffineTransform());
         
         GraphicsNode root;

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFBridgeContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFBridgeContext.java?rev=603632&r1=603631&r2=603632&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFBridgeContext.java
(original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFBridgeContext.java
Wed Dec 12 06:52:09 2007
@@ -26,7 +26,10 @@
 import org.apache.batik.bridge.BridgeContext;
 import org.apache.batik.bridge.DocumentLoader;
 import org.apache.batik.bridge.UserAgent;
+
 import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.image2.ImageManager;
+import org.apache.fop.image2.ImageSessionContext;
 
 /**
  * BridgeContext which registers the custom bridges for PDF output.
@@ -36,6 +39,9 @@
     /** The font list. */
     private final FontInfo fontInfo;
 
+    private final ImageManager imageManager;
+    private final ImageSessionContext imageSessionContext;
+
     private AffineTransform linkTransform;
     
     /**
@@ -50,9 +56,13 @@
     public PDFBridgeContext(UserAgent userAgent,
                             DocumentLoader loader,
                             FontInfo fontInfo,
+                            ImageManager imageManager,
+                            ImageSessionContext imageSessionContext,
                             AffineTransform linkTransform) {
         super(userAgent, loader);
         this.fontInfo = fontInfo;
+        this.imageManager = imageManager;
+        this.imageSessionContext = imageSessionContext;
         this.linkTransform = linkTransform;
     }
 
@@ -66,9 +76,13 @@
      */
     public PDFBridgeContext(UserAgent userAgent, 
                             FontInfo fontInfo, 
+                            ImageManager imageManager,
+                            ImageSessionContext imageSessionContext,
                             AffineTransform linkTransform) {
         super(userAgent);
         this.fontInfo = fontInfo;
+        this.imageManager = imageManager;
+        this.imageSessionContext = imageSessionContext;
         this.linkTransform = linkTransform;
     }
 
@@ -78,10 +92,29 @@
      * @param fontInfo the font list for the text painter, may be null
      *                 in which case text is painted as shapes
      */
-    public PDFBridgeContext(UserAgent userAgent, FontInfo fontInfo) {
-        this(userAgent, fontInfo, null);
+    public PDFBridgeContext(UserAgent userAgent,
+                            FontInfo fontInfo,
+                            ImageManager imageManager,
+                            ImageSessionContext imageSessionContext) {
+        this(userAgent, fontInfo, imageManager, imageSessionContext, null);
+    }
+
+    /**
+     * Returns the ImageManager to be used by the ImageElementBridge.
+     * @return the image manager
+     */
+    public ImageManager getImageManager() {
+        return this.imageManager;
     }
 
+    /**
+     * Returns the ImageSessionContext to be used by the ImageElementBridge.
+     * @return the image session context
+     */
+    public ImageSessionContext getImageSessionContext() {
+        return this.imageSessionContext;
+    }
+    
     private void putPDFElementBridgeConditional(String className, String testFor) {
         try {
             Class.forName(testFor);
@@ -136,7 +169,10 @@
     //TODO There's no matching method in the super-class here
     public BridgeContext createBridgeContext() {
         return new PDFBridgeContext(getUserAgent(), getDocumentLoader(),
-                                    fontInfo, linkTransform);
+                                    fontInfo,
+                                    getImageManager(),
+                                    getImageSessionContext(),
+                                    linkTransform);
     }
-    
+
 }

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFGraphics2D.java?rev=603632&r1=603631&r2=603632&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFGraphics2D.java
(original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFGraphics2D.java
Wed Dec 12 06:52:09 2007
@@ -62,13 +62,16 @@
 import org.apache.batik.ext.awt.RenderingHintsKeyExt;
 import org.apache.batik.gvt.GraphicsNode;
 import org.apache.batik.gvt.PatternPaint;
+import org.apache.xmlgraphics.java2d.AbstractGraphics2D;
+import org.apache.xmlgraphics.java2d.GraphicContext;
+
 import org.apache.fop.fonts.CIDFont;
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontSetup;
 import org.apache.fop.fonts.FontTriplet;
 import org.apache.fop.fonts.LazyFont;
-import org.apache.fop.image.JpegImage;
+import org.apache.fop.image2.impl.ImageRawJPEG;
 import org.apache.fop.pdf.BitmapImage;
 import org.apache.fop.pdf.PDFAnnotList;
 import org.apache.fop.pdf.PDFColor;
@@ -76,6 +79,7 @@
 import org.apache.fop.pdf.PDFDeviceColorSpace;
 import org.apache.fop.pdf.PDFDocument;
 import org.apache.fop.pdf.PDFGState;
+import org.apache.fop.pdf.PDFImage;
 import org.apache.fop.pdf.PDFImageXObject;
 import org.apache.fop.pdf.PDFLink;
 import org.apache.fop.pdf.PDFName;
@@ -86,10 +90,8 @@
 import org.apache.fop.pdf.PDFState;
 import org.apache.fop.pdf.PDFText;
 import org.apache.fop.pdf.PDFXObject;
-import org.apache.fop.render.pdf.FopPDFImage;
+import org.apache.fop.render.pdf.ImageRawJPEGAdapter;
 import org.apache.fop.util.ColorExt;
-import org.apache.xmlgraphics.java2d.AbstractGraphics2D;
-import org.apache.xmlgraphics.java2d.GraphicContext;
 
 /**
  * PDF Graphics 2D.
@@ -397,7 +399,7 @@
      * @param width the width to draw the image
      * @param height the height to draw the image
      */
-    public void addJpegImage(JpegImage jpeg, float x, float y, 
+    public void addJpegImage(ImageRawJPEG jpeg, float x, float y, 
                              float width, float height) {
         preparePainting();
         // Need to include hash code as when invoked from FO you
@@ -405,9 +407,9 @@
         // count is not enough.
         String key = "__AddJPEG_" + hashCode() + "_" + jpegCount[0];
         jpegCount[0]++;
-        FopPDFImage fopimage = new FopPDFImage(jpeg, key);
+        PDFImage pdfimage = new ImageRawJPEGAdapter(jpeg, key);
         PDFName imageName = this.pdfDoc.addImage(resourceContext, 
-                                              fopimage).getName();
+                                              pdfimage).getName();
         AffineTransform at = getTransform();
         double[] matrix = new double[6];
         at.getMatrix(matrix);

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFImageElementBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFImageElementBridge.java?rev=603632&r1=603631&r2=603632&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFImageElementBridge.java
(original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFImageElementBridge.java
Wed Dec 12 06:52:09 2007
@@ -19,24 +19,28 @@
  
 package org.apache.fop.svg;
 
-import org.apache.batik.bridge.SVGImageElementBridge;
-
-import java.awt.Shape;
 import java.awt.Graphics2D;
+import java.awt.Shape;
 import java.awt.geom.Rectangle2D;
-import java.io.BufferedInputStream;
-import java.io.InputStream;
 
 import org.w3c.dom.Element;
+import org.w3c.dom.svg.SVGDocument;
 
 import org.apache.batik.bridge.BridgeContext;
+import org.apache.batik.bridge.SVGImageElementBridge;
 import org.apache.batik.gvt.AbstractGraphicsNode;
 import org.apache.batik.gvt.GraphicsNode;
 import org.apache.batik.util.ParsedURL;
 
-import org.apache.fop.image.JpegImage;
-import org.apache.fop.image.FopImage;
-import org.apache.fop.image.analyser.ImageReaderFactory;
+import org.apache.fop.image2.Image;
+import org.apache.fop.image2.ImageException;
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
+import org.apache.fop.image2.ImageManager;
+import org.apache.fop.image2.ImageSessionContext;
+import org.apache.fop.image2.impl.ImageGraphics2D;
+import org.apache.fop.image2.impl.ImageRawJPEG;
+import org.apache.fop.image2.impl.ImageXMLDOM;
 
 /**
  * Bridge class for the <image> element when jpeg images.
@@ -50,6 +54,10 @@
      */
     public PDFImageElementBridge() { }
 
+    private final ImageFlavor[] supportedFlavors = new ImageFlavor[]
+                                               {ImageFlavor.RAW_JPEG,
+                                                ImageFlavor.GRAPHICS2D,
+                                                ImageFlavor.XML_DOM};
     /**
      * Create the raster image node.
      * THis checks if it is a jpeg file and creates a jpeg node
@@ -60,51 +68,68 @@
      * @return a new graphics node
      */
     protected GraphicsNode createImageGraphicsNode
-        (BridgeContext ctx, Element imageElement, ParsedURL purl) {
+                (BridgeContext ctx, Element imageElement, ParsedURL purl) {
+        PDFBridgeContext pdfCtx = (PDFBridgeContext)ctx;
+        
+        ImageManager manager = pdfCtx.getImageManager();
+        ImageSessionContext sessionContext = pdfCtx.getImageSessionContext();
         try {
-            InputStream is = purl.openStream();
-            if (!is.markSupported()) {
-                is = new BufferedInputStream(is, 1024);
-            }
+            ImageInfo info = manager.getImageInfo(purl.toString(), sessionContext);
+            Image image = manager.getImage(info, supportedFlavors, sessionContext);
             
-            is.mark(3);
-            byte [] data = new byte[3];
-            is.read(data);
-            is.reset();
-            if ((data[0] == (byte)0xFF) 
-                    && (data[1] == (byte)0xD8) 
-                    && (data[2] == (byte)0xFF)) {
-                FopImage.ImageInfo ii = ImageReaderFactory.make
-                        (purl.toString(), is, null);
-                JpegImage jpeg = new JpegImage(ii);
-                jpeg.load(FopImage.ORIGINAL_DATA);
-                PDFJpegNode node = new PDFJpegNode(jpeg, ctx, imageElement, purl);
-    
-                Rectangle2D imgBounds = getImageBounds(ctx, imageElement);
-                Rectangle2D bounds = node.getPrimitiveBounds();
-                float [] vb = new float[4];
-                vb[0] = 0; // x
-                vb[1] = 0; // y
-                vb[2] = (float) bounds.getWidth(); // width
-                vb[3] = (float) bounds.getHeight(); // height
-    
-                // handles the 'preserveAspectRatio', 'overflow' and 'clip' 
-                // and sets the appropriate AffineTransform to the image node
-                initializeViewport(ctx, imageElement, node, vb, imgBounds);
-                return node;
+            AbstractGraphicsNode specializedNode = null;
+            if (image instanceof ImageXMLDOM) {
+                ImageXMLDOM xmlImage = (ImageXMLDOM)image;
+                if (xmlImage.getDocument() instanceof SVGDocument) {
+                    return createSVGImageNode(ctx, imageElement,
+                            (SVGDocument)xmlImage.getDocument());
+                } else {
+                    //Convert image to Graphics2D
+                    image = manager.convertImage(xmlImage,
+                            new ImageFlavor[] {ImageFlavor.GRAPHICS2D});
+                }
+            }
+            if (image instanceof ImageRawJPEG) {
+                ImageRawJPEG jpegImage = (ImageRawJPEG)image;
+                specializedNode = new PDFJpegNode(jpegImage, ctx, imageElement, purl);
+                
+            } else if (image instanceof ImageGraphics2D) {
+                ImageGraphics2D g2dImage = (ImageGraphics2D)image;
+                specializedNode = new Graphics2DNode(g2dImage);
+            } else {
+                ctx.getUserAgent().displayError(
+                        new ImageException("Cannot convert an image to a usable format: "
+ purl));
             }
-        } catch (Exception ex) {
-            //TODO Handle this exception
+            
+            Rectangle2D imgBounds = getImageBounds(ctx, imageElement);
+            Rectangle2D bounds = specializedNode.getPrimitiveBounds();
+            float [] vb = new float[4];
+            vb[0] = 0; // x
+            vb[1] = 0; // y
+            vb[2] = (float) bounds.getWidth(); // width
+            vb[3] = (float) bounds.getHeight(); // height
+
+            // handles the 'preserveAspectRatio', 'overflow' and 'clip' 
+            // and sets the appropriate AffineTransform to the image node
+            initializeViewport(ctx, imageElement, specializedNode, vb, imgBounds);
+            return specializedNode;
+        } catch (Exception e) {
+            ctx.getUserAgent().displayError(e);
         }
-
+        
         return superCreateGraphicsNode(ctx, imageElement, purl);
     }
 
     /**
+     * Calls the superclass' createImageGraphicNode() method to create the normal GraphicsNode.
+     * @param ctx the bridge context
+     * @param imageElement the image element
+     * @param purl the parsed URL
+     * @return the newly created graphics node
      * @see org.apache.batik.bridge.SVGImageElementBridge#createGraphicsNode(BridgeContext,
Element)
      */
     protected GraphicsNode superCreateGraphicsNode
-        (BridgeContext ctx, Element imageElement, ParsedURL purl) {
+            (BridgeContext ctx, Element imageElement, ParsedURL purl) {
         return super.createImageGraphicsNode(ctx, imageElement, purl);
     }
 
@@ -116,21 +141,21 @@
      */
     public class PDFJpegNode extends AbstractGraphicsNode {
         
-        private JpegImage jpeg;
+        private ImageRawJPEG jpeg;
         private BridgeContext ctx;
         private Element imageElement;
         private ParsedURL purl;
         private GraphicsNode origGraphicsNode = null;
         
         /**
-         * Create a new pdf jpeg node for drawing jpeg images
+         * Create a new PDF JPEG node for drawing JPEG images
          * into pdf graphics.
-         * @param j the jpeg image
+         * @param j the JPEG image
          * @param ctx the bridge context
          * @param imageElement the SVG image element
          * @param purl the URL to the image
          */
-        public PDFJpegNode(JpegImage j, BridgeContext ctx, 
+        public PDFJpegNode(ImageRawJPEG j, BridgeContext ctx, 
                            Element imageElement, ParsedURL purl) {
             this.jpeg = j;
             this.ctx  = ctx;
@@ -138,32 +163,23 @@
             this.purl = purl;
         }
 
-        /**
-         * Get the outline of this image.
-         * @return the outline shape which is the primitive bounds
-         */
+        /** {@inheritDoc} */
         public Shape getOutline() {
             return getPrimitiveBounds();
         }
 
-        /**
-         * Paint this jpeg image.
-         * As this is used for inserting jpeg into pdf
-         * it adds the jpeg image to the PDFGraphics2D.
-         * @param g2d the graphics to draw the image on
-         */
+        /** {@inheritDoc} */
         public void primitivePaint(Graphics2D g2d) {
             if (g2d instanceof PDFGraphics2D) {
                 PDFGraphics2D pdfg = (PDFGraphics2D) g2d;
                 float x = 0;
                 float y = 0;
                 try {
-                    float width = jpeg.getWidth();
-                    float height = jpeg.getHeight();
+                    float width = jpeg.getSize().getWidthPx();
+                    float height = jpeg.getSize().getHeightPx();
                     pdfg.addJpegImage(jpeg, x, y, width, height);
                 } catch (Exception e) {
-                    //TODO Handle this exception properly
-                    e.printStackTrace();
+                    ctx.getUserAgent().displayError(e);
                 }
             } else {
                 // Not going directly into PDF so use
@@ -179,40 +195,71 @@
             }
         }
 
-        /**
-         * Get the geometrix bounds of the image.
-         * @return the primitive bounds
-         */
+        /** {@inheritDoc} */
         public Rectangle2D getGeometryBounds() {
             return getPrimitiveBounds();
         }
 
-        /**
-         * Get the primitive bounds of this bridge element.
-         * @return the bounds of the jpeg image
-         */
+        /** {@inheritDoc} */
         public Rectangle2D getPrimitiveBounds() {
-            try {
-                return new Rectangle2D.Double(0, 0, jpeg.getWidth(),
-                                              jpeg.getHeight());
-            } catch (Exception e) {
-                //TODO Handle this exception properly
-                e.printStackTrace();
-            }
-            return null;
+            return new Rectangle2D.Double(0, 0,
+                       jpeg.getSize().getWidthPx(),
+                       jpeg.getSize().getHeightPx());
         }
 
+        /** {@inheritDoc} */
+        public Rectangle2D getSensitiveBounds() {
+            //No interactive features, just return primitive bounds
+            return getPrimitiveBounds();
+        }
+
+    }
+
+    /**
+     * A node that holds a Graphics2D image.
+     */
+    public class Graphics2DNode extends AbstractGraphicsNode {
+        
+        private ImageGraphics2D image;
+        
         /**
-         * Returns the bounds of the sensitive area covered by this node,
-         * This includes the stroked area but does not include the effects
-         * of clipping, masking or filtering.
-         * @return the bounds of the sensitive area
+         * Create a new Graphics2D node.
+         * @param g2d the Graphics2D image
          */
+        public Graphics2DNode(ImageGraphics2D g2d) {
+            this.image = g2d;
+        }
+
+        /** {@inheritDoc} */
+        public Shape getOutline() {
+            return getPrimitiveBounds();
+        }
+
+        /** {@inheritDoc} */
+        public void primitivePaint(Graphics2D g2d) {
+            int width = image.getSize().getWidthPx();
+            int height = image.getSize().getHeightPx();
+            Rectangle2D area = new Rectangle2D.Double(0, 0, width, height);
+            image.getGraphics2DImagePainter().paint(g2d, area);
+        }
+
+        /** {@inheritDoc} */
+        public Rectangle2D getGeometryBounds() {
+            return getPrimitiveBounds();
+        }
+
+        /** {@inheritDoc} */
+        public Rectangle2D getPrimitiveBounds() {
+            return new Rectangle2D.Double(0, 0,
+                    image.getSize().getWidthPx(),
+                    image.getSize().getHeightPx());
+        }
+
+        /** {@inheritDoc} */
         public Rectangle2D getSensitiveBounds() {
             //No interactive features, just return primitive bounds
             return getPrimitiveBounds();
         }
 
     }
-
 }

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFTranscoder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFTranscoder.java?rev=603632&r1=603631&r2=603632&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFTranscoder.java
(original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/svg/PDFTranscoder.java
Wed Dec 12 06:52:09 2007
@@ -21,6 +21,13 @@
 
 import java.awt.Color;
 import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.svg.SVGLength;
 
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
@@ -36,10 +43,14 @@
 import org.apache.batik.transcoder.image.ImageTranscoder;
 import org.apache.batik.transcoder.keys.BooleanKey;
 import org.apache.batik.transcoder.keys.FloatKey;
+import org.apache.batik.util.ParsedURL;
+
 import org.apache.fop.Version;
 import org.apache.fop.fonts.FontInfo;
-import org.w3c.dom.Document;
-import org.w3c.dom.svg.SVGLength;
+import org.apache.fop.image2.ImageContext;
+import org.apache.fop.image2.ImageManager;
+import org.apache.fop.image2.ImageSessionContext;
+import org.apache.fop.image2.impl.AbstractImageSessionContext;
 
 /**
  * This class enables to transcode an input to a pdf document.
@@ -95,6 +106,9 @@
     /** Graphics2D instance that is used to paint to */
     protected PDFDocumentGraphics2D graphics = null;
 
+    private ImageManager imageManager;
+    private ImageSessionContext imageSessionContext;
+    
     /**
      * Constructs a new <tt>PDFTranscoder</tt>.
      */
@@ -137,6 +151,11 @@
         graphics.getPDFDocument().getInfo().setProducer("Apache FOP Version " 
                 + Version.getVersion() 
                 + ": PDF Transcoder for Batik");
+        if (hints.containsKey(KEY_DEVICE_RESOLUTION)) {
+            graphics.setDeviceDPI(((Float)hints.get(KEY_DEVICE_RESOLUTION)).floatValue());
+        }
+        
+        setupImageInfrastructure(uri);
         
         try {
             Configuration effCfg = this.cfg; 
@@ -192,9 +211,6 @@
         //int h = (int)(height + 0.5);
 
         try {
-            if (hints.containsKey(KEY_DEVICE_RESOLUTION)) {
-                graphics.setDeviceDPI(((Float)hints.get(KEY_DEVICE_RESOLUTION)).floatValue());
-            }
             graphics.setupDocument(output.getOutputStream(), w, h);
             graphics.setSVGDimension(width, height);
 
@@ -219,6 +235,39 @@
         }
     }
 
+    private void setupImageInfrastructure(final String baseURI) {
+        final ImageContext imageContext = new ImageContext() {
+            public float getSourceResolution() {
+                return 25.4f / userAgent.getPixelUnitToMillimeter();
+            }
+        };
+        this.imageManager = new ImageManager(imageContext);
+        this.imageSessionContext = new AbstractImageSessionContext() {
+
+            public ImageContext getParentContext() {
+                return imageContext;
+            }
+
+            public float getTargetResolution() {
+                return graphics.getDeviceDPI();
+            }
+
+            public Source resolveURI(String uri) {
+                System.out.println("resolve " + uri);
+                try {
+                    ParsedURL url = new ParsedURL(baseURI, uri);
+                    InputStream in = url.openStream();
+                    StreamSource source = new StreamSource(in, url.toString());
+                    return source;
+                } catch (IOException ioe) {
+                    userAgent.displayError(ioe);
+                    return null;
+                }
+            }
+            
+        };
+    }
+
     /** {@inheritDoc} */
     protected BridgeContext createBridgeContext() {
         //For compatibility with Batik 1.6
@@ -231,7 +280,8 @@
         if (isTextStroked()) {
             fontInfo = null;
         }
-        BridgeContext ctx = new PDFBridgeContext(userAgent, fontInfo);
+        BridgeContext ctx = new PDFBridgeContext(userAgent, fontInfo,
+                this.imageManager, this.imageSessionContext);
         return ctx;
     }
     



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