You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2008/07/16 11:10:04 UTC

svn commit: r677204 [1/2] - in /xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src: java/META-INF/services/ java/org/apache/fop/cli/ java/org/apache/fop/render/ java/org/apache/fop/render/iform/ java/org/apache/fop/render/intermediate/ java/org/apache...

Author: jeremias
Date: Wed Jul 16 02:10:02 2008
New Revision: 677204

URL: http://svn.apache.org/viewvc?rev=677204&view=rev
Log:
Renamed "iform" package to "intermediate" (iform was too cryptic for my taste)
Changed IFRenderer to work against the IFPainter interface.
Started IFPainter implementations for the IF format (IFSerializer), SVG 1.1 and SVG Print. They currently support very simple FOs only (like examples/fo/basic/simple.fo).

Added:
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractIFPainterMaker.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/DelegatingFragmentContentHandler.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFConstants.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFContentHandler.java   (contents, props changed)
      - copied, changed from r675854, xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/iform/IFContentHandler.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFException.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java   (contents, props changed)
      - copied, changed from r675854, xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/iform/IFPainter.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java   (contents, props changed)
      - copied, changed from r675854, xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/iform/IFRenderer.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRendererMaker.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFState.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/META-INF/services/org.apache.fop.render.intermediate.IFPainter
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGConstants.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainter.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainterMaker.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainter.java   (with props)
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainterMaker.java   (with props)
Removed:
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/iform/IFContentHandler.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/iform/IFPainter.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/iform/IFRenderer.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/META-INF/services/org.apache.fop.render.Renderer
Modified:
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.render.Renderer
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/cli/CommandLineOptions.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererFactory.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/util/DelegatingContentHandler.java

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.render.Renderer
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.render.Renderer?rev=677204&r1=677203&r2=677204&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.render.Renderer (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.render.Renderer Wed Jul 16 02:10:02 2008
@@ -8,3 +8,4 @@
 org.apache.fop.render.print.PrintRendererMaker
 org.apache.fop.render.afp.AFPRendererMaker
 org.apache.fop.render.pcl.PCLRendererMaker
+org.apache.fop.render.intermediate.IFRendererMaker

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/cli/CommandLineOptions.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/cli/CommandLineOptions.java?rev=677204&r1=677203&r2=677204&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/cli/CommandLineOptions.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/cli/CommandLineOptions.java Wed Jul 16 02:10:02 2008
@@ -45,7 +45,7 @@
 import org.apache.fop.pdf.PDFXMode;
 import org.apache.fop.render.Renderer;
 import org.apache.fop.render.awt.AWTRenderer;
-import org.apache.fop.render.iform.IFRenderer;
+import org.apache.fop.render.intermediate.IFRenderer;
 import org.apache.fop.render.pdf.PDFRenderer;
 import org.apache.fop.render.print.PagesMode;
 import org.apache.fop.render.print.PrintRenderer;

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererFactory.java?rev=677204&r1=677203&r2=677204&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererFactory.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/RendererFactory.java Wed Jul 16 02:10:02 2008
@@ -5,9 +5,9 @@
  * 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.
@@ -16,7 +16,7 @@
  */
 
 /* $Id$ */
- 
+
 package org.apache.fop.render;
 
 import java.io.OutputStream;
@@ -34,27 +34,31 @@
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.area.AreaTreeHandler;
 import org.apache.fop.fo.FOEventHandler;
+import org.apache.fop.render.intermediate.AbstractIFPainterMaker;
+import org.apache.fop.render.intermediate.IFPainter;
+import org.apache.fop.render.intermediate.IFRenderer;
 
 /**
  * Factory for FOEventHandlers and Renderers.
  */
 public class RendererFactory {
-    
+
     /** the logger */
     private static Log log = LogFactory.getLog(RendererFactory.class);
 
     private Map rendererMakerMapping = new java.util.HashMap();
     private Map eventHandlerMakerMapping = new java.util.HashMap();
-    
-    
+    private Map painterMakerMapping = new java.util.HashMap();
+
     /**
      * Main constructor.
      */
     public RendererFactory() {
         discoverRenderers();
         discoverFOEventHandlers();
+        discoverPainters();
     }
-    
+
     /**
      * Add a new RendererMaker. If another maker has already been registered for a
      * particular MIME type, this call overwrites the existing one.
@@ -65,13 +69,13 @@
         for (int i = 0; i < mimes.length; i++) {
             //This overrides any renderer previously set for a MIME type
             if (rendererMakerMapping.get(mimes[i]) != null) {
-                log.trace("Overriding renderer for " + mimes[i] 
+                log.trace("Overriding renderer for " + mimes[i]
                         + " with " + maker.getClass().getName());
             }
             rendererMakerMapping.put(mimes[i], maker);
         }
     }
-    
+
     /**
      * Add a new FOEventHandlerMaker. If another maker has already been registered for a
      * particular MIME type, this call overwrites the existing one.
@@ -82,13 +86,30 @@
         for (int i = 0; i < mimes.length; i++) {
             //This overrides any event handler previously set for a MIME type
             if (eventHandlerMakerMapping.get(mimes[i]) != null) {
-                log.trace("Overriding FOEventHandler for " + mimes[i] 
+                log.trace("Overriding FOEventHandler for " + mimes[i]
                         + " with " + maker.getClass().getName());
             }
             eventHandlerMakerMapping.put(mimes[i], maker);
         }
     }
-    
+
+    /**
+     * Add a new painter maker. If another maker has already been registered for a
+     * particular MIME type, this call overwrites the existing one.
+     * @param maker the painter maker
+     */
+    public void addPainterMaker(AbstractIFPainterMaker maker) {
+        String[] mimes = maker.getSupportedMimeTypes();
+        for (int i = 0; i < mimes.length; i++) {
+            //This overrides any renderer previously set for a MIME type
+            if (painterMakerMapping.get(mimes[i]) != null) {
+                log.trace("Overriding painter for " + mimes[i]
+                        + " with " + maker.getClass().getName());
+            }
+            painterMakerMapping.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.
@@ -114,7 +135,7 @@
                                                + AbstractRendererMaker.class.getName());
         }
     }
-    
+
     /**
      * Add a new FOEventHandlerMaker. If another maker has already been registered for a
      * particular MIME type, this call overwrites the existing one.
@@ -140,7 +161,33 @@
                                                + AbstractFOEventHandlerMaker.class.getName());
         }
     }
-    
+
+    /**
+     * Add a new painter 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 painter maker
+     */
+    public void addPainterMaker(String className) {
+        try {
+            AbstractIFPainterMaker makerInstance
+                = (AbstractIFPainterMaker)Class.forName(className).newInstance();
+            addPainterMaker(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 "
+                                               + AbstractIFPainterMaker.class.getName());
+        }
+    }
+
     /**
      * Returns a RendererMaker which handles the given MIME type.
      * @param mime the requested output format
@@ -151,7 +198,7 @@
             = (AbstractRendererMaker)rendererMakerMapping.get(mime);
         return maker;
     }
-    
+
     /**
      * Returns a FOEventHandlerMaker which handles the given MIME type.
      * @param mime the requested output format
@@ -162,7 +209,18 @@
             = (AbstractFOEventHandlerMaker)eventHandlerMakerMapping.get(mime);
         return maker;
     }
-    
+
+    /**
+     * 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 AbstractIFPainterMaker getPainterMaker(String mime) {
+        AbstractIFPainterMaker maker
+            = (AbstractIFPainterMaker)painterMakerMapping.get(mime);
+        return maker;
+    }
+
     /**
      * Creates a Renderer object based on render-type desired
      * @param userAgent the user agent for access to configuration
@@ -170,27 +228,36 @@
      * @return the new Renderer instance
      * @throws FOPException if the renderer cannot be properly constructed
      */
-    public Renderer createRenderer(FOUserAgent userAgent, String outputFormat) 
+    public Renderer createRenderer(FOUserAgent userAgent, String outputFormat)
                     throws FOPException {
         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 {
+                AbstractIFPainterMaker painterMaker = getPainterMaker(outputFormat);
+                if (painterMaker != null) {
+                    IFRenderer rend = new IFRenderer();
+                    rend.setUserAgent(userAgent);
+                    IFPainter painter = painterMaker.makePainter(userAgent);
+                    rend.setPainter(painter);
+                    return rend;
+                } else {
+                    throw new UnsupportedOperationException(
+                            "No renderer for the requested format available: " + outputFormat);
+                }
             }
-            return rend;
         }
     }
