xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r699813 [5/5] - in /xmlgraphics/fop/branches/Temp_AreaTreeNewDesign: src/java/META-INF/services/ src/java/org/apache/fop/apps/ src/java/org/apache/fop/render/ src/java/org/apache/fop/render/bitmap/ src/java/org/apache/fop/render/intermediat...
Date Sun, 28 Sep 2008 13:18:00 GMT
Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainter.java?rev=699813&r1=699812&r2=699813&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainter.java
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainter.java
Sun Sep 28 06:17:57 2008
@@ -19,250 +19,416 @@
 
 package org.apache.fop.render.svg;
 
+import java.awt.Color;
 import java.awt.Dimension;
+import java.awt.Paint;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
+import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXResult;
-import javax.xml.transform.sax.TransformerHandler;
-import javax.xml.transform.stream.StreamResult;
+import java.util.Map;
 
 import org.w3c.dom.Document;
 
-import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
 
-import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
-import org.apache.fop.render.bitmap.MultiFileRenderingUtil;
-import org.apache.fop.render.intermediate.DelegatingFragmentContentHandler;
+import org.apache.xmlgraphics.image.loader.ImageException;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+import org.apache.xmlgraphics.util.QName;
+import org.apache.xmlgraphics.xmp.Metadata;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.events.ResourceEventProducer;
+import org.apache.fop.fo.extensions.ExtensionElementMapping;
+import org.apache.fop.render.RenderingContext;
+import org.apache.fop.render.intermediate.AbstractIFPainter;
+import org.apache.fop.render.intermediate.IFConstants;
 import org.apache.fop.render.intermediate.IFException;
+import org.apache.fop.render.intermediate.IFState;
+import org.apache.fop.render.intermediate.IFUtil;
+import org.apache.fop.traits.BorderProps;
+import org.apache.fop.traits.RuleStyle;
+import org.apache.fop.util.ColorUtil;
+import org.apache.fop.util.GenerationHelperContentHandler;
+import org.apache.fop.util.XMLUtil;
 
 /**
  * IFPainter implementation that writes SVG.
  */
