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 [32/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/intermediate/IFSerializer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/IFSerializer.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/IFSerializer.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/IFSerializer.java Thu Apr  5 16:19:19 2012
@@ -31,18 +31,18 @@ import java.util.Locale;
 import java.util.Map;
 
 import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
 
 import org.apache.xmlgraphics.util.QName;
 import org.apache.xmlgraphics.util.XMLizable;
 
-import org.apache.fop.accessibility.StructureTree;
+import org.apache.fop.accessibility.StructureTreeEventHandler;
+import org.apache.fop.fo.extensions.InternalElementMapping;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.render.PrintRendererConfigurator;
 import org.apache.fop.render.RenderingContext;
+import org.apache.fop.render.intermediate.IFStructureTreeBuilder.IFStructureTreeElement;
 import org.apache.fop.render.intermediate.extensions.AbstractAction;
 import org.apache.fop.render.intermediate.extensions.Bookmark;
 import org.apache.fop.render.intermediate.extensions.BookmarkTree;
@@ -53,9 +53,11 @@ import org.apache.fop.traits.BorderProps
 import org.apache.fop.traits.RuleStyle;
 import org.apache.fop.util.ColorUtil;
 import org.apache.fop.util.DOM2SAX;
+import org.apache.fop.util.LanguageTags;
 import org.apache.fop.util.XMLConstants;
 import org.apache.fop.util.XMLUtil;
 
+
 /**
  * IFPainter implementation that serializes the intermediate format to XML.
  */
@@ -68,13 +70,12 @@ public class IFSerializer extends Abstra
     /** Holds the intermediate format state */
     private IFState state;
 
-    /**
-     * Default constructor.
-     */
-    public IFSerializer() {
-    }
+    private String currentID = "";
+
+    private IFStructureTreeBuilder structureTreeBuilder;
 
     /** {@inheritDoc} */
+    @Override
     protected String getMainNamespace() {
         return NAMESPACE;
     }
@@ -101,6 +102,7 @@ public class IFSerializer extends Abstra
     }
 
     /** {@inheritDoc} */
+    @Override
     public IFDocumentNavigationHandler getDocumentNavigationHandler() {
         return this;
     }
@@ -145,7 +147,16 @@ public class IFSerializer extends Abstra
         }
     }
 
+    @Override
+    public StructureTreeEventHandler getStructureTreeEventHandler() {
+        if (structureTreeBuilder == null) {
+            structureTreeBuilder = new IFStructureTreeBuilder();
+        }
+        return structureTreeBuilder;
+    }
+
     /** {@inheritDoc} */
+    @Override
     public void startDocument() throws IFException {
         super.startDocument();
         try {
@@ -154,13 +165,29 @@ public class IFSerializer extends Abstra
             handler.startPrefixMapping(XLINK_PREFIX, XLINK_NAMESPACE);
             handler.startPrefixMapping(DocumentNavigationExtensionConstants.PREFIX,
                     DocumentNavigationExtensionConstants.NAMESPACE);
+            handler.startPrefixMapping(InternalElementMapping.STANDARD_PREFIX,
+                    InternalElementMapping.URI);
             handler.startElement(EL_DOCUMENT);
         } catch (SAXException e) {
             throw new IFException("SAX error in startDocument()", e);
         }
     }
 
+    @Override
+    public void setDocumentLocale(Locale locale) {
+        AttributesImpl atts  = new AttributesImpl();
+        atts.addAttribute(XML_NAMESPACE, "lang", "xml:lang", XMLUtil.CDATA,
+                LanguageTags.toLanguageTag(locale));
+        try {
+            handler.startElement(EL_LOCALE, atts);
+            handler.endElement(EL_LOCALE);
+        } catch (SAXException e) {
+            throw new RuntimeException("Unable to create the " + EL_LOCALE + " element.", e);
+        }
+    }
+
     /** {@inheritDoc} */
