xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r733456 [2/2] - in /xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java: META-INF/services/ org/apache/fop/afp/modca/ org/apache/fop/afp/ptoca/ org/apache/fop/render/ org/apache/fop/render/afp/
Date Sun, 11 Jan 2009 11:31:26 GMT
Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandler.java?rev=733456&r1=733455&r2=733456&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandler.java Sun Jan 11 03:31:24 2009
@@ -20,6 +20,7 @@
 package org.apache.fop.render.afp;
 
 import java.awt.Point;
+import java.awt.Rectangle;
 import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 import java.util.Map;
@@ -55,33 +56,64 @@
         AFPDataObjectInfo dataObjectInfo = createDataObjectInfo();
 
         // set resource information
-        Map foreignAttributes = rendererImageInfo.getForeignAttributes();
-        AFPResourceInfo resourceInfo
-            = foreignAttributeReader.getResourceInfo(foreignAttributes);
-        resourceInfo.setUri(rendererImageInfo.getURI());
-        dataObjectInfo.setResourceInfo(resourceInfo);
+        setResourceInformation(dataObjectInfo,
+                rendererImageInfo.getURI(),
+                rendererImageInfo.getForeignAttributes());
 
-        // set object area
-        AFPObjectAreaInfo objectAreaInfo = new AFPObjectAreaInfo();
 
         Point origin = rendererImageInfo.getOrigin();
         Rectangle2D position = rendererImageInfo.getPosition();
-        float srcX = origin.x + (float)position.getX();
-        float srcY = origin.y + (float)position.getY();
+        int srcX = Math.round(origin.x + (float)position.getX());
+        int srcY = Math.round(origin.y + (float)position.getY());
+        Rectangle targetRect = new Rectangle(
+                srcX,
+                srcY,
+                (int)Math.round(position.getWidth()),
+                (int)Math.round(position.getHeight()));
 
         AFPRendererContext rendererContext
             = (AFPRendererContext)rendererImageInfo.getRendererContext();
         AFPInfo afpInfo = rendererContext.getInfo();
         AFPPaintingState paintingState = afpInfo.getPaintingState();
+
+        dataObjectInfo.setObjectAreaInfo(createObjectAreaInfo(paintingState, targetRect));
+
+        return dataObjectInfo;
+    }
+
+    /**
+     * Sets resource information on the data object info.
+     * @param dataObjectInfo the data object info instance
+     * @param uri the image's URI (or null if no URI is available)
+     * @param foreignAttributes a Map of foreign attributes (or null)
+     */
+    protected void setResourceInformation(AFPDataObjectInfo dataObjectInfo,
+            String uri, Map foreignAttributes) {
+        AFPResourceInfo resourceInfo
+            = foreignAttributeReader.getResourceInfo(foreignAttributes);
+        resourceInfo.setUri(uri);
+        dataObjectInfo.setResourceInfo(resourceInfo);
+    }
+
+    /**
+     * Creates and returns an {@link AFPObjectAreaInfo} instance for the placement of the image.
+     * @param paintingState the painting state
+     * @param targetRect the target rectangle in which to place the image (coordinates in mpt)
+     * @return the newly created object area info instance
+     */
+    public static AFPObjectAreaInfo createObjectAreaInfo(AFPPaintingState paintingState,
+            Rectangle targetRect) {
+        AFPObjectAreaInfo objectAreaInfo = new AFPObjectAreaInfo();
         AFPUnitConverter unitConv = paintingState.getUnitConverter();
-        int[] coords = unitConv.mpts2units(new float[] {srcX, srcY});
+
+        int[] coords = unitConv.mpts2units(new float[] {targetRect.x, targetRect.y});
         objectAreaInfo.setX(coords[X]);
         objectAreaInfo.setY(coords[Y]);
 
-        int width = Math.round(unitConv.mpt2units((float)position.getWidth()));
+        int width = Math.round(unitConv.mpt2units(targetRect.width));
         objectAreaInfo.setWidth(width);
 
-        int height = Math.round(unitConv.mpt2units((float)position.getHeight()));
+        int height = Math.round(unitConv.mpt2units(targetRect.height));
         objectAreaInfo.setHeight(height);
 
         int resolution = paintingState.getResolution();
@@ -89,10 +121,7 @@
         objectAreaInfo.setWidthRes(resolution);
 
         objectAreaInfo.setRotation(paintingState.getRotation());
-
-        dataObjectInfo.setObjectAreaInfo(objectAreaInfo);
-
-        return dataObjectInfo;
+        return objectAreaInfo;
     }
 
     /**

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java?rev=733456&r1=733455&r2=733456&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java Sun Jan 11 03:31:24 2009
@@ -19,23 +19,29 @@
 
 package org.apache.fop.render.afp;
 
+import java.awt.Rectangle;
 import java.io.IOException;
 
+import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+import org.apache.xmlgraphics.util.MimeConstants;
+
 import org.apache.fop.afp.AFPDataObjectInfo;
 import org.apache.fop.afp.AFPGraphics2D;
 import org.apache.fop.afp.AFPGraphicsObjectInfo;
 import org.apache.fop.afp.AFPPaintingState;
 import org.apache.fop.afp.AFPResourceInfo;
 import org.apache.fop.afp.AFPResourceLevel;
-import org.apache.xmlgraphics.image.loader.ImageFlavor;
-import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
-import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
-import org.apache.xmlgraphics.util.MimeConstants;
+import org.apache.fop.render.ImageHandler;
+import org.apache.fop.render.ImageHandlerUtil;
+import org.apache.fop.render.RenderingContext;
 
 /**
  * PDFImageHandler implementation which handles Graphics2D images.
  */
-public class AFPImageHandlerGraphics2D extends AFPImageHandler {
+public class AFPImageHandlerGraphics2D extends AFPImageHandler implements ImageHandler {
 
     private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
         ImageFlavor.GRAPHICS2D
@@ -64,19 +70,13 @@
             AFPGraphicsObjectInfo graphicsObjectInfo
                 = (AFPGraphicsObjectInfo)super.generateDataObjectInfo(rendererImageInfo);
 
-            AFPResourceInfo resourceInfo = graphicsObjectInfo.getResourceInfo();
-            //level not explicitly set/changed so default to inline for GOCA graphic objects
-            // (due to a bug in the IBM AFP Workbench Viewer (2.04.01.07), hard copy works just fine)
-            if (!resourceInfo.levelChanged()) {
-                resourceInfo.setLevel(new AFPResourceLevel(AFPResourceLevel.INLINE));
-            }
+            setDefaultToInlineResourceLevel(graphicsObjectInfo);
 
             // set mime type (unsupported by MOD:CA registry)
             graphicsObjectInfo.setMimeType(MimeConstants.MIME_AFP_GOCA);
 
             // set g2d
             boolean textAsShapes = false;
-
             AFPGraphics2D g2d = afpInfo.createGraphics2D(textAsShapes);
 
             graphicsObjectInfo.setGraphics2D(g2d);
@@ -88,6 +88,15 @@
         }
     }
 