-public class SVGPainter extends AbstractSVGPainter {
+public class SVGPainter extends AbstractIFPainter implements SVGConstants {
 
-    /** Helper class for generating multiple files */
-    private MultiFileRenderingUtil multiFileUtil;
+    /** logging instance */
+    private static Log log = LogFactory.getLog(SVGPainter.class);
 
-    private StreamResult firstStream;
-    private StreamResult currentStream;
+    /** Holds the intermediate format state */
+    protected IFState state;
 
-    private Document reusedParts;
+    private AbstractSVGDocumentHandler parent;
+
+    /** The SAX content handler that receives the generated XML events. */
+    protected GenerationHelperContentHandler handler;
+
+    private static final int MODE_NORMAL = 0;
+    private static final int MODE_TEXT = 1;
+
+    private int mode = MODE_NORMAL;
 
     /**
-     * Default constructor.
+     * Main constructor.
+     * @param parent the parent document handler
+     * @param contentHandler the target SAX content handler
      */
-    public SVGPainter() {
-        //nop
+    public SVGPainter(AbstractSVGDocumentHandler parent,
+            GenerationHelperContentHandler contentHandler) {
+        super();
+        this.parent = parent;
+        this.handler = contentHandler;
+        this.state = IFState.create();
     }
 
     /** {@inheritDoc} */
-    public boolean supportsPagesOutOfOrder() {
-        return true;
+    protected FOUserAgent getUserAgent() {
+        return parent.getUserAgent();
     }
 
     /** {@inheritDoc} */
-    public String getMimeType() {
-        return MIME_TYPE;
+    public void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect)
+            throws IFException {
+        startViewport(IFUtil.toString(transform), size, clipRect);
     }
 
     /** {@inheritDoc} */
-    public void setResult(Result result) throws IFException {
-        if (result instanceof StreamResult) {
-            multiFileUtil = new MultiFileRenderingUtil(FILE_EXTENSION_SVG,
-                    getUserAgent().getOutputFile());
-            this.firstStream = (StreamResult)result;
-        } else {
-            throw new UnsupportedOperationException("Result is not supported: " + result);
-        }
+    public void startViewport(AffineTransform[] transforms, Dimension size, Rectangle clipRect)
+            throws IFException {
+        startViewport(IFUtil.toString(transforms), size, clipRect);
     }
 
-    /** {@inheritDoc} */
-    public void startDocument() throws IFException {
-        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
-        builderFactory.setNamespaceAware(true);
-        builderFactory.setValidating(false);
+    private void startViewport(String transform, Dimension size, Rectangle clipRect)
+            throws IFException {
         try {
-            DocumentBuilder builder = builderFactory.newDocumentBuilder();
-            this.reusedParts = builder.newDocument();
-        } catch (ParserConfigurationException e) {
-            throw new IFException("Error while setting up a DOM for SVG generation", e);
+            establish(MODE_NORMAL);
+            AttributesImpl atts = new AttributesImpl();
+            if (transform != null && transform.length() > 0) {
+                XMLUtil.addAttribute(atts, "transform", transform);
+            }
+            handler.startElement("g", atts);
+
+            atts.clear();
+            XMLUtil.addAttribute(atts, "width", Integer.toString(size.width));
+            XMLUtil.addAttribute(atts, "height", Integer.toString(size.height));
+            if (clipRect != null) {
+                int[] v = new int[] {
+                        clipRect.y,
+                        -clipRect.x + size.width - clipRect.width,
+                        -clipRect.y + size.height - clipRect.height,
+                        clipRect.x};
+                int sum = 0;
+                for (int i = 0; i < 4; i++) {
+                    sum += Math.abs(v[i]);
+                }
+                if (sum != 0) {
+                    StringBuffer sb = new StringBuffer("rect(");
+                    sb.append(v[0]).append(',');
+                    sb.append(v[1]).append(',');
+                    sb.append(v[2]).append(',');
+                    sb.append(v[3]).append(')');
+                    XMLUtil.addAttribute(atts, "clip", sb.toString());
+                }
+                XMLUtil.addAttribute(atts, "overflow", "hidden");
+            } else {
+                XMLUtil.addAttribute(atts, "overflow", "visible");
+            }
+            handler.startElement("svg", atts);
+        } catch (SAXException e) {
+            throw new IFException("SAX error in startBox()", e);
         }
+    }
 
+    /** {@inheritDoc} */
+    public void endViewport() throws IFException {
         try {
-            TransformerHandler toDOMHandler = tFactory.newTransformerHandler();
-            toDOMHandler.setResult(new DOMResult(this.reusedParts));
-            this.handler = toDOMHandler;
-            this.handler.startDocument();
-        } catch (SAXException se) {
-            throw new IFException("SAX error in startDocument()", se);
-        } catch (TransformerConfigurationException e) {
-            throw new IFException(
-                    "Error while setting up a TransformerHandler for SVG generation", e);
+            establish(MODE_NORMAL);
+            handler.endElement("svg");
+            handler.endElement("g");
+        } catch (SAXException e) {
+            throw new IFException("SAX error in endBox()", e);
         }
     }
 
     /** {@inheritDoc} */
-    public void endDocument() throws IFException {
-        //nop
+    public void startGroup(AffineTransform[] transforms) throws IFException {
+        startGroup(IFUtil.toString(transforms));
     }
 
     /** {@inheritDoc} */
-    public void endDocumentHeader() throws IFException {
-        super.endDocumentHeader();
+    public void startGroup(AffineTransform transform) throws IFException {
+        startGroup(IFUtil.toString(transform));
+    }
+
+    private void startGroup(String transform) throws IFException {
         try {
-            //Stop recording parts reused for each page
-            this.handler.endDocument();
-            this.handler = null;
+            AttributesImpl atts = new AttributesImpl();
+            if (transform != null && transform.length() > 0) {
+                XMLUtil.addAttribute(atts, "transform", transform);
+            }
+            handler.startElement("g", atts);
         } catch (SAXException e) {
-            throw new IFException("SAX error in endDocumentHeader()", e);
+            throw new IFException("SAX error in startGroup()", e);
         }
     }
 
     /** {@inheritDoc} */
-    public void startPageSequence(String id) throws IFException {
-        //nop
+    public void endGroup() throws IFException {
+        try {
+            establish(MODE_NORMAL);
+            handler.endElement("g");
+        } catch (SAXException e) {
+            throw new IFException("SAX error in endGroup()", e);
+        }
     }
 
-    /** {@inheritDoc} */
-    public void endPageSequence() throws IFException {
-        //nop
-    }
+    private static final QName CONVERSION_MODE
+            = new QName(ExtensionElementMapping.URI, null, "conversion-mode");
 
     /** {@inheritDoc} */
-    public void startPage(int index, String name, Dimension size) throws IFException {
-        OutputStream out;
+    public void drawImage(String uri, Rectangle rect, Map foreignAttributes) throws IFException
{
         try {
-            if (index == 0) {
-                out = null;
-            } else {
-                out = this.multiFileUtil.createOutputStream(index);
-                if (out == null) {
-                    //TODO Convert to event
-                    throw new IFException(
-                            "No filename information available. Stopping after first page.",
null);
-                }
-            }
-        } catch (IOException ioe) {
-            throw new IFException("I/O exception while setting up output file", ioe);
-        }
-        if (out == null) {
-            this.handler = createContentHandler(this.firstStream);
-        } else {
-            this.currentStream = new StreamResult(out);
-            this.handler = createContentHandler(this.currentStream);
-        }
-        if (false) {
-            final ContentHandler originalHandler = this.handler;
-            this.handler = (ContentHandler)Proxy.newProxyInstance(
-                    ContentHandler.class.getClassLoader(),
-                    new Class[] {ContentHandler.class},
-                    new InvocationHandler() {
-                        public Object invoke(Object proxy, Method method, Object[] args)
-                                throws Throwable {
-                            String methodName = method.getName();
-                            System.out.println(methodName + ":");
-                            if (args != null) {
-                                for (int i = 0; i < args.length; i++) {
-                                    System.out.println("  " + args[i]);
-                                }
-                            }
-                            return method.invoke(originalHandler, args);
-                        }
-                    });
-        }
-        try {
-            handler.startDocument();
-            handler.startPrefixMapping("", NAMESPACE);
-            handler.startPrefixMapping(XLINK_PREFIX, XLINK_NAMESPACE);
-            AttributesImpl atts = new AttributesImpl();
-            atts.addAttribute("", "version", "version", CDATA, "1.1"); //SVG 1.1
-            /*
-            atts.addAttribute("", "index", "index", CDATA, Integer.toString(index));
-            atts.addAttribute("", "name", "name", CDATA, name);
-            */
-            atts.addAttribute("", "width", "width", CDATA,
-                    Float.toString(size.width / 1000f) + "pt");
-            atts.addAttribute("", "height", "height", CDATA,
-                    Float.toString(size.height / 1000f) + "pt");
-            atts.addAttribute("", "viewBox", "viewBox", CDATA,
-                    "0 0 " + Integer.toString(size.width) + " " + Integer.toString(size.height));
-            startElement("svg", atts);
+            establish(MODE_NORMAL);
 
+            ImageManager manager = getUserAgent().getFactory().getImageManager();
+            ImageInfo info = null;
             try {
-                Transformer transformer = tFactory.newTransformer();
-                Source src = new DOMSource(this.reusedParts.getDocumentElement());
-                Result res = new SAXResult(new DelegatingFragmentContentHandler(this.handler));
-                transformer.transform(src, res);
-            } catch (TransformerConfigurationException tce) {
-                throw new IFException("Error setting up a Transformer", tce);
-            } catch (TransformerException te) {
-                if (te.getCause() instanceof SAXException) {
-                    throw (SAXException)te.getCause();
+                ImageSessionContext sessionContext = getUserAgent().getImageSessionContext();
+                info = manager.getImageInfo(uri, sessionContext);
+
+                String mime = info.getMimeType();
+                String conversionMode = (String)foreignAttributes.get(CONVERSION_MODE);
+                if ("reference".equals(conversionMode)
+                        && (MimeConstants.MIME_GIF.equals(mime)
+                        || MimeConstants.MIME_JPEG.equals(mime)
+                        || MimeConstants.MIME_PNG.equals(mime)
+                        || MimeConstants.MIME_SVG.equals(mime))) {
+                    //Just reference the image
+                    //TODO Some additional URI rewriting might be necessary
+                    AttributesImpl atts = new AttributesImpl();
+                    XMLUtil.addAttribute(atts, IFConstants.XLINK_HREF, uri);
+                    XMLUtil.addAttribute(atts, "x", Integer.toString(rect.x));
+                    XMLUtil.addAttribute(atts, "y", Integer.toString(rect.y));
+                    XMLUtil.addAttribute(atts, "width", Integer.toString(rect.width));
+                    XMLUtil.addAttribute(atts, "height", Integer.toString(rect.height));
+                    handler.element("image", atts);
                 } else {
-                    throw new IFException("Error while serializing reused parts", te);
+                    drawImageUsingImageHandler(info, rect);
                 }
+            } catch (ImageException ie) {
+                ResourceEventProducer eventProducer = ResourceEventProducer.Provider.get(
+                        getUserAgent().getEventBroadcaster());
+                eventProducer.imageError(this, (info != null ? info.toString() : uri), ie,
null);
+            } catch (FileNotFoundException fe) {
+                ResourceEventProducer eventProducer = ResourceEventProducer.Provider.get(
+                        getUserAgent().getEventBroadcaster());
+                eventProducer.imageNotFound(this, (info != null ? info.toString() : uri),
fe, null);
+            } catch (IOException ioe) {
+                ResourceEventProducer eventProducer = ResourceEventProducer.Provider.get(
+                        getUserAgent().getEventBroadcaster());
+                eventProducer.imageIOError(this, (info != null ? info.toString() : uri),
ioe, null);
             }
         } catch (SAXException e) {
-            throw new IFException("SAX error in startPage()", e);
+            throw new IFException("SAX error in drawImage()", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public void drawImage(Document doc, Rectangle rect, Map foreignAttributes) throws IFException
{
+        try {
+            establish(MODE_NORMAL);
+
+            drawImageUsingDocument(doc, rect);
+        } catch (SAXException e) {
+            throw new IFException("SAX error in drawImage()", e);
         }
     }
 
-    private void closeCurrentStream() {
-        if (this.currentStream != null) {
-            IOUtils.closeQuietly(currentStream.getOutputStream());
-            currentStream.setOutputStream(null);
-            IOUtils.closeQuietly(currentStream.getWriter());
-            currentStream.setWriter(null);
-            this.currentStream = null;
+    /** {@inheritDoc} */
+    protected RenderingContext createRenderingContext() {
+        SVGRenderingContext svgContext = new SVGRenderingContext(
+                getUserAgent(), handler);
+        return svgContext;
+    }
+
+    private static String toString(Paint paint) {
+        //TODO Paint serialization: Fine-tune and extend!
+        if (paint instanceof Color) {
+            return ColorUtil.colorToString((Color)paint);
+        } else {
+            throw new UnsupportedOperationException("Paint not supported: " + paint);
         }
     }
 
     /** {@inheritDoc} */
-    public void startPageContent() throws IFException {
-        super.startPageContent();
+    public void clipRect(Rectangle rect) throws IFException {
+        //TODO Implement me!!!
+    }
+
+    /** {@inheritDoc} */
+    public void fillRect(Rectangle rect, Paint fill) throws IFException {
+        if (fill == null) {
+            return;
+        }
         try {
-            startElement("g");
+            establish(MODE_NORMAL);
+            AttributesImpl atts = new AttributesImpl();
+            XMLUtil.addAttribute(atts, "x", Integer.toString(rect.x));
+            XMLUtil.addAttribute(atts, "y", Integer.toString(rect.y));
+            XMLUtil.addAttribute(atts, "width", Integer.toString(rect.width));
+            XMLUtil.addAttribute(atts, "height", Integer.toString(rect.height));
+            if (fill != null) {
+                XMLUtil.addAttribute(atts, "fill", toString(fill));
+            }
+            /* disabled
+            if (stroke != null) {
+                XMLUtil.addAttribute(atts, "stroke", toString(stroke));
+            }*/
+            handler.element("rect", atts);
         } catch (SAXException e) {
-            throw new IFException("SAX error in startPageContent()", e);
+            throw new IFException("SAX error in fillRect()", e);
         }
     }
 
     /** {@inheritDoc} */
-    public void endPageContent() throws IFException {
+    public void drawBorderRect(Rectangle rect, BorderProps before, BorderProps after,
+            BorderProps start, BorderProps end) throws IFException {
+        // TODO Auto-generated method stub
+    }
+
+    /** {@inheritDoc} */
+    public void drawLine(Point start, Point end, int width, Color color, RuleStyle style)
+            throws IFException {
         try {
-            endElement("g");
+            establish(MODE_NORMAL);
+            AttributesImpl atts = new AttributesImpl();
+            XMLUtil.addAttribute(atts, "x1", Integer.toString(start.x));
+            XMLUtil.addAttribute(atts, "y1", Integer.toString(start.y));
+            XMLUtil.addAttribute(atts, "x2", Integer.toString(end.x));
+            XMLUtil.addAttribute(atts, "y2", Integer.toString(end.y));
+            XMLUtil.addAttribute(atts, "stroke-width", toString(color));
+            XMLUtil.addAttribute(atts, "fill", toString(color));
+            //TODO Handle style parameter
+            handler.element("line", atts);
         } catch (SAXException e) {
-            throw new IFException("SAX error in endPageContent()", e);
+            throw new IFException("SAX error in drawLine()", e);
         }
-        super.endPageContent();
     }
 
     /** {@inheritDoc} */
-    public void endPage() throws IFException {
+    public void drawText(int x, int y, int[] dx, int[] dy, String text) throws IFException
{
         try {
-            endElement("svg");
-            this.handler.endDocument();
+            establish(MODE_TEXT);
+            AttributesImpl atts = new AttributesImpl();
+            XMLUtil.addAttribute(atts, "x", Integer.toString(x));
+            XMLUtil.addAttribute(atts, "y", Integer.toString(y));
+            if (dx != null) {
+                XMLUtil.addAttribute(atts, "dx", IFUtil.toString(dx));
+            }
+            if (dy != null) {
+                XMLUtil.addAttribute(atts, "dy", IFUtil.toString(dy));
+            }
+            handler.startElement("text", atts);
+            char[] chars = text.toCharArray();
+            handler.characters(chars, 0, chars.length);
+            handler.endElement("text");
         } catch (SAXException e) {
-            throw new IFException("SAX error in endPage()", e);
+            throw new IFException("SAX error in setFont()", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public void setFont(String family, String style, Integer weight, String variant, Integer
size,
+            Color color) throws IFException {
+        if (family != null) {
+            state.setFontFamily(family);
+        }
+        if (style != null) {
+            state.setFontStyle(style);
+        }
+        if (weight != null) {
+            state.setFontWeight(weight.intValue());
+        }
+        if (variant != null) {
+            state.setFontVariant(variant);
+        }
+        if (size != null) {
+            state.setFontSize(size.intValue());
+        }
+        if (color != null) {
+            state.setTextColor(color);
+        }
+    }
+
+    private void leaveTextMode() throws SAXException {
+        assert this.mode == MODE_TEXT;
+        handler.endElement("g");
+        this.mode = MODE_NORMAL;
+    }
+
+    private void establish(int newMode) throws SAXException {
+        switch (newMode) {
+        case MODE_TEXT:
+            enterTextMode();
+            break;
+        default:
+            if (this.mode == MODE_TEXT) {
+                leaveTextMode();
+            }
+        }
+    }
+
+    private void enterTextMode() throws SAXException {
+        if (state.isFontChanged() && this.mode == MODE_TEXT) {
+            leaveTextMode();
+        }
+        if (this.mode != MODE_TEXT) {
+            startTextGroup();
+            this.mode = MODE_TEXT;
+        }
+    }
+
+    private void startTextGroup() throws SAXException {
+        AttributesImpl atts = new AttributesImpl();
+        XMLUtil.addAttribute(atts, "font-family", state.getFontFamily());
+        XMLUtil.addAttribute(atts, "font-style", state.getFontStyle());
+        XMLUtil.addAttribute(atts, "font-weight", Integer.toString(state.getFontWeight()));
+        XMLUtil.addAttribute(atts, "font-variant", state.getFontVariant());
+        XMLUtil.addAttribute(atts, "font-size", Integer.toString(state.getFontSize()));
+        XMLUtil.addAttribute(atts, "fill", toString(state.getTextColor()));
+        handler.startElement("g", atts);
+        state.resetFontChanged();
+    }
+
+    /** {@inheritDoc} */
+    public void handleExtensionObject(Object extension) throws IFException {
+        if (extension instanceof Metadata) {
+            Metadata meta = (Metadata)extension;
+            try {
+                establish(MODE_NORMAL);
+                handler.startElement("metadata");
+                meta.toSAX(this.handler);
+                handler.endElement("metadata");
+            } catch (SAXException e) {
+                throw new IFException("SAX error while handling extension object", e);
+            }
+        } else {
+            throw new UnsupportedOperationException(
+                    "Don't know how to handle extension object: " + extension);
         }
-        closeCurrentStream();
     }
 
 }

Copied: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandler.java
(from r685784, xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainter.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandler.java?p2=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandler.java&p1=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainter.java&r1=685784&r2=699813&rev=699813&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainter.java
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandler.java
Sun Sep 28 06:17:57 2008
@@ -28,16 +28,18 @@
 
 import org.apache.fop.render.intermediate.IFConstants;
 import org.apache.fop.render.intermediate.IFException;
+import org.apache.fop.render.intermediate.IFPainter;
+import org.apache.fop.util.XMLUtil;
 
 /**
- * IFPainter implementation that writes SVG Print.
+ * {@code IFDocumentHandler} implementation that writes SVG Print.
  */
-public class SVGPrintPainter extends AbstractSVGPainter {
+public class SVGPrintDocumentHandler extends AbstractSVGDocumentHandler {
 
     /**
      * Default constructor.
      */
-    public SVGPrintPainter() {
+    public SVGPrintDocumentHandler() {
         //nop
     }
 
@@ -47,7 +49,7 @@
      * @param result the JAXP Result object to receive the generated content
      * @throws IFException if an error occurs setting up the output
      */
-    public SVGPrintPainter(Result result) throws IFException {
+    public SVGPrintDocumentHandler(Result result) throws IFException {
         setResult(result);
     }
 
@@ -69,8 +71,8 @@
             handler.startPrefixMapping(XLINK_PREFIX, XLINK_NAMESPACE);
             handler.startPrefixMapping("if", IFConstants.NAMESPACE);
             AttributesImpl atts = new AttributesImpl();
-            atts.addAttribute("", "version", "version", CDATA, "1.2"); //SVG Print is SVG
1.2
-            startElement("svg", atts);
+            XMLUtil.addAttribute(atts, "version", "1.2"); //SVG Print is SVG 1.2
+            handler.startElement("svg", atts);
         } catch (SAXException e) {
             throw new IFException("SAX error in startDocument()", e);
         }
@@ -79,7 +81,7 @@
     /** {@inheritDoc} */
     public void endDocument() throws IFException {
         try {
-            endElement("svg");
+            handler.endElement("svg");
             handler.endDocument();
         } catch (SAXException e) {
             throw new IFException("SAX error in endDocument()", e);
@@ -93,7 +95,7 @@
             if (id != null) {
                 atts.addAttribute(XML_NAMESPACE, "id", "xml:id", CDATA, id);
             }
-            startElement("pageSet", atts);
+            handler.startElement("pageSet", atts);
         } catch (SAXException e) {
             throw new IFException("SAX error in startPageSequence()", e);
         }
@@ -102,7 +104,7 @@
     /** {@inheritDoc} */
     public void endPageSequence() throws IFException {
         try {
-            endElement("pageSet");
+            handler.endElement("pageSet");
         } catch (SAXException e) {
             throw new IFException("SAX error in endPageSequence()", e);
         }
@@ -113,8 +115,8 @@
         try {
             AttributesImpl atts = new AttributesImpl();
             /*
-            atts.addAttribute("", "index", "index", CDATA, Integer.toString(index));
-            atts.addAttribute("", "name", "name", CDATA, name);
+            XMLUtil.addAttribute(atts, "index", Integer.toString(index));
+            XMLUtil.addAttribute(atts, "name", name);
             */
             //NOTE: SVG Print doesn't support individual page sizes for each page
             atts.addAttribute(IFConstants.NAMESPACE, "width", "if:width",
@@ -123,7 +125,7 @@
                     CDATA, Integer.toString(size.height));
             atts.addAttribute(IFConstants.NAMESPACE, "viewBox", "if:viewBox", CDATA,
                     "0 0 " + Integer.toString(size.width) + " " + Integer.toString(size.height));
-            startElement("page", atts);
+            handler.startElement("page", atts);
         } catch (SAXException e) {
             throw new IFException("SAX error in startPage()", e);
         }
@@ -138,23 +140,22 @@
     }
 
     /** {@inheritDoc} */
-    public void startPageContent() throws IFException {
-        super.startPageContent();
+    public IFPainter startPageContent() throws IFException {
         try {
-            startElement("g");
+            handler.startElement("g");
         } catch (SAXException e) {
             throw new IFException("SAX error in startPageContent()", e);
         }
+        return new SVGPainter(this, handler);
     }
 
     /** {@inheritDoc} */
     public void endPageContent() throws IFException {
         try {
-            endElement("g");
+            handler.endElement("g");
         } catch (SAXException e) {
             throw new IFException("SAX error in endPageContent()", e);
         }
-        super.endPageContent();
     }
 
     /** {@inheritDoc} */
@@ -168,7 +169,7 @@
     /** {@inheritDoc} */
     public void endPage() throws IFException {
         try {
-            endElement("page");
+            handler.endElement("page");
         } catch (SAXException e) {
             throw new IFException("SAX error in endPage()", e);
         }

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandler.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Sun Sep 28 06:17:57 2008
@@ -0,0 +1,2 @@
+/xmlgraphics/fop/branches/fop-0_95/src/sandbox/org/apache/fop/render/svg/SVGPrintPainter.java:684572
+/xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGPrintPainter.java:603620-685574

Copied: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandlerMaker.java
(from r685784, xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainterMaker.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandlerMaker.java?p2=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandlerMaker.java&p1=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainterMaker.java&r1=685784&r2=699813&rev=699813&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainterMaker.java
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandlerMaker.java
Sun Sep 28 06:17:57 2008
@@ -20,20 +20,22 @@
 package org.apache.fop.render.svg;
 
 import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.render.intermediate.AbstractIFPainterMaker;
-import org.apache.fop.render.intermediate.IFPainter;
-import org.apache.fop.render.intermediate.IFPainterConfigurator;
+import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
+import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
 
 /**
- * Painter factory for SVG Print output.
+ * Document handler factory for SVG Print output.
  */
-public class SVGPrintPainterMaker extends AbstractIFPainterMaker {
+public class SVGPrintDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker {
 
     private static final String[] MIMES = new String[] {SVGConstants.MIME_SVG_PRINT};
 
     /** {@inheritDoc} */
-    public IFPainter makePainter(FOUserAgent ua) {
-        return new SVGPrintPainter();
+    public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {
+        SVGPrintDocumentHandler handler = new SVGPrintDocumentHandler();
+        handler.setUserAgent(ua);
+        return handler;
     }
 
     /** {@inheritDoc} */
@@ -47,8 +49,7 @@
     }
 
     /** {@inheritDoc} */
-    public IFPainterConfigurator getConfigurator(FOUserAgent userAgent) {
-        // TODO Auto-generated method stub
+    public IFDocumentHandlerConfigurator getConfigurator(FOUserAgent userAgent) {
         return null;
     }
 

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandlerMaker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandlerMaker.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandlerMaker.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Sun Sep 28 06:17:57 2008
@@ -0,0 +1,2 @@
+/xmlgraphics/fop/branches/fop-0_95/src/sandbox/org/apache/fop/render/svg/SVGPrintPainterMaker.java:684572
+/xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGPrintPainterMaker.java:603620-685574

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFParserTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFParserTestCase.java?rev=699813&r1=699812&r2=699813&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFParserTestCase.java
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFParserTestCase.java
Sun Sep 28 06:17:57 2008
@@ -35,8 +35,8 @@
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
 import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.render.Renderer;
-import org.apache.fop.render.intermediate.IFPainter;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
 import org.apache.fop.render.intermediate.IFParser;
 import org.apache.fop.render.intermediate.IFRenderer;
 import org.apache.fop.render.intermediate.IFSerializer;
@@ -82,20 +82,20 @@
         FOUserAgent userAgent = createUserAgent();
 
         //Create an instance of the target renderer so the XMLRenderer can use its font setup
-        Renderer targetRenderer = userAgent.getRendererFactory().createRenderer(
+        IFDocumentHandler targetHandler = userAgent.getRendererFactory().createDocumentHandler(
                 userAgent, getTargetMIME());
 
-        //Setup renderer
-        IFRenderer renderer = new IFRenderer();
-        renderer.setUserAgent(userAgent);
-        renderer.mimicRenderer(targetRenderer);
-
         //Setup painter
         IFSerializer serializer = new IFSerializer();
         serializer.setUserAgent(userAgent);
+        serializer.mimicDocumentHandler(targetHandler);
         serializer.setResult(domResult);
 
-        renderer.setPainter(serializer);
+        //Setup renderer
+        IFRenderer renderer = new IFRenderer();
+        renderer.setUserAgent(userAgent);
+
+        renderer.setDocumentHandler(serializer);
         userAgent.setRendererOverride(renderer);
 
         Fop fop = fopFactory.newFop(userAgent);
@@ -111,11 +111,11 @@
 
         FOUserAgent userAgent = createUserAgent();
 
-        IFPainter painter = userAgent.getRendererFactory().createPainter(
+        IFDocumentHandler documentHandler = userAgent.getRendererFactory().createDocumentHandler(
                 userAgent, getTargetMIME());
-        painter.setResult(new StreamResult(out));
-        painter.setDefaultFontInfo();
-        parser.parse(src, painter, userAgent);
+        documentHandler.setResult(new StreamResult(out));
+        documentHandler.setDefaultFontInfo(new FontInfo());
+        parser.parse(src, documentHandler, userAgent);
     }
 
     /** {@inheritDoc} */

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFTester.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFTester.java?rev=699813&r1=699812&r2=699813&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFTester.java
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFTester.java
Sun Sep 28 06:17:57 2008
@@ -115,7 +115,7 @@
             IFSerializer serializer = new IFSerializer();
             DOMResult result = new DOMResult();
             serializer.setResult(result);
-            ifRenderer.setPainter(serializer);
+            ifRenderer.setDocumentHandler(serializer);
 
             ua.setRendererOverride(ifRenderer);
             FontInfo fontInfo = new FontInfo();



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