xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r746664 [4/8] - in /xmlgraphics/fop/trunk: ./ examples/embedding/java/embedding/atxml/ examples/embedding/java/embedding/intermediate/ examples/embedding/xml/xslt/ examples/plan/src/org/apache/fop/plan/ lib/ src/documentation/content/xdocs/...
Date Sun, 22 Feb 2009 12:40:55 GMT
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java Sun Feb 22 12:40:44 2009
@@ -45,12 +45,13 @@
      * Constructs a new Type 1 font loader.
      * @param fontFileURI the URI to the PFB file of a Type 1 font
      * @param embedded indicates whether the font is embedded or referenced
+     * @param useKerning indicates whether to load kerning information if available
      * @param resolver the font resolver used to resolve URIs
      * @throws IOException In case of an I/O error
      */
-    public Type1FontLoader(String fontFileURI, boolean embedded, FontResolver resolver)
-                throws IOException {
-        super(fontFileURI, embedded, resolver);
+    public Type1FontLoader(String fontFileURI, boolean embedded, boolean useKerning,
+            FontResolver resolver) throws IOException {
+        super(fontFileURI, embedded, useKerning, resolver);
     }
 
     private String getPFMURI(String pfbURI) {
@@ -322,7 +323,9 @@
                     singleFont.setWidth(chm.getCharCode(), (int)Math.round(chm.getWidthX()));
                 }
             }
-            returnFont.replaceKerningMap(afm.createXKerningMapEncoded());
+            if (useKerning) {
+                returnFont.replaceKerningMap(afm.createXKerningMapEncoded());
+            }
         } else {
             returnFont.setFlags(pfm.getFlags());
             returnFont.setFirstChar(pfm.getFirstChar());
@@ -330,7 +333,9 @@
             for (short i = pfm.getFirstChar(); i <= pfm.getLastChar(); i++) {
                 singleFont.setWidth(i, pfm.getCharWidth(i));
             }
-            returnFont.replaceKerningMap(pfm.getKerning());
+            if (useKerning) {
+                returnFont.replaceKerningMap(pfm.getKerning());
+            }
         }
     }
 

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/Graphics2DImagePainterImpl.java
            ('svn:mergeinfo' removed)

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/PreloaderSVG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/PreloaderSVG.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/PreloaderSVG.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/PreloaderSVG.java Sun Feb 22 12:40:44 2009
@@ -34,7 +34,6 @@
 import org.apache.batik.bridge.UnitProcessor;
 import org.apache.batik.bridge.UserAgent;
 import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
-import org.apache.batik.dom.svg.SVGDOMImplementation;
 import org.apache.batik.dom.svg.SVGOMDocument;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -198,7 +197,7 @@
 
             //The whole image had to be loaded for this, so keep it
             ImageXMLDOM xmlImage = new ImageXMLDOM(info,
-                    doc, SVGDOMImplementation.SVG_NAMESPACE_URI);
+                    doc, BatikImageFlavors.SVG_DOM);
             info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, xmlImage);
             return info;
         }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFNumber.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFNumber.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFNumber.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFNumber.java Sun Feb 22 12:40:44 2009
@@ -19,13 +19,11 @@
 
 package org.apache.fop.pdf;
 
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.util.Locale;
+import org.apache.fop.util.DecimalFormatCache;
 
 /**
  * This class represents a simple number object. It also contains contains some
- * utility methods for outputing numbers to PDF.
+ * utility methods for outputting numbers to PDF.
  */
 public class PDFNumber extends PDFObject {
 
@@ -67,33 +65,6 @@
         return doubleOut(doubleDown, 6);
     }
 