+    private void setDefaultToInlineResourceLevel(AFPGraphicsObjectInfo graphicsObjectInfo) {
+        AFPResourceInfo resourceInfo = graphicsObjectInfo.getResourceInfo();
+        //level not explicitly set/changed so default to inline for GOCA graphic objects
+        // (due to a bug in the IBM AFP Workbench Viewer (2.04.01.07), hard copy works just fine)
+        if (!resourceInfo.levelChanged()) {
+            resourceInfo.setLevel(new AFPResourceLevel(AFPResourceLevel.INLINE));
+        }
+    }
+
     /** {@inheritDoc} */
     public int getPriority() {
         return 200;
@@ -107,4 +116,54 @@
     protected AFPDataObjectInfo createDataObjectInfo() {
         return new AFPGraphicsObjectInfo();
     }
+
+    /** {@inheritDoc} */
+    public void handleImage(RenderingContext context, Image image, Rectangle pos)
+            throws IOException {
+        AFPRenderingContext afpContext = (AFPRenderingContext)context;
+
+        AFPGraphicsObjectInfo graphicsObjectInfo = (AFPGraphicsObjectInfo)createDataObjectInfo();
+
+        // set resource information
+        setResourceInformation(graphicsObjectInfo,
+                image.getInfo().getOriginalURI(),
+                afpContext.getForeignAttributes());
+
+        // Positioning
+        graphicsObjectInfo.setObjectAreaInfo(
+                createObjectAreaInfo(afpContext.getPaintingState(), pos));
+
+        setDefaultToInlineResourceLevel(graphicsObjectInfo);
+
+        // Image content
+        ImageGraphics2D imageG2D = (ImageGraphics2D)image;
+        boolean textAsShapes = false; //TODO Make configurable
+        AFPGraphics2D g2d = new AFPGraphics2D(
+                textAsShapes,
+                afpContext.getPaintingState(),
+                afpContext.getResourceManager(),
+                graphicsObjectInfo.getResourceInfo(),
+                afpContext.getFontInfo());
+        g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
+
+        graphicsObjectInfo.setGraphics2D(g2d);
+        graphicsObjectInfo.setPainter(imageG2D.getGraphics2DImagePainter());
+
+        // Create image
+        afpContext.getResourceManager().createObject(graphicsObjectInfo);
+    }
+
+    /** {@inheritDoc} */
+    public boolean isCompatible(RenderingContext targetContext, Image image) {
+        boolean supported = (image == null || image instanceof ImageGraphics2D)
+                && targetContext instanceof AFPRenderingContext;
+        if (supported) {
+            String mode = (String)targetContext.getHint(ImageHandlerUtil.CONVERSION_MODE);
+            if (ImageHandlerUtil.isConversionModeBitmap(mode)) {
+                //Disabling this image handler automatically causes a bitmap to be generated
+                return false;
+            }
+        }
+        return supported;
+    }
 }

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerRawCCITTFax.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerRawCCITTFax.java?rev=733456&r1=733455&r2=733456&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerRawCCITTFax.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerRawCCITTFax.java Sun Jan 11 03:31:24 2009
@@ -19,12 +19,15 @@
 
 package org.apache.fop.render.afp;
 
-import java.io.IOException;
+import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
+import org.apache.xmlgraphics.util.MimeConstants;
 
 import org.apache.fop.afp.AFPDataObjectInfo;
 import org.apache.fop.afp.AFPImageObjectInfo;
-import org.apache.xmlgraphics.image.loader.ImageFlavor;
-import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
+import org.apache.fop.render.RenderingContext;
 
 /**
  * AFPImageHandler implementation which handles CCITT encoded images (CCITT fax group 3/4).
@@ -36,17 +39,18 @@
     };
 
     /** {@inheritDoc} */
-    public AFPDataObjectInfo generateDataObjectInfo(
-            AFPRendererImageInfo rendererImageInfo) throws IOException {
-        AFPImageObjectInfo imageObjectInfo
-            = (AFPImageObjectInfo)super.generateDataObjectInfo(rendererImageInfo);
-
-        ImageRawCCITTFax ccitt = (ImageRawCCITTFax) rendererImageInfo.getImage();
+    protected void setAdditionalParameters(AFPDataObjectInfo dataObjectInfo,
+            ImageRawStream image) {
+        AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo)dataObjectInfo;
+        ImageRawCCITTFax ccitt = (ImageRawCCITTFax)image;
         int compression = ccitt.getCompression();
         imageObjectInfo.setCompression(compression);
 
         imageObjectInfo.setBitsPerPixel(1);
-        return imageObjectInfo;
+
+        //CCITTFax flavor doesn't have TIFF associated but the AFP library listens to
+        //that to identify CCITT encoded images. CCITT is not exclusive to TIFF.
+        imageObjectInfo.setMimeType(MimeConstants.MIME_TIFF);
     }
 
     /** {@inheritDoc} */
@@ -69,4 +73,14 @@
         return FLAVORS;
     }
 
+    /** {@inheritDoc} */
+    public boolean isCompatible(RenderingContext targetContext, Image image) {
+        if (targetContext instanceof AFPRenderingContext) {
+            AFPRenderingContext afpContext = (AFPRenderingContext)targetContext;
+            return (afpContext.getPaintingState().isNativeImagesSupported())
+                && (image == null || image instanceof ImageRawCCITTFax);
+        }
+        return false;
+    }
+
 }

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java?rev=733456&r1=733455&r2=733456&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java Sun Jan 11 03:31:24 2009
@@ -19,10 +19,15 @@
 
 package org.apache.fop.render.afp;
 
-import org.apache.fop.afp.AFPDataObjectInfo;
+import org.apache.xmlgraphics.image.loader.Image;
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawEPS;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawJPEG;
 import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
 
+import org.apache.fop.afp.AFPDataObjectInfo;
+import org.apache.fop.render.RenderingContext;
+
 /**
  * AFPImageHandler implementation which handles raw stream images.
  */
@@ -52,4 +57,14 @@
     protected AFPDataObjectInfo createDataObjectInfo() {
         return new AFPDataObjectInfo();
     }
+
+    /** {@inheritDoc} */
+    public boolean isCompatible(RenderingContext targetContext, Image image) {
+        if (targetContext instanceof AFPRenderingContext) {
+            AFPRenderingContext afpContext = (AFPRenderingContext)targetContext;
+            return (afpContext.getPaintingState().isNativeImagesSupported())
+                && (image == null || image instanceof ImageRawJPEG || image instanceof ImageRawEPS);
+        }
+        return false;
+    }
 }

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java?rev=733456&r1=733455&r2=733456&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java Sun Jan 11 03:31:24 2009
@@ -19,23 +19,29 @@
 
 package org.apache.fop.render.afp;
 
+import java.awt.Rectangle;
 import java.awt.image.RenderedImage;
 import java.io.IOException;
 
 import org.apache.commons.io.output.ByteArrayOutputStream;
