Browse Source

GOCA Text painting positional fix.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@711550 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-1_0
Adrian Cumiskey 15 years ago
parent
commit
6bfc5fa86e
1 changed files with 22 additions and 8 deletions
  1. 22
    8
      src/java/org/apache/fop/afp/AFPTextHandler.java

+ 22
- 8
src/java/org/apache/fop/afp/AFPTextHandler.java View File

@@ -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 @@ public class AFPTextHandler implements TextHandler {
/** 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 @@ public class AFPTextHandler implements TextHandler {

/**
* 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 @@ public class AFPTextHandler implements TextHandler {

/**
* Return the font information associated with this object
*
* @return the FontInfo object
*/
public FontInfo getFontInfo() {
@@ -64,23 +69,24 @@ public class AFPTextHandler implements TextHandler {
/**
* 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 @@ public class AFPTextHandler implements TextHandler {
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) {

Loading…
Cancel
Save