-    
-    
+
     /**
      * Creates FOEventHandler instances based on the desired output.
      * @param userAgent the user agent for access to configuration
@@ -199,36 +266,75 @@
      * @return the newly constructed FOEventHandler
      * @throws FOPException if the FOEventHandler cannot be properly constructed
      */
-    public FOEventHandler createFOEventHandler(FOUserAgent userAgent, 
+    public FOEventHandler createFOEventHandler(FOUserAgent userAgent,
                 String outputFormat, OutputStream out) throws FOPException {
 
         if (userAgent.getFOEventHandlerOverride() != null) {
             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.");
+                AbstractIFPainterMaker painterMaker = null;
+                boolean outputStreamMissing = (userAgent.getRendererOverride() == null);
+                if (rendMaker == null) {
+                    painterMaker = getPainterMaker(outputFormat);
+                    outputStreamMissing &= (out == null) && (painterMaker.needsOutputStream());
                 } else {
-                    if (out == null 
-                            && userAgent.getRendererOverride() == null 
-                            && rendMaker.needsOutputStream()) {
+                    outputStreamMissing &= (out == null) && (rendMaker.needsOutputStream());
+                }
+                if (userAgent.getRendererOverride() != null
+                        || rendMaker != null
+                        || painterMaker != 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 IFPainter} 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").
+     * @return the new {@code IFPainter} instance
+     * @throws FOPException if the painter cannot be properly constructed
+     */
+    public IFPainter createPainter(FOUserAgent userAgent, String outputFormat)
+                    throws FOPException {
+        /*
+        if (userAgent.getIFPainterOverride() != null) {
+            return userAgent.getIFPainterOverride();
+        } else {
+        */
+            AbstractIFPainterMaker maker = getPainterMaker(outputFormat);
+            if (maker == null) {
+                throw new UnsupportedOperationException(
+                        "No renderer for the requested format available: " + outputFormat);
+            }
+            IFPainter painter = maker.makePainter(userAgent);
+            painter.setUserAgent(userAgent);
+            //TODO Add configuration
+            /*
+            RendererConfigurator configurator = maker.getConfigurator(userAgent);
+            if (configurator != null) {
+                configurator.configure(painter);
+            }*/
+            return painter;
+        //}
+    }
+
     /**
      * @return an array of all supported MIME types
      */
@@ -242,10 +348,14 @@
         while (iter.hasNext()) {
             lst.add(((String)iter.next()));
         }
+        iter = this.painterMakerMapping.keySet().iterator();
+        while (iter.hasNext()) {
+            lst.add(((String)iter.next()));
+        }
         Collections.sort(lst);
         return (String[])lst.toArray(new String[lst.size()]);
     }
-    
+
     /**
      * Discovers Renderer implementations through the classpath and dynamically
      * registers them.
@@ -259,7 +369,7 @@
                 AbstractRendererMaker maker = (AbstractRendererMaker)providers.next();
                 try {
                     if (log.isDebugEnabled()) {
-                        log.debug("Dynamically adding maker for Renderer: " 
+                        log.debug("Dynamically adding maker for Renderer: "
                                 + maker.getClass().getName());
                     }
                     addRendererMaker(maker);
@@ -270,7 +380,7 @@
             }
         }
     }
-    
+
     /**
      * Discovers FOEventHandler implementations through the classpath and dynamically
      * registers them.
@@ -284,7 +394,7 @@
                 AbstractFOEventHandlerMaker maker = (AbstractFOEventHandlerMaker)providers.next();
                 try {
                     if (log.isDebugEnabled()) {
-                        log.debug("Dynamically adding maker for FOEventHandler: " 
+                        log.debug("Dynamically adding maker for FOEventHandler: "
                                 + maker.getClass().getName());
                     }
                     addFOEventHandlerMaker(maker);
@@ -295,5 +405,30 @@
             }
         }
     }
-    
+
+    /**
+     * Discovers {@code IFPainter} implementations through the classpath and dynamically
+     * registers them.
+     */
+    private void discoverPainters() {
+        // add mappings from available services
+        Iterator providers
+            = Service.providers(IFPainter.class);
+        if (providers != null) {
+            while (providers.hasNext()) {
+                AbstractIFPainterMaker maker = (AbstractIFPainterMaker)providers.next();
+                try {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Dynamically adding maker for IFPainter: "
+                                + maker.getClass().getName());
+                    }
+                    addPainterMaker(maker);
+                } catch (IllegalArgumentException e) {
+                    log.error("Error while adding maker for IFPainter", e);
+                }
+
+            }
+        }
+    }
+
 }

Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java Wed Jul 16 02:10:02 2008
@@ -0,0 +1,50 @@
+/*
+ * 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.intermediate;
+
+import org.apache.fop.apps.FOUserAgent;
+
+/**
+ * Abstract base class for IFPainter implementations.
+ */
+public abstract class AbstractIFPainter implements IFPainter {
+
+    private FOUserAgent userAgent;
+
+    /**
+     * Default constructor.
+     */
+    public AbstractIFPainter() {
+    }
+
+    /** {@inheritDoc} */
+    public void setUserAgent(FOUserAgent ua) {
+        this.userAgent = ua;
+    }
+
+    /**
+     * Returns the user agent.
+     * @return the user agent
+     */
+    protected FOUserAgent getUserAgent() {
+        return this.userAgent;
+    }
+
+}

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

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

Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractIFPainterMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractIFPainterMaker.java?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractIFPainterMaker.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractIFPainterMaker.java Wed Jul 16 02:10:02 2008
@@ -0,0 +1,72 @@
+/*
+ * 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.intermediate;
+
+import org.apache.fop.apps.FOUserAgent;
+
+/**
+ * Base class for factory classes which instantiate {@code IFPainter}s and provide information
+ * about them.
+ */
+public abstract class AbstractIFPainterMaker {
+
+    /**
+     * Instantiates a new {@code IFPainter}.
+     * @param userAgent the user agent
+     * @return the newly instantiated painter
+     */
+    public abstract IFPainter makePainter(FOUserAgent userAgent);
+
+    /**
+     * @return Indicates whether this painter requires an OutputStream to work with.
+     */
+    public abstract boolean needsOutputStream();
+
+    /**
+     * @return an array of MIME types the painter supports.
+     */
+    public abstract String[] getSupportedMimeTypes();
+
+    /**
+     * Returns a renderer config object that can be used to
+     * configure the painter.
+     * @param userAgent user agent
+     * @return a config object that can be used to configure the painter
+     */
+    /*
+    public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
+        return null;
+    }*/
+
+    /**
+     * Indicates whether a specific MIME type is supported by this painter.
+     * @param mimeType the MIME type (ex. "application/pdf")
+     * @return true if the MIME type is supported
+     */
+    public boolean isMimeTypeSupported(String mimeType) {
+        String[] mimes = getSupportedMimeTypes();
+        for (int i = 0; i < mimes.length; i++) {
+            if (mimes[i].equals(mimeType)) {
+                return true;
+            }
+        }
+        return false;
+    }
+}

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

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

Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java Wed Jul 16 02:10:02 2008
@@ -0,0 +1,206 @@
+/*
+ * 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.intermediate;
+
+import java.awt.geom.AffineTransform;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.util.Locale;
+
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import javax.xml.transform.sax.TransformerHandler;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * Abstract base class for XML-writing IFPainter implementations.
+ */
+public abstract class AbstractXMLWritingIFPainter extends AbstractIFPainter {
+
+    private static final Attributes EMPTY_ATTS = new AttributesImpl();
+
+    /** Constant for the "CDATA" attribute type. */
+    protected static final String CDATA = "CDATA";
+
+    /**
+     * Default SAXTransformerFactory that can be used by subclasses.
+     */
+    protected SAXTransformerFactory tFactory
+        = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
+
+    /** Main SAX ContentHandler to receive the generated SAX events. */
+    protected ContentHandler handler;
+
+    /** {@inheritDoc} */
+    public ContentHandler getContentHandler() {
+        return this.handler;
+    }
+
+    /** {@inheritDoc} */
+    public void setResult(Result result) throws IFException {
+        if (result instanceof SAXResult) {
+            SAXResult saxResult = (SAXResult)result;
+            this.handler = saxResult.getHandler();
+        } else {
+            this.handler = createContentHandler(result);
+        }
+    }
+
+    /**
+     * Returns the main namespace used for generated XML content.
+     * @return the main namespace
+     */
+    protected abstract String getMainNamespace();
+
+    /**
+     * Creates a ContentHandler for the given JAXP Result instance.
+     * @param result the JAXP Result instance
+     * @return the requested SAX ContentHandler
+     * @throws IFException if an error occurs setting up the output
+     */
+    protected ContentHandler createContentHandler(Result result) throws IFException {
+        try {
+            TransformerHandler tHandler = tFactory.newTransformerHandler();
+            Transformer transformer = tHandler.getTransformer();
+            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+            tHandler.setResult(result);
+            return tHandler;
+        } catch (TransformerConfigurationException tce) {
+            throw new IFException(
+                    "Error while setting up the serializer for SVG output", tce);
+        }
+    }
+
+    /* ---=== helper methods ===--- */
+
+    private static final String BASE_FORMAT = "0.################";
+
+    private static class DecimalFormatThreadLocal extends ThreadLocal {
+
+        protected synchronized Object initialValue() {
+            DecimalFormat df = new DecimalFormat(BASE_FORMAT, new DecimalFormatSymbols(Locale.US));
+            return df;
+        }
+    };
+
+    //DecimalFormat is not thread-safe!
+    private static final ThreadLocal DECIMAL_FORMAT = new DecimalFormatThreadLocal();
+
+    private static String format(double value) {
+        DecimalFormat df = (DecimalFormat)DECIMAL_FORMAT.get();
+        return df.format(value);
+    }
+
+    /**
+     * Converts an {@code AffineTransform} instance to an SVG style transform method.
+     * @param transform the transformation matrix
+     * @param sb the StringBuffer to write the transform method to
+     * @return the StringBuffer passed to this method
+     */
+    protected StringBuffer toString(AffineTransform transform, StringBuffer sb) {
+        double[] matrix = new double[6];
+        transform.getMatrix(matrix);
+        if (matrix[0] == 1 && matrix[3] == 1 && matrix[1] == 0 && matrix[2] == 0) {
+            sb.append("translate(");
+            sb.append(format(matrix[4]));
+            if (matrix[5] != 0) {
+                sb.append(',').append(format(matrix[5]));
+            }
+        } else {
+            sb.append("matrix(");
+            for (int i = 0; i < 6; i++) {
+                if (i > 0) {
+                    sb.append(',');
+                }
+                sb.append(format(matrix[i]));
+            }
+        }
+        sb.append(')');
+        return sb;
+    }
+
+
+    /**
+     * Convenience method to generate a startElement SAX event.
+     * @param localName the local name of the element
+     * @param atts the attributes
+     * @throws SAXException if a SAX exception occurs
+     */
+    protected void startElement(String localName, Attributes atts) throws SAXException {
+        handler.startElement(getMainNamespace(), localName, localName, atts);
+    }
+
+    /**
+     * Convenience method to generate a startElement SAX event.
+     * @param localName the local name of the element
+     * @throws SAXException if a SAX exception occurs
+     */
+    protected void startElement(String localName) throws SAXException {
+        handler.startElement(getMainNamespace(), localName, localName, EMPTY_ATTS);
+    }
+
+    /**
+     * Convenience method to generate a endElement SAX event.
+     * @param localName the local name of the element
+     * @throws SAXException if a SAX exception occurs
+     */
+    protected void endElement(String localName) throws SAXException {
+        handler.endElement(getMainNamespace(), localName, localName);
+    }
+
+    /**
+     * Convenience method to generate an empty element.
+     * @param localName the local name of the element
+     * @param atts the attributes
+     * @throws SAXException if a SAX exception occurs
+     */
+    protected void element(String localName, Attributes atts) throws SAXException {
+        handler.startElement(getMainNamespace(), localName, localName, atts);
+        handler.endElement(getMainNamespace(), localName, localName);
+    }
+
+    /**
+     * Converts an array of integer coordinates into a space-separated string.
+     * @param coordinates the coordinates
+     * @return the space-separated array of coordinates
+     */
+    protected String toString(int[] coordinates) {
+        if (coordinates == null) {
+            return "";
+        }
+        StringBuffer sb = new StringBuffer();
+        for (int i = 0, c = coordinates.length; i < c; i++) {
+            if (i > 0) {
+                sb.append(' ');
+            }
+            sb.append(Integer.toString(coordinates[i]));
+        }
+        return sb.toString();
+    }
+}

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

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

Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/DelegatingFragmentContentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/DelegatingFragmentContentHandler.java?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/DelegatingFragmentContentHandler.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/DelegatingFragmentContentHandler.java Wed Jul 16 02:10:02 2008
@@ -0,0 +1,68 @@
+/*
+ * 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.intermediate;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.DTDHandler;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+import org.apache.fop.util.DelegatingContentHandler;
+
+/**
+ * This class is a {@code DelegatingContentHandler} subclass which swallows the
+ * {@code #startDocument()} and {@code #endDocument()} methods. This is useful for handling
+ * XML fragments.
+ */
+public class DelegatingFragmentContentHandler extends DelegatingContentHandler {
+
+    /**
+     * Main constructor
+     * @param delegate the content handler to delegate the SAX events to
+     */
+    public DelegatingFragmentContentHandler(ContentHandler delegate) {
+        setDelegateContentHandler(delegate);
+        if (delegate instanceof LexicalHandler) {
+            setDelegateLexicalHandler((LexicalHandler)delegate);
+        }
+        if (delegate instanceof DTDHandler) {
+            setDelegateDTDHandler((DTDHandler)delegate);
+        }
+        if (delegate instanceof EntityResolver) {
+            setDelegateEntityResolver((EntityResolver)delegate);
+        }
+        if (delegate instanceof ErrorHandler) {
+            setDelegateErrorHandler((ErrorHandler)delegate);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public void startDocument() throws SAXException {
+        //nop/ignore
+    }
+
+    /** {@inheritDoc} */
+    public void endDocument() throws SAXException {
+        //nop/ignore
+    }
+
+}

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

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

Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFConstants.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFConstants.java?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFConstants.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFConstants.java Wed Jul 16 02:10:02 2008
@@ -0,0 +1,51 @@
+/*
+ * 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.intermediate;
+
+import org.apache.fop.apps.MimeConstants;
+
+/**
+ * Constants for the intermediate format.
+ */
+public interface IFConstants {
+
+    /** MIME type of the intermediate format. */
+    String MIME_TYPE = MimeConstants.MIME_FOP_IF;
+
+    /** XML namespace of the intermediate format. */
+    String NAMESPACE = "http://xmlgraphics.apache.org/fop/intermediate";
+
+    /** XML namespace. */
+    String XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
+
+    /** Namespace prefix for XLink */
+    String XLINK_PREFIX = "xlink";
+    /** XML namespace for XLink */
+    String XLINK_NAMESPACE = "http://www.w3.org/1999/xlink";
+
+    String EL_DOCUMENT = "document";
+    String EL_HEADER = "header";
+    String EL_PAGE_SEQUENCE = "page-sequence";
+    String EL_PAGE = "page";
+    String EL_PAGE_HEADER = "page-header";
+    String EL_PAGE_TRAILER = "page-trailer";
+    String EL_PAGE_CONTENT = "content";
+    String EL_BOX = "box";
+}

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

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

Copied: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFContentHandler.java (from r675854, xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/iform/IFContentHandler.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFContentHandler.java?p2=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFContentHandler.java&p1=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/iform/IFContentHandler.java&r1=675854&r2=677204&rev=677204&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/iform/IFContentHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFContentHandler.java Wed Jul 16 02:10:02 2008
@@ -5,9 +5,9 @@
  * 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.
@@ -17,7 +17,7 @@
 
 /* $Id$ */
 
-package org.apache.fop.render.iform;
+package org.apache.fop.render.intermediate;
 
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;

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

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

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFContentHandler.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFException.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFException.java?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFException.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFException.java Wed Jul 16 02:10:02 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.intermediate;
+
+/**
+ * Exception thrown by code dealing with FOP's intermediate format.
+ */
+public class IFException extends Exception {
+
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * Constructs a new exception with the specified detail message and
+     * cause.  <p>Note that the detail message associated with
+     * <code>cause</code> is <i>not</i> automatically incorporated in
+     * this exception's detail message.
+     *
+     * @param  message the detail message (which is saved for later retrieval
+     *         by the {@link #getMessage()} method).
+     * @param  cause the cause (which is saved for later retrieval by the
+     *         {@link #getCause()} method).  (A <tt>null</tt> value is
+     *         permitted, and indicates that the cause is nonexistent or
+     *         unknown.)
+     */
+    public IFException(String message, Exception cause) {
+        super(message, cause);
+    }
+
+}

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

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

Copied: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java (from r675854, xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/iform/IFPainter.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java?p2=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java&p1=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/iform/IFPainter.java&r1=675854&r2=677204&rev=677204&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/iform/IFPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java Wed Jul 16 02:10:02 2008
@@ -5,9 +5,9 @@
  * 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.
@@ -17,52 +17,238 @@
 
 /* $Id$ */
 
-package org.apache.fop.render.iform;
+package org.apache.fop.render.intermediate;
 
+import java.awt.Color;
 import java.awt.Dimension;
+import java.awt.Paint;
 import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
 
-import org.xml.sax.ContentHandler;
+import javax.xml.transform.Result;
 
-public interface IFPainter {
+import org.apache.fop.apps.FOUserAgent;
 
-    //for foreign content and extensions
-    ContentHandler getContentHandler();
+/**
+ * Interface used to paint whole documents layouted by Apache FOP.
+ * <p>
+ * Call sequence:
+ * <p>
+ * <pre>
+ * startDocument()
+ *   startDocumentHeader()
+ *   [handleExtension()]*
+ *   endDocumentHeader()
+ *   [
+ *   startPageSequence()
+ *     [
+ *     startPage()
+ *       startPageHeader()
+ *         [handleExtension()]*
+ *       endPageHeader()
+ *       startPageContent()
+ *         (#pageContent)+
+ *       endPageContent()
+ *       startPageTrailer()
+ *         (addTarget())*
+ *       endPageTrailer()
+ *     endPage()
+ *     ]*
+ *   endPageSequence()
+ *   ]*
+ * endDocument()
+ *
+ * #box:
+ * startBox()
+ * (#pageContent)+
+ * endBox()
+ *
+ * #pageContent:
+ * (
+ *   setFont() |
+ *   drawText() |
+ *   drawRect() |
+ *   drawImage() |
+ *   TODO etc. etc. |
+ *   handleExtensionObject()
+ * )
+ * </pre>
+ */
+public interface IFPainter {
 
-    void startDocument();
-    void endDocument();
+    /**
+     * Set the user agent.
+     * @param userAgent  The user agent
+     */
+    void setUserAgent(FOUserAgent userAgent);
+
+    /**
+     * Sets the JAXP Result object to receive the generated content.
+     * @param result the JAXP Result object to receive the generated content
+     * @throws IFException if an error occurs setting up the output
+     */
+    void setResult(Result result) throws IFException;
+
+    /**
+     * Indicates whether the painter supports to handle the pages in mixed order rather than
+     * ascending order.
+     * @return true if out-of-order handling is supported
+     */
+    boolean supportsPagesOutOfOrder();
+
+    /**
+     * Indicates the start of a document. This method may only be called once before any other
+     * event method.
+     * @throws IFException if an error occurs while handling this event
+     */
+    void startDocument() throws IFException;
+
+    /**
+     * Indicates the end of a document. This method may only be called once after the whole
+     * document has been handled. Implementations can release resources (close streams). It is
+     * an error to call any event method after this method.
+     * @throws IFException if an error occurs while handling this event
+     */
+    void endDocument() throws IFException;
+
+    /**
+     * Indicates the start of the document header. This method is called right after the
+     * {@code #startDocument()} method. Extensions sent to this painter between
+     * {@code #startDocumentHeader()} and {@code #endDocumentHeader()} apply to the document as
+     * a whole (like document metadata).
+     * @throws IFException if an error occurs while handling this event
+     */
+    void startDocumentHeader() throws IFException;
+
+    /**
+     * Indicates the end of the document header. This method is called before the first
+     * page sequence.
+     * @throws IFException if an error occurs while handling this event
+     */
+    void endDocumentHeader() throws IFException;
+
+    /**
+     * Indicates the start of a new page sequence.
+     * @param id the page sequence's identifier (or null if none is available)
+     * @throws IFException if an error occurs while handling this event
+     */
+    void startPageSequence(String id) throws IFException;
+    /**
+     * Indicates the end of a page sequence.
+     * @throws IFException if an error occurs while handling this event
+     */
+    void endPageSequence() throws IFException;
+
+    /**
+     * Indicates the start of a new page.
+     * @param index the index of the page within the document (0-based)
+     * @param name the page name (usually the formatted page number)
+     * @param size the size of the page (equivalent to the MediaBox in PDF)
+     * @throws IFException if an error occurs while handling this event
+     */
+    void startPage(int index, String name, Dimension size) throws IFException;
+
+    /**
+     * Indicates the end of a page
+     * @throws IFException if an error occurs while handling this event
+     */
+    void endPage() throws IFException;
+
+    /**
+     * Indicates the start of the page header.
+     * @throws IFException if an error occurs while handling this event
+     */
+    void startPageHeader() throws IFException;
+
+    /**
+     * Indicates the end of the page header.
+     * @throws IFException if an error occurs while handling this event
+     */
+    void endPageHeader() throws IFException;
+
+    /**
+     * Indicates the start of the page content.
+     * @throws IFException if an error occurs while handling this event
+     */
+    void startPageContent() throws IFException;
+
+    /**
+     * Indicates the end of the page content.
+     * @throws IFException if an error occurs while handling this event
+     */
+    void endPageContent() throws IFException;
+
+    /**
+     * Indicates the start of the page trailer. The page trailer is used for writing down page
+     * elements which are only know after handling the page itself (like PDF targets).
+     * @throws IFException if an error occurs while handling this event
+     */
+    void startPageTrailer() throws IFException;
+
+    /**
+     * @todo Solve with extension because not all formats support that?
+     */
+    void addTarget(String name, int x, int y) throws IFException;
+
+    /**
+     * Indicates the end of the page trailer.
+     * @throws IFException if an error occurs while handling this event
+     */
+    void endPageTrailer() throws IFException;
+
+    void startBox(AffineTransform transform, Dimension size, boolean clip) throws IFException;
+    void startBox(AffineTransform[] transforms, Dimension size, boolean clip) throws IFException;
+    //For transform, Batik's org.apache.batik.parser.TransformListHandler/Parser can be used
+    void endBox() throws IFException;
+
+    /**
+     * Updates the current font.
+     * @param family the font family (or null if there's no change)
+     * @param style the font style (or null if there's no change)
+     * @param weight the font weight (or null if there's no change)
+     * @param variant the font variant (or null if there's no change)
+     * @param size the font size (or null if there's no change)
+     * @param color the text color (or null if there's no change)
+     * @throws IFException if an error occurs while handling this event
+     */
+    void setFont(String family, String style, Integer weight, String variant, Integer size,
+            Color color) throws IFException;
+
+    /**
+     * Draws text. The initial coordinates (x and y) point to the starting point at the normal
+     * baseline of the font. The arrays (dx and dy) are optional and can be used to achieve
+     * effects like kerning.
+     * @param x X-coordinate of the starting point of the text
+     * @param y Y-coordinate of the starting point of the text
+     * @param dx an array of adjustment values for each character in X-direction
+     * @param dy an array of adjustment values for each character in Y-direction
+     * @param text the text
+     * @throws IFException if an error occurs while handling this event
+     */
+    void drawText(int x, int y, int[] dx, int[] dy, String text) throws IFException;
+
+    /**
+     * Draws a rectangle. Either fill or stroke has to be specified.
+     * @param rect the rectangle's coordinates and extent
+     * @param fill the fill paint (may be null)
+     * @param stroke the stroke color (may be null)
+     * @throws IFException if an error occurs while handling this event
+     */
+    void drawRect(Rectangle rect, Paint fill, Color stroke) throws IFException;
+    void drawImage(String uri, Rectangle rect) throws IFException; //external images
+    void startImage(Rectangle rect) throws IFException; //followed by a SAX stream (SVG etc.)
+    void endImage() throws IFException;
+    //etc. etc.
 
-    void startDocumentHeader();
-    void endDocumentHeader();
+    /**
+     * Handles an extension object. This can be a DOM document or any arbitrary
+     * object. If an implementation doesn't know how to handle a particular extension it is simply
+     * ignored.
+     * @param extension the extension object
+     * @throws IFException if an error occurs while handling this event
+     */
+    void handleExtensionObject(Object extension) throws IFException;
 
-    void startPageSequence(String id);
-    void endPageSequence();
-
-    void startPage(int index, String name);
-    void endPage();
-
-    void startPageHeader();
-    void endPageHeader();
-
-    void startPageContent();
-    void endPageContent();
-
-    void startPageTrailer();
-    void addTarget(String name, int x, int y);
-    void endPageTrailer();
-
-    void startBox(AffineTransform transform, Dimension size, boolean clip);
-    void startBox(String transform, Dimension size, boolean clip);
-    //For transform, something like Batik's org.apache.batik.parser.TransformListHandler/Parser can be used
-    void endBox();
-
-    void setFont(String family, String style, Integer weight, String variant, Integer size, String color);
-    //All of setFont()'s parameters can be null if no state change is necessary
-    void drawText(int[] x, int[] y, String text);
-    void drawRect(Rectangle rect, String fill, String stroke);
-    void drawImage(String uri, Rectangle rect); //external images
-    void startImage(Rectangle rect); //followed by a SAX stream (SVG etc.)
-    void endImage();
-    //etc. etc.
+    //TODO Prototype the following:
+    //ContentHandler handleExtension() throws Exception
 }

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

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

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFPainter.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java (from r675854, xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/iform/IFRenderer.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java?p2=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java&p1=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/iform/IFRenderer.java&r1=675854&r2=677204&rev=677204&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/iform/IFRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java Wed Jul 16 02:10:02 2008
@@ -5,9 +5,9 @@
  * 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.
@@ -17,273 +17,549 @@
 
 /* $Id$ */
 
-package org.apache.fop.render.iform;
+package org.apache.fop.render.intermediate;
 
 import java.awt.Color;
-import java.awt.color.ColorSpace;
+import java.awt.Dimension;
+import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+
+import javax.xml.transform.stream.StreamResult;
+
+import org.xml.sax.SAXException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.java2d.GraphicContext;
+import org.apache.xmlgraphics.xmp.Metadata;
+import org.apache.xmlgraphics.xmp.schemas.DublinCoreAdapter;
+import org.apache.xmlgraphics.xmp.schemas.DublinCoreSchema;
+import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter;
+import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema;
+
+import org.apache.fop.Version;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.area.Area;
 import org.apache.fop.area.Block;
-import org.apache.fop.area.BookmarkData;
 import org.apache.fop.area.CTM;
-import org.apache.fop.area.LineArea;
+import org.apache.fop.area.OffDocumentExtensionAttachment;
+import org.apache.fop.area.OffDocumentItem;
+import org.apache.fop.area.PageSequence;
 import org.apache.fop.area.PageViewport;
 import org.apache.fop.area.Trait;
-import org.apache.fop.area.Trait.Background;
-import org.apache.fop.area.inline.ForeignObject;
+import org.apache.fop.area.inline.AbstractTextArea;
 import org.apache.fop.area.inline.Image;
-import org.apache.fop.area.inline.InlineArea;
 import org.apache.fop.area.inline.SpaceArea;
 import org.apache.fop.area.inline.TextArea;
 import org.apache.fop.area.inline.WordArea;
+import org.apache.fop.fo.extensions.ExtensionAttachment;
+import org.apache.fop.fo.extensions.xmp.XMPMetadata;
 import org.apache.fop.fonts.Font;
+import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontTriplet;
-import org.apache.fop.render.RendererContext;
-import org.apache.fop.render.xml.AbstractXMLRenderer;
-import org.xml.sax.SAXException;
+import org.apache.fop.fonts.LazyFont;
+import org.apache.fop.fonts.Typeface;
+import org.apache.fop.render.AbstractPathOrientedRenderer;
+import org.apache.fop.render.Renderer;
 
-public class IFRenderer extends AbstractXMLRenderer {
+public class IFRenderer extends AbstractPathOrientedRenderer {
 
     /** logging instance */
-    protected static Log log = LogFactory.getLog("IFRenderer");
+    protected static Log log = LogFactory.getLog(IFRenderer.class);
 
     /** XML MIME type */
     public static final String IF_MIME_TYPE = MimeConstants.MIME_FOP_IF;
-    private boolean pageSeqStarted = false;
 
-    private String currentText;
+    private IFPainter painter;
+
+    /** If not null, the XMLRenderer will mimic another renderer by using its font setup. */
+    protected Renderer mimic;
+
+    private boolean inPageSequence = false;
+
+    private Stack graphicContextStack = new Stack();
+    private GraphicContext graphicContext = new GraphicContext();
+
+    private Metadata documentMetadata;
 
-    private Area parentArea;
-    
     /**
      * Main constructor
      */
     public IFRenderer() {
-        context = new RendererContext(this, IF_MIME_TYPE);
+    }
+
+    /** {@inheritDoc} */
+    public String getMimeType() {
+        return IF_MIME_TYPE;
     }
 
     /**
-     * {@inheritDoc}
+     * Sets the {@code IFPainter} to be used by the {@code IFRenderer}.
+     * @param painter the {@code IFPainter}
      */
-    public void startRenderer(OutputStream outputStream)
-                throws IOException {
-        log.debug("Rendering areas to intermediate format XML");
-        super.startRenderer(outputStream);
-        if (userAgent.getProducer() != null) {
-            comment("Produced by " + userAgent.getProducer());
-        }
-        startElement("document");
-        startElement("content");
-        startElement("svg");
+    public void setPainter(IFPainter painter) {
+        this.painter = painter;
+    }
+
+    /**
+     * Call this method to make the XMLRenderer mimic a different renderer by using its font
+     * setup. This is useful when working with the intermediate format parser.
+     * @param renderer the renderer to mimic
+     */
+    public void mimicRenderer(Renderer renderer) {
+        this.mimic = renderer;
     }
 
     /** {@inheritDoc} */
-    public void startPageSequence(LineArea seqTitle) {
-        if (pageSeqStarted) {
-            endElement("pageSet");            
+    public void setupFontInfo(FontInfo inFontInfo) {
+        if (mimic != null) {
+            mimic.setupFontInfo(inFontInfo);
+        } else {
+            super.setupFontInfo(inFontInfo);
         }
-        pageSeqStarted = true;
-        startElement("pageSet");
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public void stopRenderer() throws IOException {
-        if (pageSeqStarted) {
-            endElement("pageSet");            
+    private void handleIFException(IFException ife) {
+        if (ife.getCause() instanceof SAXException) {
+            throw new RuntimeException(ife.getCause());
+        } else {
+            throw new RuntimeException(ife);
         }
-        endElement("svg");
-        endElement("content");
-        endElement("document");
-        super.stopRenderer();
-        log.debug("Written out intermediate format XML");
     }
 
-//    /**
-//     * {@inheritDoc}
-//     */
-//    protected void renderFlow(NormalFlow flow) {
-//        log.debug("renderFlow() " + flow);
-//        super.renderFlow(flow);
-//    }
-//    
-    /**
-     * {@inheritDoc}
-     */
-    protected void renderBlock(Block block) {
-        log.debug("renderBlock() " + block);
-        addTraitAttributes(block);
-        startElement("g", atts);
-        this.parentArea = block;
-        super.renderBlock(block);
-        this.parentArea = null;
-        endElement("g");
-    }
-        
-    /**
-     * Renders an fo:foreing-object.
-     * @param fo the foreign object
-     * @param pos the position of the foreign object
-     * @see org.apache.fop.render.AbstractRenderer#renderForeignObject(ForeignObject, Rectangle2D)
-     */
-    public void renderForeignObject(ForeignObject fo, Rectangle2D pos) {
-        log.debug("renderForeignObject() fo=" + fo + ", pos=" + pos);
-        super.renderForeignObject(fo, pos);
+    private void handleIFExceptionWithIOException(IFException ife) throws IOException {
+        if (ife.getCause() instanceof IOException) {
+            throw (IOException)ife.getCause();
+        } else {
+            handleIFException(ife);
+        }
     }
-    
+
     /**
-     * {@inheritDoc}
+     * Creates a default {@code IFPainter} when none has been set.
+     * @return the default IFPainter
      */
-    public void renderPage(PageViewport page) throws IOException, FOPException {
-        log.debug("renderPage() " + page);
-        atts.clear();
-        startElement("page");
-        handlePageExtensionAttachments(page);
-        super.renderPage(page);
-        endElement("page");
-    }
-         
-    private boolean parentHasTrait(Integer traitKey, Object trait) {
-        return ((parentArea != null
-                && parentArea.hasTrait(traitKey)
-                && parentArea.getTrait(traitKey).equals(trait)));        
+    protected IFPainter createDefaultPainter() {
+        return new IFSerializer();
     }
-    
-    /**
-     * Adds attributes from traits of an Area.
-     * @param area Area to extract traits from
-     */
-    protected void addTraitAttributes(Area area) {
-        Object trait = area.getTrait(Trait.FONT);
-        if (trait != null && !parentHasTrait(Trait.FONT, trait)) {
-            FontTriplet fontTriplet = (FontTriplet)trait;
-            addAttribute("font-family", fontTriplet.getName());
-            int weight = fontTriplet.getWeight();
-            if (weight != Font.WEIGHT_NORMAL) {
-                addAttribute("font-weight", weight);
+
+    /** {@inheritDoc} */
+    public void startRenderer(OutputStream outputStream)
+                throws IOException {
+        try {
+            if (outputStream != null) {
+                StreamResult result = new StreamResult(outputStream);
+                if (getUserAgent().getOutputFile() != null) {
+                    result.setSystemId(
+                            getUserAgent().getOutputFile().toURI().toURL().toExternalForm());
+                }
+                if (this.painter == null) {
+                    this.painter = new IFSerializer();
+                }
+                this.painter.setUserAgent(getUserAgent());
+                this.painter.setResult(result);
             }
-            String style = fontTriplet.getStyle();
-            if (!Font.STYLE_NORMAL.equals(style)) {
-                addAttribute("text-decoration", style);
+            super.startRenderer(null);
+            if (log.isDebugEnabled()) {
+                log.debug("Rendering areas via painter ("
+                        + this.painter.getClass().getName() + ")...");
             }
-        }                
-        trait = area.getTrait(Trait.FONT_SIZE);
-        if (trait != null && !parentHasTrait(Trait.FONT_SIZE, trait)) {
-            addAttribute("font-size", ((Integer)trait).intValue() / 1000);
-        }
-        trait = area.getTrait(Trait.COLOR);
-        if (trait != null && !parentHasTrait(Trait.COLOR, trait)) {
-            addColorAttribute("stroke", (Color)trait);
-        }
-        trait = area.getTrait(Trait.BACKGROUND);
-        if (trait != null && !parentHasTrait(Trait.BACKGROUND, trait)) {
-            addColorAttribute("fill", ((Background)trait).getColor());
+            painter.startDocument();
+            painter.startDocumentHeader();
+        } catch (IFException e) {
+            handleIFExceptionWithIOException(e);
         }
     }
 
-    private void addColorAttribute(String attrName, Color col) {
-        ColorSpace colSpace = col.getColorSpace();
-        int colSpaceType = colSpace.getType();
-        StringBuffer colStr = new StringBuffer();
-        if (colSpace != null) {
-            if (colSpaceType == ColorSpace.TYPE_RGB) {
-                colStr.append("rgb(");
-            } else if (colSpaceType == ColorSpace.TYPE_CMYK) {
-                colStr.append("icc-color(myCMYK,");
-            } else if (colSpaceType == ColorSpace.TYPE_GRAY) {
-                colStr.append("icc-color(myGRAY,");
+    /** {@inheritDoc} */
+    public void stopRenderer() throws IOException {
+        try {
+            if (this.inPageSequence) {
+                painter.endPageSequence();
+                this.inPageSequence = false;
             }
-            float[] colComp = col.getColorComponents(null);
-            for (int i = 0; i < colComp.length; i++) {
-                colStr.append((int)(colComp[i] * 255));
-                colStr.append(",");
+            painter.endDocument();
+        } catch (IFException e) {
+            handleIFExceptionWithIOException(e);
+        }
+        super.stopRenderer();
+        log.debug("Rendering finished.");
+    }
+
+    /** {@inheritDoc} */
+    public void processOffDocumentItem(OffDocumentItem odi) {
+        if (odi instanceof OffDocumentExtensionAttachment) {
+            ExtensionAttachment attachment = ((OffDocumentExtensionAttachment)odi).getAttachment();
+            if (XMPMetadata.CATEGORY.equals(attachment.getCategory())) {
+                renderXMPMetadata((XMPMetadata)attachment);
             }
-            colStr.replace(colStr.length() - 1, colStr.length(), ")");
         }
-        addAttribute(attrName, colStr.toString());
     }
-    
-    /**
-     * {@inheritDoc}
-     */
+
+    private void renderXMPMetadata(XMPMetadata metadata) {
+        this.documentMetadata = metadata.getMetadata();
+    }
+
+    /** {@inheritDoc} */
+    public void startPageSequence(PageSequence pageSequence) {
+        try {
+            if (this.inPageSequence) {
+                painter.endPageSequence();
+            } else {
+                if (this.documentMetadata == null) {
+                    this.documentMetadata = createDefaultDocumentMetadata();
+                }
+                painter.handleExtensionObject(this.documentMetadata);
+                painter.endDocumentHeader();
+                this.inPageSequence = true;
+            }
+            //TODO Put the page-sequence's ID in the area tree
+            painter.startPageSequence(null);
+        } catch (IFException e) {
+            handleIFException(e);
+        }
+    }
+
+    private Metadata createDefaultDocumentMetadata() {
+        Metadata xmp = new Metadata();
+        DublinCoreAdapter dc = DublinCoreSchema.getAdapter(xmp);
+        if (getUserAgent().getTitle() != null) {
+            dc.setTitle(getUserAgent().getTitle());
+        }
+        if (getUserAgent().getAuthor() != null) {
+            dc.addCreator(getUserAgent().getAuthor());
+        }
+        if (getUserAgent().getKeywords() != null) {
+            dc.addSubject(getUserAgent().getKeywords());
+        }
+        XMPBasicAdapter xmpBasic = XMPBasicSchema.getAdapter(xmp);
+        if (getUserAgent().getProducer() != null) {
+            xmpBasic.setCreatorTool(getUserAgent().getProducer());
+        } else {
+            xmpBasic.setCreatorTool(Version.getVersion());
+        }
+        xmpBasic.setMetadataDate(new java.util.Date());
+        if (getUserAgent().getCreationDate() != null) {
+            xmpBasic.setCreateDate(getUserAgent().getCreationDate());
+        } else {
+            xmpBasic.setCreateDate(xmpBasic.getMetadataDate());
+        }
+        return xmp;
+    }
+
+    /** {@inheritDoc} */
+    public void renderPage(PageViewport page) throws IOException, FOPException {
+        if (log.isDebugEnabled()) {
+            log.debug("renderPage() " + page);
+        }
+        try {
+            Rectangle2D viewArea = page.getViewArea();
+            Dimension dim = new Dimension(
+                    (int)Math.ceil(viewArea.getWidth()),
+                    (int)Math.ceil(viewArea.getHeight()));
+            painter.startPage(page.getPageIndex(), page.getPageNumberString(), dim);
+            painter.startPageHeader();
+            //TODO Handle page header
+            painter.endPageHeader();
+            painter.startPageContent();
+            super.renderPage(page);
+            painter.endPageContent();
+            painter.startPageTrailer();
+            //TODO Handle page trailer
+            painter.endPageTrailer();
+            painter.endPage();
+        } catch (IFException e) {
+            handleIFException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    protected void saveGraphicsState() {
+        graphicContextStack.push(graphicContext);
+        graphicContext = (GraphicContext)graphicContext.clone();
+    }
+
+    /** {@inheritDoc} */
+    protected void restoreGraphicsState() {
+        graphicContext = (GraphicContext)graphicContextStack.pop();
+    }
+
+    /** {@inheritDoc} */
+    protected List breakOutOfStateStack() {
+        log.debug("Block.FIXED --> break out");
+        List breakOutList = new java.util.ArrayList();
+        while (!this.graphicContextStack.empty()) {
+            breakOutList.add(0, this.graphicContext);
+            restoreGraphicsState();
+        }
+        return breakOutList;
+    }
+
+    /** {@inheritDoc} */
+    protected void restoreStateStackAfterBreakOut(List breakOutList) {
+        log.debug("Block.FIXED --> restoring context after break-out");
+        for (int i = 0, c = breakOutList.size(); i < c; i++) {
+            saveGraphicsState();
+            this.graphicContext = (GraphicContext)breakOutList.get(i);
+        }
+    }
+
+    /** {@inheritDoc} */
+    protected void concatenateTransformationMatrix(AffineTransform at) {
+        if (!at.isIdentity()) {
+            graphicContext.transform(ptToMpt(at));
+        }
+    }
+
+    /** {@inheritDoc} */
+    protected void beginTextObject() {
+        // TODO Auto-generated method stub
+
+    }
+
+    /** {@inheritDoc} */
+    protected void endTextObject() {
+        // TODO Auto-generated method stub
+
+    }
+
+    /** {@inheritDoc} */
+    protected void startVParea(CTM ctm, Rectangle2D clippingRect) {
+        if (log.isDebugEnabled()) {
+            log.debug("startVParea() ctm=" + ctm + ", rect=" + clippingRect);
+        }
+        saveGraphicsState();
+        AffineTransform at = new AffineTransform(ctm.toArray());
+        graphicContext.transform(at);
+        try {
+            painter.startBox(at, null, false);
+        } catch (IFException e) {
+            handleIFException(e);
+        }
+        if (log.isDebugEnabled()) {
+            log.debug("startVPArea: " + at + " --> " + graphicContext.getTransform());
+        }
+    }
+
+    /** {@inheritDoc} */
+    protected void endVParea() {
+        log.debug("endVParea()");
+        try {
+            painter.endBox();
+        } catch (IFException e) {
+            handleIFException(e);
+        }
+        restoreGraphicsState();
+        if (log.isDebugEnabled()) {
+            log.debug("endVPArea() --> " + graphicContext.getTransform());
+        }
+    }
+
+    protected void renderReferenceArea(Block block) {
+        // TODO Auto-generated method stub
+    }
+
+    /** {@inheritDoc} */
+    protected void renderBlock(Block block) {
+        if (log.isDebugEnabled()) {
+            log.debug("renderBlock() " + block);
+        }
+        super.renderBlock(block);
+    }
+
+    private Typeface getTypeface(String fontName) {
+        Typeface tf = (Typeface) fontInfo.getFonts().get(fontName);
+        if (tf instanceof LazyFont) {
+            tf = ((LazyFont)tf).getRealFont();
+        }
+        return tf;
+    }
+
+    /** {@inheritDoc} */
     protected void renderText(TextArea text) {
-        log.debug("renderText() " + text);
-        atts.clear();
-        this.currentText = "";
-        addAttribute("x", text.getIPD());
-        addAttribute("y", text.getAllocBPD());
-        addTraitAttributes(text);
-        startElement("text", atts);
-        super.renderText(text);
+        if (log.isDebugEnabled()) {
+            log.debug("renderText() " + text);
+        }
+        renderInlineAreaBackAndBorders(text);
+        Color ct = (Color) text.getTrait(Trait.COLOR);
+
+        beginTextObject();
+
+        String fontName = getInternalFontNameForArea(text);
+        int size = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue();
+
+        // This assumes that *all* CIDFonts use a /ToUnicode mapping
+        Typeface tf = getTypeface(fontName);
+
+        FontTriplet triplet = (FontTriplet)text.getTrait(Trait.FONT);
         try {
-            handler.characters(currentText.toCharArray(), 0, currentText.length());
-        } catch (SAXException e) {
-            handleSAXException(e);
-        }
-        this.currentText = null;
-//        addAttribute("font-family", "Helvetica");
-        endElement("text");
+            painter.setFont(triplet.getName(), triplet.getStyle(), new Integer(triplet.getWeight()),
+                    "normal", new Integer(size), ct);
+        } catch (IFException e) {
+            handleIFException(e);
+        }
+
+        super.renderText(text);
+
+        int rx = currentIPPosition + text.getBorderAndPaddingWidthStart();
+        int bl = currentBPPosition + text.getOffset() + text.getBaselineOffset();
+        renderTextDecoration(tf, size, text, bl, rx);
     }
-    
-    /**
-     * {@inheritDoc}
-     */
+
+    /** {@inheritDoc} */
     protected void renderWord(WordArea word) {
-        log.debug("renderWord() " + word);
+        Font font = getFontFromArea(word.getParentArea());
+        String s = word.getWord();
+
+        renderText(s, word.getLetterAdjustArray(),
+                font, (AbstractTextArea)word.getParentArea());
+
         super.renderWord(word);
-        this.currentText += word.getWord();
     }
-    
-    /**
-     * {@inheritDoc}
-     */
+
+    /** {@inheritDoc} */
     protected void renderSpace(SpaceArea space) {
-        log.debug("renderSpace() " + space);
+        Font font = getFontFromArea(space.getParentArea());
+        String s = space.getSpace();
+
+        AbstractTextArea textArea = (AbstractTextArea)space.getParentArea();
+        renderText(s, null, font, textArea);
+
+        if (space.isAdjustable()) {
+            //Used for justified text, for example
+            int tws = -((TextArea) space.getParentArea()).getTextWordSpaceAdjust()
+                         - 2 * textArea.getTextLetterSpaceAdjust();
+            this.currentIPPosition -= tws;
+        }
         super.renderSpace(space);
-        this.currentText += space.getSpace();
     }
-    
+
     /**
-     * {@inheritDoc}
-     */
+     * Does low-level rendering of text.
+     * @param s text to render
+     * @param letterAdjust an array of widths for letter adjustment (may be null)
+     * @param font to font in use
+     * @param parentArea the parent text area to retrieve certain traits from
+     */
+    protected void renderText(String s,
+                           int[] letterAdjust,
+                           Font font, AbstractTextArea parentArea) {
+        int curX = currentIPPosition;
+        float fontSize = font.getFontSize() / 1000f;
+
+        int l = s.length();
+
+        int[] dx = new int[l];
+        boolean hasDX = false;
+        for (int i = 0; i < l; i++) {
+            char ch = s.charAt(i);
+            float glyphAdjust = 0;
+            if (font.hasChar(ch)) {
+                int tls = (i < l - 1 ? parentArea.getTextLetterSpaceAdjust() : 0);
+                glyphAdjust -= tls;
+            }
+            curX += font.getCharWidth(ch);
+            if (letterAdjust != null && i < l - 1) {
+                glyphAdjust -= letterAdjust[i + 1];
+            }
+
+            float adjust = glyphAdjust / fontSize;
+
+            if (adjust != 0) {
+                dx[i] = Math.round(adjust);
+                if (dx[i] != 0) {
+                    hasDX = true;
+                }
+            }
+            curX += adjust;
+        }
+        try {
+            int rx = currentIPPosition + parentArea.getBorderAndPaddingWidthStart();
+            int bl = currentBPPosition + parentArea.getOffset() + parentArea.getBaselineOffset();
+            painter.drawText(rx, bl, (hasDX ? dx : null), null, s);
+        } catch (IFException e) {
+            handleIFException(e);
+        }
+        this.currentIPPosition = curX;
+    }
+
+    /** {@inheritDoc} */
     public void renderImage(Image image, Rectangle2D pos) {
-        log.debug("renderImage() image=" + image + ", pos=" + pos);
+        if (log.isDebugEnabled()) {
+            log.debug("renderImage() image=" + image + ", pos=" + pos);
+        }
         super.renderImage(image, pos);
     }
-    
-    protected void handleExtensionAttachments(List attachments) {
-        log.debug("handleExtensionAttachments() " + attachments);
-        if (attachments != null && attachments.size() > 0) {
-        }
+
+    protected void drawImage(String url, Rectangle2D pos, Map foreignAttributes) {
+        // TODO Auto-generated method stub
+
     }
-    
-    protected void endVParea() {
-        log.debug("endVParea()");
+
+    protected void clip() {
+        // TODO Auto-generated method stub
+
     }
 
-    protected void renderInlineAreaBackAndBorders(InlineArea area) {
-        log.debug("renderInlineAreaBackAndBorders() " + area);
+    protected void clipRect(float x, float y, float width, float height) {
+        // TODO Auto-generated method stub
+
     }
 
-    protected void startVParea(CTM ctm, Rectangle2D clippingRect) {
-        log.debug("startVParea() ctm=" + ctm + ", rect=" + clippingRect);                
+    protected void closePath() {
+        // TODO Auto-generated method stub
+
+    }
+
+    protected void drawBorderLine(float x1, float y1, float x2, float y2, boolean horz,
+            boolean startOrBefore, int style, Color col) {
+        // TODO Auto-generated method stub
+
     }
 
-    protected void renderBookmarkTree(BookmarkData odi) {
-        log.debug("renderBookmarkTree() odi=" + odi);                        
+    private Rectangle toMillipointRectangle(float x, float y, float width, float height) {
+        return new Rectangle(
+                (int)(x * 1000), (int)(y * 1000), (int)(width * 1000), (int)(height * 1000));
     }
 
     /** {@inheritDoc} */
-    public String getMimeType() {
-        return IF_MIME_TYPE;
+    protected void fillRect(float x, float y, float width, float height) {
+        try {
+            painter.drawRect(
+                    toMillipointRectangle(x, y, width, height),
+                    this.graphicContext.getPaint(), null);
+        } catch (IFException e) {
+            handleIFException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    protected void moveTo(float x, float y) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /** {@inheritDoc} */
+    protected void lineTo(float x, float y) {
+        // TODO Auto-generated method stub
+
     }
+
+    /** {@inheritDoc} */
+    protected void updateColor(Color col, boolean fill) {
+        if (fill) {
+            this.graphicContext.setPaint(col);
+        } else {
+            this.graphicContext.setColor(col);
+        }
+
+    }
+
 }

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

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

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRenderer.java
------------------------------------------------------------------------------
    svn:mergeinfo = 



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org