-import org.apache.fop.afp.AFPDataObjectInfo;
-import org.apache.fop.afp.AFPImageObjectInfo;
-import org.apache.fop.afp.AFPObjectAreaInfo;
-import org.apache.fop.afp.AFPPaintingState;
+
+import org.apache.xmlgraphics.image.loader.Image;
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
 import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
 import org.apache.xmlgraphics.ps.ImageEncodingHelper;
 import org.apache.xmlgraphics.util.MimeConstants;
 
+import org.apache.fop.afp.AFPDataObjectInfo;
+import org.apache.fop.afp.AFPImageObjectInfo;
+import org.apache.fop.afp.AFPObjectAreaInfo;
+import org.apache.fop.afp.AFPPaintingState;
+import org.apache.fop.render.ImageHandler;
+import org.apache.fop.render.RenderingContext;
+
 /**
  * PDFImageHandler implementation which handles RenderedImage instances.
  */
-public class AFPImageHandlerRenderedImage extends AFPImageHandler {
+public class AFPImageHandlerRenderedImage extends AFPImageHandler implements ImageHandler {
 
     private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
         ImageFlavor.BUFFERED_IMAGE,
@@ -52,13 +58,22 @@
             = (AFPRendererContext)rendererImageInfo.getRendererContext();
         AFPInfo afpInfo = rendererContext.getInfo();
         AFPPaintingState paintingState = afpInfo.getPaintingState();
+        ImageRendered imageRendered = (ImageRendered) rendererImageInfo.img;
+
+        updateDataObjectInfo(imageObjectInfo, paintingState, imageRendered);
+        return imageObjectInfo;
+    }
+
+    private AFPDataObjectInfo updateDataObjectInfo(AFPImageObjectInfo imageObjectInfo,
+            AFPPaintingState paintingState, ImageRendered imageRendered)
+            throws IOException {
+
         int resolution = paintingState.getResolution();
 
         imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS45);
         imageObjectInfo.setDataHeightRes(resolution);
         imageObjectInfo.setDataWidthRes(resolution);
 
-        ImageRendered imageRendered = (ImageRendered) rendererImageInfo.img;
         RenderedImage renderedImage = imageRendered.getRenderedImage();
 
         int dataHeight = renderedImage.getHeight();
@@ -67,6 +82,13 @@
         int dataWidth = renderedImage.getWidth();
         imageObjectInfo.setDataWidth(dataWidth);
 
+        //TODO This needs to be improved: Buffering whole images in memory is bad.
+        //Images with fewer bits per pixel than the required output format are unnecessarily
+        //increased in size (extreme case: 1-bit images are blown up to 24 bits if color is
+        //enabled). For grayscale output, encoding is even a two-step process which
+        //needs to be streamlined to a single step. The resulting bitmap is then still buffered
+        //in memory. To reduce AFP file size, investigate using a compression scheme.
+        //Currently, all image data is uncompressed.
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ImageEncodingHelper.encodeRenderedImageAsRGB(renderedImage, baos);
         byte[] imageData = baos.toByteArray();
@@ -113,4 +135,33 @@
         return FLAVORS;
     }
 