-    private static final String BASE_FORMAT = "0.################";
-
-    private static class DecimalFormatThreadLocal extends ThreadLocal {
-        
-        private int dec;
-        
-        public DecimalFormatThreadLocal(int dec) {
-            this.dec = dec;
-        }
-        
-        protected synchronized Object initialValue() {
-            String s = "0";
-            if (dec > 0) {
-                s = BASE_FORMAT.substring(0, dec + 2);
-            }
-            DecimalFormat df = new DecimalFormat(s, new DecimalFormatSymbols(Locale.US));
-            return df;
-        }
-    };
-    //DecimalFormat is not thread-safe!
-    private static final ThreadLocal[] DECIMAL_FORMAT_CACHE = new DecimalFormatThreadLocal[17];
-    static {
-        for (int i = 0, c = DECIMAL_FORMAT_CACHE.length; i < c; i++) {
-            DECIMAL_FORMAT_CACHE[i] = new DecimalFormatThreadLocal(i);
-        }
-    }
-    
     /**
      * Output a double value to a string suitable for PDF.
      * In this method it is possible to set the maximum
@@ -104,12 +75,7 @@
      * @return the value as a string
      */
     public static String doubleOut(double doubleDown, int dec) {
-        if (dec < 0 || dec >= DECIMAL_FORMAT_CACHE.length) {
-            throw new IllegalArgumentException("Parameter dec must be between 1 and "
-                    + (DECIMAL_FORMAT_CACHE.length + 1));
-        }
-        DecimalFormat df = (DecimalFormat)DECIMAL_FORMAT_CACHE[dec].get();
-        return df.format(doubleDown);
+        return DecimalFormatCache.getDecimalFormat(dec).format(doubleDown);
     }
 
     /** {@inheritDoc} */

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFPaintingState.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFPaintingState.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFPaintingState.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFPaintingState.java Sun Feb 22 12:40:44 2009
@@ -62,14 +62,15 @@
      * @return true if the new paint changes the current paint
      */
     public boolean setPaint(Paint p) {
-        Paint paint = ((PDFData)getData()).paint;
+        PDFData data = getPDFData();
+        Paint paint = data.paint;
         if (paint == null) {
             if (p != null) {
-                ((PDFData)getData()).paint = p;
+                data.paint = p;
                 return true;
             }
         } else if (!paint.equals(p)) {
-            ((PDFData)getData()).paint = p;
+            data.paint = p;
             return true;
         }
         return false;
@@ -88,7 +89,7 @@
      * @return true if the clip will change the current clip.
      */
     public boolean checkClip(Shape cl) {
-        Shape clip = ((PDFData)getData()).clip;
+        Shape clip = getPDFData().clip;
         if (clip == null) {
             if (cl != null) {
                 return true;
@@ -108,17 +109,40 @@
      * @param cl the new clip in the current state
      */
     public void setClip(Shape cl) {
-        Shape clip = ((PDFData)getData()).clip;
+        PDFData data = getPDFData();
+        Shape clip = data.clip;
         if (clip != null) {
             Area newClip = new Area(clip);
             newClip.intersect(new Area(cl));
-            ((PDFData)getData()).clip = new GeneralPath(newClip);
+            data.clip = new GeneralPath(newClip);
         } else {
-            ((PDFData)getData()).clip = cl;
+            data.clip = cl;
         }
     }
 
     /**
+     * Sets the character spacing (Tc).
+     * @param value the new value
+     * @return true if the value was changed with respect to the previous value
+     */
+    public boolean setCharacterSpacing(float value) {
+        PDFData data = getPDFData();
+        if (value != data.characterSpacing) {
+            data.characterSpacing = value;
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Returns the current character spacing (Tc) value.
+     * @return the Tc value
+     */
+    public float getCharacterSpacing() {
+        return getPDFData().characterSpacing;
+    }
+
+    /**
      * Get the current stack level.
      *
      * @return the current stack level
@@ -149,8 +173,8 @@
                 newState.addValues(state);
             }
         }
-        if (((PDFData)getData()).gstate != null) {
-            newState.addValues(((PDFData)getData()).gstate);
+        if (getPDFData().gstate != null) {
+            newState.addValues(getPDFData().gstate);
         }
         return newState;
     }
@@ -177,32 +201,38 @@
         getStateStack().add(copy);
     }
 
+    private PDFData getPDFData() {
+        return (PDFData)getData();
+    }
+
     private class PDFData extends org.apache.fop.util.AbstractPaintingState.AbstractData {
 
         private static final long serialVersionUID = 3527950647293177764L;
 
         private Paint paint = null;
         private Paint backPaint = null;
-        private int lineCap = 0;
-        private int lineJoin = 0;
-        private float miterLimit = 0;
-        private boolean text = false;
-        private int dashOffset = 0;
+        //private int lineCap = 0; //Disabled the ones that are not used, yet
+        //private int lineJoin = 0;
+        //private float miterLimit = 0;
+        //private int dashOffset = 0;
         private Shape clip = null;
         private PDFGState gstate = null;
 
+        //text state
+        private float characterSpacing = 0f;
+
         /** {@inheritDoc} */
         public Object clone() {
             PDFData obj = (PDFData)super.clone();
             obj.paint = this.paint;
             obj.backPaint = this.paint;
-            obj.lineCap = this.lineCap;
-            obj.lineJoin = this.lineJoin;
-            obj.miterLimit = this.miterLimit;
-            obj.text = this.text;
-            obj.dashOffset = this.dashOffset;
+            //obj.lineCap = this.lineCap;
+            //obj.lineJoin = this.lineJoin;
+            //obj.miterLimit = this.miterLimit;
+            //obj.dashOffset = this.dashOffset;
             obj.clip = this.clip;
             obj.gstate = this.gstate;
+            obj.characterSpacing = this.characterSpacing;
             return obj;
         }
 
@@ -211,10 +241,9 @@
             return super.toString()
                 + ", paint=" + paint
                 + ", backPaint=" + backPaint
-                + ", lineCap=" + lineCap
-                + ", miterLimit=" + miterLimit
-                + ", text=" + text
-                + ", dashOffset=" + dashOffset
+                //+ ", lineCap=" + lineCap
+                //+ ", miterLimit=" + miterLimit
+                //+ ", dashOffset=" + dashOffset
                 + ", clip=" + clip
                 + ", gstate=" + gstate;
         }

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFPaintingState.java
            ('svn:mergeinfo' removed)

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFReference.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFReference.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFReference.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFReference.java Sun Feb 22 12:40:44 2009
@@ -33,7 +33,8 @@
  */
 public class PDFReference implements PDFWritable {
 
-    private String indirectReference;
+    private int objectNumber;
+    private int generation;
 
     private Reference objReference;
 
@@ -42,7 +43,8 @@
      * @param obj the object to be referenced
      */
     public PDFReference(PDFObject obj) {
-        this.indirectReference = obj.referencePDF();
+        this.objectNumber = obj.getObjectNumber();
+        this.generation = obj.getGeneration();
         this.objReference = new SoftReference(obj);
     }
 
@@ -54,7 +56,11 @@
         if (ref == null) {
             throw new NullPointerException("ref must not be null");
         }
-        this.indirectReference = ref;
+        String[] parts = ref.split(" ");
+        assert parts.length == 3;
+        this.objectNumber = Integer.parseInt(parts[0]);
+        this.generation = Integer.parseInt(parts[1]);
+        assert "R".equals(parts[2]);
     }
 
     /**
@@ -73,9 +79,25 @@
         }
     }
 
+    /**
+     * Returns the object number.
+     * @return the object number
+     */
+    public int getObjectNumber() {
+        return this.objectNumber;
+    }
+
+    /**
+     * Returns the generation.
+     * @return the generation
+     */
+    public int getGeneration() {
+        return this.generation;
+    }
+
     /** {@inheritDoc} */
     public String toString() {
-        return this.indirectReference;
+        return getObjectNumber() + " " + getGeneration() + " R";
     }
 
     /** {@inheritDoc} */

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFTextUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFTextUtil.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFTextUtil.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFTextUtil.java Sun Feb 22 12:40:44 2009
@@ -270,7 +270,15 @@
      * @param adjust the glyph adjust value in thousands of text unit space.
      */
     public void adjustGlyphTJ(double adjust) {
-        bufTJ.append(endText).append(" ");
+        if (bufTJ == null) {
+            bufTJ = new StringBuffer();
+        }
+        if (bufTJ.length() > 0) {
+            bufTJ.append(endText).append(" ");
+        }
+        if (bufTJ.length() == 0) {
+            bufTJ.append("[");
+        }
         bufTJ.append(PDFNumber.doubleOut(adjust, DEC - 4));
         bufTJ.append(" ");
         bufTJ.append(startText);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFUri.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFUri.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFUri.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFUri.java Sun Feb 22 12:40:44 2009
@@ -41,14 +41,22 @@
      * @return the action to place next to /A within a Link
      */
     public String getAction() {
+        if (hasObjectNumber()) {
+            return referencePDF();
+        } else {
+            return getDictString();
+        }
+    }
+
+    private String getDictString() {
         return "<< /URI (" + uri + ")\n/S /URI >>";
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public String toPDFString() {
-        throw new UnsupportedOperationException("This method should not be called");
+        //TODO Convert this class into a dictionary
+        return getObjectID() + getDictString() + "\nendobj\n";
+        //throw new UnsupportedOperationException("This method should not be called");
     }
 
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java Sun Feb 22 12:40:44 2009
@@ -33,11 +33,9 @@
 import org.apache.batik.gvt.GraphicsNode;
 
 import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
-import org.apache.xmlgraphics.util.QName;
 
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.events.EventBroadcaster;
-import org.apache.fop.fo.extensions.ExtensionElementMapping;
 import org.apache.fop.image.loader.batik.BatikUtil;
 import org.apache.fop.image.loader.batik.Graphics2DImagePainterImpl;
 import org.apache.fop.render.RendererContext.RendererContextWrapper;
@@ -52,13 +50,6 @@
  */
 public abstract class AbstractGenericSVGHandler implements XMLHandler, RendererContextConstants {
 
-    /** Qualified name for the "conversion-mode" extension attribute. */
-    protected static final QName CONVERSION_MODE = new QName(
-            ExtensionElementMapping.URI, null, "conversion-mode");
-
-    /** "bitmap" value for the "conversion-mode" extension attribute. */
-    protected static final String BITMAP = "bitmap";
-
     /** {@inheritDoc} */
     public void handleXML(RendererContext context,
                 Document doc, String ns) throws Exception {
@@ -82,9 +73,9 @@
     }
 
     /**
-     * Builds the GVT root
+     * Builds the GVT root.
      *
-     * @param rendererContext the renderer context
+     * @param userAgent the user agent
      * @param ctx the batik bridge context
      * @param doc the document
      * @return a built GVT root tree

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java Sun Feb 22 12:40:44 2009
@@ -27,6 +27,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.apache.xmlgraphics.image.loader.Image;
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
 import org.apache.xmlgraphics.util.Service;
@@ -43,8 +44,8 @@
 
     private static final Comparator HANDLER_COMPARATOR = new Comparator() {
         public int compare(Object o1, Object o2) {
-            ImageHandler h1 = (ImageHandler)o1;
-            ImageHandler h2 = (ImageHandler)o2;
+            ImageHandlerBase h1 = (ImageHandlerBase)o1;
+            ImageHandlerBase h2 = (ImageHandlerBase)o2;
             return h1.getPriority() - h2.getPriority();
         }
     };
@@ -76,8 +77,8 @@
      */
     public void addHandler(String classname) {
         try {
-            ImageHandler handlerInstance
-                = (ImageHandler)Class.forName(classname).newInstance();
+            ImageHandlerBase handlerInstance
+                = (ImageHandlerBase)Class.forName(classname).newInstance();
             addHandler(handlerInstance);
         } catch (ClassNotFoundException e) {
             throw new IllegalArgumentException("Could not find "
@@ -99,13 +100,13 @@
      * Add an image handler. The handler itself is inspected to find out what it supports.
      * @param handler the ImageHandler instance
      */
-    public synchronized void addHandler(ImageHandler handler) {
+    public synchronized void addHandler(ImageHandlerBase handler) {
         this.handlers.put(handler.getSupportedImageClass(), handler);
 
         //Sorted insert
         ListIterator iter = this.handlerList.listIterator();
         while (iter.hasNext()) {
-            ImageHandler h = (ImageHandler)iter.next();
+            ImageHandlerBase h = (ImageHandlerBase)iter.next();
             if (getHandlerComparator().compare(handler, h) < 0) {
                 iter.previous();
                 break;
@@ -121,7 +122,7 @@
      * @param img the Image to be handled
      * @return the ImageHandler responsible for handling the image or null if none is available
      */
-    public ImageHandler getHandler(Image img) {
+    public ImageHandlerBase getHandler(Image img) {
         return getHandler(img.getClass());
     }
 
@@ -131,11 +132,11 @@
      * @param imageClass the Image subclass for which to get a handler
      * @return the ImageHandler responsible for handling the image or null if none is available
      */
-    public synchronized ImageHandler getHandler(Class imageClass) {
-        ImageHandler handler = null;
+    public synchronized ImageHandlerBase getHandler(Class imageClass) {
+        ImageHandlerBase handler = null;
         Class cl = imageClass;
         while (cl != null) {
-            handler = (ImageHandler)handlers.get(cl);
+            handler = (ImageHandlerBase)handlers.get(cl);
             if (handler != null) {
                 break;
             }
@@ -154,7 +155,7 @@
             List flavors = new java.util.ArrayList();
             Iterator iter = this.handlerList.iterator();
             while (iter.hasNext()) {
-                ImageFlavor[] f = ((ImageHandler)iter.next()).getSupportedImageFlavors();
+                ImageFlavor[] f = ((ImageHandlerBase)iter.next()).getSupportedImageFlavors();
                 for (int i = 0; i < f.length; i++) {
                     flavors.add(f[i]);
                 }
@@ -175,7 +176,7 @@
         Iterator providers = Service.providers(imageHandlerClass);
         if (providers != null) {
             while (providers.hasNext()) {
-                ImageHandler handler = (ImageHandler)providers.next();
+                ImageHandlerBase handler = (ImageHandlerBase)providers.next();
                 try {
                     if (log.isDebugEnabled()) {
                         log.debug("Dynamically adding ImageHandler: "

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java Sun Feb 22 12:40:44 2009
@@ -475,7 +475,8 @@
         }
     }
 
-    private static final QName FOX_TRANSFORM
+    /** Constant for the fox:transform extension attribute */
+    protected static final QName FOX_TRANSFORM
             = new QName(ExtensionElementMapping.URI, "fox:transform");
 
     /** {@inheritDoc} */

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRenderer.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRenderer.java Sun Feb 22 12:40:44 2009
@@ -21,6 +21,7 @@
 
 // Java
 import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -111,7 +112,7 @@
     private Set warnedXMLHandlers;
 
     /** {@inheritDoc} */
-    public abstract void setupFontInfo(FontInfo fontInfo);
+    public abstract void setupFontInfo(FontInfo fontInfo) throws FOPException;
 
     /** {@inheritDoc} */
     public void setUserAgent(FOUserAgent agent) {
@@ -833,4 +834,34 @@
     public String getMimeType() {
         return null;
     }
+
+    /**
+     * Converts a millipoint-based transformation matrix to points.
+     * @param at a millipoint-based transformation matrix
+     * @return a point-based transformation matrix
+     */
+    protected AffineTransform mptToPt(AffineTransform at) {
+        double[] matrix = new double[6];
+        at.getMatrix(matrix);
+        //Convert to points
+        matrix[4] = matrix[4] / 1000;
+        matrix[5] = matrix[5] / 1000;
+        return new AffineTransform(matrix);
+    }
+
+    /**
+     * Converts a point-based transformation matrix to millipoints.
+     * @param at a point-based transformation matrix
+     * @return a millipoint-based transformation matrix
+     */
+    protected AffineTransform ptToMpt(AffineTransform at) {
+        double[] matrix = new double[6];
+        at.getMatrix(matrix);
+        //Convert to millipoints
+        //Math.round() because things like this can happen: 65.6 * 1000 = 65.599999999999999
+        //which is bad for testing
+        matrix[4] = Math.round(matrix[4] * 1000);
+        matrix[5] = Math.round(matrix[5] * 1000);
+        return new AffineTransform(matrix);
+    }
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRendererConfigurator.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRendererConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRendererConfigurator.java Sun Feb 22 12:40:44 2009
@@ -23,6 +23,7 @@
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.apache.fop.apps.FOUserAgent;
 
 /**
@@ -68,7 +69,7 @@
      * @param mimeType the MIME type of the renderer
      * @return the requested configuration subtree, null if there's no configuration
      */
-    private Configuration getRendererConfig(String mimeType) {
+    protected Configuration getRendererConfig(String mimeType) {
         Configuration cfg = userAgent.getFactory().getUserConfig();
         if (cfg == null) {
             if (log.isDebugEnabled()) {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/Graphics2DImagePainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/Graphics2DImagePainter.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/Graphics2DImagePainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/Graphics2DImagePainter.java Sun Feb 22 12:40:44 2009
@@ -27,4 +27,4 @@
 public interface Graphics2DImagePainter
         extends org.apache.xmlgraphics.java2d.Graphics2DImagePainter {
 
-}
\ No newline at end of file
+}

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ImageAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ImageAdapter.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ImageAdapter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ImageAdapter.java Sun Feb 22 12:40:44 2009
@@ -34,10 +34,10 @@
      * Paints an image at the given position.
      * @param image the image which will be painted
      * @param context the renderer context for the current renderer
-     * @param x X position of the image
-     * @param y Y position of the image
-     * @param width width of the image
-     * @param height height of the image
+     * @param x X position of the image (in millipoints)
+     * @param y Y position of the image (in millipoints)
+     * @param width width of the image (in millipoints)
+     * @param height height of the image (in millipoints)
      * @throws IOException In case of an I/O error while writing the output format
      */
     void paintImage(RenderedImage image,

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java Sun Feb 22 12:40:44 2009
@@ -24,6 +24,9 @@
 import java.util.List;
 import java.util.Map;
 
+import org.w3c.dom.Document;
+
+import org.apache.fop.apps.FOPException;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.Trait;
 import org.apache.fop.fonts.CustomFontCollection;
@@ -34,7 +37,6 @@
 import org.apache.fop.fonts.FontResolver;
 import org.apache.fop.fonts.FontTriplet;
 import org.apache.fop.fonts.base14.Base14FontCollection;
-import org.w3c.dom.Document;
 
 /** Abstract base class of "Print" type renderers.  */
 public abstract class PrintRenderer extends AbstractRenderer {
@@ -74,12 +76,8 @@
         return this.embedFontInfoList;
     }
 
-    /**
-     * Set up the font info
-     *
-     * @param inFontInfo  font info to set up
-     */
-    public void setupFontInfo(FontInfo inFontInfo) {
+    /** {@inheritDoc} */
+    public void setupFontInfo(FontInfo inFontInfo) throws FOPException {
         this.fontInfo = inFontInfo;
         FontManager fontManager = userAgent.getFactory().getFontManager();
         FontCollection[] fontCollections = new FontCollection[] {
@@ -96,7 +94,13 @@
      */
     protected String getInternalFontNameForArea(Area area) {
         FontTriplet triplet = (FontTriplet)area.getTrait(Trait.FONT);
-        return fontInfo.getInternalFontKey(triplet);
+        String key = fontInfo.getInternalFontKey(triplet);
+        if (key == null) {
+            //Find a default fallback font as last resort
+            triplet = new FontTriplet("any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
+            key = fontInfo.getInternalFontKey(triplet);
+        }
+        return key;
     }
 
     /**

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java Sun Feb 22 12:40:44 2009
@@ -41,9 +41,11 @@
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.FopFactory;
+import org.apache.fop.fonts.CustomFontCollection;
 import org.apache.fop.fonts.EmbedFontInfo;
 import org.apache.fop.fonts.EncodingMode;
 import org.apache.fop.fonts.FontCache;
+import org.apache.fop.fonts.FontCollection;
 import org.apache.fop.fonts.FontEventAdapter;
 import org.apache.fop.fonts.FontEventListener;
 import org.apache.fop.fonts.FontInfo;
@@ -53,13 +55,16 @@
 import org.apache.fop.fonts.FontUtil;
 import org.apache.fop.fonts.autodetect.FontFileFinder;
 import org.apache.fop.fonts.autodetect.FontInfoFinder;
+import org.apache.fop.fonts.base14.Base14FontCollection;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
+import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
 import org.apache.fop.util.LogUtil;
 
 /**
  * Base Print renderer configurator (mostly handles font configuration)
  */
 public class PrintRendererConfigurator extends AbstractRendererConfigurator
-            implements RendererConfigurator {
+            implements RendererConfigurator, IFDocumentHandlerConfigurator {
 
     /** logger instance */
     protected static Log log = LogFactory.getLog(PrintRendererConfigurator.class);
@@ -87,6 +92,23 @@
 
         PrintRenderer printRenderer = (PrintRenderer)renderer;
         FontResolver fontResolver = printRenderer.getFontResolver();
+
+        FontEventListener listener = new FontEventAdapter(
+                renderer.getUserAgent().getEventBroadcaster());
+        List embedFontInfoList = buildFontList(cfg, fontResolver, listener);
+        printRenderer.addFontList(embedFontInfoList);
+    }
+
+    /**
+     * Builds the font list from configuration.
+     * @param cfg the configuration object
+     * @param fontResolver a font resolver
+     * @param listener the font event listener
+     * @return the list of {@code EmbedFontInfo} objects
+     * @throws FOPException if an error occurs while processing the configuration
+     */
+    protected List buildFontList(Configuration cfg, FontResolver fontResolver,
+                    FontEventListener listener) throws FOPException {
         FopFactory factory = userAgent.getFactory();
         FontManager fontManager = factory.getFontManager();
         if (fontResolver == null) {
@@ -97,15 +119,13 @@
         boolean strict = factory.validateUserConfigStrictly();
         FontCache fontCache = fontManager.getFontCache();
 
-        FontEventListener listener = new FontEventAdapter(
-                renderer.getUserAgent().getEventBroadcaster());
         List/*<EmbedFontInfo>*/ embedFontInfoList = buildFontListFromConfiguration(cfg,
                 fontResolver, strict, fontManager, listener);
 
         if (fontCache != null && fontCache.hasChanged()) {
             fontCache.save();
         }
-        printRenderer.addFontList(embedFontInfoList);
+        return embedFontInfoList;
     }
 
     /**
@@ -437,4 +457,33 @@
         return embedFontInfo;
     }
 
+    // ---=== IFDocumentHandler configuration ===---
+
+    /** {@inheritDoc} */
+    public void configure(IFDocumentHandler documentHandler) throws FOPException {
+        //nop
+    }
+
+    /** {@inheritDoc} */
+    public void setupFontInfo(IFDocumentHandler documentHandler, FontInfo fontInfo)
+                throws FOPException {
+        FontManager fontManager = userAgent.getFactory().getFontManager();
+        List fontCollections = new java.util.ArrayList();
+        fontCollections.add(new Base14FontCollection(fontManager.isBase14KerningEnabled()));
+
+        Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
+        if (cfg != null) {
+            FontResolver fontResolver = new DefaultFontResolver(userAgent);
+            FontEventListener listener = new FontEventAdapter(
+                    userAgent.getEventBroadcaster());
+            List fontList = buildFontList(cfg, fontResolver, listener);
+            fontCollections.add(new CustomFontCollection(fontResolver, fontList));
+        }
+
+        fontManager.setup(fontInfo,
+                (FontCollection[])fontCollections.toArray(
+                        new FontCollection[fontCollections.size()]));
+        documentHandler.setFontInfo(fontInfo);
+    }
+
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/Renderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/Renderer.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/Renderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/Renderer.java Sun Feb 22 12:40:44 2009
@@ -98,8 +98,9 @@
      * Set up the given FontInfo.
      *
      * @param fontInfo  The font information
+     * @throws FOPException if an error occurs while setting up the font info object
      */
-    void setupFontInfo(FontInfo fontInfo);
+    void setupFontInfo(FontInfo fontInfo) throws FOPException;
 
     /**
      * Reports if out of order rendering is supported. <p>

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererContext.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererContext.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererContext.java Sun Feb 22 12:40:44 2009
@@ -24,8 +24,6 @@
 import java.util.Map;
 
 import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.fo.extensions.ExtensionElementMapping;
-import org.apache.xmlgraphics.util.QName;
 
 /**
  * The Render Context for external handlers. This provides a rendering context
@@ -33,12 +31,6 @@
  * render target.
  */
 public class RendererContext {
-    /** conversion-mode extension attribute */
-    protected static final QName CONVERSION_MODE = new QName(
-            ExtensionElementMapping.URI, null, "conversion-mode");
-
-    /** "bitmap" value for the "conversion-mode" extension attribute. */
-    protected static final String BITMAP = "bitmap";
 
     private final String mime;
     private final AbstractRenderer renderer;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java Sun Feb 22 12:40:44 2009
@@ -34,6 +34,10 @@
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.area.AreaTreeHandler;
 import org.apache.fop.fo.FOEventHandler;
+import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
+import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
+import org.apache.fop.render.intermediate.IFRenderer;
 
 /**
  * Factory for FOEventHandlers and Renderers.
@@ -45,7 +49,7 @@
 
     private Map rendererMakerMapping = new java.util.HashMap();
     private Map eventHandlerMakerMapping = new java.util.HashMap();
-
+    private Map documentHandlerMakerMapping = new java.util.HashMap();
 
     /**
      * Main constructor.
@@ -53,6 +57,7 @@
     public RendererFactory() {
         discoverRenderers();
         discoverFOEventHandlers();
+        discoverDocumentHandlers();
     }
 
     /**
@@ -90,6 +95,23 @@
     }
 
     /**
+     * Add a new document handler maker. If another maker has already been registered for a
+     * particular MIME type, this call overwrites the existing one.
+     * @param maker the intermediate format document handler maker
+     */
+    public void addDocumentHandlerMaker(AbstractIFDocumentHandlerMaker maker) {
+        String[] mimes = maker.getSupportedMimeTypes();
+        for (int i = 0; i < mimes.length; i++) {
+            //This overrides any renderer previously set for a MIME type
+            if (documentHandlerMakerMapping.get(mimes[i]) != null) {
+                log.trace("Overriding document handler for " + mimes[i]
+                        + " with " + maker.getClass().getName());
+            }
+            documentHandlerMakerMapping.put(mimes[i], maker);
+        }
+    }
+
+    /**
      * Add a new RendererMaker. If another maker has already been registered for a
      * particular MIME type, this call overwrites the existing one.
      * @param className the fully qualified class name of the RendererMaker
@@ -142,6 +164,32 @@
     }
 
     /**
+     * Add a new document handler maker. If another maker has already been registered for a
+     * particular MIME type, this call overwrites the existing one.
+     * @param className the fully qualified class name of the document handler maker
+     */
+    public void addDocumentHandlerMaker(String className) {
+        try {
+            AbstractIFDocumentHandlerMaker makerInstance
+                = (AbstractIFDocumentHandlerMaker)Class.forName(className).newInstance();
+            addDocumentHandlerMaker(makerInstance);
+        } catch (ClassNotFoundException e) {
+            throw new IllegalArgumentException("Could not find "
+                                               + className);
+        } catch (InstantiationException e) {
+            throw new IllegalArgumentException("Could not instantiate "
+                                               + className);
+        } catch (IllegalAccessException e) {
+            throw new IllegalArgumentException("Could not access "
+                                               + className);
+        } catch (ClassCastException e) {
+            throw new IllegalArgumentException(className
+                                               + " is not an "
+                                               + AbstractIFDocumentHandlerMaker.class.getName());
+        }
+    }
+
+    /**
      * Returns a RendererMaker which handles the given MIME type.
      * @param mime the requested output format
      * @return the requested RendererMaker or null if none is available
@@ -164,6 +212,17 @@
     }
 
     /**
+     * Returns a RendererMaker which handles the given MIME type.
+     * @param mime the requested output format
+     * @return the requested RendererMaker or null if none is available
+     */
+    public AbstractIFDocumentHandlerMaker getDocumentHandlerMaker(String mime) {
+        AbstractIFDocumentHandlerMaker maker
+            = (AbstractIFDocumentHandlerMaker)documentHandlerMakerMapping.get(mime);
+        return maker;
+    }
+
+    /**
      * Creates a Renderer object based on render-type desired
      * @param userAgent the user agent for access to configuration
      * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
@@ -172,24 +231,41 @@
      */
     public Renderer createRenderer(FOUserAgent userAgent, String outputFormat)
                     throws FOPException {
-        if (userAgent.getRendererOverride() != null) {
+        if (userAgent.getDocumentHandlerOverride() != null) {
+            return createRendererForDocumentHandler(userAgent.getDocumentHandlerOverride());
+        } else if (userAgent.getRendererOverride() != null) {
             return userAgent.getRendererOverride();
         } else {
             AbstractRendererMaker maker = getRendererMaker(outputFormat);
-            if (maker == null) {
-                throw new UnsupportedOperationException(
-                        "No renderer for the requested format available: " + outputFormat);
-            }
-            Renderer rend = maker.makeRenderer(userAgent);
-            rend.setUserAgent(userAgent);
-            RendererConfigurator configurator = maker.getConfigurator(userAgent);
-            if (configurator != null) {
-                configurator.configure(rend);
+            if (maker != null) {
+                Renderer rend = maker.makeRenderer(userAgent);
+                rend.setUserAgent(userAgent);
+                RendererConfigurator configurator = maker.getConfigurator(userAgent);
+                if (configurator != null) {
+                    configurator.configure(rend);
+                }
+                return rend;
+            } else {
+                AbstractIFDocumentHandlerMaker documentHandlerMaker
+                    = getDocumentHandlerMaker(outputFormat);
+                if (documentHandlerMaker != null) {
+                    IFDocumentHandler documentHandler = createDocumentHandler(
+                            userAgent, outputFormat);
+                    return createRendererForDocumentHandler(documentHandler);
+                } else {
+                    throw new UnsupportedOperationException(
+                            "No renderer for the requested format available: " + outputFormat);
+                }
             }
-            return rend;
         }
     }
 
+    private Renderer createRendererForDocumentHandler(IFDocumentHandler documentHandler) {
+        IFRenderer rend = new IFRenderer();
+        rend.setUserAgent(documentHandler.getContext().getUserAgent());
+        rend.setDocumentHandler(documentHandler);
+        return rend;
+    }
 
     /**
      * Creates FOEventHandler instances based on the desired output.
@@ -206,30 +282,65 @@
             return userAgent.getFOEventHandlerOverride();
         } else {
             AbstractFOEventHandlerMaker maker = getFOEventHandlerMaker(outputFormat);
-            if (maker == null) {
+            if (maker != null) {
+                return maker.makeFOEventHandler(userAgent, out);
+            } else {
                 AbstractRendererMaker rendMaker = getRendererMaker(outputFormat);
-                if (rendMaker == null && userAgent.getRendererOverride() == null) {
-                    throw new UnsupportedOperationException(
-                            "Don't know how to handle \"" + outputFormat + "\" as an output format."
-                            + " Neither an FOEventHandler, nor a Renderer could be found"
-                            + " for this output format.");
+                AbstractIFDocumentHandlerMaker documentHandlerMaker = null;
+                boolean outputStreamMissing = (userAgent.getRendererOverride() == null)
+                    && (userAgent.getDocumentHandlerOverride() == null);
+                if (rendMaker == null) {
+                    documentHandlerMaker = getDocumentHandlerMaker(outputFormat);
+                    if (documentHandlerMaker != null) {
+                        outputStreamMissing &= (out == null)
+                                && (documentHandlerMaker.needsOutputStream());
+                    }
                 } else {
-                    if (out == null
-                            && userAgent.getRendererOverride() == null
-                            && rendMaker.needsOutputStream()) {
+                    outputStreamMissing &= (out == null) && (rendMaker.needsOutputStream());
+                }
+                if (userAgent.getRendererOverride() != null
+                        || rendMaker != null
+                        || userAgent.getDocumentHandlerOverride() != null
+                        || documentHandlerMaker != null) {
+                    if (outputStreamMissing) {
                         throw new FOPException(
                             "OutputStream has not been set");
                     }
                     //Found a Renderer so we need to construct an AreaTreeHandler.
                     return new AreaTreeHandler(userAgent, outputFormat, out);
+                } else {
+                    throw new UnsupportedOperationException(
+                            "Don't know how to handle \"" + outputFormat + "\" as an output format."
+                            + " Neither an FOEventHandler, nor a Renderer could be found"
+                            + " for this output format.");
                 }
-            } else {
-                return maker.makeFOEventHandler(userAgent, out);
             }
         }
     }
 
     /**
+     * Creates a {@code IFDocumentHandler} object based on the desired output format.
+     * @param userAgent the user agent for access to configuration
+     * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
+     * @return the new {@code IFDocumentHandler} instance
+     * @throws FOPException if the document handler cannot be properly constructed
+     */
+    public IFDocumentHandler createDocumentHandler(FOUserAgent userAgent, String outputFormat)
+                    throws FOPException {
+        AbstractIFDocumentHandlerMaker maker = getDocumentHandlerMaker(outputFormat);
+        if (maker == null) {
+            throw new UnsupportedOperationException(
+                "No IF document handler for the requested format available: " + outputFormat);
+        }
+        IFDocumentHandler documentHandler = maker.makeIFDocumentHandler(userAgent);
+        IFDocumentHandlerConfigurator configurator = documentHandler.getConfigurator();
+        if (configurator != null) {
+            configurator.configure(documentHandler);
+        }
+        return documentHandler;
+    }
+
+    /**
      * @return an array of all supported MIME types
      */
     public String[] listSupportedMimeTypes() {
@@ -242,6 +353,10 @@
         while (iter.hasNext()) {
             lst.add(((String)iter.next()));
         }
+        iter = this.documentHandlerMakerMapping.keySet().iterator();
+        while (iter.hasNext()) {
+            lst.add(((String)iter.next()));
+        }
         Collections.sort(lst);
         return (String[])lst.toArray(new String[lst.size()]);
     }
@@ -296,4 +411,29 @@
         }
     }
 
+    /**
+     * Discovers {@code IFDocumentHandler} implementations through the classpath and dynamically
+     * registers them.
+     */
+    private void discoverDocumentHandlers() {
+        // add mappings from available services
+        Iterator providers = Service.providers(IFDocumentHandler.class);
+        if (providers != null) {
+            while (providers.hasNext()) {
+                AbstractIFDocumentHandlerMaker maker
+                    = (AbstractIFDocumentHandlerMaker)providers.next();
+                try {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Dynamically adding maker for IFDocumentHandler: "
+                                + maker.getClass().getName());
+                    }
+                    addDocumentHandlerMaker(maker);
+                } catch (IllegalArgumentException e) {
+                    log.error("Error while adding maker for IFDocumentHandler", e);
+                }
+
+            }
+        }
+    }
+
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPForeignAttributeReader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPForeignAttributeReader.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPForeignAttributeReader.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPForeignAttributeReader.java Sun Feb 22 12:40:44 2009
@@ -24,10 +24,12 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.util.QName;
+
 import org.apache.fop.afp.AFPResourceInfo;
 import org.apache.fop.afp.AFPResourceLevel;
 import org.apache.fop.render.afp.extensions.AFPElementMapping;
-import org.apache.xmlgraphics.util.QName;
 
 /**
  * Parses any AFP foreign attributes
@@ -36,13 +38,16 @@
     private static final Log log = LogFactory.getLog("org.apache.xmlgraphics.afp");
 
     /** the resource-name attribute */
-    public static final String RESOURCE_NAME = "afp:resource-name";
+    public static final QName RESOURCE_NAME = new QName(
+            AFPElementMapping.NAMESPACE, "afp:resource-name");
 
     /** the resource-level attribute */
-    public static final String RESOURCE_LEVEL = "afp:resource-level";
+    public static final QName RESOURCE_LEVEL = new QName(
+            AFPElementMapping.NAMESPACE, "afp:resource-level");
 
     /** the resource-group-file attribute */
-    public static final String RESOURCE_GROUP_FILE = "afp:resource-group-file";
+    public static final QName RESOURCE_GROUP_FILE = new QName(
+            AFPElementMapping.NAMESPACE, "afp:resource-group-file");
 
     /**
      * Main constructor
@@ -59,8 +64,7 @@
     public AFPResourceInfo getResourceInfo(Map/*<QName, String>*/ foreignAttributes) {
         AFPResourceInfo resourceInfo = new AFPResourceInfo();
         if (foreignAttributes != null && !foreignAttributes.isEmpty()) {
-            QName resourceNameKey = new QName(AFPElementMapping.NAMESPACE, RESOURCE_NAME);
-            String resourceName = (String)foreignAttributes.get(resourceNameKey);
+            String resourceName = (String)foreignAttributes.get(RESOURCE_NAME);
             if (resourceName != null) {
                 resourceInfo.setName(resourceName);
             }
@@ -81,16 +85,13 @@
     public AFPResourceLevel getResourceLevel(Map/*<QName, String>*/ foreignAttributes) {
         AFPResourceLevel resourceLevel = null;
         if (foreignAttributes != null && !foreignAttributes.isEmpty()) {
-            QName resourceLevelKey = new QName(AFPElementMapping.NAMESPACE, RESOURCE_LEVEL);
-            if (foreignAttributes.containsKey(resourceLevelKey)) {
-                String levelString = (String)foreignAttributes.get(resourceLevelKey);
+            if (foreignAttributes.containsKey(RESOURCE_LEVEL)) {
+                String levelString = (String)foreignAttributes.get(RESOURCE_LEVEL);
                 resourceLevel = AFPResourceLevel.valueOf(levelString);
                 // if external get resource group file attributes
                 if (resourceLevel != null && resourceLevel.isExternal()) {
-                    QName resourceGroupFileKey = new QName(AFPElementMapping.NAMESPACE,
-                            RESOURCE_GROUP_FILE);
                     String resourceGroupFile
-                        = (String)foreignAttributes.get(resourceGroupFileKey);
+                        = (String)foreignAttributes.get(RESOURCE_GROUP_FILE);
                     if (resourceGroupFile == null) {
                         String msg = RESOURCE_GROUP_FILE + " not specified";
                         log.error(msg);

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPForeignAttributeReader.java
            ('svn:mergeinfo' removed)

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandler.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandler.java Sun Feb 22 12:40:44 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;
@@ -29,12 +30,12 @@
 import org.apache.fop.afp.AFPPaintingState;
 import org.apache.fop.afp.AFPResourceInfo;
 import org.apache.fop.afp.AFPUnitConverter;
-import org.apache.fop.render.ImageHandler;
+import org.apache.fop.render.ImageHandlerBase;
 
 /**
  * A base abstract AFP image handler
  */
-public abstract class AFPImageHandler implements ImageHandler {
+public abstract class AFPImageHandler implements ImageHandlerBase {
     private static final int X = 0;
     private static final int Y = 1;
 
@@ -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/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java Sun Feb 22 12:40:44 2009
@@ -19,8 +19,10 @@
 
 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;
@@ -31,12 +33,16 @@
 import org.apache.fop.afp.AFPGraphicsObjectInfo;
 import org.apache.fop.afp.AFPPaintingState;
 import org.apache.fop.afp.AFPResourceInfo;
+import org.apache.fop.afp.AFPResourceManager;
 import org.apache.fop.afp.modca.ResourceObject;
+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
@@ -65,18 +71,13 @@
             AFPGraphicsObjectInfo graphicsObjectInfo
                 = (AFPGraphicsObjectInfo)super.generateDataObjectInfo(rendererImageInfo);
 
-            AFPResourceInfo resourceInfo = graphicsObjectInfo.getResourceInfo();
-            if (!resourceInfo.levelChanged()) {
-                resourceInfo.setLevel(afpInfo.getResourceManager().getResourceLevelDefaults()
-                        .getDefaultResourceLevel(ResourceObject.TYPE_GRAPHIC));
-            }
+            setDefaultResourceLevel(graphicsObjectInfo, afpInfo.getResourceManager());
 
             // 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 +89,15 @@
         }
     }
 
+    private void setDefaultResourceLevel(AFPGraphicsObjectInfo graphicsObjectInfo,
+            AFPResourceManager resourceManager) {
+        AFPResourceInfo resourceInfo = graphicsObjectInfo.getResourceInfo();
+        if (!resourceInfo.levelChanged()) {
+            resourceInfo.setLevel(resourceManager.getResourceLevelDefaults()
+                    .getDefaultResourceLevel(ResourceObject.TYPE_GRAPHIC));
+        }
+    }
+
     /** {@inheritDoc} */
     public int getPriority() {
         return 200;
@@ -107,4 +117,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));
+
+        setDefaultResourceLevel(graphicsObjectInfo, afpContext.getResourceManager());
+
+        // 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/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRawCCITTFax.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRawCCITTFax.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRawCCITTFax.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRawCCITTFax.java Sun Feb 22 12:40:44 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/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java Sun Feb 22 12:40:44 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/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java Sun Feb 22 12:40:44 2009
@@ -20,6 +20,7 @@
 package org.apache.fop.render.afp;
 
 import java.awt.Dimension;
+import java.awt.Rectangle;
 import java.awt.image.ColorModel;
 import java.awt.image.RenderedImage;
 import java.io.IOException;
@@ -28,6 +29,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.xmlgraphics.image.loader.Image;
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
 import org.apache.xmlgraphics.image.loader.ImageInfo;
 import org.apache.xmlgraphics.image.loader.ImageSize;
@@ -41,13 +43,16 @@
 import org.apache.fop.afp.AFPObjectAreaInfo;
 import org.apache.fop.afp.AFPPaintingState;
 import org.apache.fop.afp.AFPResourceInfo;
+import org.apache.fop.afp.AFPResourceManager;
 import org.apache.fop.afp.modca.ResourceObject;
+import org.apache.fop.render.ImageHandler;
+import org.apache.fop.render.RenderingContext;
 import org.apache.fop.util.bitmap.BitmapImageUtil;
 
 /**
  * PDFImageHandler implementation which handles RenderedImage instances.
  */
-public class AFPImageHandlerRenderedImage extends AFPImageHandler {
+public class AFPImageHandlerRenderedImage extends AFPImageHandler implements ImageHandler {
 
     /** logging instance */
     private static Log log = LogFactory.getLog(AFPImageHandlerRenderedImage.class);
@@ -67,34 +72,40 @@
             = (AFPRendererContext)rendererImageInfo.getRendererContext();
         AFPInfo afpInfo = rendererContext.getInfo();
 
-        AFPResourceInfo resourceInfo = imageObjectInfo.getResourceInfo();
-        if (!resourceInfo.levelChanged()) {
-            resourceInfo.setLevel(afpInfo.getResourceManager().getResourceLevelDefaults()
-                    .getDefaultResourceLevel(ResourceObject.TYPE_IMAGE));
-        }
+        setDefaultResourceLevel(imageObjectInfo, afpInfo.getResourceManager());
 
         AFPPaintingState paintingState = afpInfo.getPaintingState();
+        ImageRendered imageRendered = (ImageRendered) rendererImageInfo.img;
+        Dimension targetSize = new Dimension(afpInfo.getWidth(), afpInfo.getHeight());
+
+        updateDataObjectInfo(imageObjectInfo, paintingState, imageRendered, targetSize);
+        return imageObjectInfo;
+    }
+
+    private AFPDataObjectInfo updateDataObjectInfo(AFPImageObjectInfo imageObjectInfo,
+            AFPPaintingState paintingState, ImageRendered imageRendered, Dimension targetSize)
+            throws IOException {
+
         int resolution = paintingState.getResolution();
         int maxPixelSize = paintingState.getBitsPerPixel();
         if (paintingState.isColorImages()) {
             maxPixelSize *= 3; //RGB only at the moment
         }
-        ImageRendered imageRendered = (ImageRendered) rendererImageInfo.img;
         RenderedImage renderedImage = imageRendered.getRenderedImage();
 
-        ImageInfo imageInfo = rendererImageInfo.getImageInfo();
+        ImageInfo imageInfo = imageRendered.getInfo();
         ImageSize intrinsicSize = imageInfo.getSize();
 
         boolean useFS10 = (maxPixelSize == 1) || BitmapImageUtil.isMonochromeImage(renderedImage);
         boolean usePageSegments = useFS10
-                    && !resourceInfo.getLevel().isInline();
+                    && !imageObjectInfo.getResourceInfo().getLevel().isInline();
 
         ImageSize effIntrinsicSize = intrinsicSize;
         if (usePageSegments) {
             //Resize, optionally resample and convert image
             Dimension resampledDim = new Dimension(
-                    (int)Math.ceil(UnitConv.mpt2px(afpInfo.getWidth(), resolution)),
-                    (int)Math.ceil(UnitConv.mpt2px(afpInfo.getHeight(), resolution)));
+                    (int)Math.ceil(UnitConv.mpt2px(targetSize.getWidth(), resolution)),
+                    (int)Math.ceil(UnitConv.mpt2px(targetSize.getHeight(), resolution)));
 
             imageObjectInfo.setCreatePageSegment(true);
             imageObjectInfo.getResourceInfo().setImageDimension(resampledDim);
@@ -130,6 +141,8 @@
         int dataWidth = renderedImage.getWidth();
         imageObjectInfo.setDataWidth(dataWidth);
 
+        //TODO To reduce AFP file size, investigate using a compression scheme.
+        //Currently, all image data is uncompressed.
         ColorModel cm = renderedImage.getColorModel();
         if (log.isTraceEnabled()) {
             log.trace("ColorModel: " + cm);
@@ -209,6 +222,15 @@
         return imageObjectInfo;
     }
 
+    private void setDefaultResourceLevel(AFPImageObjectInfo imageObjectInfo,
+            AFPResourceManager resourceManager) {
+        AFPResourceInfo resourceInfo = imageObjectInfo.getResourceInfo();
+        if (!resourceInfo.levelChanged()) {
+            resourceInfo.setLevel(resourceManager.getResourceLevelDefaults()
+                    .getDefaultResourceLevel(ResourceObject.TYPE_IMAGE));
+        }
+    }
+
     /** {@inheritDoc} */
     protected AFPDataObjectInfo createDataObjectInfo() {
         return new AFPImageObjectInfo();
@@ -229,4 +251,35 @@
         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());
+        setDefaultResourceLevel(imageObjectInfo, afpContext.getResourceManager());
+
+        // Positioning
+        imageObjectInfo.setObjectAreaInfo(createObjectAreaInfo(afpContext.getPaintingState(), pos));
+        Dimension targetSize = pos.getSize();
+
+        // Image content
+        ImageRendered imageRend = (ImageRendered)image;
+        updateDataObjectInfo(imageObjectInfo, afpContext.getPaintingState(), imageRend, targetSize);
+
+        // Create image
+        afpContext.getResourceManager().createObject(imageObjectInfo);
+    }
+
+    /** {@inheritDoc} */
+    public boolean isCompatible(RenderingContext targetContext, Image image) {
+        return (image == null || image instanceof ImageRendered)
+            && targetContext instanceof AFPRenderingContext;
+    }
+
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java?rev=746664&r1=746663&r2=746664&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java Sun Feb 22 12:40:44 2009
@@ -136,7 +136,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;
@@ -543,6 +543,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;
 
@@ -679,7 +680,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
@@ -689,68 +690,39 @@
         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);
     }
 
-    /**
-     * Sets the resource level defaults. The object passed in provides information which resource
-     * level shall be used by default for various kinds of resources.
-     * @param defaults the resource level defaults
-     */
+    /** {@inheritDoc} */
     public void setResourceLevelDefaults(AFPResourceLevelDefaults defaults) {
         resourceManager.setResourceLevelDefaults(defaults);
     }



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