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

package org.apache.fop.afp; package org.apache.fop.afp;


import java.awt.Color; import java.awt.Color;
import java.awt.geom.AffineTransform;
import java.io.IOException; import java.io.IOException;


import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
/** logging instance */ /** logging instance */
private static Log log = LogFactory.getLog(AFPTextHandler.class); private static Log log = LogFactory.getLog(AFPTextHandler.class);


private static final int X = 0;
private static final int Y = 1;

private AFPGraphics2D g2d = null; private AFPGraphics2D g2d = null;


/** Overriding FontState */ /** Overriding FontState */


/** /**
* Main constructor. * Main constructor.
* @param g2d the PSGraphics2D instance this instances is used by
* @param g2d the AFPGraphics2D instance
*/ */
public AFPTextHandler(AFPGraphics2D g2d) { public AFPTextHandler(AFPGraphics2D g2d) {
this.g2d = g2d; this.g2d = g2d;


/** /**
* Return the font information associated with this object * Return the font information associated with this object
*
* @return the FontInfo object * @return the FontInfo object
*/ */
public FontInfo getFontInfo() { public FontInfo getFontInfo() {
/** /**
* Add a text string to the current data object of the AFP datastream. * Add a text string to the current data object of the AFP datastream.
* The text is painted using text operations. * The text is painted using text operations.
*
* {@inheritDoc} * {@inheritDoc}
*/ */
public void drawString(String str, float x, float y) throws IOException { public void drawString(String str, float x, float y) throws IOException {
log.debug("drawString() str=" + str + ", x=" + x + ", y=" + y); log.debug("drawString() str=" + str + ", x=" + x + ", y=" + y);
GraphicsObject graphicsObj = g2d.getGraphicsObject(); 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) { if (overrideFont != null) {
FontInfo fontInfo = getFontInfo(); FontInfo fontInfo = getFontInfo();
AFPPageFonts pageFonts = state.getPageFonts();
AFPPageFonts pageFonts = paintingState.getPageFonts();
String internalFontName = overrideFont.getFontName(); String internalFontName = overrideFont.getFontName();
int fontSize = overrideFont.getFontSize(); 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); AFPFont font = (AFPFont)fontInfo.getFonts().get(internalFontName);
AFPFontAttributes afpFontAttributes = pageFonts.registerFont( AFPFontAttributes afpFontAttributes = pageFonts.registerFont(
internalFontName, internalFontName,
graphicsObj.setCharacterSet(fontReference); 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. * Sets the overriding font.
*
* @param overrideFont Overriding Font to set * @param overrideFont Overriding Font to set
*/ */
public void setOverrideFont(Font overrideFont) { public void setOverrideFont(Font overrideFont) {

Loading…
Cancel
Save