+    /** {@inheritDoc} */
+    public void handleImage(RenderingContext context, Image image, Rectangle pos)
+            throws IOException {
+        AFPRenderingContext afpContext = (AFPRenderingContext)context;
+
+        AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo)createDataObjectInfo();
+
+        // set resource information
+        setResourceInformation(imageObjectInfo,
+                image.getInfo().getOriginalURI(),
+                afpContext.getForeignAttributes());
+
+        // Positioning
+        imageObjectInfo.setObjectAreaInfo(createObjectAreaInfo(afpContext.getPaintingState(), pos));
+
+        // Image content
+        ImageRendered imageRend = (ImageRendered)image;
+        updateDataObjectInfo(imageObjectInfo, afpContext.getPaintingState(), imageRend);
+
+        // Create image
+        afpContext.getResourceManager().createObject(imageObjectInfo);
+    }
+
+    /** {@inheritDoc} */
+    public boolean isCompatible(RenderingContext targetContext, Image image) {
+        return (image == null || image instanceof ImageRendered)
+            && targetContext instanceof AFPRenderingContext;
+    }
+
 }

Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java?rev=733456&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java Sun Jan 11 03:31:24 2009
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.afp;
+
+import java.awt.Dimension;
+import java.awt.Rectangle;
+import java.io.IOException;
+
+import org.w3c.dom.Document;
+
+import org.apache.batik.bridge.BridgeContext;
+import org.apache.batik.bridge.GVTBuilder;
+import org.apache.batik.gvt.GraphicsNode;
+
+import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+
+import org.apache.fop.afp.AFPDataObjectInfo;
+import org.apache.fop.afp.AFPGraphics2D;
+import org.apache.fop.afp.AFPGraphicsObjectInfo;
+import org.apache.fop.afp.AFPObjectAreaInfo;
+import org.apache.fop.afp.AFPPaintingState;
+import org.apache.fop.afp.AFPResourceInfo;
+import org.apache.fop.afp.AFPResourceLevel;
+import org.apache.fop.afp.AFPResourceManager;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.image.loader.batik.BatikImageFlavors;
+import org.apache.fop.image.loader.batik.BatikUtil;
+import org.apache.fop.image.loader.batik.Graphics2DImagePainterImpl;
+import org.apache.fop.render.ImageHandler;
+import org.apache.fop.render.ImageHandlerUtil;
+import org.apache.fop.render.RenderingContext;
+import org.apache.fop.svg.SVGEventProducer;
+
+/**
+ * Image handler implementation which handles SVG images for AFP output.
+ * <p>
+ * Note: This class is not intended to be used as an {@link AFPImageHandler} but only as an
+ * {@link ImageHandler}. It subclasses {@link AFPImageHandler} only to get access to common
+ * methods.
+ */
+public class AFPImageHandlerSVG implements ImageHandler {
+
+    private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
+        BatikImageFlavors.SVG_DOM
+    };
+
+    /** {@inheritDoc} */
+    protected AFPDataObjectInfo createDataObjectInfo() {
+        return new AFPGraphicsObjectInfo();
+    }
+
+    /** {@inheritDoc} */
+    public void handleImage(RenderingContext context, Image image, Rectangle pos)
+                throws IOException {
+        AFPRenderingContext afpContext = (AFPRenderingContext)context;
+        ImageXMLDOM imageSVG = (ImageXMLDOM)image;
+        FOUserAgent userAgent = afpContext.getUserAgent();
+
+        AFPGraphicsObjectInfo graphicsObjectInfo = (AFPGraphicsObjectInfo)createDataObjectInfo();
+        AFPResourceInfo resourceInfo = graphicsObjectInfo.getResourceInfo();
+        setDefaultToInlineResourceLevel(graphicsObjectInfo);
+
+        // Create a new AFPGraphics2D
+        final boolean textAsShapes = false; //afpInfo.strokeText(); //TODO make configurable
+        AFPGraphics2D g2d = new AFPGraphics2D(
+                textAsShapes,
+                afpContext.getPaintingState(),
+                afpContext.getResourceManager(),
+                resourceInfo,
+                afpContext.getFontInfo());
+        g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
+
+        AFPPaintingState paintingState = g2d.getPaintingState();
+        paintingState.setImageUri(image.getInfo().getOriginalURI());
+
+        // Create an AFPBridgeContext
+        BridgeContext bridgeContext = AFPSVGHandler.createBridgeContext(userAgent, g2d);
+
+        // Cloning SVG DOM as Batik attaches non-thread-safe facilities (like the CSS engine)
+        // to it.
+        Document clonedDoc = BatikUtil.cloneSVGDocument(imageSVG.getDocument());
+
+        // Build the SVG DOM and provide the painter with it
+        GraphicsNode root;
+        try {
+            GVTBuilder builder = new GVTBuilder();
+            root = builder.build(bridgeContext, clonedDoc);
+        } catch (Exception e) {
+            SVGEventProducer eventProducer = SVGEventProducer.Provider.get(
+                    context.getUserAgent().getEventBroadcaster());
+            eventProducer.svgNotBuilt(this, e, image.getInfo().getOriginalURI());
+            return;
+        }
+
+        paintingState.save(); // save
+
+        // Image positioning
+        AFPObjectAreaInfo objectAreaInfo = AFPImageHandler.createObjectAreaInfo(paintingState, pos);
+        graphicsObjectInfo.setObjectAreaInfo(objectAreaInfo);
+
+        //Set up painter and target
+        graphicsObjectInfo.setGraphics2D(g2d);
+        // Create Graphics2DImagePainter
+        Dimension imageSize = image.getSize().getDimensionMpt();
+        Graphics2DImagePainter painter = new Graphics2DImagePainterImpl(
+                root, bridgeContext, imageSize);
+        graphicsObjectInfo.setPainter(painter);
+
+        // Create the GOCA GraphicsObject in the DataStream
+        AFPResourceManager resourceManager = afpContext.getResourceManager();
+        resourceManager.createObject(graphicsObjectInfo);
+
+        paintingState.restore(); // resume
+    }
+
+    private void setDefaultToInlineResourceLevel(AFPGraphicsObjectInfo graphicsObjectInfo) {
+        AFPResourceInfo resourceInfo = graphicsObjectInfo.getResourceInfo();
+        //level not explicitly set/changed so default to inline for GOCA graphic objects
+        // (due to a bug in the IBM AFP Workbench Viewer (2.04.01.07), hard copy works just fine)
+        if (!resourceInfo.levelChanged()) {
+            resourceInfo.setLevel(new AFPResourceLevel(AFPResourceLevel.INLINE));
+        }
+    }
+
+    /** {@inheritDoc} */
+    public int getPriority() {
+        return 400;
+    }
+
+    /** {@inheritDoc} */
+    public Class getSupportedImageClass() {
+        return ImageXMLDOM.class;
+    }
+
+    /** {@inheritDoc} */
+    public ImageFlavor[] getSupportedImageFlavors() {
+        return FLAVORS;
+    }
+
+    /** {@inheritDoc} */
+    public boolean isCompatible(RenderingContext targetContext, Image image) {
+        boolean supported = (image == null || (image instanceof ImageXMLDOM
+                && image.getFlavor().isCompatible(BatikImageFlavors.SVG_DOM)))
+                && targetContext instanceof AFPRenderingContext;
+        if (supported) {
+            String mode = (String)targetContext.getHint(ImageHandlerUtil.CONVERSION_MODE);
+            if (ImageHandlerUtil.isConversionModeBitmap(mode)) {
+                //Disabling this image handler automatically causes a bitmap to be generated
+                return false;
+            }
+        }
+        return supported;
+    }
+
+}

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

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

Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPPainter.java?rev=733456&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPPainter.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPPainter.java Sun Jan 11 03:31:24 2009
@@ -0,0 +1,342 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.afp;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Paint;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
+import java.io.IOException;
+import java.util.Map;
+
+import org.w3c.dom.Document;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.image.loader.ImageProcessingHints;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+
+import org.apache.fop.afp.AFPBorderPainter;
+import org.apache.fop.afp.AFPPaintingState;
+import org.apache.fop.afp.AFPRectanglePainter;
+import org.apache.fop.afp.AFPUnitConverter;
+import org.apache.fop.afp.DataStream;
+import org.apache.fop.afp.RectanglePaintingInfo;
+import org.apache.fop.afp.fonts.AFPFont;
+import org.apache.fop.afp.fonts.AFPFontAttributes;
+import org.apache.fop.afp.fonts.AFPPageFonts;
+import org.apache.fop.afp.fonts.CharacterSet;
+import org.apache.fop.afp.modca.AbstractPageObject;
+import org.apache.fop.afp.modca.PresentationTextObject;
+import org.apache.fop.afp.ptoca.PtocaBuilder;
+import org.apache.fop.afp.ptoca.PtocaProducer;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontTriplet;
+import org.apache.fop.render.RenderingContext;
+import org.apache.fop.render.intermediate.AbstractIFPainter;
+import org.apache.fop.render.intermediate.IFContext;
+import org.apache.fop.render.intermediate.IFException;
+import org.apache.fop.render.intermediate.IFState;
+import org.apache.fop.traits.BorderProps;
+import org.apache.fop.traits.RuleStyle;
+
+/**
+ * IFPainter implementation that produces AFP (MO:DCA).
+ */
+public class AFPPainter extends AbstractIFPainter {
+
+    /** logging instance */
+    private static Log log = LogFactory.getLog(AFPPainter.class);
+
+    private static final int X = 0;
+    private static final int Y = 1;
+
+    private AFPDocumentHandler documentHandler;
+
+    /** the line painter */
+    private AFPBorderPainter borderPainter;
+    /** the rectangle painter */
+    private AFPRectanglePainter rectanglePainter;
+
+    /** unit converter */
+    private final AFPUnitConverter unitConv;
+
+    /**
+     * Default constructor.
+     * @param documentHandler the parent document handler
+     */
+    public AFPPainter(AFPDocumentHandler documentHandler) {
+        super();
+        this.documentHandler = documentHandler;
+        this.state = IFState.create();
+        this.borderPainter = new AFPBorderPainter(getPaintingState(), getDataStream());
+        this.rectanglePainter = new AFPRectanglePainter(getPaintingState(), getDataStream());
+        this.unitConv = getPaintingState().getUnitConverter();
+    }
+
+    /** {@inheritDoc} */
+    protected IFContext getContext() {
+        return this.documentHandler.getContext();
+    }
+
+    FontInfo getFontInfo() {
+        return this.documentHandler.getFontInfo();
+    }
+
+    AFPPaintingState getPaintingState() {
+        return this.documentHandler.getPaintingState();
+    }
+
+    DataStream getDataStream() {
+        return this.documentHandler.getDataStream();
+    }
+
+    /** {@inheritDoc} */
+    public void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect)
+            throws IFException {
+        //AFP doesn't support clipping, so we treat viewport like a group
+        //this is the same code as for startGroup()
+        try {
+            saveGraphicsState();
+            concatenateTransformationMatrix(transform);
+        } catch (IOException ioe) {
+            throw new IFException("I/O error in startViewport()", ioe);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public void endViewport() throws IFException {
+        try {
+            restoreGraphicsState();
+        } catch (IOException ioe) {
+            throw new IFException("I/O error in endViewport()", ioe);
+        }
+    }
+
+    private void concatenateTransformationMatrix(AffineTransform at) {
+        if (!at.isIdentity()) {
+            getPaintingState().concatenate(at);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public void startGroup(AffineTransform transform) throws IFException {
+        try {
+            saveGraphicsState();
+            concatenateTransformationMatrix(transform);
+        } catch (IOException ioe) {
+            throw new IFException("I/O error in startGroup()", ioe);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public void endGroup() throws IFException {
+        try {
+            restoreGraphicsState();
+        } catch (IOException ioe) {
+            throw new IFException("I/O error in endGroup()", ioe);
+        }
+    }
+
+    /** {@inheritDoc} */
+    protected Map createDefaultImageProcessingHints(ImageSessionContext sessionContext) {
+        Map hints = super.createDefaultImageProcessingHints(sessionContext);
+
+        //AFP doesn't support alpha channels
+        hints.put(ImageProcessingHints.TRANSPARENCY_INTENT,
+                ImageProcessingHints.TRANSPARENCY_INTENT_IGNORE);
+        return hints;
+    }
+
+    /** {@inheritDoc} */
+    protected RenderingContext createRenderingContext() {
+        AFPRenderingContext psContext = new AFPRenderingContext(
+                getUserAgent(),
+                documentHandler.getResourceManager(),
+                getPaintingState(),
+                getFontInfo(),
+                getContext().getForeignAttributes());
+        return psContext;
+    }
+
+    /** {@inheritDoc} */
+    public void drawImage(String uri, Rectangle rect) throws IFException {
+        drawImageUsingURI(uri, rect);
+    }
+
+    /** {@inheritDoc} */
+    public void drawImage(Document doc, Rectangle rect) throws IFException {
+        drawImageUsingDocument(doc, rect);
+    }
+
+    /** {@inheritDoc} */
+    public void clipRect(Rectangle rect) throws IFException {
+        //Not supported!
+    }
+
+    private float toPoint(int mpt) {
+        return mpt / 1000f;
+    }
+
+    /** {@inheritDoc} */
+    public void fillRect(Rectangle rect, Paint fill) throws IFException {
+        if (fill == null) {
+            return;
+        }
+        if (rect.width != 0 && rect.height != 0) {
+            if (fill instanceof Color) {
+                getPaintingState().setColor((Color)fill);
+            } else {
+                throw new UnsupportedOperationException("Non-Color paints NYI");
+            }
+            RectanglePaintingInfo rectanglePaintInfo = new RectanglePaintingInfo(
+                    toPoint(rect.x), toPoint(rect.y), toPoint(rect.width), toPoint(rect.height));
+            rectanglePainter.paint(rectanglePaintInfo);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public void drawBorderRect(Rectangle rect, BorderProps before, BorderProps after,
+            BorderProps start, BorderProps end) throws IFException {
+        if (before != null || after != null || start != null || end != null) {
+            /*
+            try {
+                endTextObject();
+                this.borderPainter.drawBorders(rect, before, after, start, end);
+            } catch (IOException ioe) {
+                throw new IFException("I/O error in drawBorderRect()", ioe);
+            }*/
+        }
+    }
+
+    /** {@inheritDoc} */
+    public void drawLine(Point start, Point end, int width, Color color, RuleStyle style)
+                throws IFException {
+        /*
+        try {
+            endTextObject();
+            this.borderPainter.drawLine(start, end, width, color, style);
+        } catch (IOException ioe) {
+            throw new IFException("I/O error in drawLine()", ioe);
+        }*/
+    }
+
+    /** {@inheritDoc} */
+    public void drawText(int x, int y, final int[] dx, int[] dy, final String text)
+            throws IFException {
+        int fontSize = this.state.getFontSize();
+        getPaintingState().setFontSize(fontSize);
+
+        FontTriplet triplet = new FontTriplet(
+                state.getFontFamily(), state.getFontStyle(), state.getFontWeight());
+        //TODO Ignored: state.getFontVariant()
+        String fontKey = getFontInfo().getInternalFontKey(triplet);
+
+        // register font as necessary
+        Map/*<String,FontMetrics>*/ fontMetricMap = documentHandler.getFontInfo().getFonts();
+        final AFPFont afpFont = (AFPFont)fontMetricMap.get(fontKey);
+        AFPPageFonts pageFonts = getPaintingState().getPageFonts();
+        AFPFontAttributes fontAttributes = pageFonts.registerFont(fontKey, afpFont, fontSize);
+
+        final int fontReference = fontAttributes.getFontReference();
+
+        final int[] coords = unitConv.mpts2units(new float[] {x, y} );
+
+        final CharacterSet charSet = afpFont.getCharacterSet(fontSize);
+
+        AbstractPageObject page = getDataStream().getCurrentPage();
+        PresentationTextObject pto = page.getPresentationTextObject();
+        try {
+            pto.createControlSequences(new PtocaProducer() {
+
+                public void produce(PtocaBuilder builder) throws IOException {
+                    Point p = getPaintingState().getPoint(coords[X], coords[Y]);
+                    builder.setTextOrientation(getPaintingState().getRotation());
+                    builder.absoluteMoveBaseline(p.y);
+                    builder.absoluteMoveInline(p.x);
+
+                    builder.setVariableSpaceCharacterIncrement(0);
+                    builder.setInterCharacterAdjustment(0);
+                    builder.setExtendedTextColor(state.getTextColor());
+                    builder.setCodedFont((byte)fontReference);
+
+                    if (dx == null) {
+                        //No glyph-shifting necessary, so take a shortcut
+                        builder.addTransparentData(text.getBytes(charSet.getEncoding()));
+                    } else {
+                        int l = text.length();
+                        int dxl = dx.length;
+                        StringBuffer sb = new StringBuffer();
+
+                        if (dxl > 0 && dx[0] != 0) {
+                            int dxu = Math.round(unitConv.mpt2units(dx[0]));
+                            builder.relativeMoveInline(-dxu);
+                        }
+                        for (int i = 0; i < l; i++) {
+                            sb.append(text.charAt(i));
+                            float glyphAdjust = 0;
+
+                            if (i < dxl - 1) {
+                                glyphAdjust += dx[i + 1];
+                            }
+
+                            if (glyphAdjust != 0) {
+                                if (sb.length() > 0) {
+                                    String t = sb.toString();
+                                    builder.addTransparentData(t.getBytes(charSet.getEncoding()));
+                                    sb.setLength(0);
+                                }
+                                int increment = Math.round(unitConv.mpt2units(glyphAdjust));
+                                builder.relativeMoveInline(increment);
+                            }
+                        }
+                        if (sb.length() > 0) {
+                            String t = sb.toString();
+                            builder.addTransparentData(t.getBytes(charSet.getEncoding()));
+                        }
+                    }
+                }
+
+            });
+        } catch (IOException ioe) {
+            throw new IFException("I/O error in drawText()", ioe);
+        }
+    }
+
+    /**
+     * Saves the graphics state of the rendering engine.
+     * @throws IOException if an I/O error occurs
+     */
+    protected void saveGraphicsState() throws IOException {
+        getPaintingState().save();
+    }
+
+    /**
+     * Restores the last graphics state of the rendering engine.
+     * @throws IOException if an I/O error occurs
+     */
+    protected void restoreGraphicsState() throws IOException {
+        getPaintingState().restore();
+    }
+
+}

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

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

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRenderer.java?rev=733456&r1=733455&r2=733456&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRenderer.java Sun Jan 11 03:31:24 2009
@@ -33,6 +33,14 @@
 import java.util.List;
 import java.util.Map;
 
+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.util.ImageUtil;
+import org.apache.xmlgraphics.ps.ImageEncodingHelper;
+
 import org.apache.fop.afp.AFPBorderPainter;
 import org.apache.fop.afp.AFPDataObjectInfo;
 import org.apache.fop.afp.AFPEventProducer;
@@ -72,13 +80,6 @@
 import org.apache.fop.render.RendererContext;
 import org.apache.fop.render.afp.extensions.AFPElementMapping;
 import org.apache.fop.render.afp.extensions.AFPPageSetup;
-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.util.ImageUtil;
-import org.apache.xmlgraphics.ps.ImageEncodingHelper;
 
 /**
  * This is an implementation of a FOP Renderer that renders areas to AFP.
@@ -134,7 +135,7 @@
  * (ie. at the start or end of the page).
  *
  */
-public class AFPRenderer extends AbstractPathOrientedRenderer {
+public class AFPRenderer extends AbstractPathOrientedRenderer implements AFPCustomizable {
 
     private static final int X = 0;
     private static final int Y = 1;
@@ -541,6 +542,7 @@
         int textWordSpaceAdjust = text.getTextWordSpaceAdjust();
         int textLetterSpaceAdjust = text.getTextLetterSpaceAdjust();
         int textWidth = font.getWidth(' ', fontSize) / 1000;
+        textWidth = 0; //JM, the above is strange
         int variableSpaceCharacterIncrement
             = textWidth + textWordSpaceAdjust + textLetterSpaceAdjust;
 
@@ -677,7 +679,7 @@
     }
 
     /**
-     * Sets the rotation to be used for landsacpe pages, valid values are 0, 90,
+     * Sets the rotation to be used for landscape pages, valid values are 0, 90,
      * 180, 270 (default).
      *
      * @param rotation
@@ -687,59 +689,34 @@
         paintingState.setLandscapeRotation(rotation);
     }
 
-    /**
-     * Sets the number of bits used per pixel
-     *
-     * @param bitsPerPixel
-     *            number of bits per pixel
-     */
+    // ---=== AFPCustomizable ===---
+
+    /** {@inheritDoc} */
     public void setBitsPerPixel(int bitsPerPixel) {
         paintingState.setBitsPerPixel(bitsPerPixel);
     }
 
-    /**
-     * Sets whether images are color or not
-     *
-     * @param colorImages
-     *            color image output
-     */
+    /** {@inheritDoc} */
     public void setColorImages(boolean colorImages) {
         paintingState.setColorImages(colorImages);
     }
 
-    /**
-     * Sets whether images are supported natively or not
-     *
-     * @param nativeImages
-     *            native image support
-     */
+    /** {@inheritDoc} */
     public void setNativeImagesSupported(boolean nativeImages) {
         paintingState.setNativeImagesSupported(nativeImages);
     }
 
-    /**
-     * Sets the output/device resolution
-     *
-     * @param resolution
-     *            the output resolution (dpi)
-     */
+    /** {@inheritDoc} */
     public void setResolution(int resolution) {
         paintingState.setResolution(resolution);
     }
 
-    /**
-     * Returns the output/device resolution.
-     *
-     * @return the resolution in dpi
-     */
+    /** {@inheritDoc} */
     public int getResolution() {
         return paintingState.getResolution();
     }
 
-    /**
-     * Sets the default resource group file path
-     * @param filePath the default resource group file path
-     */
+    /** {@inheritDoc} */
     public void setDefaultResourceGroupFilePath(String filePath) {
         resourceManager.setDefaultResourceGroupFilePath(filePath);
     }

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java?rev=733456&r1=733455&r2=733456&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java Sun Jan 11 03:31:24 2009
@@ -25,6 +25,7 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 
+import org.apache.fop.afp.fonts.AFPFontCollection;
 import org.apache.fop.afp.fonts.AFPFontInfo;
 import org.apache.fop.afp.fonts.CharacterSet;
 import org.apache.fop.afp.fonts.FopCharacterSet;
@@ -32,17 +33,23 @@
 import org.apache.fop.afp.fonts.RasterFont;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.fonts.FontCollection;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontManager;
 import org.apache.fop.fonts.FontTriplet;
 import org.apache.fop.fonts.FontUtil;
 import org.apache.fop.fonts.Typeface;
 import org.apache.fop.render.PrintRendererConfigurator;
 import org.apache.fop.render.Renderer;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
+import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
 import org.apache.fop.util.LogUtil;
 
 /**
  * AFP Renderer configurator
  */
-public class AFPRendererConfigurator extends PrintRendererConfigurator {
+public class AFPRendererConfigurator extends PrintRendererConfigurator
+            implements IFDocumentHandlerConfigurator {
 
     /**
      * Default constructor
@@ -231,6 +238,7 @@
         Configuration cfg = super.getRendererConfig(renderer);
         if (cfg != null) {
             AFPRenderer afpRenderer = (AFPRenderer)renderer;
+
             try {
                 List/*<AFPFontInfo>*/ fontList = buildFontListFromConfiguration(cfg);
                 afpRenderer.setFontList(fontList);
@@ -239,49 +247,88 @@
                         userAgent.getFactory().validateUserConfigStrictly());
             }
 
-            // image information
-            Configuration imagesCfg = cfg.getChild("images");
+            configure(afpRenderer, cfg);
+        }
+    }
+
+    private void configure(AFPCustomizable customizable, Configuration cfg) throws FOPException {
+
+        // image information
+        Configuration imagesCfg = cfg.getChild("images");
 
-            // default to grayscale images
-            String imagesMode = imagesCfg.getAttribute("mode", IMAGES_MODE_GRAYSCALE);
-            if (IMAGES_MODE_COLOR.equals(imagesMode)) {
-                afpRenderer.setColorImages(true);
+        // default to grayscale images
+        String imagesMode = imagesCfg.getAttribute("mode", IMAGES_MODE_GRAYSCALE);
+        if (IMAGES_MODE_COLOR.equals(imagesMode)) {
+            customizable.setColorImages(true);
+        } else {
+            customizable.setColorImages(false);
+            // default to 8 bits per pixel
+            int bitsPerPixel = imagesCfg.getAttributeAsInteger("bits-per-pixel", 8);
+            customizable.setBitsPerPixel(bitsPerPixel);
+        }
+
+        // native image support
+        boolean nativeImageSupport = imagesCfg.getAttributeAsBoolean("native", false);
+        customizable.setNativeImagesSupported(nativeImageSupport);
+
+        // renderer resolution
+        Configuration rendererResolutionCfg = cfg.getChild("renderer-resolution", false);
+        if (rendererResolutionCfg != null) {
+            customizable.setResolution(rendererResolutionCfg.getValueAsInteger(240));
+        }
+
+        // a default external resource group file setting
+        Configuration resourceGroupFileCfg
+            = cfg.getChild("resource-group-file", false);
+        if (resourceGroupFileCfg != null) {
+            String resourceGroupDest = null;
+            try {
+                resourceGroupDest = resourceGroupFileCfg.getValue();
+            } catch (ConfigurationException e) {
+                LogUtil.handleException(log, e,
+                        userAgent.getFactory().validateUserConfigStrictly());
+            }
+            File resourceGroupFile = new File(resourceGroupDest);
+            if (resourceGroupFile.canWrite()) {
+                customizable.setDefaultResourceGroupFilePath(resourceGroupDest);
             } else {
-                afpRenderer.setColorImages(false);
-                // default to 8 bits per pixel
-                int bitsPerPixel = imagesCfg.getAttributeAsInteger("bits-per-pixel", 8);
-                afpRenderer.setBitsPerPixel(bitsPerPixel);
+                log.warn("Unable to write to default external resource group file '"
+                            + resourceGroupDest + "'");
             }
+        }
+    }
 
-            // native image support
-            boolean nativeImageSupport = imagesCfg.getAttributeAsBoolean("native", false);
-            afpRenderer.setNativeImagesSupported(nativeImageSupport);
-
-            // renderer resolution
-            Configuration rendererResolutionCfg = cfg.getChild("renderer-resolution", false);
-            if (rendererResolutionCfg != null) {
-                afpRenderer.setResolution(rendererResolutionCfg.getValueAsInteger(240));
-            }
+    /** {@inheritDoc} */
+    public void configure(IFDocumentHandler documentHandler) throws FOPException {
+        Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
+        if (cfg != null) {
+            AFPDocumentHandler afpDocumentHandler = (AFPDocumentHandler)documentHandler;
+            configure(afpDocumentHandler, cfg);
+        }
+    }
 
-            // a default external resource group file setting
-            Configuration resourceGroupFileCfg
-                = cfg.getChild("resource-group-file", false);
-            if (resourceGroupFileCfg != null) {
-                String resourceGroupDest = null;
-                try {
-                    resourceGroupDest = resourceGroupFileCfg.getValue();
-                } catch (ConfigurationException e) {
-                    LogUtil.handleException(log, e,
-                            userAgent.getFactory().validateUserConfigStrictly());
-                }
-                File resourceGroupFile = new File(resourceGroupDest);
-                if (resourceGroupFile.canWrite()) {
-                    afpRenderer.setDefaultResourceGroupFilePath(resourceGroupDest);
-                } else {
-                    log.warn("Unable to write to default external resource group file '"
-                                + resourceGroupDest + "'");
-                }
+    /** {@inheritDoc} */
+    public void setupFontInfo(IFDocumentHandler documentHandler, FontInfo fontInfo)
+            throws FOPException {
+        FontManager fontManager = userAgent.getFactory().getFontManager();
+        List fontCollections = new java.util.ArrayList();
+
+        Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
+        if (cfg != null) {
+            try {
+                List fontList = buildFontListFromConfiguration(cfg);
+                fontCollections.add(new AFPFontCollection(
+                        userAgent.getEventBroadcaster(), fontList));
+            } catch (ConfigurationException e) {
+                LogUtil.handleException(log, e,
+                        userAgent.getFactory().validateUserConfigStrictly());
             }
+
         }
+
+        fontManager.setup(fontInfo,
+                (FontCollection[])fontCollections.toArray(
+                        new FontCollection[fontCollections.size()]));
+        documentHandler.setFontInfo(fontInfo);
     }
 }

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRendererContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRendererContext.java?rev=733456&r1=733455&r2=733456&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRendererContext.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRendererContext.java Sun Jan 11 03:31:24 2009
@@ -22,14 +22,19 @@
 import java.util.Map;
 
 import org.apache.avalon.framework.configuration.Configuration;
+
 import org.apache.fop.afp.AFPPaintingState;
 import org.apache.fop.afp.AFPResourceInfo;
 import org.apache.fop.afp.AFPResourceLevel;
 import org.apache.fop.afp.AFPResourceManager;
 import org.apache.fop.render.AbstractRenderer;
+import org.apache.fop.render.ImageHandlerUtil;
 import org.apache.fop.render.RendererContext;
 import org.apache.fop.render.RendererContextConstants;
 
+/**
+ * AFP-specific renderer context class.
+ */
 public class AFPRendererContext extends RendererContext {
 
     /**
@@ -64,8 +69,7 @@
 
         Map foreignAttributes = (Map)getProperty(RendererContextConstants.FOREIGN_ATTRIBUTES);
         if (foreignAttributes != null) {
-            String conversionMode = (String)foreignAttributes.get(CONVERSION_MODE);
-            boolean paintAsBitmap = BITMAP.equalsIgnoreCase(conversionMode);
+            boolean paintAsBitmap = ImageHandlerUtil.isConversionModeBitmap(foreignAttributes);
             info.setPaintAsBitmap(paintAsBitmap);
 
             AFPForeignAttributeReader foreignAttributeReader

Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRenderingContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRenderingContext.java?rev=733456&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRenderingContext.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPRenderingContext.java Sun Jan 11 03:31:24 2009
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.afp;
+
+import java.util.Map;
+
+import org.apache.xmlgraphics.util.MimeConstants;
+
+import org.apache.fop.afp.AFPPaintingState;
+import org.apache.fop.afp.AFPResourceManager;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.render.AbstractRenderingContext;
+
+/**
+ * Rendering context for AFP (MO:DCA) production.
+ */
+public class AFPRenderingContext extends AbstractRenderingContext {
+
+    private AFPResourceManager resourceManager;
+    private AFPPaintingState paintingState;
+    private FontInfo fontInfo;
+    private Map foreignAttributes;
+
+    /**
+     * Main constructor.
+     * @param userAgent the user agent
+     * @param resourceManager the resource manager
+     * @param fontInfo the font list
+     * @param foreignAttributes a map of foreign attributes
+     */
+    public AFPRenderingContext(FOUserAgent userAgent,
+            AFPResourceManager resourceManager,
+            AFPPaintingState paintingState,
+            FontInfo fontInfo, Map foreignAttributes) {
+        super(userAgent);
+        this.resourceManager = resourceManager;
+        this.paintingState = paintingState;
+        this.fontInfo = fontInfo;
+        this.foreignAttributes = foreignAttributes;
+    }
+
+    /** {@inheritDoc} */
+    public String getMimeType() {
+        return MimeConstants.MIME_AFP;
+    }
+
+    /**
+     * Returns the resource manager.
+     * @return the resource manager
+     */
+    public AFPResourceManager getResourceManager() {
+        return this.resourceManager;
+    }
+
+    public AFPPaintingState getPaintingState() {
+        return this.paintingState;
+    }
+
+    /**
+     * Returns the font list.
+     * @return the font list
+     */
+    public FontInfo getFontInfo() {
+        return this.fontInfo;
+    }
+
+    /**
+     * Returns a Map of foreign attributes.
+     * @return the foreign attributes (Map&lt;QName, Object&gt;)
+     */
+    public Map getForeignAttributes() {
+        return this.foreignAttributes;
+    }
+
+}

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

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

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPSVGHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPSVGHandler.java?rev=733456&r1=733455&r2=733456&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPSVGHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AFPSVGHandler.java Sun Jan 11 03:31:24 2009
@@ -123,7 +123,7 @@
             = RendererContext.wrapRendererContext(rendererContext);
         Dimension imageSize = getImageSize(wrappedContext);
         Graphics2DImagePainter painter
-            = createGrapics2DImagePainter(bridgeContext, root, imageSize);
+            = createGraphics2DImagePainter(bridgeContext, root, imageSize);
 
         // Create AFPObjectAreaInfo
         RendererContextWrapper rctx = RendererContext.wrapRendererContext(rendererContext);
@@ -217,8 +217,8 @@
         context.setProperty(AFPRendererContextConstants.AFP_GRAYSCALE, Boolean.FALSE);
     }
 
-    /** {@inheritDoc} */
-    protected Graphics2DImagePainter createGrapics2DImagePainter(BridgeContext ctx, GraphicsNode root, Dimension imageSize) {
+    private Graphics2DImagePainter createGraphics2DImagePainter(BridgeContext ctx,
+            GraphicsNode root, Dimension imageSize) {
         Graphics2DImagePainter painter = null;
         if (paintAsBitmap()) {
             // paint as IOCA Image

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AbstractAFPImageHandlerRawStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AbstractAFPImageHandlerRawStream.java?rev=733456&r1=733455&r2=733456&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AbstractAFPImageHandlerRawStream.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/afp/AbstractAFPImageHandlerRawStream.java Sun Jan 11 03:31:24 2009
@@ -19,33 +19,55 @@
 
 package org.apache.fop.render.afp;
 
+import java.awt.Rectangle;
 import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.commons.io.IOUtils;
+
+import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.ImageSize;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
+
 import org.apache.fop.afp.AFPDataObjectInfo;
 import org.apache.fop.afp.AFPObjectAreaInfo;
 import org.apache.fop.afp.AFPPaintingState;
-import org.apache.xmlgraphics.image.loader.ImageInfo;
-import org.apache.xmlgraphics.image.loader.ImageSize;
-import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
+import org.apache.fop.render.ImageHandler;
+import org.apache.fop.render.RenderingContext;
 
 /**
  * A base abstract AFP raw stream image handler
  */
-public abstract class AbstractAFPImageHandlerRawStream extends AFPImageHandler {
+public abstract class AbstractAFPImageHandlerRawStream extends AFPImageHandler
+        implements ImageHandler {
 
     /** {@inheritDoc} */
     public AFPDataObjectInfo generateDataObjectInfo(
             AFPRendererImageInfo rendererImageInfo) throws IOException {
         AFPDataObjectInfo dataObjectInfo = super.generateDataObjectInfo(rendererImageInfo);
-
-        ImageInfo imageInfo = rendererImageInfo.getImageInfo();
-        String mimeType = imageInfo.getMimeType();
-        if (mimeType != null) {
-            dataObjectInfo.setMimeType(mimeType);
-        }
         ImageRawStream rawStream = (ImageRawStream) rendererImageInfo.getImage();
+
+
+        updateDataObjectInfo(dataObjectInfo, rawStream);
+
+        setAdditionalParameters(dataObjectInfo, rawStream);
+        return dataObjectInfo;
+    }
+
+    /**
+     * Sets additional parameters on the image object info being built. By default, this
+     * method does nothing but it can be overridden to provide additional functionality.
+     * @param imageObjectInfo the image object info being built
+     * @param image the image being processed
+     */
+    protected void setAdditionalParameters(AFPDataObjectInfo imageObjectInfo,
+            ImageRawStream image) {
+        //nop
+    }
+
+    private void updateDataObjectInfo(AFPDataObjectInfo dataObjectInfo,
+            ImageRawStream rawStream) throws IOException {
+        dataObjectInfo.setMimeType(rawStream.getFlavor().getMimeType());
         InputStream inputStream = rawStream.createInputStream();
         try {
             dataObjectInfo.setData(IOUtils.toByteArray(inputStream));
@@ -62,18 +84,38 @@
         ImageSize imageSize = rawStream.getSize();
         dataObjectInfo.setDataHeightRes((int) (imageSize.getDpiHorizontal() * 10));
         dataObjectInfo.setDataWidthRes((int) (imageSize.getDpiVertical() * 10));
+    }
+
+    /** {@inheritDoc} */
+    public void handleImage(RenderingContext context, Image image, Rectangle pos)
+            throws IOException {
+        AFPRenderingContext afpContext = (AFPRenderingContext)context;
+
+        AFPDataObjectInfo dataObjectInfo = createDataObjectInfo();
+
+        // set resource information
+        setResourceInformation(dataObjectInfo,
+                image.getInfo().getOriginalURI(),
+                afpContext.getForeignAttributes());
+
+        // Positioning
+        dataObjectInfo.setObjectAreaInfo(createObjectAreaInfo(afpContext.getPaintingState(), pos));
 
         // set object area info
-        AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
-        AFPRendererContext rendererContext
-            = (AFPRendererContext)rendererImageInfo.getRendererContext();
-        AFPInfo afpInfo = rendererContext.getInfo();
-        AFPPaintingState paintingState = afpInfo.getPaintingState();
+        //AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
+        AFPPaintingState paintingState = afpContext.getPaintingState();
         int resolution = paintingState.getResolution();
+        AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
         objectAreaInfo.setWidthRes(resolution);
         objectAreaInfo.setHeightRes(resolution);
 
-        return dataObjectInfo;
+        // Image content
+        ImageRawStream imageStream = (ImageRawStream)image;
+        updateDataObjectInfo(dataObjectInfo, imageStream);
+        setAdditionalParameters(dataObjectInfo, imageStream);
+
+        // Create image
+        afpContext.getResourceManager().createObject(dataObjectInfo);
     }
 
 }



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