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 vh...@apache.org on 2012/04/05 18:20:17 UTC

svn commit: r1309921 [36/42] - in /xmlgraphics/fop/branches/Temp_TrueTypeInPostScript: ./ examples/embedding/ examples/embedding/java/embedding/ examples/embedding/java/embedding/atxml/ examples/embedding/java/embedding/tools/ examples/plan/src/org/apa...

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/xml/XMLRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/xml/XMLRenderer.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/xml/XMLRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/xml/XMLRenderer.java Thu Apr  5 16:19:19 2012
@@ -21,6 +21,7 @@ package org.apache.fop.render.xml;
 
 // Java
 import java.awt.Color;
+import java.awt.Rectangle;
 import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -34,9 +35,6 @@ import javax.xml.transform.sax.Transform
 import javax.xml.transform.stream.StreamResult;
 
 import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
 import org.xml.sax.SAXException;
 
 import org.apache.xmlgraphics.util.QName;
@@ -74,23 +72,21 @@ import org.apache.fop.area.inline.Image;
 import org.apache.fop.area.inline.InlineArea;
 import org.apache.fop.area.inline.InlineBlockParent;
 import org.apache.fop.area.inline.InlineParent;
+import org.apache.fop.area.inline.InlineViewport;
 import org.apache.fop.area.inline.Leader;
 import org.apache.fop.area.inline.Space;
 import org.apache.fop.area.inline.SpaceArea;
 import org.apache.fop.area.inline.TextArea;
-import org.apache.fop.area.inline.Viewport;
 import org.apache.fop.area.inline.WordArea;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.extensions.ExtensionAttachment;
-import org.apache.fop.fo.extensions.ExtensionElementMapping;
-import org.apache.fop.fo.extensions.InternalElementMapping;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontTriplet;
 import org.apache.fop.render.Renderer;
 import org.apache.fop.render.RendererContext;
 import org.apache.fop.render.XMLHandler;
 import org.apache.fop.util.ColorUtil;
-import org.apache.fop.util.DOM2SAX;
+import org.apache.fop.util.XMLUtil;
 
 /**
  * Renderer that renders areas to XML for debugging purposes.
@@ -110,21 +106,12 @@ public class XMLRenderer extends Abstrac
     /** If not null, the XMLRenderer will mimic another renderer by using its font setup. */
     protected Renderer mimic;
 
-    private int pageSequenceIndex;
-
     /**
-     * Creates a new XML renderer.
+     * @param userAgent the user agent that contains configuration details. This cannot be null.
      */
