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 ac...@apache.org on 2008/11/05 11:28:26 UTC

svn commit: r711550 - /xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/afp/AFPTextHandler.java

Author: acumiskey
Date: Wed Nov  5 02:28:26 2008
New Revision: 711550

URL: http://svn.apache.org/viewvc?rev=711550&view=rev
Log:
GOCA Text painting positional fix.

Modified:
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/afp/AFPTextHandler.java

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/afp/AFPTextHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/afp/AFPTextHandler.java?rev=711550&r1=711549&r2=711550&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/afp/AFPTextHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/afp/AFPTextHandler.java Wed Nov  5 02:28:26 2008
@@ -20,6 +20,7 @@
 package org.apache.fop.afp;
 
 import java.awt.Color;
+import java.awt.geom.AffineTransform;
 import java.io.IOException;
 
 import org.apache.commons.logging.Log;
@@ -40,6 +41,9 @@
     /** logging instance */
     private static Log log = LogFactory.getLog(AFPTextHandler.class);
 
+    private static final int X = 0;
+    private static final int Y = 1;
+
     private AFPGraphics2D g2d = null;
 
     /** Overriding FontState */
@@ -47,7 +51,7 @@
 
     /**
      * Main constructor.
-     * @param g2d the PSGraphics2D instance this instances is used by
+     * @param g2d the AFPGraphics2D instance
      */
     public AFPTextHandler(AFPGraphics2D g2d) {
         this.g2d = g2d;
@@ -55,6 +59,7 @@
 
     /**
      * Return the font information associated with this object
+     *
      * @return the FontInfo object
      */
     public FontInfo getFontInfo() {
@@ -64,23 +69,24 @@
     /**
      * Add a text string to the current data object of the AFP datastream.
      * The text is painted using text operations.
+     *
      * {@inheritDoc}
      */
     public void drawString(String str, float x, float y) throws IOException {
         log.debug("drawString() str=" + str + ", x=" + x + ", y=" + y);
         GraphicsObject graphicsObj = g2d.getGraphicsObject();
-        Color col = g2d.getColor();
+        Color color = g2d.getColor();
 
-        AFPPaintingState state = g2d.getPaintingState();
-        if (state.setColor(col)) {
-            graphicsObj.setColor(col);
+        AFPPaintingState paintingState = g2d.getPaintingState();
+        if (paintingState.setColor(color)) {
+            graphicsObj.setColor(color);
         }
         if (overrideFont != null) {
             FontInfo fontInfo = getFontInfo();
-            AFPPageFonts pageFonts = state.getPageFonts();
+            AFPPageFonts pageFonts = paintingState.getPageFonts();
             String internalFontName = overrideFont.getFontName();
             int fontSize = overrideFont.getFontSize();
-            if (state.setFontName(internalFontName) || state.setFontSize(fontSize)) {
+            if (paintingState.setFontName(internalFontName) || paintingState.setFontSize(fontSize)) {
                 AFPFont font = (AFPFont)fontInfo.getFonts().get(internalFontName);
                 AFPFontAttributes afpFontAttributes = pageFonts.registerFont(
                         internalFontName,
@@ -91,11 +97,19 @@
                 graphicsObj.setCharacterSet(fontReference);
             }
         }
-        graphicsObj.addString(str, Math.round(x), Math.round(y));
+
+        // calculate x, y plotting coordinates from graphics context
+        AffineTransform at = g2d.getTransform();
+        float[] srcPts = new float[] { x, y };
+        float[] dstPts = new float[srcPts.length];
+        at.transform(srcPts, 0, dstPts, 0, 1);
+
+        graphicsObj.addString(str, Math.round(dstPts[X]), Math.round(dstPts[Y]));
     }
 
     /**
      * Sets the overriding font.
+     *
      * @param overrideFont Overriding Font to set
      */
     public void setOverrideFont(Font overrideFont) {



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