+    @Override
     public void startDocumentHeader() throws IFException {
         try {
             handler.startElement(EL_HEADER);
@@ -170,6 +197,7 @@ public class IFSerializer extends Abstra
     }
 
     /** {@inheritDoc} */
+    @Override
     public void endDocumentHeader() throws IFException {
         try {
             handler.endElement(EL_HEADER);
@@ -179,6 +207,7 @@ public class IFSerializer extends Abstra
     }
 
     /** {@inheritDoc} */
+    @Override
     public void startDocumentTrailer() throws IFException {
         try {
             handler.startElement(EL_TRAILER);
@@ -188,6 +217,7 @@ public class IFSerializer extends Abstra
     }
 
     /** {@inheritDoc} */
+    @Override
     public void endDocumentTrailer() throws IFException {
         try {
             handler.endElement(EL_TRAILER);
@@ -217,20 +247,14 @@ public class IFSerializer extends Abstra
             Locale lang = getContext().getLanguage();
             if (lang != null) {
                 atts.addAttribute(XML_NAMESPACE, "lang", "xml:lang", XMLUtil.CDATA,
-                        XMLUtil.toRFC3066(lang));
+                        LanguageTags.toLanguageTag(lang));
             }
             XMLUtil.addAttribute(atts, XMLConstants.XML_SPACE, "preserve");
             addForeignAttributes(atts);
             handler.startElement(EL_PAGE_SEQUENCE, atts);
             if (this.getUserAgent().isAccessibilityEnabled()) {
-                StructureTree structureTree = getUserAgent().getStructureTree();
-                handler.startElement(EL_STRUCTURE_TREE); // add structure tree
-                NodeList nodes = structureTree.getPageSequence(pageSequenceIndex++);
-                for (int i = 0, n = nodes.getLength(); i < n; i++) {
-                    Node node = nodes.item(i);
-                    new DOM2SAX(handler).writeFragment(node);
-                }
-                handler.endElement(EL_STRUCTURE_TREE);
+                assert (structureTreeBuilder != null);
+                structureTreeBuilder.replayEventsForPageSequence(handler, pageSequenceIndex++);
             }
         } catch (SAXException e) {
             throw new IFException("SAX error in startPageSequence()", e);
@@ -240,6 +264,7 @@ public class IFSerializer extends Abstra
     /** {@inheritDoc} */
     public void endPageSequence() throws IFException {
         try {
+
             handler.endElement(EL_PAGE_SEQUENCE);
         } catch (SAXException e) {
             throw new IFException("SAX error in endPageSequence()", e);
@@ -264,6 +289,7 @@ public class IFSerializer extends Abstra
     }
 
     /** {@inheritDoc} */
+    @Override
     public void startPageHeader() throws IFException {
         try {
             handler.startElement(EL_PAGE_HEADER);
@@ -273,6 +299,7 @@ public class IFSerializer extends Abstra
     }
 
     /** {@inheritDoc} */
+    @Override
     public void endPageHeader() throws IFException {
         try {
             handler.endElement(EL_PAGE_HEADER);
@@ -296,6 +323,7 @@ public class IFSerializer extends Abstra
     public void endPageContent() throws IFException {
         try {
             this.state = null;
+            currentID = "";
             handler.endElement(EL_PAGE_CONTENT);
         } catch (SAXException e) {
             throw new IFException("SAX error in endPageContent()", e);
@@ -303,6 +331,7 @@ public class IFSerializer extends Abstra
     }
 
     /** {@inheritDoc} */
+    @Override
     public void startPageTrailer() throws IFException {
         try {
             handler.startElement(EL_PAGE_TRAILER);
@@ -312,6 +341,7 @@ public class IFSerializer extends Abstra
     }
 
     /** {@inheritDoc} */
+    @Override
     public void endPageTrailer() throws IFException {
         try {
             commitNavigation();
@@ -405,6 +435,7 @@ public class IFSerializer extends Abstra
     /** {@inheritDoc} */
     public void drawImage(String uri, Rectangle rect) throws IFException {
         try {
+            addID();
             AttributesImpl atts = new AttributesImpl();
             addAttribute(atts, XLINK_HREF, uri);
             addAttribute(atts, "x", Integer.toString(rect.x));
@@ -412,7 +443,7 @@ public class IFSerializer extends Abstra
             addAttribute(atts, "width", Integer.toString(rect.width));
             addAttribute(atts, "height", Integer.toString(rect.height));
             addForeignAttributes(atts);
-            addStructurePointerAttribute(atts);
+            addStructureReference(atts);
             handler.element(EL_IMAGE, atts);
         } catch (SAXException e) {
             throw new IFException("SAX error in startGroup()", e);
@@ -433,13 +464,14 @@ public class IFSerializer extends Abstra
     /** {@inheritDoc} */
     public void drawImage(Document doc, Rectangle rect) throws IFException {
         try {
+            addID();
             AttributesImpl atts = new AttributesImpl();
             addAttribute(atts, "x", Integer.toString(rect.x));
             addAttribute(atts, "y", Integer.toString(rect.y));
             addAttribute(atts, "width", Integer.toString(rect.width));
             addAttribute(atts, "height", Integer.toString(rect.height));
             addForeignAttributes(atts);
-            addStructurePointerAttribute(atts);
+            addStructureReference(atts);
             handler.startElement(EL_IMAGE, atts);
             new DOM2SAX(handler).writeDocument(doc, true);
             handler.endElement(EL_IMAGE);
@@ -489,9 +521,9 @@ public class IFSerializer extends Abstra
     }
 
     /** {@inheritDoc} */
-    public void drawBorderRect(Rectangle rect, BorderProps before, BorderProps after,
-            BorderProps start, BorderProps end) throws IFException {
-        if (before == null && after == null && start == null && end == null) {
+    public void drawBorderRect(Rectangle rect, BorderProps top, BorderProps bottom,
+            BorderProps left, BorderProps right) throws IFException {
+        if (top == null && bottom == null && left == null && right == null) {
             return;
         }
         try {
@@ -500,17 +532,17 @@ public class IFSerializer extends Abstra
             addAttribute(atts, "y", Integer.toString(rect.y));
             addAttribute(atts, "width", Integer.toString(rect.width));
             addAttribute(atts, "height", Integer.toString(rect.height));
-            if (before != null) {
-                addAttribute(atts, "before", before.toString());
+            if (top != null) {
+                addAttribute(atts, "top", top.toString());
             }
-            if (after != null) {
-                addAttribute(atts, "after", after.toString());
+            if (bottom != null) {
+                addAttribute(atts, "bottom", bottom.toString());
             }
-            if (start != null) {
-                addAttribute(atts, "start", start.toString());
+            if (left != null) {
+                addAttribute(atts, "left", left.toString());
             }
-            if (end != null) {
-                addAttribute(atts, "end", end.toString());
+            if (right != null) {
+                addAttribute(atts, "right", right.toString());
             }
             handler.element(EL_BORDER_RECT, atts);
         } catch (SAXException e) {
@@ -522,6 +554,7 @@ public class IFSerializer extends Abstra
     public void drawLine(Point start, Point end, int width, Color color, RuleStyle style)
             throws IFException {
         try {
+            addID();
             AttributesImpl atts = new AttributesImpl();
             addAttribute(atts, "x1", Integer.toString(start.x));
             addAttribute(atts, "y1", Integer.toString(start.y));
@@ -538,8 +571,9 @@ public class IFSerializer extends Abstra
 
     /** {@inheritDoc} */
     public void drawText(int x, int y, int letterSpacing, int wordSpacing,
-            int[] dx, String text) throws IFException {
+            int[][] dp, String text) throws IFException {
         try {
+            addID();
             AttributesImpl atts = new AttributesImpl();
             addAttribute(atts, "x", Integer.toString(x));
             addAttribute(atts, "y", Integer.toString(y));
@@ -549,10 +583,19 @@ public class IFSerializer extends Abstra
             if (wordSpacing != 0) {
                 addAttribute(atts, "word-spacing", Integer.toString(wordSpacing));
             }
-            if (dx != null) {
-                addAttribute(atts, "dx", IFUtil.toString(dx));
+            if (dp != null) {
+                if ( IFUtil.isDPIdentity(dp) ) {
+                    // don't add dx or dp attribute
+                } else if ( IFUtil.isDPOnlyDX(dp) ) {
+                    // add dx attribute only
+                    int[] dx = IFUtil.convertDPToDX(dp);
+                    addAttribute(atts, "dx", IFUtil.toString(dx));
+                } else {
+                    // add dp attribute only
+                    addAttribute(atts, "dp", XMLUtil.encodePositionAdjustments(dp));
+                }
             }
-            addStructurePointerAttribute(atts);
+            addStructureReference(atts);
             handler.startElement(EL_TEXT, atts);
             char[] chars = text.toCharArray();
             handler.characters(chars, 0, chars.length);
@@ -604,7 +647,8 @@ public class IFSerializer extends Abstra
                 }
             }
             if (color != null) {
-                changed = !color.equals(state.getTextColor());
+                changed = !org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor(
+                        color, state.getTextColor());
                 if (changed) {
                     state.setTextColor(color);
                     addAttribute(atts, "color", toString(color));
@@ -651,14 +695,32 @@ public class IFSerializer extends Abstra
         XMLUtil.addAttribute(atts, localName, value);
     }
 
-    private void addStructurePointerAttribute(AttributesImpl atts) {
-        String ptr = getContext().getStructurePointer();
-        if (ptr != null) {
-            addAttribute(atts, "ptr", ptr);
+    private void addStructureReference(AttributesImpl atts) {
+        IFStructureTreeElement structureTreeElement
+                = (IFStructureTreeElement) getContext().getStructureTreeElement();
+        if (structureTreeElement != null) {
+            addStructRefAttribute(atts, structureTreeElement.getId());
         }
     }
 
-    // ---=== IFDocumentNavigationHandler ===---
+    private void addStructRefAttribute(AttributesImpl atts, String id) {
+        atts.addAttribute(InternalElementMapping.URI,
+                InternalElementMapping.STRUCT_REF,
+                InternalElementMapping.STANDARD_PREFIX + ":" + InternalElementMapping.STRUCT_REF,
+                XMLConstants.CDATA,
+                id);
+    }
+
+    private void addID() throws SAXException {
+        String id = getContext().getID();
+        if (!currentID.equals(id)) {
+            AttributesImpl atts = new AttributesImpl();
+            addAttribute(atts, "name", id);
+            handler.startElement(EL_ID, atts);
+            handler.endElement(EL_ID);
+            currentID = id;
+        }
+    }
 
     private Map incompleteActions = new java.util.HashMap();
     private List completeActions = new java.util.LinkedList();
@@ -696,7 +758,9 @@ public class IFSerializer extends Abstra
             Iterator iter = tree.getBookmarks().iterator();
             while (iter.hasNext()) {
                 Bookmark b = (Bookmark)iter.next();
-                serializeBookmark(b);
+                if (b.getAction() != null) {
+                    serializeBookmark(b);
+                }
             }
             handler.endElement(DocumentNavigationExtensionConstants.BOOKMARK_TREE);
         } catch (SAXException e) {
@@ -716,10 +780,11 @@ public class IFSerializer extends Abstra
         Iterator iter = bookmark.getChildBookmarks().iterator();
         while (iter.hasNext()) {
             Bookmark b = (Bookmark)iter.next();
-            serializeBookmark(b);
+            if (b.getAction() != null) {
+                serializeBookmark(b);
+            }
         }
         handler.endElement(DocumentNavigationExtensionConstants.BOOKMARK);
-
     }
 
     /** {@inheritDoc} */
@@ -730,7 +795,8 @@ public class IFSerializer extends Abstra
         atts.addAttribute(null, "rect", "rect",
                 XMLConstants.CDATA, IFUtil.toString(link.getTargetRect()));
         if (getUserAgent().isAccessibilityEnabled()) {
-            addAttribute(atts, "ptr", link.getAction().getStructurePointer());
+            addStructRefAttribute(atts,
+                    ((IFStructureTreeElement) link.getAction().getStructureTreeElement()).getId());
         }
         try {
             handler.startElement(DocumentNavigationExtensionConstants.LINK, atts);
@@ -774,5 +840,4 @@ public class IFSerializer extends Abstra
             throw new IFException("SAX error serializing object", e);
         }
     }
-
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/IFSerializerMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/IFSerializerMaker.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/IFSerializerMaker.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/IFSerializerMaker.java Thu Apr  5 16:19:19 2012
@@ -31,6 +31,9 @@ public class IFSerializerMaker extends A
     public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {
         IFSerializer handler = new IFSerializer();
         handler.setContext(new IFContext(ua));
+        if (ua.isAccessibilityEnabled()) {
+            ua.setStructureTreeEventHandler(handler.getStructureTreeEventHandler());
+        }
         return handler;
     }
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/IFState.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/IFState.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/IFState.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/IFState.java Thu Apr  5 16:19:19 2012
@@ -21,6 +21,8 @@ package org.apache.fop.render.intermedia
 
 import java.awt.Color;
 
+import org.apache.xmlgraphics.java2d.color.ColorUtil;
+
 /** a state class for intermediate format data */
 public final class IFState {
 
@@ -184,7 +186,7 @@ public final class IFState {
      * @param color the new text color
      */
     public void setTextColor(Color color) {
-        if (!color.equals(this.textColor)) {
+        if (!ColorUtil.isSameColor(color, this.textColor)) {
             this.fontChanged = true;
         }
         this.textColor = color;

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/IFUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/IFUtil.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/IFUtil.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/IFUtil.java Thu Apr  5 16:19:19 2012
@@ -23,7 +23,6 @@ import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
 
 import org.apache.fop.apps.FOPException;
-import org.apache.fop.apps.FopFactory;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.util.DecimalFormatCache;
 
@@ -199,4 +198,183 @@ public final class IFUtil {
         return documentHandler.getMimeType();
     }
 
+    /**
+     * Convert the general gpos 'dp' adjustments to the older 'dx' adjustments.
+     * This utility method is used to provide backward compatibility in implementations
+     * of IFPainter that have not yet been upgraded to the general position adjustments format.
+     * @param dp an array of 4-tuples, expressing [X,Y] placment
+     * adjustments and [X,Y] advancement adjustments, in that order (may be null)
+     * @param count if <code>dp</code> is not null, then a count of dp values to convert
+     * @return if <code>dp</code> is not null, then an array of adjustments to the current
+     * x position prior to rendering individual glyphs; otherwise, null
+     */
+    public static int[] convertDPToDX ( int[][] dp, int count ) {
+        int[] dx;
+        if ( dp != null ) {
+            dx = new int [ count ];
+            for ( int i = 0, n = count; i < n; i++ ) {
+                dx [ i ] = dp [ i ] [ 0 ];      // xPlaAdjust[i]
+            }
+        } else {
+            dx = null;
+        }
+        return dx;
+    }
+
+    /**
+     * Convert the general gpos 'dp' adjustments to the older 'dx' adjustments.
+     * This utility method is used to provide backward compatibility in implementations
+     * of IFPainter that have not yet been upgraded to the general position adjustments format.
+     * @param dp an array of 4-tuples, expressing [X,Y] placment
+     * adjustments and [X,Y] advancement adjustments, in that order (may be null)
+     * @return if <code>dp</code> is not null, then an array of adjustments to the current
+     * x position prior to rendering individual glyphs; otherwise, null
+     */
+    public static int[] convertDPToDX ( int[][] dp ) {
+        return convertDPToDX ( dp, ( dp != null ) ? dp.length : 0 );
+    }
+
+    /**
+     * Convert the general gpos 'dp' adjustments to the older 'dx' adjustments.
+     * This utility method is used to provide backward compatibility in implementations
+     * of IFPainter that have not yet been upgraded to the general position adjustments format.
+     * @param dx an array of adjustments to the current x position prior to rendering
+     * individual glyphs or null
+     * @param count if <code>dx</code> is not null, then a count of dx values to convert
+     * @return if <code>dx</code> is not null, then an array of 4-tuples, expressing [X,Y]
+     * placment adjustments and [X,Y] advancement adjustments, in that order; otherwise, null
+     */
+    public static int[][] convertDXToDP ( int[] dx, int count ) {
+        int[][] dp;
+        if ( dx != null ) {
+            dp = new int [ count ] [ 4 ];
+            for ( int i = 0, n = count; i < n; i++ ) {
+                int[] pa = dp [ i ];
+                int   d  = dx [ i ];
+                pa [ 0 ] = d;                   // xPlaAdjust[i]
+                pa [ 2 ] = d;                   // xAdvAdjust[i]
+            }
+        } else {
+            dp = null;
+        }
+        return dp;
+    }
+
+    /**
+     * Convert the general gpos 'dp' adjustments to the older 'dx' adjustments.
+     * This utility method is used to provide backward compatibility in implementations
+     * of IFPainter that have not yet been upgraded to the general position adjustments format.
+     * @param dx an array of adjustments to the current x position prior to rendering
+     * individual glyphs or null
+     * @return if <code>dx</code> is not null, then an array of 4-tuples, expressing [X,Y]
+     * placment adjustments and [X,Y] advancement adjustments, in that order; otherwise, null
+     */
+    public static int[][] convertDXToDP ( int[] dx ) {
+        return convertDXToDP ( dx, ( dx != null ) ? dx.length : 0 );
+    }
+
+    /**
+     * Determine if position adjustment is the identity adjustment, i.e., no non-zero adjustment.
+     * @param pa a 4-tuple, expressing [X,Y] placment and [X,Y] advance adjuustments (may be null)
+     * @return true if <code>dp</code> is null or contains no non-zero adjustment
+     */
+    public static boolean isPAIdentity ( int[] pa ) {
+        if ( pa == null ) {
+            return true;
+        } else {
+            for ( int k = 0; k < 4; k++ ) {
+                if ( pa[k] != 0 ) {
+                    return false;
+                }
+            }
+            return true;
+        }
+    }
+
+    /**
+     * Determine if position adjustments is the identity adjustment, i.e., no non-zero adjustment.
+     * @param dp an array of 4-tuples, expressing [X,Y] placment
+     * adjustments and [X,Y] advancement adjustments, in that order (may be null)
+     * @return true if <code>dp</code> is null or contains no non-zero adjustment
+     */
+    public static boolean isDPIdentity ( int[][] dp ) {
+        if ( dp == null ) {
+            return true;
+        } else {
+            for ( int i = 0, n = dp.length; i < n; i++ ) {
+                if ( !isPAIdentity ( dp[i] ) ) {
+                    return false;
+                }
+            }
+            return true;
+        }
+    }
+
+    /**
+     * Determine if position adjustments comprises only DX adjustments as encoded by
+     * {@link #convertDPToDX}. Note that if given a set of all all zero position
+     * adjustments, both this method and {@link #isDPIdentity} will return true;
+     * however, this method may return true when {@link #isDPIdentity} returns false.
+     * @param dp an array of 4-tuples, expressing [X,Y] placment
+     * adjustments and [X,Y] advancement adjustments, in that order (may be null)
+     * @return true if <code>dp</code> is not null and contains only xPlaAdjust
+     * and xAdvAdjust values consistent with the output of {@link #convertDPToDX}.
+     */
+    public static boolean isDPOnlyDX ( int[][] dp ) {
+        if ( dp == null ) {
+            return false;
+        } else {
+            for ( int i = 0, n = dp.length; i < n; i++ ) {
+                int[] pa = dp[i];
+                if ( pa[0] != pa[2] ) {
+                    return false;
+                }
+            }
+            return true;
+        }
+    }
+
+    /**
+     * Adjust a position adjustments array. If both <code>paDst</code> and <code>paSrc</code> are
+     * non-null, then <code>paSrc[i]</code> is added to <code>paDst[i]</code>.
+     * @param paDst a 4-tuple, expressing [X,Y] placment
+     * and [X,Y] advance adjuustments (may be null)
+     * @param paSrc a 4-tuple, expressing [X,Y] placment
+     * and [X,Y] advance adjuustments (may be null)
+     */
+    public static void adjustPA ( int[] paDst, int[] paSrc ) {
+        if ( ( paDst != null ) && ( paSrc != null ) ) {
+            assert paDst.length == 4;
+            assert paSrc.length == 4;
+            for ( int i = 0; i < 4; i++ ) {
+                paDst[i] += paSrc[i];
+            }
+        }
+    }
+
+    /**
+     * Copy entries from position adjustments.
+     * @param dp an array of 4-tuples, expressing [X,Y] placment
+     * adjustments and [X,Y] advancement adjustments, in that order
+     * @param offset starting offset from which to copy
+     * @param count number of entries to copy
+     * @return a deep copy of the count position adjustment entries start at
+     * offset
+     */
+    public static int[][] copyDP ( int[][] dp, int offset, int count ) {
+        if ( ( dp == null ) || ( offset > dp.length ) || ( ( offset + count ) > dp.length ) ) {
+            throw new IllegalArgumentException();
+        } else {
+            int[][] dpNew = new int [ count ] [ 4 ];
+            for ( int i = 0, n = count; i < n; i++ ) {
+                int[] paDst = dpNew [ i ];
+                int[] paSrc = dp [ i + offset ];
+                for ( int k = 0; k < 4; k++ ) {
+                    paDst [ k ] = paSrc [ k ];
+                }
+            }
+            return dpNew;
+        }
+    }
+
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java Thu Apr  5 16:19:19 2012
@@ -21,13 +21,15 @@ package org.apache.fop.render.intermedia
 
 import org.apache.xmlgraphics.util.XMLizable;
 
+import org.apache.fop.accessibility.StructureTreeElement;
+
 /**
  * Abstract base class for document actions, like "go-to" actions with absolute page coordinates.
  */
 public abstract class AbstractAction implements XMLizable {
 
     private String id;
-    private String structurePointer;
+    private StructureTreeElement structureTreeElement;
 
     /**
      * Sets an ID to make the action referencable.
@@ -47,18 +49,18 @@ public abstract class AbstractAction imp
 
     /**
      * Sets the structure element corresponding to this action.
-     * @param structurePointer a reference to the structure element
+     * @param structureTreeElement a reference to the structure element
      */
-    public void setStructurePointer(String structurePointer) {
-        this.structurePointer = structurePointer;
+    public void setStructureTreeElement(StructureTreeElement structureTreeElement) {
+        this.structureTreeElement = structureTreeElement;
     }
 
     /**
      * Returns the structure element corresponding to this action.
      * @return the reference to the structure element
      */
-    public String getStructurePointer() {
-        return structurePointer;
+    public StructureTreeElement getStructureTreeElement() {
+        return structureTreeElement;
     }
 
     /**

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java Thu Apr  5 16:19:19 2012
@@ -21,6 +21,7 @@ package org.apache.fop.render.intermedia
 
 import java.awt.Point;
 import java.awt.Rectangle;
+import java.util.Map;
 import java.util.Stack;
 
 import org.xml.sax.Attributes;
@@ -30,6 +31,8 @@ import org.xml.sax.helpers.DefaultHandle
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.fop.accessibility.StructureTreeElement;
+import org.apache.fop.fo.extensions.InternalElementMapping;
 import org.apache.fop.render.intermediate.IFDocumentNavigationHandler;
 import org.apache.fop.render.intermediate.IFException;
 import org.apache.fop.util.XMLUtil;
@@ -48,14 +51,20 @@ public class DocumentNavigationHandler e
 
     private IFDocumentNavigationHandler navHandler;
 
-    private String structurePointer;
+    private StructureTreeElement structureTreeElement;
+
+    private Map<String, StructureTreeElement> structureTreeElements;
 
     /**
      * Main constructor.
      * @param navHandler the navigation handler that will receive the events
+     * @param structureTreeElements the elements representing the structure of the document
      */
-    public DocumentNavigationHandler(IFDocumentNavigationHandler navHandler) {
+    public DocumentNavigationHandler(IFDocumentNavigationHandler navHandler,
+            Map<String, StructureTreeElement> structureTreeElements) {
         this.navHandler = navHandler;
+        assert structureTreeElements != null;
+        this.structureTreeElements = structureTreeElements;
     }
 
     /** {@inheritDoc} */
@@ -98,7 +107,8 @@ public class DocumentNavigationHandler e
                     throw new SAXException(localName + " must be the root element!");
                 }
                 Rectangle targetRect = XMLUtil.getAttributeAsRectangle(attributes, "rect");
-                structurePointer = attributes.getValue("ptr");
+                structureTreeElement = structureTreeElements.get(attributes.getValue(
+                        InternalElementMapping.URI, InternalElementMapping.STRUCT_REF));
                 Link link = new Link(null, targetRect);
                 objectStack.push(link);
             } else if (GOTO_XY.getLocalName().equals(localName)) {
@@ -121,8 +131,8 @@ public class DocumentNavigationHandler e
                     }
                     action = new GoToXYAction(id, pageIndex, location);
                 }
-                if (structurePointer != null) {
-                    action.setStructurePointer(structurePointer);
+                if (structureTreeElement != null) {
+                    action.setStructureTreeElement(structureTreeElement);
                 }
                 objectStack.push(action);
             } else if (GOTO_URI.getLocalName().equals(localName)) {
@@ -134,8 +144,8 @@ public class DocumentNavigationHandler e
                 if (id != null) {
                     action.setID(id);
                 }
-                if (structurePointer != null) {
-                    action.setStructurePointer(structurePointer);
+                if (structureTreeElement != null) {
+                    action.setStructureTreeElement(structureTreeElement);
                 }
                 objectStack.push(action);
             } else {

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/util/IFDocumentHandlerProxy.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/util/IFDocumentHandlerProxy.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/util/IFDocumentHandlerProxy.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/intermediate/util/IFDocumentHandlerProxy.java Thu Apr  5 16:19:19 2012
@@ -20,9 +20,11 @@
 package org.apache.fop.render.intermediate.util;
 
 import java.awt.Dimension;
+import java.util.Locale;
 
 import javax.xml.transform.Result;
 
+import org.apache.fop.accessibility.StructureTreeEventHandler;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.render.intermediate.IFContext;
 import org.apache.fop.render.intermediate.IFDocumentHandler;
@@ -94,6 +96,11 @@ public class IFDocumentHandlerProxy impl
     }
 
     /** {@inheritDoc} */
+    public StructureTreeEventHandler getStructureTreeEventHandler() {
+        return this.delegate.getStructureTreeEventHandler();
+    }
+
+    /** {@inheritDoc} */
     public void setResult(Result result) throws IFException {
         this.delegate.setResult(result);
     }
@@ -104,6 +111,12 @@ public class IFDocumentHandlerProxy impl
     }
 
     /** {@inheritDoc} */
+    public void setDocumentLocale(Locale locale) {
+         this.delegate.setDocumentLocale(locale);
+
+    }
+
+    /** {@inheritDoc} */
     public void startDocumentHeader() throws IFException {
         this.delegate.startDocumentHeader();
     }
@@ -184,4 +197,4 @@ public class IFDocumentHandlerProxy impl
         this.delegate.handleExtensionObject(extension);
     }
 
-}
\ No newline at end of file
+}

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Base14FontCollection.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Base14FontCollection.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Base14FontCollection.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Base14FontCollection.java Thu Apr  5 16:19:19 2012
@@ -19,8 +19,6 @@
 
 package org.apache.fop.render.java2d;
 
-import java.awt.Graphics2D;
-
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontCollection;
 import org.apache.fop.fonts.FontInfo;
@@ -30,14 +28,15 @@ import org.apache.fop.fonts.FontInfo;
  */
 public class Base14FontCollection implements FontCollection {
 
-    private Graphics2D graphics2d = null;
+    /** required when creating new instances of SystemFontMetricsMapper */
+    private final Java2DFontMetrics java2DFontMetrics;
 
     /**
      * Main constructor
-     * @param graphics2d a graphics 2D
+     * @param java2DFontMetrics required when creating new instances of SystemFontMetricsMapper
      */
-    public Base14FontCollection(Graphics2D graphics2d) {
-        this.graphics2d = graphics2d;
+    public Base14FontCollection(Java2DFontMetrics java2DFontMetrics) {
+        this.java2DFontMetrics = java2DFontMetrics;
     }
 
     /**
@@ -56,47 +55,47 @@ public class Base14FontCollection implem
         final int bolditalic = java.awt.Font.BOLD + java.awt.Font.ITALIC;
 
         FontMetricsMapper metric;
-        metric = new SystemFontMetricsMapper("SansSerif", normal, graphics2d);
+        metric = new SystemFontMetricsMapper("SansSerif", normal, java2DFontMetrics);
         // --> goes to  F1
         fontInfo.addMetrics("F1", metric);
-        metric = new SystemFontMetricsMapper("SansSerif", italic, graphics2d);
+        metric = new SystemFontMetricsMapper("SansSerif", italic, java2DFontMetrics);
         // --> goes to  F2
         fontInfo.addMetrics("F2", metric);
-        metric = new SystemFontMetricsMapper("SansSerif", bold, graphics2d);
+        metric = new SystemFontMetricsMapper("SansSerif", bold, java2DFontMetrics);
         // --> goes to  F3
         fontInfo.addMetrics("F3", metric);
-        metric = new SystemFontMetricsMapper("SansSerif", bolditalic, graphics2d);
+        metric = new SystemFontMetricsMapper("SansSerif", bolditalic, java2DFontMetrics);
         // --> goes to  F4
         fontInfo.addMetrics("F4", metric);
 
 
-        metric = new SystemFontMetricsMapper("Serif", normal, graphics2d);
+        metric = new SystemFontMetricsMapper("Serif", normal, java2DFontMetrics);
         // --> goes to  F5
         fontInfo.addMetrics("F5", metric);
-        metric = new SystemFontMetricsMapper("Serif", italic, graphics2d);
+        metric = new SystemFontMetricsMapper("Serif", italic, java2DFontMetrics);
         // --> goes to  F6
         fontInfo.addMetrics("F6", metric);
-        metric = new SystemFontMetricsMapper("Serif", bold, graphics2d);
+        metric = new SystemFontMetricsMapper("Serif", bold, java2DFontMetrics);
         // --> goes to  F7
         fontInfo.addMetrics("F7", metric);
-        metric = new SystemFontMetricsMapper("Serif", bolditalic, graphics2d);
+        metric = new SystemFontMetricsMapper("Serif", bolditalic, java2DFontMetrics);
         // --> goes to  F8
         fontInfo.addMetrics("F8", metric);
 
-        metric = new SystemFontMetricsMapper("MonoSpaced", normal, graphics2d);
+        metric = new SystemFontMetricsMapper("MonoSpaced", normal, java2DFontMetrics);
         // --> goes to  F9
         fontInfo.addMetrics("F9", metric);
-        metric = new SystemFontMetricsMapper("MonoSpaced", italic, graphics2d);
+        metric = new SystemFontMetricsMapper("MonoSpaced", italic, java2DFontMetrics);
         // --> goes to  F10
         fontInfo.addMetrics("F10", metric);
-        metric = new SystemFontMetricsMapper("MonoSpaced", bold, graphics2d);
+        metric = new SystemFontMetricsMapper("MonoSpaced", bold, java2DFontMetrics);
         // --> goes to  F11
         fontInfo.addMetrics("F11", metric);
-        metric = new SystemFontMetricsMapper("MonoSpaced", bolditalic, graphics2d);
+        metric = new SystemFontMetricsMapper("MonoSpaced", bolditalic, java2DFontMetrics);
         // --> goes to  F12
         fontInfo.addMetrics("F12", metric);
 
-        metric = new SystemFontMetricsMapper("Serif", normal, graphics2d);
+        metric = new SystemFontMetricsMapper("Serif", normal, java2DFontMetrics);
         //"Symbol" doesn't seem to work here, but "Serif" does the job just fine. *shrug*
         // --> goes to  F13 and F14
         fontInfo.addMetrics("F13", metric);

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java Thu Apr  5 16:19:19 2012
@@ -50,13 +50,14 @@ public class ConfiguredFontCollection im
      * Main constructor
      * @param fontResolver a font resolver
      * @param customFonts the list of custom fonts
+     * @param useComplexScriptFeatures true if complex script features enabled
      */
     public ConfiguredFontCollection(FontResolver fontResolver,
-            List/*<EmbedFontInfo>*/ customFonts) {
+            List/*<EmbedFontInfo>*/ customFonts, boolean useComplexScriptFeatures) {
         this.fontResolver = fontResolver;
         if (this.fontResolver == null) {
             //Ensure that we have minimal font resolution capabilities
-            this.fontResolver = FontManager.createMinimalFontResolver();
+            this.fontResolver = FontManager.createMinimalFontResolver(useComplexScriptFeatures);
         }
         this.embedFontInfoList = customFonts;
     }
@@ -88,7 +89,9 @@ public class ConfiguredFontCollection im
                 } else {
                     CustomFont fontMetrics = FontLoader.loadFont(
                             fontFile, null, true, configFontInfo.getEmbeddingMode(),
-                            EncodingMode.AUTO, configFontInfo.getKerning(), fontResolver);
+                            EncodingMode.AUTO,
+                            configFontInfo.getKerning(),
+                            configFontInfo.getAdvanced(), fontResolver);
                     font = new CustomFontMetricsMapper(fontMetrics);
                 }
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java Thu Apr  5 16:19:19 2012
@@ -30,7 +30,6 @@ import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.fop.fonts.CustomFont;
-import org.apache.fop.fonts.FontMetrics;
 import org.apache.fop.fonts.FontType;
 import org.apache.fop.fonts.LazyFont;
 import org.apache.fop.fonts.Typeface;

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/InstalledFontCollection.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/InstalledFontCollection.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/InstalledFontCollection.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/InstalledFontCollection.java Thu Apr  5 16:19:19 2012
@@ -19,12 +19,12 @@
 
 package org.apache.fop.render.java2d;
 
-import java.awt.Graphics2D;
 import java.awt.GraphicsEnvironment;
 import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontCollection;
 import org.apache.fop.fonts.FontInfo;
@@ -38,10 +38,10 @@ public class InstalledFontCollection imp
 
     private static Log log = LogFactory.getLog(InstalledFontCollection.class);
 
-    private static final Set HARDCODED_FONT_NAMES;
+    private static final Set<String> HARDCODED_FONT_NAMES;
 
     static {
-        HARDCODED_FONT_NAMES = new java.util.HashSet();
+        HARDCODED_FONT_NAMES = new java.util.HashSet<String>();
         HARDCODED_FONT_NAMES.add("any");
         HARDCODED_FONT_NAMES.add("sans-serif");
         HARDCODED_FONT_NAMES.add("serif");
@@ -57,15 +57,16 @@ public class InstalledFontCollection imp
         HARDCODED_FONT_NAMES.add("Computer-Modern-Typewriter");
     }
 
-    private Graphics2D graphics2D = null;
+    /** Required by new instances of FontMetricsMapper */
+    private final Java2DFontMetrics java2DFontMetrics;
 
     /**
      * Main constructor
      *
-     * @param graphics2D a graphics 2D
+     * @param java2DFontMetrics required by new instances of FontMetricsMapper
      */
-    public InstalledFontCollection(Graphics2D graphics2D) {
-        this.graphics2D  = graphics2D;
+    public InstalledFontCollection(Java2DFontMetrics java2DFontMetrics) {
+        this.java2DFontMetrics  = java2DFontMetrics;
     }
 
     /**
@@ -98,7 +99,7 @@ public class InstalledFontCollection imp
             num++;
             String fontKey = "F" + num;
             int style = convertToAWTFontStyle(guessedStyle, guessedWeight);
-            addFontMetricsMapper(fontInfo, f.getName(), fontKey, graphics2D, style);
+            addFontMetricsMapper(fontInfo, f.getName(), fontKey, java2DFontMetrics, style);
 
             //Register appropriate font triplets matching the font. Two different strategies:
             //Example: "Arial Bold", normal, normal
@@ -120,8 +121,8 @@ public class InstalledFontCollection imp
     }
 
     private static void addFontMetricsMapper(FontInfo fontInfo, String family, String fontKey,
-            Graphics2D graphics, int style) {
-        FontMetricsMapper metric = new SystemFontMetricsMapper(family, style, graphics);
+            Java2DFontMetrics java2DFontMetrics, int style) {
+        FontMetricsMapper metric = new SystemFontMetricsMapper(family, style, java2DFontMetrics);
         fontInfo.addMetrics(fontKey, metric);
     }
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java Thu Apr  5 16:19:19 2012
@@ -109,13 +109,13 @@ public class Java2DFontMetrics {
     /**
      * Temp graphics object needed to get the font metrics
      */
-    private Graphics2D graphics;
+    private final Graphics2D graphics;
 
     /**
      * Creates a Graphics2D object for the sole purpose of getting font metrics.
      * @return a Graphics2D object
      */
-    public static Graphics2D createFontMetricsGraphics2D() {
+    private static Graphics2D createFontMetricsGraphics2D() {
         BufferedImage fontImage = new BufferedImage(100, 100,
                 BufferedImage.TYPE_INT_RGB);
         Graphics2D graphics2D = fontImage.createGraphics();
@@ -127,11 +127,9 @@ public class Java2DFontMetrics {
 
     /**
      * Constructs a new Font-metrics.
-     * @param graphics a temp graphics object - this is needed  so
-     * that we can get an instance of java.awt.FontMetrics
      */
-    public Java2DFontMetrics(Graphics2D graphics) {
-        this.graphics = graphics;
+    public Java2DFontMetrics() {
+        this.graphics = createFontMetricsGraphics2D();
     }
 
     /**
@@ -142,7 +140,7 @@ public class Java2DFontMetrics {
      * @param size font size
      * @return ascent in milliponts
      */
-    public synchronized int getMaxAscent(String family, int style, int size) {
+    public int getMaxAscent(String family, int style, int size) {
         setFont(family, style, size);
         return Math.round(lineMetrics.getAscent() * FONT_FACTOR);
     }
@@ -155,7 +153,7 @@ public class Java2DFontMetrics {
      * @param size font size
      * @return ascent in milliponts
      */
-    public synchronized int getAscender(String family, int style, int size) {
+    public int getAscender(String family, int style, int size) {
         setFont(family, style, size);
         return ascender * 1000;
 
@@ -193,7 +191,7 @@ public class Java2DFontMetrics {
      * @param size font size
      * @return capital height in millipoints
      */
-    public synchronized int getCapHeight(String family, int style, int size) {
+    public int getCapHeight(String family, int style, int size) {
         // currently just gets Ascent value but maybe should use
         // getMaxAcent() at some stage
         return getAscender(family, style, size);
@@ -207,7 +205,7 @@ public class Java2DFontMetrics {
      * @param size font size
      * @return descent in milliponts
      */
-    public synchronized int getDescender(String family, int style, int size) {
+    public int getDescender(String family, int style, int size) {
         setFont(family, style, size);
         return descender * 1000;
     }
@@ -220,7 +218,7 @@ public class Java2DFontMetrics {
      * @param size font size
      * @return font height in milliponts
      */
-    public synchronized int getXHeight(String family, int style, int size) {
+    public int getXHeight(String family, int style, int size) {
         setFont(family, style, size);
         return xHeight * 1000;
     }
@@ -234,7 +232,7 @@ public class Java2DFontMetrics {
      * @param size font size
      * @return character width in millipoints
      */
-    public synchronized int width(int i, String family, int style, int size) {
+    public int width(int i, String family, int style, int size) {
         int w;
         setFont(family, style, size);
         w = internalCharWidth(i) * 1000;
@@ -256,7 +254,7 @@ public class Java2DFontMetrics {
      * @param size font size
      * @return array of character widths in millipoints
      */
-    public synchronized int[] getWidths(String family, int style, int size) {
+    public int[] getWidths(String family, int style, int size) {
         int i;
 
         if (width == null) {
@@ -351,7 +349,7 @@ public class Java2DFontMetrics {
      * @param size font size
      * @return font with the desired characeristics.
      */
-    public synchronized java.awt.Font getFont(String family, int style, int size) {
+    public java.awt.Font getFont(String family, int style, int size) {
         setFont(family, style, size);
         return f1;
         /*
@@ -372,7 +370,7 @@ public class Java2DFontMetrics {
      * @param c the glyph to check
      * @return true if the character is supported
      */
-    public synchronized boolean hasChar(String family, int style, int size, char c) {
+    public boolean hasChar(String family, int style, int size, char c) {
         setFont(family, style, size);
         return f1.canDisplay(c);
     }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DGraphicsState.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DGraphicsState.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DGraphicsState.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DGraphicsState.java Thu Apr  5 16:19:19 2012
@@ -28,6 +28,8 @@ import java.awt.geom.AffineTransform;
 import java.awt.geom.Area;
 import java.awt.geom.GeneralPath;
 
+import org.apache.xmlgraphics.java2d.color.ColorUtil;
+
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fonts.FontInfo;
 
@@ -103,7 +105,7 @@ public class Java2DGraphicsState {
      * @return true if the background color has changed
      */
     public boolean updateColor(Color col) {
-        if (!col.equals(getGraph().getColor())) {
+        if (!ColorUtil.isSameColor(col, getGraph().getColor())) {
             getGraph().setColor(col);
             return true;
         } else {
@@ -217,12 +219,18 @@ public class Java2DGraphicsState {
      * @return true if the new paint changes the current paint
      */
     public boolean updatePaint(Paint p) {
-        if (getGraph().getPaint() == null) {
+        Paint currentPaint = getGraph().getPaint();
+        if (currentPaint == null) {
             if (p != null) {
                 getGraph().setPaint(p);
                 return true;
             }
-        } else if (!p.equals(getGraph().getPaint())) {
+        } else if (p instanceof Color && currentPaint instanceof Color) {
+            if (!ColorUtil.isSameColor((Color)p, (Color)currentPaint)) {
+                getGraph().setPaint(p);
+                return true;
+            }
+        } else if (!p.equals(currentPaint)) {
             getGraph().setPaint(p);
             return true;
         }
@@ -271,6 +279,7 @@ public class Java2DGraphicsState {
     }
 
     /** {@inheritDoc} */
+    @Override
     public String toString() {
         String s = "Java2DGraphicsState " + currentGraphics.toString()
                 + ", Stroke (width: " + currentStrokeWidth + " style: "

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DPainter.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DPainter.java Thu Apr  5 16:19:19 2012
@@ -40,8 +40,8 @@ import org.apache.fop.render.RenderingCo
 import org.apache.fop.render.intermediate.AbstractIFPainter;
 import org.apache.fop.render.intermediate.IFContext;
 import org.apache.fop.render.intermediate.IFException;
-import org.apache.fop.render.intermediate.IFPainter;
 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.CharUtilities;
@@ -184,11 +184,11 @@ public class Java2DPainter extends Abstr
     }
 
     /** {@inheritDoc} */
-    public void drawBorderRect(Rectangle rect, BorderProps before, BorderProps after,
-            BorderProps start, BorderProps end) throws IFException {
-        if (before != null || after != null || start != null || end != null) {
+    public void drawBorderRect(Rectangle rect, BorderProps top, BorderProps bottom,
+            BorderProps left, BorderProps right) throws IFException {
+        if (top != null || bottom != null || left != null || right != null) {
             try {
-                this.borderPainter.drawBorders(rect, before, after, start, end);
+                this.borderPainter.drawBorders(rect, top, bottom, left, right);
             } catch (IOException e) {
                 //Won't happen with Java2D
                 throw new IllegalStateException("Unexpected I/O error");
@@ -203,7 +203,7 @@ public class Java2DPainter extends Abstr
     }
 
     /** {@inheritDoc} */
-    public void drawText(int x, int y, int letterSpacing, int wordSpacing, int[] dx, String text)
+    public void drawText(int x, int y, int letterSpacing, int wordSpacing, int[][] dp, String text)
             throws IFException {
         g2dState.updateColor(state.getTextColor());
         FontTriplet triplet = new FontTriplet(
@@ -220,6 +220,7 @@ public class Java2DPainter extends Abstr
         Point2D cursor = new Point2D.Float(0, 0);
 
         int l = text.length();
+        int[] dx = IFUtil.convertDPToDX ( dp );
         int dxl = (dx != null ? dx.length : 0);
 
         if (dx != null && dxl > 0 && dx[0] != 0) {

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DRenderer.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DRenderer.java Thu Apr  5 16:19:19 2012
@@ -146,16 +146,18 @@ public abstract class Java2DRenderer ext
 
     private GeneralPath currentPath = null;
 
-    /** Default constructor */
-    public Java2DRenderer() {
-    }
+    /**
+     * Default constructor
+     *
+     * @param userAgent the user agent that contains configuration details. This cannot be null.
+     */
+    public Java2DRenderer(FOUserAgent userAgent) {
+        super(userAgent);
 
-    /** {@inheritDoc} */
-    public void setUserAgent(FOUserAgent foUserAgent) {
-        super.setUserAgent(foUserAgent);
+        // MH: necessary? the caller has access to FOUserAgent
         userAgent.setRendererOverride(this); // for document regeneration
 
-        String s = (String)userAgent.getRendererOptions().get(JAVA2D_TRANSPARENT_PAGE_BACKGROUND);
+        String s = (String) userAgent.getRendererOptions().get(JAVA2D_TRANSPARENT_PAGE_BACKGROUND);
         if (s != null) {
             this.transparentPageBackground = "true".equalsIgnoreCase(s);
         }
@@ -171,12 +173,13 @@ public abstract class Java2DRenderer ext
         //Don't call super.setupFontInfo() here! Java2D needs a special font setup
         // create a temp Image to test font metrics on
         this.fontInfo = inFontInfo;
-        Graphics2D graphics2D = Java2DFontMetrics.createFontMetricsGraphics2D();
+        final Java2DFontMetrics java2DFontMetrics = new Java2DFontMetrics();
 
         FontCollection[] fontCollections = new FontCollection[] {
-                new Base14FontCollection(graphics2D),
-                new InstalledFontCollection(graphics2D),
-                new ConfiguredFontCollection(getFontResolver(), getFontList())
+                new Base14FontCollection(java2DFontMetrics),
+                new InstalledFontCollection(java2DFontMetrics),
+                new ConfiguredFontCollection(getFontResolver(), getFontList(),
+                                             userAgent.isComplexScriptFeaturesEnabled())
         };
         userAgent.getFactory().getFontManager().setup(
                 getFontInfo(), fontCollections);
@@ -445,7 +448,7 @@ public abstract class Java2DRenderer ext
     }
 
     /** {@inheritDoc} */
-    protected void startVParea(CTM ctm, Rectangle2D clippingRect) {
+    protected void startVParea(CTM ctm, Rectangle clippingRect) {
 
         saveGraphicsState();
 
@@ -713,7 +716,7 @@ public abstract class Java2DRenderer ext
         renderInlineAreaBackAndBorders(text);
 
         int rx = currentIPPosition + text.getBorderAndPaddingWidthStart();
-        int bl = currentBPPosition + text.getOffset() + text.getBaselineOffset();
+        int bl = currentBPPosition + text.getBlockProgressionOffset() + text.getBaselineOffset();
         int saveIP = currentIPPosition;
 
         Font font = getFontFromArea(text);
@@ -825,7 +828,7 @@ public abstract class Java2DRenderer ext
         // TODO Colors do not work on Leaders yet
 
         float startx = (currentIPPosition + area.getBorderAndPaddingWidthStart()) / 1000f;
-        float starty = ((currentBPPosition + area.getOffset()) / 1000f);
+        float starty = ((currentBPPosition + area.getBlockProgressionOffset()) / 1000f);
         float endx = (currentIPPosition + area.getBorderAndPaddingWidthStart()
                 + area.getIPD()) / 1000f;
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DRendererConfigurator.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DRendererConfigurator.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DRendererConfigurator.java Thu Apr  5 16:19:19 2012
@@ -20,6 +20,7 @@
 package org.apache.fop.render.java2d;
 
 import org.apache.avalon.framework.configuration.Configuration;
+
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.render.PrintRendererConfigurator;

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DSVGHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DSVGHandler.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DSVGHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DSVGHandler.java Thu Apr  5 16:19:19 2012
@@ -25,11 +25,12 @@ import java.util.Map;
 
 import org.w3c.dom.Document;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import org.apache.batik.bridge.BridgeContext;
 import org.apache.batik.bridge.GVTBuilder;
 import org.apache.batik.gvt.GraphicsNode;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 import org.apache.fop.image.loader.batik.BatikUtil;
 import org.apache.fop.render.AbstractGenericSVGHandler;

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DUtil.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DUtil.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/Java2DUtil.java Thu Apr  5 16:19:19 2012
@@ -19,8 +19,6 @@
 
 package org.apache.fop.render.java2d;
 
-import java.awt.Graphics2D;
-
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.fonts.FontCollection;
 import org.apache.fop.fonts.FontEventAdapter;
@@ -44,12 +42,12 @@ public final class Java2DUtil {
      */
     public static FontInfo buildDefaultJava2DBasedFontInfo(
             FontInfo fontInfo, FOUserAgent userAgent) {
-        Graphics2D graphics2D = Java2DFontMetrics.createFontMetricsGraphics2D();
+        Java2DFontMetrics java2DFontMetrics = new Java2DFontMetrics();
 
         FontManager fontManager = userAgent.getFactory().getFontManager();
         FontCollection[] fontCollections = new FontCollection[] {
-                new org.apache.fop.render.java2d.Base14FontCollection(graphics2D),
-                new InstalledFontCollection(graphics2D)
+                new org.apache.fop.render.java2d.Base14FontCollection(java2DFontMetrics),
+                new InstalledFontCollection(java2DFontMetrics)
         };
 
         FontInfo fi = (fontInfo != null ? fontInfo : new FontInfo());

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/SystemFontMetricsMapper.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/SystemFontMetricsMapper.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/SystemFontMetricsMapper.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/SystemFontMetricsMapper.java Thu Apr  5 16:19:19 2012
@@ -20,7 +20,6 @@
 package org.apache.fop.render.java2d;
 
 // Java
-import java.awt.Graphics2D;
 import java.util.Map;
 import java.util.Set;
 
@@ -42,7 +41,7 @@ public class SystemFontMetricsMapper ext
      * This is a Java2DFontMetrics that does the real calculation.
      * It is only one class that dynamically determines the font-size.
      */
-    private static Java2DFontMetrics metric = null;
+    private final Java2DFontMetrics java2DFontMetrics;
 
     /**
      * The java name of the font.
@@ -60,15 +59,14 @@ public class SystemFontMetricsMapper ext
      * Constructs a new Font-metrics.
      * @param family the family name of the font (java value)
      * @param style the java type style value of the font
-     * @param graphics a Graphics2D object - this is needed  so
-     * that we can get an instance of java.awt.FontMetrics
+     * @param java2DFontMetrics metric calculations delegated to this
      */
-    public SystemFontMetricsMapper(String family, int style, Graphics2D graphics) {
+    public SystemFontMetricsMapper(String family, int style, Java2DFontMetrics java2DFontMetrics) {
         this.family = family;
+
         this.style = style;
-        if (metric == null) {
-            metric = new Java2DFontMetrics(graphics);
-        }
+
+        this.java2DFontMetrics = java2DFontMetrics;
     }
 
     /** {@inheritDoc} */
@@ -104,42 +102,42 @@ public class SystemFontMetricsMapper ext
      * {@inheritDoc}
      */
     public int getMaxAscent(int size) {
-        return metric.getMaxAscent(family, style, size);
+        return java2DFontMetrics.getMaxAscent(family, style, size);
     }
 
     /**
      * {@inheritDoc}
      */
     public int getAscender(int size) {
-        return metric.getAscender(family, style, size);
+        return java2DFontMetrics.getAscender(family, style, size);
     }
 
     /**
      * {@inheritDoc}
      */
     public int getCapHeight(int size) {
-        return metric.getCapHeight(family, style, size);
+        return java2DFontMetrics.getCapHeight(family, style, size);
     }
 
     /**
      * {@inheritDoc}
      */
     public int getDescender(int size) {
-        return metric.getDescender(family, style, size);
+        return java2DFontMetrics.getDescender(family, style, size);
     }
 
     /**
      * {@inheritDoc}
      */
     public int getXHeight(int size) {
-        return metric.getXHeight(family, style, size);
+        return java2DFontMetrics.getXHeight(family, style, size);
     }
 
     /**
      * {@inheritDoc}
      */
     public int getWidth(int i, int size) {
-        return metric.width(i, family, style, size);
+        return java2DFontMetrics.width(i, family, style, size);
     }
 
 
@@ -147,14 +145,14 @@ public class SystemFontMetricsMapper ext
      * {@inheritDoc}
      */
     public int[] getWidths() {
-        return metric.getWidths(family, style, Java2DFontMetrics.FONT_SIZE);
+        return java2DFontMetrics.getWidths(family, style, Java2DFontMetrics.FONT_SIZE);
     }
 
     /**
      * {@inheritDoc}
      */
     public java.awt.Font getFont(int size) {
-        return metric.getFont(family, style, size);
+        return java2DFontMetrics.getFont(family, style, size);
     }
 
     /**
@@ -183,7 +181,7 @@ public class SystemFontMetricsMapper ext
 
     /** {@inheritDoc} */
     public boolean hasChar(char c) {
-        return metric.hasChar(family, style, Java2DFontMetrics.FONT_SIZE, c);
+        return java2DFontMetrics.hasChar(family, style, Java2DFontMetrics.FONT_SIZE, c);
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java Thu Apr  5 16:19:19 2012
@@ -37,7 +37,6 @@ import org.apache.fop.apps.MimeConstants
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
 import org.apache.fop.render.intermediate.IFContext;
-import org.apache.fop.render.intermediate.IFDocumentHandler;
 import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
 import org.apache.fop.render.intermediate.IFException;
 import org.apache.fop.render.intermediate.IFPainter;
@@ -88,6 +87,7 @@ public class PCLDocumentHandler extends 
     }
 
     /** {@inheritDoc} */
+    @Override
     public void setContext(IFContext context) {
         super.setContext(context);
         this.pclUtil = new PCLRenderingUtil(context.getUserAgent());
@@ -99,6 +99,7 @@ public class PCLDocumentHandler extends 
     }
 
     /** {@inheritDoc} */
+    @Override
     public void setDefaultFontInfo(FontInfo fontInfo) {
         FontInfo fi = Java2DUtil.buildDefaultJava2DBasedFontInfo(fontInfo, getUserAgent());
         setFontInfo(fi);
@@ -114,7 +115,7 @@ public class PCLDocumentHandler extends 
 
     /** @return the target resolution */
     protected int getResolution() {
-        int resolution = (int)Math.round(getUserAgent().getTargetResolution());
+        int resolution = Math.round(getUserAgent().getTargetResolution());
         if (resolution <= 300) {
             return 300;
         } else {
@@ -125,10 +126,12 @@ public class PCLDocumentHandler extends 
     //----------------------------------------------------------------------------------------------
 
     /** {@inheritDoc} */
+    @Override
     public void startDocument() throws IFException {
         super.startDocument();
         try {
             this.gen = new PCLGenerator(this.outputStream, getResolution());
+            this.gen.setDitheringQuality(pclUtil.getDitheringQuality());
 
             if (!pclUtil.isPJLDisabled()) {
                 gen.universalEndOfLanguage();
@@ -148,10 +151,12 @@ public class PCLDocumentHandler extends 
     }
 
     /** {@inheritDoc} */
+    @Override
     public void endDocumentHeader() throws IFException {
     }
 
     /** {@inheritDoc} */
+    @Override
     public void endDocument() throws IFException {
         try {
             gen.separateJobs();

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLGenerator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLGenerator.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLGenerator.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLGenerator.java Thu Apr  5 16:19:19 2012
@@ -49,7 +49,6 @@ import org.apache.xmlgraphics.util.UnitC
 
 import org.apache.fop.util.bitmap.BitmapImageUtil;
 import org.apache.fop.util.bitmap.DitherUtil;
-import org.apache.fop.util.bitmap.MonochromeBitmapConverter;
 
 /**
  * This class provides methods for generating PCL print files.
@@ -76,6 +75,7 @@ public class PCLGenerator {
     private boolean currentPatternTransparency = true;
 
     private int maxBitmapResolution = PCL_RESOLUTIONS[PCL_RESOLUTIONS.length - 1];
+    private float ditheringQuality = 0.5f;
 
     /**
      * true: Standard PCL shades are used (poor quality). false: user-defined pattern are used
@@ -541,13 +541,31 @@ public class PCLGenerator {
     }
 
     /**
+     * Sets the dithering quality used when encoding gray or color images. If not explicitely
+     * set a medium setting (0.5f) is used.
+     * @param quality a quality setting between 0.0f (worst/fastest) and 1.0f (best/slowest)
+     */
+    public void setDitheringQuality(float quality) {
+        quality = Math.min(Math.max(0f, quality), 1.0f);
+        this.ditheringQuality = quality;
+    }
+
+    /**
+     * Returns the dithering quality used when encoding gray or color images.
+     * @return the quality setting between 0.0f (worst/fastest) and 1.0f (best/slowest)
+     */
+    public float getDitheringQuality() {
+        return this.ditheringQuality;
+    }
+
+    /**
      * Indicates whether an image is a monochrome (b/w) image.
      * @param img the image
      * @return true if it's a monochrome image
      */
     public static boolean isMonochromeImage(RenderedImage img) {
         return BitmapImageUtil.isMonochromeImage(img);
-        }
+    }
 
     /**
      * Indicates whether an image is a grayscale image.
@@ -618,18 +636,6 @@ public class PCLGenerator {
         return resolution == calculatePCLResolution(resolution);
     }
 
-    private Dimension getAdjustedDimension(Dimension orgDim, double orgResolution,
-            int pclResolution) {
-        if (orgResolution == pclResolution) {
-            return orgDim;
-        } else {
-            Dimension result = new Dimension();
-            result.width = (int)Math.round((double)orgDim.width * pclResolution / orgResolution);
-            result.height = (int)Math.round((double)orgDim.height * pclResolution / orgResolution);
-            return result;
-        }
-    }
-
     //Threshold table to convert an alpha channel (8-bit) into a clip mask (1-bit)
     private static final byte[] THRESHOLD_TABLE = new byte[256];
     static { // Initialize the arrays
@@ -724,34 +730,8 @@ public class PCLGenerator {
                 popCursorPos();
             }
 
-            BufferedImage src = null;
-            if (img instanceof BufferedImage && !scaled) {
-                if (!isGrayscaleImage(img) || img.getColorModel().hasAlpha()) {
-                    /* Disabled as this doesn't work reliably, use the fallback below
-                    src = new BufferedImage(effDim.width, effDim.height,
-                            BufferedImage.TYPE_BYTE_GRAY);
-                    Graphics2D g2d = src.createGraphics();
-                    try {
-                        clearBackground(g2d, effDim);
-                    } finally {
-                        g2d.dispose();
-                    }
-                    ColorConvertOp op = new ColorConvertOp(
-                            ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
-                    op.filter((BufferedImage)img, src);
-                    */
-                } else {
-                    src = (BufferedImage)img;
-                }
-            }
-            if (src == null) {
-                src = BitmapImageUtil.convertToGrayscale(img, effDim);
-                }
-            MonochromeBitmapConverter converter
-                = BitmapImageUtil.createDefaultMonochromeBitmapConverter();
-            converter.setHint("quality", "false");
-
-            RenderedImage red = converter.convertToMonochrome(src);
+            RenderedImage red = BitmapImageUtil.convertToMonochrome(
+                    img, effDim, this.ditheringQuality);
             selectCurrentPattern(0, 0); //Solid black
             setTransparencyMode(sourceTransparency || mask != null, true);
             paintMonochromeBitmap(red, effResolution);
@@ -766,12 +746,6 @@ public class PCLGenerator {
         }
     }
 
-    private void clearBackground(Graphics2D g2d, Dimension effDim) {
-        //white background
-        g2d.setBackground(Color.WHITE);
-        g2d.clearRect(0, 0, effDim.width, effDim.height);
-    }
-
     private int toGray(int rgb) {
         // see http://www.jguru.com/faq/view.jsp?EID=221919
         double greyVal = 0.072169d * (rgb & 0xff);

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java Thu Apr  5 16:19:19 2012
@@ -127,8 +127,8 @@ public class PCLGraphics2D extends Abstr
 
     /** {@inheritDoc} */
     public GraphicsConfiguration getDeviceConfiguration() {
-        return GraphicsEnvironment.getLocalGraphicsEnvironment().
-                getDefaultScreenDevice().getDefaultConfiguration();
+        return GraphicsEnvironment.getLocalGraphicsEnvironment()
+                .getDefaultScreenDevice().getDefaultConfiguration();
     }
 
     /**

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLImageHandlerGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLImageHandlerGraphics2D.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLImageHandlerGraphics2D.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLImageHandlerGraphics2D.java Thu Apr  5 16:19:19 2012
@@ -85,6 +85,7 @@ public class PCLImageHandlerGraphics2D i
         boolean painted = false;
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
         PCLGenerator tempGen = new PCLGenerator(baout, gen.getMaximumBitmapResolution());
+        tempGen.setDitheringQuality(gen.getDitheringQuality());
         try {
             GraphicContext ctx = (GraphicContext)pclContext.getGraphicContext().clone();
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLPainter.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/pcl/PCLPainter.java Thu Apr  5 16:19:19 2012
@@ -49,8 +49,8 @@ import org.apache.fop.render.RenderingCo
 import org.apache.fop.render.intermediate.AbstractIFPainter;
 import org.apache.fop.render.intermediate.IFContext;
 import org.apache.fop.render.intermediate.IFException;
-import org.apache.fop.render.intermediate.IFPainter;
 import org.apache.fop.render.intermediate.IFState;
+import org.apache.fop.render.intermediate.IFUtil;
 import org.apache.fop.render.java2d.FontMetricsMapper;
 import org.apache.fop.render.java2d.Java2DPainter;
 import org.apache.fop.traits.BorderProps;
@@ -206,13 +206,13 @@ public class PCLPainter extends Abstract
 
     /** {@inheritDoc} */
     public void drawBorderRect(final Rectangle rect,
-            final BorderProps before, final BorderProps after,
-            final BorderProps start, final BorderProps end) throws IFException {
+            final BorderProps top, final BorderProps bottom,
+            final BorderProps left, final BorderProps right) throws IFException {
         if (isSpeedOptimized()) {
-            super.drawBorderRect(rect, before, after, start, end);
+            super.drawBorderRect(rect, top, bottom, left, right);
             return;
         }
-        if (before != null || after != null || start != null || end != null) {
+        if (top != null || bottom != null || left != null || right != null) {
             final Rectangle boundingBox = rect;
             final Dimension dim = boundingBox.getSize();
 
@@ -224,7 +224,7 @@ public class PCLPainter extends Abstract
                     Java2DPainter painter = new Java2DPainter(g2d,
                             getContext(), parent.getFontInfo(), state);
                     try {
-                        painter.drawBorderRect(rect, before, after, start, end);
+                        painter.drawBorderRect(rect, top, bottom, left, right);
                     } catch (IFException e) {
                         //This should never happen with the Java2DPainter
                         throw new RuntimeException("Unexpected error while painting borders", e);
@@ -307,7 +307,7 @@ public class PCLPainter extends Abstract
     }
 
     /** {@inheritDoc} */
-    public void drawText(int x, int y, int letterSpacing, int wordSpacing, int[] dx, String text)
+    public void drawText(int x, int y, int letterSpacing, int wordSpacing, int[][] dp, String text)
                 throws IFException {
         try {
             FontTriplet triplet = new FontTriplet(
@@ -319,13 +319,13 @@ public class PCLPainter extends Abstract
                         ? false
                         : HardcodedFonts.setFont(gen, fontKey, state.getFontSize(), text);
             if (pclFont) {
-                drawTextNative(x, y, letterSpacing, wordSpacing, dx, text, triplet);
+                drawTextNative(x, y, letterSpacing, wordSpacing, dp, text, triplet);
             } else {
-                drawTextAsBitmap(x, y, letterSpacing, wordSpacing, dx, text, triplet);
+                drawTextAsBitmap(x, y, letterSpacing, wordSpacing, dp, text, triplet);
                 if (DEBUG) {
                     state.setTextColor(Color.GRAY);
                     HardcodedFonts.setFont(gen, "F1", state.getFontSize(), text);
-                    drawTextNative(x, y, letterSpacing, wordSpacing, dx, text, triplet);
+                    drawTextNative(x, y, letterSpacing, wordSpacing, dp, text, triplet);
                 }
             }
         } catch (IOException ioe) {
@@ -333,7 +333,7 @@ public class PCLPainter extends Abstract
         }
     }
 
-    private void drawTextNative(int x, int y, int letterSpacing, int wordSpacing, int[] dx,
+    private void drawTextNative(int x, int y, int letterSpacing, int wordSpacing, int[][] dp,
             String text, FontTriplet triplet) throws IOException {
         Color textColor = state.getTextColor();
         if (textColor != null) {
@@ -347,6 +347,7 @@ public class PCLPainter extends Abstract
         float fontSize = state.getFontSize() / 1000f;
         Font font = parent.getFontInfo().getFontInstance(triplet, state.getFontSize());
         int l = text.length();
+        int[] dx = IFUtil.convertDPToDX ( dp );
         int dxl = (dx != null ? dx.length : 0);
 
         StringBuffer sb = new StringBuffer(Math.max(16, l));
@@ -392,7 +393,7 @@ public class PCLPainter extends Abstract
 
     private Rectangle getTextBoundingBox(                        // CSOK: ParameterNumber
             int x, int y,
-            int letterSpacing, int wordSpacing, int[] dx,
+            int letterSpacing, int wordSpacing, int[][] dp,
             String text,
             Font font, FontMetricsMapper metrics) {
         int maxAscent = metrics.getMaxAscent(font.getFontSize()) / 1000;
@@ -403,6 +404,7 @@ public class PCLPainter extends Abstract
                 0, maxAscent - descent + 2 * safetyMargin);
 
         int l = text.length();
+        int[] dx = IFUtil.convertDPToDX ( dp );
         int dxl = (dx != null ? dx.length : 0);
 
         if (dx != null && dxl > 0 && dx[0] != 0) {
@@ -432,7 +434,7 @@ public class PCLPainter extends Abstract
     }
 
     private void drawTextAsBitmap(final int x, final int y,
-            final int letterSpacing, final int wordSpacing, final int[] dx,
+            final int letterSpacing, final int wordSpacing, final int[][] dp,
             final String text, FontTriplet triplet) throws IFException {
         //Use Java2D to paint different fonts via bitmap
         final Font font = parent.getFontInfo().getFontInstance(triplet, state.getFontSize());
@@ -447,7 +449,7 @@ public class PCLPainter extends Abstract
         final int baselineOffset = maxAscent + safetyMargin;
 
         final Rectangle boundingBox = getTextBoundingBox(x, y,
-                letterSpacing, wordSpacing, dx, text, font, mapper);
+                letterSpacing, wordSpacing, dp, text, font, mapper);
         final Dimension dim = boundingBox.getSize();
 
         Graphics2DImagePainter painter = new Graphics2DImagePainter() {
@@ -470,7 +472,7 @@ public class PCLPainter extends Abstract
                 Java2DPainter painter = new Java2DPainter(g2d,
                         getContext(), parent.getFontInfo(), state);
                 try {
-                    painter.drawText(x, y, letterSpacing, wordSpacing, dx, text);
+                    painter.drawText(x, y, letterSpacing, wordSpacing, dp, text);
                 } catch (IFException e) {
                     //This should never happen with the Java2DPainter
                     throw new RuntimeException("Unexpected error while painting text", e);



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