-    public XMLRenderer() {
+    public XMLRenderer(FOUserAgent userAgent) {
+        super(userAgent);
         context = new RendererContext(this, XML_MIME_TYPE);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void setUserAgent(FOUserAgent agent) {
-        super.setUserAgent(agent);
-
         XMLHandler xmlHandler = new XMLXMLHandler();
         userAgent.getXMLHandlerRegistry().addXMLHandler(xmlHandler);
         Boolean b = (Boolean)userAgent.getRendererOptions().get("compact-format");
@@ -143,6 +130,7 @@ public class XMLRenderer extends Abstrac
     }
 
     /** {@inheritDoc} */
+    @Override
     public void setupFontInfo(FontInfo inFontInfo) throws FOPException {
         if (mimic != null) {
             mimic.setupFontInfo(inFontInfo);
@@ -170,6 +158,7 @@ public class XMLRenderer extends Abstrac
     protected void addAreaAttributes(Area area) {
         addAttribute("ipd", area.getIPD());
         addAttribute("bpd", area.getBPD());
+        maybeAddLevelAttribute(area);
         if (isDetailedFormat()) {
             if (area.getIPD() != 0) {
                 addAttribute("ipda", area.getAllocIPD());
@@ -214,7 +203,7 @@ public class XMLRenderer extends Abstrac
                     //TODO Remove the following line (makes changes in the test checks necessary)
                     addAttribute(name, bkg.toString());
                     if (bkg.getColor() != null) {
-                        addAttribute("bkg-color", bkg.getColor().toString());
+                        addAttribute("bkg-color", ColorUtil.colorToString(bkg.getColor()));
                     }
                     if (bkg.getURL() != null) {
                         addAttribute("bkg-img", bkg.getURL());
@@ -277,6 +266,7 @@ public class XMLRenderer extends Abstrac
     }
 
     /** {@inheritDoc} */
+    @Override
     public void processOffDocumentItem(OffDocumentItem oDI) {
         if (oDI instanceof BookmarkData) {
             renderBookmarkTree((BookmarkData) oDI);
@@ -298,6 +288,7 @@ public class XMLRenderer extends Abstrac
      * Renders a BookmarkTree object
      * @param bookmarkRoot the BookmarkData object representing the top of the tree
      */
+    @Override
     protected void renderBookmarkTree(BookmarkData bookmarkRoot) {
         if (bookmarkRoot.getWhenToProcess() == OffDocumentItem.END_OF_DOC) {
             endPageSequence();
@@ -346,6 +337,7 @@ public class XMLRenderer extends Abstrac
     }
 
     /** {@inheritDoc} */
+    @Override
     public void startRenderer(OutputStream outputStream)
                 throws IOException {
         log.debug("Rendering areas to Area Tree XML");
@@ -377,6 +369,7 @@ public class XMLRenderer extends Abstrac
     }
 
     /** {@inheritDoc} */
+    @Override
     public void stopRenderer() throws IOException {
         endPageSequence();
         endElement("areaTree");
@@ -392,6 +385,7 @@ public class XMLRenderer extends Abstrac
     }
 
     /** {@inheritDoc} */
+    @Override
     public void renderPage(PageViewport page) throws IOException, FOPException {
         atts.clear();
         addAttribute("bounds", page.getViewArea());
@@ -416,6 +410,7 @@ public class XMLRenderer extends Abstrac
     }
 
     /** {@inheritDoc} */
+    @Override
     protected void handleExtensionAttachments(List attachments) {
         if (attachments != null && attachments.size() > 0) {
             startElement("extension-attachments");
@@ -438,6 +433,7 @@ public class XMLRenderer extends Abstrac
     }
 
     /** {@inheritDoc} */
+    @Override
     public void startPageSequence(PageSequence pageSequence) {
         handleDocumentExtensionAttachments();
         endPageSequence();  // move this before handleDocumentExtensionAttachments() ?
@@ -451,29 +447,6 @@ public class XMLRenderer extends Abstrac
         }
         transferForeignObjects(pageSequence);
         startElement("pageSequence", atts);
-        if (this.getUserAgent().isAccessibilityEnabled()) {
-            String structureTreeElement = "structureTree";
-            startElement(structureTreeElement);
-            try {
-                this.handler.startPrefixMapping("foi", InternalElementMapping.URI);
-                this.handler.startPrefixMapping("fox", ExtensionElementMapping.URI);
-                NodeList nodes = getUserAgent().getStructureTree().getPageSequence(
-                        pageSequenceIndex++);
-                for (int i = 0, n = nodes.getLength(); i < n; i++) {
-                    Node node = nodes.item(i);
-                    try {
-                        new DOM2SAX(handler).writeFragment(node);
-                    } catch (SAXException e) {
-                        handleSAXException(e);
-                    }
-                }
-                this.handler.endPrefixMapping("fox");
-                this.handler.endPrefixMapping("foi");
-            } catch (SAXException se) {
-                handleSAXException(se);
-            }
-            endElement(structureTreeElement);
-        }
         handleExtensionAttachments(pageSequence.getExtensionAttachments());
         LineArea seqTitle = pageSequence.getTitle();
         if (seqTitle != null) {
@@ -502,13 +475,14 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void renderRegionViewport(RegionViewport port) {
         if (port != null) {
             atts.clear();
             addAreaAttributes(port);
             addTraitAttributes(port);
             addAttribute("rect", port.getViewArea());
-            if (port.isClip()) {
+            if (port.hasClip()) {
                 addAttribute("clipped", "true");
             }
             startElement("regionViewport", atts);
@@ -548,12 +522,13 @@ public class XMLRenderer extends Abstrac
         }
     }
 
-    /** {@inheritDoc} */
-    protected void startVParea(CTM ctm, Rectangle2D clippingRect) {
+    @Override
+    protected void startVParea(CTM ctm, Rectangle clippingRect) {
         //only necessary for graphical output
     }
 
     /** {@inheritDoc} */
+    @Override
     protected void endVParea() {
         //only necessary for graphical output
     }
@@ -562,6 +537,7 @@ public class XMLRenderer extends Abstrac
      * {@inheritDoc}
      *          org.apache.fop.area.inline.InlineArea)
      */
+    @Override
     protected void renderInlineAreaBackAndBorders(InlineArea area) {
         //only necessary for graphical output
     }
@@ -569,6 +545,7 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void renderBeforeFloat(BeforeFloat bf) {
         startElement("beforeFloat");
         super.renderBeforeFloat(bf);
@@ -578,6 +555,7 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void renderFootnote(Footnote footnote) {
         atts.clear();
         addAttribute("top-offset", footnote.getTop());
@@ -589,6 +567,7 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void renderMainReference(MainReference mr) {
         atts.clear();
         addAreaAttributes(mr);
@@ -610,7 +589,7 @@ public class XMLRenderer extends Abstrac
             addTraitAttributes(span);
             startElement("span", atts);
             for (int c = 0; c < span.getColumnCount(); c++) {
-                NormalFlow flow = (NormalFlow) span.getNormalFlow(c);
+                NormalFlow flow = span.getNormalFlow(c);
 
                 renderFlow(flow);
             }
@@ -622,6 +601,7 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void renderFlow(NormalFlow flow) {
         // the normal flow reference area contains stacked blocks
         atts.clear();
@@ -633,6 +613,7 @@ public class XMLRenderer extends Abstrac
     }
 
     /** {@inheritDoc} */
+    @Override
     protected void renderReferenceArea(Block block) {
         handleBlockTraits(block);
 
@@ -643,6 +624,7 @@ public class XMLRenderer extends Abstrac
     }
 
     /** {@inheritDoc} */
+    @Override
     protected void renderBlock(Block block) {
         atts.clear();
         addAreaAttributes(block);
@@ -660,7 +642,7 @@ public class XMLRenderer extends Abstrac
                 addAttribute("top-position", bvp.getYOffset());
             }
             addAttribute("ctm", bvp.getCTM().toString());
-            if (bvp.getClip()) {
+            if (bvp.hasClip()) {
                 addAttribute("clipped", "true");
             }
         } else {
@@ -691,6 +673,7 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void renderLineArea(LineArea line) {
         atts.clear();
         addAreaAttributes(line);
@@ -703,6 +686,7 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void renderInlineArea(InlineArea inlineArea) {
         atts.clear();
         if (inlineArea.getClass() == InlineArea.class) {
@@ -721,23 +705,25 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
-    protected void renderViewport(Viewport viewport) {
+    @Override
+    protected void renderInlineViewport(InlineViewport viewport) {
         atts.clear();
         addAreaAttributes(viewport);
         addTraitAttributes(viewport);
-        addAttribute("offset", viewport.getOffset());
+        addAttribute("offset", viewport.getBlockProgressionOffset());
         addAttribute("pos", viewport.getContentPosition());
-        if (viewport.getClip()) {
+        if (viewport.hasClip()) {
             addAttribute("clip", "true");
         }
         startElement("viewport", atts);
-        super.renderViewport(viewport);
+        super.renderInlineViewport(viewport);
         endElement("viewport");
     }
 
     /**
      * {@inheritDoc}
      */
+    @Override
     public void renderImage(Image image, Rectangle2D pos) {
         atts.clear();
         addAreaAttributes(image);
@@ -751,6 +737,7 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     public void renderContainer(Container cont) {
         startElement("container");
         super.renderContainer(cont);
@@ -763,6 +750,7 @@ public class XMLRenderer extends Abstrac
      * @param pos the position of the foreign object
      * @see org.apache.fop.render.AbstractRenderer#renderForeignObject(ForeignObject, Rectangle2D)
      */
+    @Override
     public void renderForeignObject(ForeignObject fo, Rectangle2D pos) {
         atts.clear();
         addAreaAttributes(fo);
@@ -779,11 +767,12 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void renderInlineSpace(Space space) {
         atts.clear();
         addAreaAttributes(space);
         addTraitAttributes(space);
-        addAttribute("offset", space.getOffset());
+        addAttribute("offset", space.getBlockProgressionOffset());
         startElement("space", atts);
         endElement("space");
     }
@@ -791,6 +780,7 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void renderText(TextArea text) {
         atts.clear();
         if (text.getTextWordSpaceAdjust() != 0) {
@@ -799,7 +789,7 @@ public class XMLRenderer extends Abstrac
         if (text.getTextLetterSpaceAdjust() != 0) {
             addAttribute("tlsadjust", text.getTextLetterSpaceAdjust());
         }
-        addAttribute("offset", text.getOffset());
+        addAttribute("offset", text.getBlockProgressionOffset());
         addAttribute("baseline", text.getBaselineOffset());
         addAreaAttributes(text);
         addTraitAttributes(text);
@@ -811,9 +801,13 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void renderWord(WordArea word) {
         atts.clear();
-        addAttribute("offset", word.getOffset());
+        int offset = word.getBlockProgressionOffset();
+        if ( offset != 0 ) {
+            addAttribute("offset", offset);
+        }
         int[] letterAdjust = word.getLetterAdjustArray();
         if (letterAdjust != null) {
             StringBuffer sb = new StringBuffer(64);
@@ -829,6 +823,11 @@ public class XMLRenderer extends Abstrac
                 addAttribute("letter-adjust", sb.toString());
             }
         }
+        maybeAddLevelAttribute(word);
+        maybeAddPositionAdjustAttribute(word);
+        if ( word.isReversed() ) {
+            addAttribute("reversed", "true");
+        }
         startElement("word", atts);
         characters(word.getWord());
         endElement("word");
@@ -838,9 +837,14 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void renderSpace(SpaceArea space) {
         atts.clear();
-        addAttribute("offset", space.getOffset());
+        int offset = space.getBlockProgressionOffset();
+        if ( offset != 0 ) {
+            addAttribute("offset", offset);
+        }
+        maybeAddLevelAttribute(space);
         if (!space.isAdjustable()) {
             addAttribute("adj", "false"); //default is true
         }
@@ -853,11 +857,12 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void renderInlineParent(InlineParent ip) {
         atts.clear();
         addAreaAttributes(ip);
         addTraitAttributes(ip);
-        addAttribute("offset", ip.getOffset());
+        addAttribute("offset", ip.getBlockProgressionOffset());
         startElement("inlineparent", atts);
         super.renderInlineParent(ip);
         endElement("inlineparent");
@@ -866,11 +871,12 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void renderInlineBlockParent(InlineBlockParent ibp) {
         atts.clear();
         addAreaAttributes(ibp);
         addTraitAttributes(ibp);
-        addAttribute("offset", ibp.getOffset());
+        addAttribute("offset", ibp.getBlockProgressionOffset());
         startElement("inlineblockparent", atts);
         super.renderInlineBlockParent(ibp);
         endElement("inlineblockparent");
@@ -879,11 +885,12 @@ public class XMLRenderer extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void renderLeader(Leader area) {
         atts.clear();
         addAreaAttributes(area);
         addTraitAttributes(area);
-        addAttribute("offset", area.getOffset());
+        addAttribute("offset", area.getBlockProgressionOffset());
         addAttribute("ruleStyle", area.getRuleStyleAsString());
         addAttribute("ruleThickness", area.getRuleThickness());
         startElement("leader", atts);
@@ -896,5 +903,19 @@ public class XMLRenderer extends Abstrac
         return XML_MIME_TYPE;
     }
 
-}
+    private void maybeAddLevelAttribute ( Area a ) {
+        int level = a.getBidiLevel();
+        if ( level >= 0 ) {
+            addAttribute ( "level", level );
+        }
+    }
+
+    private void maybeAddPositionAdjustAttribute ( WordArea w ) {
+        int[][] adjustments = w.getGlyphPositionAdjustments();
+        if ( adjustments != null ) {
+            addAttribute ( "position-adjust", XMLUtil.encodePositionAdjustments ( adjustments ) );
+        }
+    }
+
 
+}

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/xml/XMLRendererMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/xml/XMLRendererMaker.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/xml/XMLRendererMaker.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/xml/XMLRendererMaker.java Thu Apr  5 16:19:19 2012
@@ -35,7 +35,7 @@ public class XMLRendererMaker extends Ab
 
     /**{@inheritDoc} */
     public Renderer makeRenderer(FOUserAgent userAgent) {
-        return new XMLRenderer();
+        return new XMLRenderer(userAgent);
     }
 
     /**{@inheritDoc} */

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/xml/XMLXMLHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/xml/XMLXMLHandler.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/xml/XMLXMLHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/xml/XMLXMLHandler.java Thu Apr  5 16:19:19 2012
@@ -19,13 +19,13 @@
 
 package org.apache.fop.render.xml;
 
+import org.xml.sax.ContentHandler;
+
 import org.apache.fop.render.Renderer;
-import org.apache.fop.render.XMLHandler;
 import org.apache.fop.render.RendererContext;
+import org.apache.fop.render.XMLHandler;
 import org.apache.fop.util.DOM2SAX;
 
-import org.xml.sax.ContentHandler;
-
 /**
  * XML handler for the XML renderer.
  */

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/servlet/FopPrintServlet.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/servlet/FopPrintServlet.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/servlet/FopPrintServlet.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/servlet/FopPrintServlet.java Thu Apr  5 16:19:19 2012
@@ -24,10 +24,10 @@ import java.io.PrintWriter;
 
 import javax.servlet.http.HttpServletResponse;
 
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
 import javax.xml.transform.Result;
 import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
 import javax.xml.transform.sax.SAXResult;
 
 import org.apache.fop.apps.FOPException;
@@ -55,9 +55,6 @@ import org.apache.fop.apps.MimeConstants
  * <br/>
  * <b>Note:</b> This servlet is derived from FopServlet. Most methods are inherited from the
  * superclass. Only the differences to the base class are necessary.
- *
- * @author <a href="mailto:fop-dev@xmlgraphics.apache.org">Apache FOP Development Team</a>
- * @version $Id$
  */
 public class FopPrintServlet extends FopServlet {
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/servlet/FopServlet.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/servlet/FopServlet.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/servlet/FopServlet.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/servlet/FopServlet.java Thu Apr  5 16:19:19 2012
@@ -63,9 +63,6 @@ import org.apache.fop.apps.MimeConstants
  * <br/>
  * For this to work with Internet Explorer, you might need to append "&ext=.pdf"
  * to the URL.
- *
- * @author <a href="mailto:fop-dev@xmlgraphics.apache.org">Apache FOP Development Team</a>
- * @version $Id$
  * (todo) Ev. add caching mechanism for Templates objects
  */
 public class FopServlet extends HttpServlet {

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/ACIUtils.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/ACIUtils.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/ACIUtils.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/ACIUtils.java Thu Apr  5 16:19:19 2012
@@ -19,29 +19,171 @@
 
 package org.apache.fop.svg;
 
+import java.awt.font.TextAttribute;
 import java.text.AttributedCharacterIterator;
+import java.text.AttributedCharacterIterator.Attribute;
 import java.text.CharacterIterator;
-import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.batik.bridge.SVGFontFamily;
+import org.apache.batik.gvt.font.GVTFont;
+import org.apache.batik.gvt.font.GVTFontFamily;
+import org.apache.batik.gvt.text.GVTAttributedCharacterIterator;
+
+import org.apache.fop.fonts.Font;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontTriplet;
 
 /**
  * Utilities for java.text.AttributedCharacterIterator.
  */
 public final class ACIUtils {
 
+    /** the logger for this class */
+    private static final Log LOG = LogFactory.getLog(ACIUtils.class);
+
     private ACIUtils() {
         //This class shouldn't be instantiated.
     }
 
     /**
+     * Tries to find matching fonts in FOP's {@link FontInfo} instance for fonts used by
+     * Apache Batik. The method inspects the various GVT attributes found in the ACI.
+     * @param aci the ACI to find matching fonts for
+     * @param fontInfo the font info instance with FOP's fonts
+     * @return an array of matching fonts
+     */
+    public static Font[] findFontsForBatikACI(AttributedCharacterIterator aci, FontInfo fontInfo) {
+        List<Font> fonts = new java.util.ArrayList<Font>();
+        @SuppressWarnings("unchecked")
+        List<GVTFontFamily> gvtFonts = (List<GVTFontFamily>) aci.getAttribute(
+                GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES);
+        Float posture = (Float) aci.getAttribute(TextAttribute.POSTURE);
+        Float taWeight = (Float) aci.getAttribute(TextAttribute.WEIGHT);
+        Float fontSize = (Float) aci.getAttribute(TextAttribute.SIZE);
+
+        String style = toStyle(posture);
+        int weight = toCSSWeight(taWeight);
+        int fsize = (int)(fontSize.floatValue() * 1000);
+
+        String firstFontFamily = null;
+
+        //GVT_FONT can sometimes be different from the fonts in GVT_FONT_FAMILIES
+        //or GVT_FONT_FAMILIES can even be empty and only GVT_FONT is set
+        /* The following code section is not available until Batik 1.7 is released. */
+        GVTFont gvtFont = (GVTFont)aci.getAttribute(
+                GVTAttributedCharacterIterator.TextAttribute.GVT_FONT);
+        if (gvtFont != null) {
+            String gvtFontFamily = gvtFont.getFamilyName();
+            if (fontInfo.hasFont(gvtFontFamily, style, weight)) {
+                FontTriplet triplet = fontInfo.fontLookup(gvtFontFamily, style,
+                                                          weight);
+                Font f = fontInfo.getFontInstance(triplet, fsize);
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Found a font that matches the GVT font: "
+                              + gvtFontFamily + ", " + weight + ", " + style
+                              + " -> " + f);
+                }
+                fonts.add(f);
+            }
+            firstFontFamily = gvtFontFamily;
+        }
+
+        if (gvtFonts != null) {
+            boolean haveInstanceOfSVGFontFamily = false;
+            for (GVTFontFamily fam : gvtFonts) {
+                if (fam instanceof SVGFontFamily) {
+                    haveInstanceOfSVGFontFamily = true;
+                }
+                String fontFamily = fam.getFamilyName();
+                if (fontInfo.hasFont(fontFamily, style, weight)) {
+                    FontTriplet triplet = fontInfo.fontLookup(fontFamily, style,
+                                                       weight);
+                    Font f = fontInfo.getFontInstance(triplet, fsize);
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Found a font that matches the GVT font family: "
+                                + fontFamily + ", " + weight + ", " + style
+                                + " -> " + f);
+                    }
+                    fonts.add(f);
+                }
+                if (firstFontFamily == null) {
+                    firstFontFamily = fontFamily;
+                }
+            }
+            // SVG fonts are embedded fonts in the SVG document and are rarely used; however if they
+            // are used but the fonts also exists in the system and are known to FOP then FOP should
+            // use them; then the decision whether Batik should stroke the text should be made after
+            // no matching fonts are found
+            if (fonts.isEmpty() && haveInstanceOfSVGFontFamily) {
+                fontInfo.notifyStrokingSVGTextAsShapes(firstFontFamily);
+                return null; // Let Batik paint this text!
+            }
+        }
+        if (fonts.isEmpty()) {
+            if (firstFontFamily == null) {
+                //This will probably never happen. Just to be on the safe side.
+                firstFontFamily = "any";
+            }
+            //lookup with fallback possibility (incl. substitution notification)
+            FontTriplet triplet = fontInfo.fontLookup(firstFontFamily, style, weight);
+            Font f = fontInfo.getFontInstance(triplet, fsize);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Falling back to adjustable font lookup up for: "
+                        + firstFontFamily + ", " + weight + ", " + style
+                        + " -> " + f);
+            }
+            fonts.add(f);
+        }
+        return fonts.toArray(new Font[fonts.size()]);
+    }
+
+    private static int toCSSWeight(Float weight) {
+        if (weight == null) {
+            return 400;
+        } else if (weight <= TextAttribute.WEIGHT_EXTRA_LIGHT.floatValue()) {
+            return 100;
+        } else if (weight <= TextAttribute.WEIGHT_LIGHT.floatValue()) {
+            return 200;
+        } else if (weight <= TextAttribute.WEIGHT_DEMILIGHT.floatValue()) {
+            return 300;
+        } else if (weight <= TextAttribute.WEIGHT_REGULAR.floatValue()) {
+            return 400;
+        } else if (weight <= TextAttribute.WEIGHT_SEMIBOLD.floatValue()) {
+            return 500;
+        } else if (weight <  TextAttribute.WEIGHT_BOLD.floatValue()) {
+            return 600;
+        } else if (weight == TextAttribute.WEIGHT_BOLD.floatValue()) {
+            return 700;
+        } else if (weight <= TextAttribute.WEIGHT_HEAVY.floatValue()) {
+            return 800;
+        } else if (weight <= TextAttribute.WEIGHT_EXTRABOLD.floatValue()) {
+            return 900;
+        } else {
+            return 900;
+        }
+    }
+
+    private static String toStyle(Float posture) {
+        return ((posture != null) && (posture.floatValue() > 0.0))
+                       ? Font.STYLE_ITALIC
+                       : Font.STYLE_NORMAL;
+    }
+
+    /**
      * Dumps the contents of an ACI to System.out. Used for debugging only.
      * @param aci the ACI to dump
      */
     public static void dumpAttrs(AttributedCharacterIterator aci) {
         aci.first();
-        Iterator i = aci.getAttributes().entrySet().iterator();
-        while (i.hasNext()) {
-            Map.Entry entry = (Map.Entry)i.next();
+        Set<Entry<Attribute, Object>> entries = aci.getAttributes().entrySet();
+        for (Map.Entry<Attribute, Object> entry : entries) {
             if (entry.getValue() != null) {
                 System.out.println(entry.getKey() + ": " + entry.getValue());
             }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPImageElementBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPImageElementBridge.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPImageElementBridge.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPImageElementBridge.java Thu Apr  5 16:19:19 2012
@@ -23,11 +23,15 @@ import java.awt.Graphics2D;
 import java.awt.Shape;
 import java.awt.geom.Rectangle2D;
 
+import org.w3c.dom.Element;
+import org.w3c.dom.svg.SVGDocument;
+
 import org.apache.batik.bridge.BridgeContext;
 import org.apache.batik.bridge.SVGImageElementBridge;
 import org.apache.batik.gvt.AbstractGraphicsNode;
 import org.apache.batik.gvt.GraphicsNode;
 import org.apache.batik.util.ParsedURL;
+
 import org.apache.xmlgraphics.image.loader.Image;
 import org.apache.xmlgraphics.image.loader.ImageException;
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
@@ -39,13 +43,13 @@ import org.apache.xmlgraphics.image.load
 import org.apache.xmlgraphics.image.loader.impl.ImageRawJPEG;
 import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
 import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
-import org.w3c.dom.Element;
-import org.w3c.dom.svg.SVGDocument;
+
+import org.apache.fop.image.loader.batik.BatikUtil;
 
 /**
- * Bridge class for the &lt;image> element when jpeg images.
+ * <p>Bridge class for the &lt;image> element when jpeg images.</p>
  *
- * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
+ * <p>This work was authored by Keiron Liddle (keiron@aftexsw.com).</p>
  */
 public abstract class AbstractFOPImageElementBridge extends SVGImageElementBridge {
 
@@ -63,6 +67,7 @@ public abstract class AbstractFOPImageEl
      * @param purl the parsed url for the image resource
      * @return a new graphics node
      */
+    @Override
     protected GraphicsNode createImageGraphicsNode
                 (BridgeContext ctx, Element imageElement, ParsedURL purl) {
         AbstractFOPBridgeContext bridgeCtx = (AbstractFOPBridgeContext)ctx;
@@ -80,8 +85,11 @@ public abstract class AbstractFOPImageEl
             if (image instanceof ImageXMLDOM) {
                 ImageXMLDOM xmlImage = (ImageXMLDOM)image;
                 if (xmlImage.getDocument() instanceof SVGDocument) {
-                    return createSVGImageNode(ctx, imageElement,
-                            (SVGDocument)xmlImage.getDocument());
+                    //Clone DOM because the Batik's CSS Parser attaches to the DOM and is therefore
+                    //not thread-safe.
+                    SVGDocument clonedDoc = (SVGDocument)BatikUtil.cloneSVGDocument(
+                            xmlImage.getDocument());
+                    return createSVGImageNode(ctx, imageElement, clonedDoc);
                 } else {
                     //Convert image to Graphics2D
                     image = manager.convertImage(xmlImage,
@@ -100,22 +108,25 @@ public abstract class AbstractFOPImageEl
                         new ImageException("Cannot convert an image to a usable format: " + purl));
             }
 
-            Rectangle2D imgBounds = getImageBounds(ctx, imageElement);
-            Rectangle2D bounds = specializedNode.getPrimitiveBounds();
-            float [] vb = new float[4];
-            vb[0] = 0; // x
-            vb[1] = 0; // y
-            vb[2] = (float) bounds.getWidth(); // width
-            vb[3] = (float) bounds.getHeight(); // height
-
-            // handles the 'preserveAspectRatio', 'overflow' and 'clip'
-            // and sets the appropriate AffineTransform to the image node
-            initializeViewport(ctx, imageElement, specializedNode, vb, imgBounds);
-            return specializedNode;
+            if (specializedNode != null) {
+                Rectangle2D imgBounds = getImageBounds(ctx, imageElement);
+                Rectangle2D bounds = specializedNode.getPrimitiveBounds();
+                float [] vb = new float[4];
+                vb[0] = 0; // x
+                vb[1] = 0; // y
+                vb[2] = (float) bounds.getWidth(); // width
+                vb[3] = (float) bounds.getHeight(); // height
+
+                // handles the 'preserveAspectRatio', 'overflow' and 'clip'
+                // and sets the appropriate AffineTransform to the image node
+                initializeViewport(ctx, imageElement, specializedNode, vb, imgBounds);
+                return specializedNode;
+            }
         } catch (Exception e) {
             ctx.getUserAgent().displayError(e);
         }
 
+        //Fallback
         return superCreateGraphicsNode(ctx, imageElement, purl);
     }
 
@@ -241,7 +252,7 @@ public abstract class AbstractFOPImageEl
     /**
      * A node that holds a Graphics2D image.
      */
-    public class Graphics2DNode extends AbstractGraphicsNode {
+    public static class Graphics2DNode extends AbstractGraphicsNode {
 
         private final ImageGraphics2D image;
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPTextElementBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPTextElementBridge.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPTextElementBridge.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPTextElementBridge.java Thu Apr  5 16:19:19 2012
@@ -28,11 +28,11 @@ import org.apache.batik.gvt.TextNode;
 import org.apache.batik.gvt.TextPainter;
 
 /**
- * Bridge class for the &lt;text> element.
+ * <p>Bridge class for the &lt;text> element.
  * This bridge will use the direct text painter if the text
- * for the element is simple.
+ * for the element is simple.</p>
  *
- * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
+ * <p>This work was authored by Keiron Liddle (keiron@aftexsw.com).</p>
  */
 public abstract class AbstractFOPTextElementBridge extends SVGTextElementBridge {
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPTextPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPTextPainter.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPTextPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPTextPainter.java Thu Apr  5 16:19:19 2012
@@ -33,21 +33,19 @@ import java.text.CharacterIterator;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import org.apache.batik.dom.svg.SVGOMTextElement;
 import org.apache.batik.gvt.TextNode;
 import org.apache.batik.gvt.TextPainter;
-import org.apache.batik.gvt.font.GVTFontFamily;
 import org.apache.batik.gvt.renderer.StrokingTextPainter;
 import org.apache.batik.gvt.text.GVTAttributedCharacterIterator;
 import org.apache.batik.gvt.text.Mark;
 import org.apache.batik.gvt.text.TextPaintInfo;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 import org.apache.fop.afp.AFPGraphics2D;
 import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontTriplet;
 
 /**
  * Renders the attributed character iterator of a {@link TextNode}.
@@ -336,53 +334,9 @@ public abstract class AbstractFOPTextPai
         }
     }
 
-    private String getStyle(AttributedCharacterIterator aci) {
-        Float posture = (Float)aci.getAttribute(TextAttribute.POSTURE);
-        return ((posture != null) && (posture.floatValue() > 0.0))
-                       ? Font.STYLE_ITALIC
-                       : Font.STYLE_NORMAL;
-    }
-
-    private int getWeight(AttributedCharacterIterator aci) {
-        Float taWeight = (Float)aci.getAttribute(TextAttribute.WEIGHT);
-        return ((taWeight != null) &&  (taWeight.floatValue() > 1.0))
-                       ? Font.WEIGHT_BOLD
-                       : Font.WEIGHT_NORMAL;
-    }
-
     private Font getFont(AttributedCharacterIterator aci) {
-        Float fontSize = (Float)aci.getAttribute(TextAttribute.SIZE);
-        if (fontSize == null) {
-            fontSize = new Float(10f);
-        }
-        String style = getStyle(aci);
-        int weight = getWeight(aci);
-
-        FontInfo fontInfo = nativeTextHandler.getFontInfo();
-        String fontFamily = null;
-        List gvtFonts = (List) aci.getAttribute(
-                      GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES);
-        if (gvtFonts != null) {
-            Iterator i = gvtFonts.iterator();
-            while (i.hasNext()) {
-                GVTFontFamily fam = (GVTFontFamily) i.next();
-                /* (todo) Enable SVG Font painting
-                if (fam instanceof SVGFontFamily) {
-                    PROXY_PAINTER.paint(node, g2d);
-                    return;
-                }*/
-                fontFamily = fam.getFamilyName();
-                if (fontInfo.hasFont(fontFamily, style, weight)) {
-                    FontTriplet triplet = fontInfo.fontLookup(
-                            fontFamily, style, weight);
-                    int fsize = (int)(fontSize.floatValue() * 1000);
-                    return fontInfo.getFontInstance(triplet, fsize);
-                }
-            }
-        }
-        FontTriplet triplet = fontInfo.fontLookup("any", style, Font.WEIGHT_NORMAL);
-        int fsize = (int)(fontSize.floatValue() * 1000);
-        return fontInfo.getFontInstance(triplet, fsize);
+        Font[] fonts = ACIUtils.findFontsForBatikACI(aci, nativeTextHandler.getFontInfo());
+        return fonts[0];
     }
 
     private float getStringWidth(String str, Font font) {

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/AbstractFOPTranscoder.java Thu Apr  5 16:19:19 2012
@@ -32,6 +32,10 @@ import org.apache.avalon.framework.confi
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.SimpleLog;
+
 import org.apache.batik.bridge.UserAgent;
 import org.apache.batik.dom.svg.SVGDOMImplementation;
 import org.apache.batik.dom.util.DocumentFactory;
@@ -44,8 +48,6 @@ import org.apache.batik.transcoder.keys.
 import org.apache.batik.transcoder.keys.FloatKey;
 import org.apache.batik.util.ParsedURL;
 import org.apache.batik.util.SVGConstants;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.impl.SimpleLog;
 
 import org.apache.xmlgraphics.image.GraphicsConstants;
 import org.apache.xmlgraphics.image.loader.ImageContext;
@@ -269,7 +271,6 @@ public abstract class AbstractFOPTransco
             }
 
             public Source resolveURI(String uri) {
-                System.out.println("resolve " + uri);
                 try {
                     ParsedURL url = new ParsedURL(baseURI, uri);
                     InputStream in = url.openStream();

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/NativeTextPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/NativeTextPainter.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/NativeTextPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/NativeTextPainter.java Thu Apr  5 16:19:19 2012
@@ -20,24 +20,18 @@
 package org.apache.fop.svg;
 
 import java.awt.Graphics2D;
-import java.awt.font.TextAttribute;
 import java.io.IOException;
 import java.text.AttributedCharacterIterator;
-import java.util.Iterator;
 import java.util.List;
 
-import org.apache.batik.bridge.SVGFontFamily;
-import org.apache.batik.gvt.font.GVTFont;
-import org.apache.batik.gvt.font.GVTFontFamily;
-import org.apache.batik.gvt.renderer.StrokingTextPainter;
-import org.apache.batik.gvt.text.GVTAttributedCharacterIterator;
-import org.apache.batik.gvt.text.TextSpanLayout;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.batik.gvt.renderer.StrokingTextPainter;
+import org.apache.batik.gvt.text.TextSpanLayout;
+
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontTriplet;
 import org.apache.fop.util.CharUtilities;
 
 /**
@@ -77,6 +71,7 @@ public abstract class NativeTextPainter 
     protected abstract void paintTextRun(TextRun textRun, Graphics2D g2d) throws IOException;
 
     /** {@inheritDoc} */
+    @Override
     protected void paintTextRuns(List textRuns, Graphics2D g2d) {
         if (log.isTraceEnabled()) {
             log.trace("paintTextRuns: count = " + textRuns.size());
@@ -102,100 +97,8 @@ public abstract class NativeTextPainter 
      * @return the array of fonts
      */
     protected Font[] findFonts(AttributedCharacterIterator aci) {
-        List fonts = new java.util.ArrayList();
-        List gvtFonts = (List) aci.getAttribute(
-                GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES);
-        Float posture = (Float) aci.getAttribute(TextAttribute.POSTURE);
-        Float taWeight = (Float) aci.getAttribute(TextAttribute.WEIGHT);
-        Float fontSize = (Float) aci.getAttribute(TextAttribute.SIZE);
-
-        String style = ((posture != null) && (posture.floatValue() > 0.0))
-                       ? Font.STYLE_ITALIC : Font.STYLE_NORMAL;
-        int weight = toCSSWeight(taWeight != null
-                ? taWeight.floatValue()
-                        : TextAttribute.WEIGHT_REGULAR.floatValue());
-
-        String firstFontFamily = null;
-
-        //GVT_FONT can sometimes be different from the fonts in GVT_FONT_FAMILIES
-        //or GVT_FONT_FAMILIES can even be empty and only GVT_FONT is set
-        /* The following code section is not available until Batik 1.7 is released. */
-        GVTFont gvtFont = (GVTFont)aci.getAttribute(
-                GVTAttributedCharacterIterator.TextAttribute.GVT_FONT);
-        if (gvtFont != null) {
-            try {
-                String gvtFontFamily = gvtFont.getFamilyName(); //Not available in Batik 1.6!
-                if (log.isDebugEnabled()) {
-                    log.debug("Matching font family: " + gvtFontFamily);
-                }
-                if (fontInfo.hasFont(gvtFontFamily, style, weight)) {
-                    FontTriplet triplet = fontInfo.fontLookup(gvtFontFamily, style,
-                                                       weight);
-                    int fsize = (int)(fontSize.floatValue() * 1000);
-                    fonts.add(fontInfo.getFontInstance(triplet, fsize));
-                }
-                firstFontFamily = gvtFontFamily;
-            } catch (Exception e) {
-                //Most likely NoSuchMethodError here when using Batik 1.6
-                //Just skip this section in this case
-            }
-        }
-
-        if (gvtFonts != null) {
-            Iterator i = gvtFonts.iterator();
-            while (i.hasNext()) {
-                GVTFontFamily fam = (GVTFontFamily) i.next();
-                if (fam instanceof SVGFontFamily) {
-                    return null; //Let Batik paint this text!
-                }
-                String fontFamily = fam.getFamilyName();
-                if (log.isDebugEnabled()) {
-                    log.debug("Matching font family: " + fontFamily);
-                }
-                if (fontInfo.hasFont(fontFamily, style, weight)) {
-                    FontTriplet triplet = fontInfo.fontLookup(fontFamily, style,
-                                                       weight);
-                    int fsize = (int)(fontSize.floatValue() * 1000);
-                    fonts.add(fontInfo.getFontInstance(triplet, fsize));
-                }
-                if (firstFontFamily == null) {
-                    firstFontFamily = fontFamily;
-                }
-            }
-        }
-        if (fonts.size() == 0) {
-            if (firstFontFamily == null) {
-                //This will probably never happen. Just to be on the safe side.
-                firstFontFamily = "any";
-            }
-            //lookup with fallback possibility (incl. substitution notification)
-            FontTriplet triplet = fontInfo.fontLookup(firstFontFamily, style, weight);
-            int fsize = (int)(fontSize.floatValue() * 1000);
-            fonts.add(fontInfo.getFontInstance(triplet, fsize));
-        }
-        return (Font[])fonts.toArray(new Font[fonts.size()]);
-    }
-
-    private int toCSSWeight(float weight) {
-        if (weight <= TextAttribute.WEIGHT_EXTRA_LIGHT.floatValue()) {
-            return 100;
-        } else if (weight <= TextAttribute.WEIGHT_LIGHT.floatValue()) {
-            return 200;
-        } else if (weight <= TextAttribute.WEIGHT_DEMILIGHT.floatValue()) {
-            return 300;
-        } else if (weight <= TextAttribute.WEIGHT_REGULAR.floatValue()) {
-            return 400;
-        } else if (weight <= TextAttribute.WEIGHT_SEMIBOLD.floatValue()) {
-            return 500;
-        } else if (weight <= TextAttribute.WEIGHT_BOLD.floatValue()) {
-            return 600;
-        } else if (weight <= TextAttribute.WEIGHT_HEAVY.floatValue()) {
-            return 700;
-        } else if (weight <= TextAttribute.WEIGHT_EXTRABOLD.floatValue()) {
-            return 800;
-        } else {
-            return 900;
-        }
+        Font[] fonts = ACIUtils.findFontsForBatikACI(aci, fontInfo);
+        return fonts;
     }
 
     /**

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFAElementBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFAElementBridge.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFAElementBridge.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFAElementBridge.java Thu Apr  5 16:19:19 2012
@@ -26,13 +26,12 @@ import org.w3c.dom.svg.SVGAElement;
 
 import org.apache.batik.bridge.AbstractGraphicsNodeBridge;
 import org.apache.batik.bridge.BridgeContext;
-import org.apache.batik.gvt.CompositeGraphicsNode;
 import org.apache.batik.gvt.GraphicsNode;
 
 /**
- * Bridge class for the &lt;a> element.
+ * <p>Bridge class for the &lt;a> element.</p>
  *
- * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
+ * <p>This work was authored by Keiron Liddle (keiron@aftexsw.com).</p>
  */
 public class PDFAElementBridge extends AbstractGraphicsNodeBridge {
     private AffineTransform transform;

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFANode.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFANode.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFANode.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFANode.java Thu Apr  5 16:19:19 2012
@@ -28,9 +28,9 @@ import java.util.StringTokenizer;
 import org.apache.batik.gvt.CompositeGraphicsNode;
 
 /**
- * A graphics node that represents an image described as a graphics node.
+ * <p>A graphics node that represents an image described as a graphics node.</p>
  *
- * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
+ * <p>This work was authored by Keiron Liddle (keiron@aftexsw.com).</p>
  */
 public class PDFANode extends CompositeGraphicsNode {
     private String destination;

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFBatikFlowTextElementBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFBatikFlowTextElementBridge.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFBatikFlowTextElementBridge.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFBatikFlowTextElementBridge.java Thu Apr  5 16:19:19 2012
@@ -23,6 +23,7 @@ import org.apache.batik.extension.svg.Ba
 import org.apache.batik.gvt.GraphicsNode;
 import org.apache.batik.gvt.TextNode;
 import org.apache.batik.gvt.TextPainter;
+
 import org.apache.fop.fonts.FontInfo;
 
 /**

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFBridgeContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFBridgeContext.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFBridgeContext.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFBridgeContext.java Thu Apr  5 16:19:19 2012
@@ -25,6 +25,7 @@ import org.apache.batik.bridge.BridgeCon
 import org.apache.batik.bridge.DocumentLoader;
 import org.apache.batik.bridge.SVGTextElementBridge;
 import org.apache.batik.bridge.UserAgent;
+import org.apache.batik.dom.svg.SVGOMDocument;
 import org.apache.batik.gvt.TextPainter;
 
 import org.apache.xmlgraphics.image.loader.ImageManager;
@@ -86,6 +87,7 @@ public class PDFBridgeContext extends Ab
     }
 
     /** {@inheritDoc} */
+    @Override
     public void registerSVGBridges() {
         super.registerSVGBridges();
 
@@ -123,10 +125,17 @@ public class PDFBridgeContext extends Ab
         putBridge(new PDFImageElementBridge());
     }
 
-    // Make sure any 'sub bridge contexts' also have our bridges.
-    //TODO There's no matching method in the super-class here
-    /** @return the new bridge context */
+    /** {@inheritDoc} */
+    @Override
     public BridgeContext createBridgeContext() {
+        //Retained for pre-Batik-1.7 compatibility
+        return createBridgeContext(null);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public BridgeContext createBridgeContext(SVGOMDocument doc) {
+        // Make sure any 'sub bridge contexts' also have our bridges.
         return new PDFBridgeContext(getUserAgent(), getDocumentLoader(),
                                     fontInfo,
                                     getImageManager(),

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java Thu Apr  5 16:19:19 2012
@@ -36,7 +36,7 @@ import org.apache.fop.Version;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontSetup;
 import org.apache.fop.pdf.PDFAnnotList;
-import org.apache.fop.pdf.PDFColor;
+import org.apache.fop.pdf.PDFColorHandler;
 import org.apache.fop.pdf.PDFDocument;
 import org.apache.fop.pdf.PDFFilterList;
 import org.apache.fop.pdf.PDFNumber;
@@ -101,6 +101,7 @@ public class PDFDocumentGraphics2D exten
         this.pdfDoc = new PDFDocument("Apache FOP Version " + Version.getVersion()
                 + ": PDFDocumentGraphics2D");
         this.pdfContext = new PDFContext();
+        this.colorHandler = new PDFColorHandler(this.pdfDoc.getResources());
     }
 
     /**
@@ -112,8 +113,8 @@ public class PDFDocumentGraphics2D exten
      * @param textAsShapes set this to true so that text will be rendered
      * using curves and not the font.
      * @param stream the stream that the final document should be written to.
-     * @param width the width of the document
-     * @param height the height of the document
+     * @param width the width of the document (in points)
+     * @param height the height of the document (in points)
      * @throws IOException an io exception if there is a problem
      *         writing to the output stream
      */
@@ -158,7 +159,8 @@ public class PDFDocumentGraphics2D exten
         if (fontInfo == null) {
             //Default minimal fonts
             FontInfo fontInfo = new FontInfo();
-            FontSetup.setup(fontInfo);
+            boolean base14Kerning = false;
+            FontSetup.setup(fontInfo, base14Kerning);
             setFontInfo(fontInfo);
         }
     }
@@ -232,15 +234,15 @@ public class PDFDocumentGraphics2D exten
      * @param col the background colour to fill
      */
     public void setBackgroundColor(Color col) {
-        Color c = col;
-        PDFColor currentColour = new PDFColor(c.getRed(), c.getGreen(), c.getBlue());
-        currentStream.write("q\n");
-        currentStream.write(currentColour.getColorSpaceOut(true));
-
-        currentStream.write("0 0 " + width + " " + height + " re\n");
-
-        currentStream.write("f\n");
-        currentStream.write("Q\n");
+        StringBuffer sb = new StringBuffer();
+        sb.append("q\n");
+        this.colorHandler.establishColor(sb, col, true);
+
+        sb.append("0 0 ").append(width).append(" ").append(height).append(" re\n");
+
+        sb.append("f\n");
+        sb.append("Q\n");
+        currentStream.write(sb.toString());
     }
 
     /**
@@ -252,6 +254,19 @@ public class PDFDocumentGraphics2D exten
     }
 
     /**
+     * Is called to prepare the PDFDocumentGraphics2D for the next page to be painted. Basically,
+     * this closes the current page. A new page is prepared as soon as painting starts.
+     * This method allows to start the new page (and following pages) with a different page size.
+     * @param width the width of the new page (in points)
+     * @param height the height of the new page (in points)
+     */
+    public void nextPage(int width, int height) {
+        this.width = width;
+        this.height = height;
+        nextPage();
+    }
+
+    /**
      * Closes the current page and adds it to the PDF file.
      */
     protected void closePage() {
@@ -275,6 +290,7 @@ public class PDFDocumentGraphics2D exten
     }
 
     /** {@inheritDoc} */
+    @Override
     protected void preparePainting() {
         if (pdfContext.isPagePending()) {
             return;
@@ -390,7 +406,9 @@ public class PDFDocumentGraphics2D exten
      * @return     a new graphics context that is a copy of
      * this graphics context.
      */
+    @Override
     public Graphics create() {
+        preparePainting();
         return new PDFDocumentGraphics2D(this);
     }
 
@@ -402,6 +420,7 @@ public class PDFDocumentGraphics2D exten
      * @param x the x position
      * @param y the y position
      */
+    @Override
     public void drawString(String s, float x, float y) {
         if (super.textAsShapes) {
             Font font = super.getFont();

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFDocumentGraphics2DConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFDocumentGraphics2DConfigurator.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFDocumentGraphics2DConfigurator.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFDocumentGraphics2DConfigurator.java Thu Apr  5 16:19:19 2012
@@ -46,9 +46,11 @@ public class PDFDocumentGraphics2DConfig
      * Configures a PDFDocumentGraphics2D instance using an Avalon Configuration object.
      * @param graphics the PDFDocumentGraphics2D instance
      * @param cfg the configuration
+     * @param useComplexScriptFeatures true if complex script features enabled
      * @throws ConfigurationException if an error occurs while configuring the object
      */
-    public void configure(PDFDocumentGraphics2D graphics, Configuration cfg)
+    public void configure(PDFDocumentGraphics2D graphics, Configuration cfg,
+                          boolean useComplexScriptFeatures )
             throws ConfigurationException {
         PDFDocument pdfDoc = graphics.getPDFDocument();
 
@@ -58,7 +60,7 @@ public class PDFDocumentGraphics2DConfig
 
         //Fonts
         try {
-            FontInfo fontInfo = createFontInfo(cfg);
+            FontInfo fontInfo = createFontInfo(cfg, useComplexScriptFeatures);
             graphics.setFontInfo(fontInfo);
         } catch (FOPException e) {
             throw new ConfigurationException("Error while setting up fonts", e);
@@ -68,13 +70,15 @@ public class PDFDocumentGraphics2DConfig
     /**
      * Creates the {@link FontInfo} instance for the given configuration.
      * @param cfg the configuration
+     * @param useComplexScriptFeatures true if complex script features enabled
      * @return the font collection
      * @throws FOPException if an error occurs while setting up the fonts
      */
-    public static FontInfo createFontInfo(Configuration cfg) throws FOPException {
+    public static FontInfo createFontInfo(Configuration cfg, boolean useComplexScriptFeatures)
+        throws FOPException {
         FontInfo fontInfo = new FontInfo();
         final boolean strict = false;
-        FontResolver fontResolver = FontManager.createMinimalFontResolver();
+        FontResolver fontResolver = FontManager.createMinimalFontResolver(useComplexScriptFeatures);
         //TODO The following could be optimized by retaining the FontManager somewhere
         FontManager fontManager = new FontManager();
         if (cfg != null) {
@@ -92,7 +96,8 @@ public class PDFDocumentGraphics2DConfig
                 = new FontInfoConfigurator(cfg, fontManager, fontResolver, listener, strict);
             List/*<EmbedFontInfo>*/ fontInfoList = new java.util.ArrayList/*<EmbedFontInfo>*/();
             fontInfoConfigurator.configure(fontInfoList);
-            fontCollections.add(new CustomFontCollection(fontResolver, fontInfoList));
+            fontCollections.add(new CustomFontCollection(fontResolver, fontInfoList,
+                                fontResolver.isComplexScriptFeaturesEnabled()));
         }
         fontManager.setup(fontInfo,
                 (FontCollection[])fontCollections.toArray(

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFFlowExtTextPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFFlowExtTextPainter.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFFlowExtTextPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFFlowExtTextPainter.java Thu Apr  5 16:19:19 2012
@@ -24,6 +24,7 @@ import java.util.List;
 
 import org.apache.batik.extension.svg.FlowExtTextPainter;
 import org.apache.batik.gvt.TextNode;
+
 import org.apache.fop.fonts.FontInfo;
 
 /**

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFFlowTextPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFFlowTextPainter.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFFlowTextPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFFlowTextPainter.java Thu Apr  5 16:19:19 2012
@@ -24,6 +24,7 @@ import java.util.List;
 
 import org.apache.batik.gvt.TextNode;
 import org.apache.batik.gvt.flow.FlowTextPainter;
+
 import org.apache.fop.fonts.FontInfo;
 
 /**

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFGraphics2D.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFGraphics2D.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFGraphics2D.java Thu Apr  5 16:19:19 2012
@@ -75,6 +75,7 @@ import org.apache.fop.fonts.FontSetup;
 import org.apache.fop.pdf.BitmapImage;
 import org.apache.fop.pdf.PDFAnnotList;
 import org.apache.fop.pdf.PDFColor;
+import org.apache.fop.pdf.PDFColorHandler;
 import org.apache.fop.pdf.PDFConformanceException;
 import org.apache.fop.pdf.PDFDeviceColorSpace;
 import org.apache.fop.pdf.PDFDocument;
@@ -92,15 +93,14 @@ import org.apache.fop.pdf.PDFXObject;
 import org.apache.fop.render.pdf.ImageRawCCITTFaxAdapter;
 import org.apache.fop.render.pdf.ImageRawJPEGAdapter;
 import org.apache.fop.render.pdf.ImageRenderedAdapter;
-import org.apache.fop.util.ColorExt;
 
 /**
- * PDF Graphics 2D.
+ * <p>PDF Graphics 2D.
  * Used for drawing into a pdf document as if it is a graphics object.
- * This takes a pdf document and draws into it.
+ * This takes a pdf document and draws into it.</p>
+ *
+ * <p>This work was authored by Keiron Liddle (keiron@aftexsw.com).</p>
  *
- * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
- * @version $Id$
  * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D
  */
 public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHandler {
@@ -132,6 +132,9 @@ public class PDFGraphics2D extends Abstr
      */
     protected PDFPaintingState paintingState;
 
+    /** the PDF color handler */
+    protected PDFColorHandler colorHandler;
+
     /**
      * The PDF graphics state level that this svg is being drawn into.
      */
@@ -194,6 +197,7 @@ public class PDFGraphics2D extends Abstr
                          PDFResourceContext page, String pref, String font, float size) {
         this(textAsShapes);
         pdfDoc = doc;
+        this.colorHandler = new PDFColorHandler(doc.getResources());
         resourceContext = page;
         currentFontName = font;
         currentFontSize = size;
@@ -220,6 +224,7 @@ public class PDFGraphics2D extends Abstr
     public PDFGraphics2D(PDFGraphics2D g) {
         super(g);
         this.pdfDoc = g.pdfDoc;
+        this.colorHandler = g.colorHandler;
         this.resourceContext = g.resourceContext;
         this.currentFontName = g.currentFontName;
         this.currentFontSize = g.currentFontSize;
@@ -238,6 +243,7 @@ public class PDFGraphics2D extends Abstr
      * @return     a new graphics context that is a copy of
      * this graphics context.
      */
+    @Override
     public Graphics create() {
         return new PDFGraphics2D(this);
     }
@@ -481,6 +487,7 @@ public class PDFGraphics2D extends Abstr
      * @see      java.awt.image.ImageObserver
      * @see      java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
      */
+    @Override
     public boolean drawImage(Image img, int x, int y,
                              ImageObserver observer) {
         preparePainting();
@@ -501,6 +508,7 @@ public class PDFGraphics2D extends Abstr
     }
 
     /** {@inheritDoc} */
+    @Override
     public boolean drawImage(Image img, int x, int y, int width, int height,
                                ImageObserver observer) {
         preparePainting();
@@ -571,6 +579,7 @@ public class PDFGraphics2D extends Abstr
      * @see         java.awt.Component#getGraphics
      * @see         java.awt.Graphics#create
      */
+    @Override
     public void dispose() {
         pdfDoc = null;
         fontInfo = null;
@@ -594,6 +603,7 @@ public class PDFGraphics2D extends Abstr
      * @see #setClip
      * @see #setComposite
      */
+    @Override
     public void draw(Shape s) {
         preparePainting();
 
@@ -614,8 +624,7 @@ public class PDFGraphics2D extends Abstr
                                && !trans.isIdentity();
 
         if (newClip || newTransform) {
-            currentStream.write("q\n");
-            paintingState.save();
+            saveGraphicsState();
             if (newTransform) {
                 concatMatrix(tranvals);
             }
@@ -640,8 +649,7 @@ public class PDFGraphics2D extends Abstr
                 applyUnknownPaint(paint, ss);
 
                 if (newClip || newTransform) {
-                    currentStream.write("Q\n");
-                    paintingState.restore();
+                    restoreGraphicsState();
                 }
                 return;
             }
@@ -652,8 +660,7 @@ public class PDFGraphics2D extends Abstr
         processPathIterator(iter);
         doDrawing(false, true, false);
         if (newClip || newTransform) {
-            currentStream.write("Q\n");
-            paintingState.restore();
+            restoreGraphicsState();
         }
     }
 
@@ -732,38 +739,31 @@ public class PDFGraphics2D extends Abstr
     protected void applyColor(Color col, boolean fill) {
         preparePainting();
 
-        Color c = col;
-        if (col instanceof ColorExt) {
-            PDFColor currentColour = new PDFColor(this.pdfDoc, col);
-            currentStream.write(currentColour.getColorSpaceOut(fill));
-        } else if (c.getColorSpace().getType()
-                == ColorSpace.TYPE_RGB) {
-            PDFColor currentColour = new PDFColor(c.getRed(), c.getGreen(),
-                                         c.getBlue());
-            currentStream.write(currentColour.getColorSpaceOut(fill));
-        } else if (c.getColorSpace().getType()
-                   == ColorSpace.TYPE_CMYK) {
-            if (pdfDoc.getProfile().getPDFAMode().isPDFA1LevelB()) {
-                //See PDF/A-1, ISO 19005:1:2005(E), 6.2.3.3
-                //FOP is currently restricted to DeviceRGB if PDF/A-1 is active.
-                throw new PDFConformanceException(
-                        "PDF/A-1 does not allow mixing DeviceRGB and DeviceCMYK.");
-            }
-            PDFColor currentColour = new PDFColor(c);
-            currentStream.write(currentColour.getColorSpaceOut(fill));
-        } else if (c.getColorSpace().getType()
-                   == ColorSpace.TYPE_2CLR) {
-            // used for black/magenta
-            float[] cComps = c.getColorComponents(new float[1]);
-            double[] blackMagenta = new double[1];
-            for (int i = 0; i < 1; i++) {
-                blackMagenta[i] = cComps[i];
+        //TODO Handle this in PDFColorHandler by automatically converting the color.
+        //This won't work properly anyway after the redesign of ColorExt
+        if (col.getColorSpace().getType() == ColorSpace.TYPE_CMYK) {
+             if (pdfDoc.getProfile().getPDFAMode().isPDFA1LevelB()) {
+                 //See PDF/A-1, ISO 19005:1:2005(E), 6.2.3.3
+                 //FOP is currently restricted to DeviceRGB if PDF/A-1 is active.
+                 throw new PDFConformanceException(
+                         "PDF/A-1 does not allow mixing DeviceRGB and DeviceCMYK.");
+             }
+        }
+
+        boolean doWrite = false;
+        if (fill) {
+            if (paintingState.setBackColor(col)) {
+                doWrite = true;
             }
-            //PDFColor  currentColour = new PDFColor(blackMagenta[0], blackMagenta[1]);
-            //currentStream.write(currentColour.getColorSpaceOut(fill));
         } else {
-            throw new UnsupportedOperationException(
-                    "Color Space not supported by PDFGraphics2D: " + c.getColorSpace());
+            if (paintingState.setColor(col)) {
+                doWrite = true;
+            }
+        }
+        if (doWrite) {
+            StringBuffer sb = new StringBuffer();
+            colorHandler.establishColor(sb, col, fill);
+            currentStream.write(sb.toString());
         }
     }
 
@@ -819,7 +819,7 @@ public class PDFGraphics2D extends Abstr
             transform.concatenate(getTransform());
             transform.concatenate(gp.getTransform());
 
-            List theMatrix = new java.util.ArrayList();
+            List<Double> theMatrix = new java.util.ArrayList<Double>();
             double [] mat = new double[6];
             transform.getMatrix(mat);
             for (int idx = 0; idx < mat.length; idx++) {
@@ -828,29 +828,29 @@ public class PDFGraphics2D extends Abstr
 
             Point2D p1 = gp.getStartPoint();
             Point2D p2 = gp.getEndPoint();
-            List theCoords = new java.util.ArrayList();
+            List<Double> theCoords = new java.util.ArrayList<Double>();
             theCoords.add(new Double(p1.getX()));
             theCoords.add(new Double(p1.getY()));
             theCoords.add(new Double(p2.getX()));
             theCoords.add(new Double(p2.getY()));
 
-            List theExtend = new java.util.ArrayList();
-            theExtend.add(new Boolean(true));
-            theExtend.add(new Boolean(true));
+            List<Boolean> theExtend = new java.util.ArrayList<Boolean>();
+            theExtend.add(Boolean.TRUE);
+            theExtend.add(Boolean.TRUE);
 
-            List theDomain = new java.util.ArrayList();
+            List<Double> theDomain = new java.util.ArrayList<Double>();
             theDomain.add(new Double(0));
             theDomain.add(new Double(1));
 
-            List theEncode = new java.util.ArrayList();
+            List<Double> theEncode = new java.util.ArrayList<Double>();
             theEncode.add(new Double(0));
             theEncode.add(new Double(1));
             theEncode.add(new Double(0));
             theEncode.add(new Double(1));
 
-            List theBounds = new java.util.ArrayList();
+            List<Double> theBounds = new java.util.ArrayList<Double>();
 
-            List someColors = new java.util.ArrayList();
+            List<Color> someColors = new java.util.ArrayList<Color>();
 
             for (int count = 0; count < cols.length; count++) {
                 Color c1 = cols[count];
@@ -858,14 +858,15 @@ public class PDFGraphics2D extends Abstr
                     return false;  // PDF can't do alpha
                 }
 
-                PDFColor color1 = new PDFColor(c1.getRed(), c1.getGreen(),
-                                               c1.getBlue());
-                someColors.add(color1);
+                //PDFColor color1 = new PDFColor(c1.getRed(), c1.getGreen(),
+                //                               c1.getBlue());
+                someColors.add(c1);
                 if (count > 0 && count < cols.length - 1) {
                     theBounds.add(new Double(fractions[count]));
                 }
             }
 
+            //Gradients are currently restricted to sRGB
             PDFDeviceColorSpace aColorSpace;
             aColorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
             PDFPattern myPat = pdfDoc.getFactory().makeGradient(
@@ -895,7 +896,7 @@ public class PDFGraphics2D extends Abstr
             transform.concatenate(getTransform());
             transform.concatenate(rgp.getTransform());
 
-            List theMatrix = new java.util.ArrayList();
+            List<Double> theMatrix = new java.util.ArrayList<Double>();
             double [] mat = new double[6];
             transform.getMatrix(mat);
             for (int idx = 0; idx < mat.length; idx++) {
@@ -906,7 +907,7 @@ public class PDFGraphics2D extends Abstr
             Point2D ac = rgp.getCenterPoint();
             Point2D af = rgp.getFocusPoint();
 
-            List theCoords = new java.util.ArrayList();
+            List<Double> theCoords = new java.util.ArrayList<Double>();
             double dx = af.getX() - ac.getX();
             double dy = af.getY() - ac.getY();
             double d = Math.sqrt(dx * dx + dy * dy);
@@ -926,19 +927,18 @@ public class PDFGraphics2D extends Abstr
             theCoords.add(new Double(ar));
 
             Color[] cols = rgp.getColors();
-            List someColors = new java.util.ArrayList();
+            List<Color> someColors = new java.util.ArrayList<Color>();
             for (int count = 0; count < cols.length; count++) {
                 Color cc = cols[count];
                 if (cc.getAlpha() != 255) {
                     return false;  // PDF can't do alpha
                 }
 
-                someColors.add(new PDFColor(cc.getRed(), cc.getGreen(),
-                                            cc.getBlue()));
+                someColors.add(cc);
             }
 
             float[] fractions = rgp.getFractions();
-            List theBounds = new java.util.ArrayList();
+            List<Double> theBounds = new java.util.ArrayList<Double>();
             for (int count = 1; count < fractions.length - 1; count++) {
                 float offset = fractions[count];
                 theBounds.add(new Double(offset));
@@ -965,7 +965,8 @@ public class PDFGraphics2D extends Abstr
         preparePainting();
 
         FontInfo specialFontInfo = new FontInfo();
-        FontSetup.setup(specialFontInfo);
+        boolean base14Kerning = false;
+        FontSetup.setup(specialFontInfo, base14Kerning);
 
         PDFResources res = pdfDoc.getFactory().makeResources();
         PDFResourceContext context = new PDFResourceContext(res);
@@ -978,7 +979,7 @@ public class PDFGraphics2D extends Abstr
         pattGraphic.setOutputStream(outputStream);
 
         GraphicsNode gn = pp.getGraphicsNode();
-        Rectangle2D gnBBox = gn.getBounds();
+        //Rectangle2D gnBBox = gn.getBounds();
         Rectangle2D rect = pp.getPatternRect();
 
         // if (!pp.getOverflow()) {
@@ -1014,7 +1015,7 @@ public class PDFGraphics2D extends Abstr
         //     }
         // }
 
-        List bbox = new java.util.ArrayList();
+        List<Double> bbox = new java.util.ArrayList<Double>();
         bbox.add(new Double(rect.getX()));
         bbox.add(new Double(rect.getHeight() + rect.getY()));
         bbox.add(new Double(rect.getWidth() + rect.getX()));
@@ -1025,7 +1026,7 @@ public class PDFGraphics2D extends Abstr
         transform.concatenate(getTransform());
         transform.concatenate(pp.getPatternTransform());
 
-        List theMatrix = new java.util.ArrayList();
+        List<Double> theMatrix = new java.util.ArrayList<Double>();
         double [] mat = new double[6];
         transform.getMatrix(mat);
         for (int idx = 0; idx < mat.length; idx++) {
@@ -1063,7 +1064,8 @@ public class PDFGraphics2D extends Abstr
         preparePainting();
 
         Shape clip = getClip();
-        Rectangle2D usrClipBounds, usrBounds;
+        Rectangle2D usrClipBounds;
+        Rectangle2D usrBounds;
         usrBounds = shape.getBounds2D();
         if (clip != null) {
             usrClipBounds  = clip.getBounds2D();
@@ -1077,7 +1079,9 @@ public class PDFGraphics2D extends Abstr
         double usrW = usrBounds.getWidth();
         double usrH = usrBounds.getHeight();
 
-        Rectangle devShapeBounds, devClipBounds, devBounds;
+        Rectangle devShapeBounds;
+        Rectangle devClipBounds;
+        Rectangle devBounds;
         AffineTransform at = getTransform();
         devShapeBounds = at.createTransformedShape(shape).getBounds();
         if (clip != null) {
@@ -1116,7 +1120,10 @@ public class PDFGraphics2D extends Abstr
             final byte[] rgb  = new byte[devW * devH * 3];
             final int[]  line = new int[devW];
             final byte[] mask;
-            int x, y, val, rgbIdx = 0;
+            int x;
+            int y;
+            int val;
+            int rgbIdx = 0;
 
             if (pcm.hasAlpha()) {
                 mask = new byte[devW * devH];
@@ -1233,6 +1240,7 @@ public class PDFGraphics2D extends Abstr
     }
 
     /** {@inheritDoc} */
+    @Override
     public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
         String key = "TempImage:" + img.toString();
         drawInnerRenderedImage(key, img, xform);
@@ -1282,6 +1290,7 @@ public class PDFGraphics2D extends Abstr
     }
 
     /** {@inheritDoc} */
+    @Override
     public void drawRenderableImage(RenderableImage img,
                                     AffineTransform xform) {
         //TODO Check if this is good enough
@@ -1312,6 +1321,7 @@ public class PDFGraphics2D extends Abstr
      * @see #setComposite
      * @see #setClip
      */
+    @Override
     public void drawString(String s, float x, float y) {
         preparePainting();
 
@@ -1328,14 +1338,14 @@ public class PDFGraphics2D extends Abstr
         }
         updateCurrentFont(fontState);
 
-        currentStream.write("q\n");
+        saveGraphicsState();
 
         Color c = getColor();
         applyColor(c, true);
         applyPaint(getPaint(), true);
         applyAlpha(c.getAlpha(), OPAQUE);
 
-        Map kerning = fontState.getKerning();
+        Map<Integer, Map<Integer, Integer>> kerning = fontState.getKerning();
         boolean kerningAvailable = (kerning != null && !kerning.isEmpty());
 
         boolean useMultiByte = isMultiByteFont(currentFontName);
@@ -1393,8 +1403,8 @@ public class PDFGraphics2D extends Abstr
             }
 
             if (kerningAvailable && (i + 1) < l) {
-                addKerning(currentStream, (new Integer(ch)),
-                           (new Integer(fontState.mapChar(s.charAt(i + 1)))),
+                addKerning(currentStream, (Integer.valueOf(ch)),
+                           (Integer.valueOf(fontState.mapChar(s.charAt(i + 1)))),
                            kerning, startText, endText);
             }
 
@@ -1403,7 +1413,7 @@ public class PDFGraphics2D extends Abstr
 
         currentStream.write("] TJ\n");
         currentStream.write("ET\n");
-        currentStream.write("Q\n");
+        restoreGraphicsState();
     }
 
     /**
@@ -1414,7 +1424,7 @@ public class PDFGraphics2D extends Abstr
     protected void applyAlpha(int fillAlpha, int strokeAlpha) {
         if (fillAlpha != OPAQUE || strokeAlpha != OPAQUE) {
             checkTransparencyAllowed();
-            Map vals = new java.util.HashMap();
+            Map<String, Float> vals = new java.util.HashMap<String, Float>();
             if (fillAlpha != OPAQUE) {
                 vals.put(PDFGState.GSTATE_ALPHA_NONSTROKE, new Float(fillAlpha / 255f));
             }
@@ -1451,6 +1461,7 @@ public class PDFGraphics2D extends Abstr
      * @return the internal Font
      * @deprecated use FontInfo.getFontInstanceForAWTFont(java.awt.Font awtFont) instead
      */
+    @Deprecated
     protected Font getInternalFontForAWTFont(java.awt.Font awtFont) {
         return fontInfo.getFontInstanceForAWTFont(awtFont);
     }
@@ -1463,18 +1474,18 @@ public class PDFGraphics2D extends Abstr
     protected boolean isMultiByteFont(String name) {
         // This assumes that *all* CIDFonts use a /ToUnicode mapping
         org.apache.fop.fonts.Typeface f
-            = (org.apache.fop.fonts.Typeface)fontInfo.getFonts().get(name);
+            = fontInfo.getFonts().get(name);
         return f.isMultiByte();
     }
 
     private void addKerning(StringWriter buf, Integer ch1, Integer ch2,
-                            Map kerning, String startText,
+                            Map<Integer, Map<Integer, Integer>> kerning, String startText,
                             String endText) {
         preparePainting();
-        Map kernPair = (Map)kerning.get(ch1);
+        Map<Integer, Integer> kernPair = kerning.get(ch1);
 
         if (kernPair != null) {
-            Integer width = (Integer)kernPair.get(ch2);
+            Integer width = kernPair.get(ch2);
             if (width != null) {
                 currentStream.write(endText + (-width.intValue()) + " " + startText);
             }
@@ -1586,6 +1597,7 @@ public class PDFGraphics2D extends Abstr
      * @see #clip
      * @see #setClip
      */
+    @Override
     public void fill(Shape s) {
         preparePainting();
 
@@ -1609,8 +1621,7 @@ public class PDFGraphics2D extends Abstr
                                && !trans.isIdentity();
 
         if (newClip || newTransform) {
-            currentStream.write("q\n");
-            paintingState.save();
+            saveGraphicsState();
             if (newTransform) {
                 concatMatrix(tranvals);
             }
@@ -1633,24 +1644,40 @@ public class PDFGraphics2D extends Abstr
                 applyUnknownPaint(paint, s);
 
                 if (newClip || newTransform) {
-                    currentStream.write("Q\n");
-                    paintingState.restore();
+                    restoreGraphicsState();
                 }
                 return;
             }
         }
 
-        //PathIterator iter = s.getPathIterator(getTransform());
-        PathIterator iter = s.getPathIterator(IDENTITY_TRANSFORM);
-        processPathIterator(iter);
-        doDrawing(true, false,
-                  iter.getWindingRule() == PathIterator.WIND_EVEN_ODD);
+        if (s instanceof Rectangle2D) {
+            Rectangle2D rect = (Rectangle2D)s;
+            currentStream.write(PDFNumber.doubleOut(rect.getMinX(), DEC) + " "
+                    + PDFNumber.doubleOut(rect.getMinY(), DEC) + " ");
+            currentStream.write(PDFNumber.doubleOut(rect.getWidth(), DEC) + " "
+                    + PDFNumber.doubleOut(rect.getHeight(), DEC) + " re ");
+            doDrawing(true, false, false);
+        } else {
+            PathIterator iter = s.getPathIterator(IDENTITY_TRANSFORM);
+            processPathIterator(iter);
+            doDrawing(true, false,
+                    iter.getWindingRule() == PathIterator.WIND_EVEN_ODD);
+        }
         if (newClip || newTransform) {
-            currentStream.write("Q\n");
-            paintingState.restore();
+            restoreGraphicsState();
         }
     }
 
+    void saveGraphicsState() {
+        currentStream.write("q\n");
+        paintingState.save();
+    }
+
+    void restoreGraphicsState() {
+        currentStream.write("Q\n");
+        paintingState.restore();
+    }
+
     /** Checks whether the use of transparency is allowed. */
     protected void checkTransparencyAllowed() {
         pdfDoc.getProfile().verifyTransparencyAllowed("Java2D graphics");
@@ -1734,6 +1761,7 @@ public class PDFGraphics2D extends Abstr
      *
      * @return the PDF graphics configuration
      */
+    @Override
     public GraphicsConfiguration getDeviceConfiguration() {
         return new PDFGraphicsConfiguration();
     }
@@ -1758,6 +1786,7 @@ public class PDFGraphics2D extends Abstr
      * @see       java.awt.FontMetrics
      * @see       java.awt.Graphics#getFontMetrics()
      */
+    @Override
     public java.awt.FontMetrics getFontMetrics(java.awt.Font f) {
         return fmg.getFontMetrics(f);
     }
@@ -1777,6 +1806,7 @@ public class PDFGraphics2D extends Abstr
      * drawn twice, then all pixels are restored to their original values.
      * @param     c1 the XOR alternation color
      */
+    @Override
     public void setXORMode(Color c1) {
         //NYI
     }
@@ -1801,6 +1831,7 @@ public class PDFGraphics2D extends Abstr
      * @param       dx the horizontal distance to copy the pixels.
      * @param       dy the vertical distance to copy the pixels.
      */
+    @Override
     public void copyArea(int x, int y, int width, int height, int dx,
                          int dy) {
         //NYI

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFGraphicsDevice.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFGraphicsDevice.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFGraphicsDevice.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/svg/PDFGraphicsDevice.java Thu Apr  5 16:19:19 2012
@@ -19,9 +19,9 @@
 
 package org.apache.fop.svg;
 
-import java.awt.GraphicsDevice;
-import java.awt.GraphicsConfiguration;
 import java.awt.GraphicsConfigTemplate;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
 
 /**
  * This implements the GraphicsDevice interface as appropriate for



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