* GenericGraphics2DImagePainter becomes a top level class. * AFPGraphics2DImagePainter implementation to correctly adjust y-axis for AFP. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@706226 13f79535-47bb-0310-9956-ffa450edef68tags/fop-1_0
@@ -0,0 +1,95 @@ | |||
package org.apache.fop.image.loader.batik; | |||
import java.awt.Dimension; | |||
import java.awt.Graphics2D; | |||
import java.awt.geom.Rectangle2D; | |||
import org.apache.batik.bridge.BridgeContext; | |||
import org.apache.batik.gvt.GraphicsNode; | |||
import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM; | |||
import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; | |||
/** | |||
* A generic graphics 2D image painter implementation | |||
*/ | |||
public class GenericGraphics2DImagePainter implements Graphics2DImagePainter { | |||
protected final ImageXMLDOM svg; | |||
protected final BridgeContext ctx; | |||
protected final GraphicsNode root; | |||
/** | |||
* Constructor | |||
* | |||
* @param svg the svg image dom | |||
* @param ctx the bridge context | |||
* @param root the graphics node root | |||
*/ | |||
public GenericGraphics2DImagePainter(ImageXMLDOM svg, BridgeContext ctx, GraphicsNode root) { | |||
this.svg = svg; | |||
this.ctx = ctx; | |||
this.root = root; | |||
} | |||
/** | |||
* Initialises the graphics 2d | |||
* | |||
* @param g2d the graphics 2d | |||
* @param area the rectangle drawing area | |||
*/ | |||
protected void init(Graphics2D g2d, Rectangle2D area) { | |||
// If no viewbox is defined in the svg file, a viewbox of 100x100 is | |||
// assumed, as defined in SVGUserAgent.getViewportSize() | |||
double tx = area.getX(); | |||
double ty = area.getY(); | |||
if (tx != 0 || ty != 0) { | |||
g2d.translate(tx, ty); | |||
} | |||
float iw = (float) ctx.getDocumentSize().getWidth(); | |||
float ih = (float) ctx.getDocumentSize().getHeight(); | |||
float w = (float) area.getWidth(); | |||
float h = (float) area.getHeight(); | |||
float sx = w / iw; | |||
float sy = h / ih; | |||
if (sx != 1.0 || sy != 1.0) { | |||
g2d.scale(sx, sy); | |||
} | |||
} | |||
/** {@inheritDoc} */ | |||
public void paint(Graphics2D g2d, Rectangle2D area) { | |||
init(g2d, area); | |||
root.paint(g2d); | |||
} | |||
/** {@inheritDoc} */ | |||
public Dimension getImageSize() { | |||
return new Dimension(svg.getSize().getWidthMpt(), svg.getSize().getHeightMpt()); | |||
} | |||
/** | |||
* Returns the svg image dom | |||
* @return the svg image dom | |||
*/ | |||
public ImageXMLDOM getImageXMLDOM() { | |||
return svg; | |||
} | |||
/** | |||
* Returns the bridge context | |||
* @return the bridge context | |||
*/ | |||
public BridgeContext getBridgeContext() { | |||
return ctx; | |||
} | |||
/** | |||
* Returns the graphics root node | |||
* @return the graphics root node | |||
*/ | |||
public GraphicsNode getRoot() { | |||
return root; | |||
} | |||
} |
@@ -19,10 +19,7 @@ | |||
package org.apache.fop.image.loader.batik; | |||
import java.awt.Dimension; | |||
import java.awt.Graphics2D; | |||
import java.awt.geom.AffineTransform; | |||
import java.awt.geom.Rectangle2D; | |||
import java.util.Map; | |||
import org.apache.batik.bridge.BridgeContext; | |||
@@ -109,59 +106,6 @@ public class ImageConverterSVG2G2D extends AbstractImageConverter { | |||
}; | |||
} | |||
/** | |||
* A generic graphics 2D image painter implementation | |||
*/ | |||
protected class GenericGraphics2DImagePainter implements Graphics2DImagePainter { | |||
private final ImageXMLDOM svg; | |||
private final BridgeContext ctx; | |||
private final GraphicsNode root; | |||
/** | |||
* Constructor | |||
* | |||
* @param svg the svg image dom | |||
* @param ctx the bridge context | |||
* @param root the graphics node root | |||
*/ | |||
public GenericGraphics2DImagePainter(ImageXMLDOM svg, BridgeContext ctx, GraphicsNode root) { | |||
this.svg = svg; | |||
this.ctx = ctx; | |||
this.root = root; | |||
} | |||
protected void init(Graphics2D g2d, Rectangle2D area) { | |||
// If no viewbox is defined in the svg file, a viewbox of 100x100 is | |||
// assumed, as defined in SVGUserAgent.getViewportSize() | |||
double tx = area.getX(); | |||
double ty = area.getY(); | |||
if (tx != 0 || ty != 0) { | |||
g2d.translate(tx, ty); | |||
} | |||
float iw = (float) ctx.getDocumentSize().getWidth(); | |||
float ih = (float) ctx.getDocumentSize().getHeight(); | |||
float w = (float) area.getWidth(); | |||
float h = (float) area.getHeight(); | |||
float sx = w / iw; | |||
float sy = h / ih; | |||
if (sx != 1.0 || sy != 1.0) { | |||
g2d.scale(sx, sy); | |||
} | |||
} | |||
public void paint(Graphics2D g2d, Rectangle2D area) { | |||
init(g2d, area); | |||
root.paint(g2d); | |||
} | |||
public Dimension getImageSize() { | |||
return new Dimension(svg.getSize().getWidthMpt(), svg.getSize().getHeightMpt()); | |||
} | |||
} | |||
/** | |||
* Creates a Graphics 2D image painter | |||
* |
@@ -123,12 +123,17 @@ public class AFPDataObjectFactory { | |||
* @return a new graphics object | |||
*/ | |||
public GraphicsObject createGraphic(AFPGraphicsObjectInfo graphicsObjectInfo) { | |||
// set newly created graphics object in g2d | |||
GraphicsObject graphicsObj = factory.createGraphicsObject(); | |||
AFPGraphics2D g2d = graphicsObjectInfo.getGraphics2D(); | |||
g2d.setGraphicsObject(graphicsObj); | |||
// paint to graphics object | |||
Graphics2DImagePainter painter = graphicsObjectInfo.getPainter(); | |||
Rectangle2D area = graphicsObjectInfo.getArea(); | |||
painter.paint(g2d, area); | |||
// return painted graphics object | |||
return graphicsObj; | |||
} | |||
@@ -153,7 +158,7 @@ public class AFPDataObjectFactory { | |||
// object container | |||
includeObj.setObjectType(IncludeObject.TYPE_OTHER); | |||
// set mandatory object classification | |||
// set mandatory object classification (type other) | |||
Registry.ObjectType objectType = dataObjectInfo.getObjectType(); | |||
if (objectType != null) { | |||
// set object classification |
@@ -70,6 +70,19 @@ public class AFPGraphics2D extends AbstractGraphics2D { | |||
private static final Log log = LogFactory.getLog(AFPGraphics2D.class); | |||
private static final int X = 0; | |||
private static final int Y = 1; | |||
private static final int X1 = 0; | |||
private static final int Y1 = 1; | |||
private static final int X2 = 2; | |||
private static final int Y2 = 3; | |||
/** graphics object */ | |||
private GraphicsObject graphicsObj = null; | |||
@@ -204,12 +217,14 @@ public class AFPGraphics2D extends AbstractGraphics2D { | |||
if (!fill) { | |||
graphicsObj.newSegment(); | |||
} | |||
Color col = getColor(); | |||
if (state.setColor(col)) { | |||
graphicsObj.setColor(col); | |||
Color color = getColor(); | |||
if (state.setColor(color)) { | |||
graphicsObj.setColor(color); | |||
} | |||
applyStroke(getStroke()); | |||
Stroke stroke = getStroke(); | |||
applyStroke(stroke); | |||
if (fill) { | |||
graphicsObj.beginArea(); | |||
@@ -217,47 +232,47 @@ public class AFPGraphics2D extends AbstractGraphics2D { | |||
AffineTransform trans = super.getTransform(); | |||
PathIterator iter = shape.getPathIterator(trans); | |||
double[] vals = new double[6]; | |||
double[] dstPts = new double[6]; | |||
int[] coords = null; | |||
if (shape instanceof Line2D) { | |||
iter.currentSegment(vals); | |||
iter.currentSegment(dstPts); | |||
coords = new int[4]; | |||
coords[0] = (int) Math.round(vals[0]); //x1 | |||
coords[1] = (int) Math.round(vals[1]); //y1 | |||
coords[X1] = (int) Math.round(dstPts[X]); | |||
coords[Y1] = (int) Math.round(dstPts[Y]); | |||
iter.next(); | |||
iter.currentSegment(vals); | |||
coords[2] = (int) Math.round(vals[0]); //x2 | |||
coords[3] = (int) Math.round(vals[1]); //y2 | |||
iter.currentSegment(dstPts); | |||
coords[X2] = (int) Math.round(dstPts[X]); | |||
coords[Y2] = (int) Math.round(dstPts[Y]); | |||
graphicsObj.addLine(coords); | |||
} else if (shape instanceof Rectangle2D) { | |||
iter.currentSegment(vals); | |||
iter.currentSegment(dstPts); | |||
coords = new int[4]; | |||
coords[2] = (int) Math.round(vals[0]); //x1 | |||
coords[3] = (int) Math.round(vals[1]); //y1 | |||
coords[X2] = (int) Math.round(dstPts[X]); | |||
coords[Y2] = (int) Math.round(dstPts[Y]); | |||
iter.next(); | |||
iter.next(); | |||
iter.currentSegment(vals); | |||
coords[0] = (int) Math.round(vals[0]); //x2 | |||
coords[1] = (int) Math.round(vals[1]); //y2 | |||
iter.currentSegment(dstPts); | |||
coords[X1] = (int) Math.round(dstPts[X]); | |||
coords[Y1] = (int) Math.round(dstPts[Y]); | |||
graphicsObj.addBox(coords); | |||
} else if (shape instanceof Ellipse2D) { | |||
Ellipse2D elip = (Ellipse2D) shape; | |||
int resolution = info.getResolution(); | |||
final double factor = resolution / 100f; | |||
double scale = trans.getScaleX(); | |||
double radiusWidth = elip.getWidth() / 2; | |||
double radiusHeight = elip.getHeight() / 2; | |||
graphicsObj.setArcParams( | |||
(int)Math.round(elip.getWidth() * factor), | |||
(int)Math.round(elip.getHeight() * factor), | |||
(int)Math.round(radiusWidth * scale), | |||
(int)Math.round(radiusHeight * scale), | |||
0, | |||
0 | |||
); | |||
trans.transform( | |||
new double[] {elip.getCenterX(), elip.getCenterY()}, 0, | |||
vals, 0, 1); | |||
double[] srcPts = new double[] {elip.getCenterX(), elip.getCenterY()}; | |||
trans.transform(srcPts, 0, dstPts, 0, 1); | |||
final int mh = 1; | |||
final int mhr = 0; | |||
graphicsObj.addFullArc( | |||
(int)Math.round(vals[0]), | |||
(int)Math.round(vals[1]), | |||
(int)Math.round(dstPts[X]), | |||
(int)Math.round(dstPts[Y]), | |||
mh, | |||
mhr | |||
); | |||
@@ -268,10 +283,10 @@ public class AFPGraphics2D extends AbstractGraphics2D { | |||
!iter.isDone(); iter.next()) { | |||
// round the coordinate values and combine with current position | |||
// coordinates | |||
int type = iter.currentSegment(vals); | |||
int type = iter.currentSegment(dstPts); | |||
if (type == PathIterator.SEG_MOVETO) { | |||
openingCoords[0] = currCoords[0] = (int)Math.round(vals[0]); | |||
openingCoords[1] = currCoords[1] = (int)Math.round(vals[1]); | |||
openingCoords[X] = currCoords[X] = (int)Math.round(dstPts[X]); | |||
openingCoords[Y] = currCoords[Y] = (int)Math.round(dstPts[Y]); | |||
} else { | |||
int numCoords; | |||
if (type == PathIterator.SEG_LINETO) { | |||
@@ -284,10 +299,10 @@ public class AFPGraphics2D extends AbstractGraphics2D { | |||
// close of the graphics segment | |||
if (type == PathIterator.SEG_CLOSE) { | |||
coords = new int[] { | |||
coords[coords.length - 2], | |||
coords[coords.length - 1], | |||
openingCoords[0], | |||
openingCoords[1] | |||
coords[coords.length - 2], //prev X | |||
coords[coords.length - 1], //prev Y | |||
openingCoords[X], | |||
openingCoords[Y] | |||
}; | |||
graphicsObj.addLine(coords); | |||
} else { | |||
@@ -299,10 +314,10 @@ public class AFPGraphics2D extends AbstractGraphics2D { | |||
// combine current position coordinates with new graphics | |||
// segment coordinates | |||
coords = new int[numCoords + 2]; | |||
coords[0] = currCoords[0]; | |||
coords[1] = currCoords[1]; | |||
coords[X] = currCoords[X]; | |||
coords[Y] = currCoords[Y]; | |||
for (int i = 0; i < numCoords; i++) { | |||
coords[i + 2] = (int) Math.round(vals[i]); | |||
coords[i + 2] = (int) Math.round(dstPts[i]); | |||
} | |||
if (type == PathIterator.SEG_LINETO) { | |||
graphicsObj.addLine(coords); | |||
@@ -311,8 +326,8 @@ public class AFPGraphics2D extends AbstractGraphics2D { | |||
graphicsObj.addFillet(coords); | |||
} | |||
// update current position coordinates | |||
currCoords[0] = coords[coords.length - 2]; | |||
currCoords[1] = coords[coords.length - 1]; | |||
currCoords[X] = coords[coords.length - 2]; | |||
currCoords[Y] = coords[coords.length - 1]; | |||
} | |||
} | |||
} | |||
@@ -346,12 +361,12 @@ public class AFPGraphics2D extends AbstractGraphics2D { | |||
} | |||
/** {@inheritDoc} */ | |||
public void drawString(String s, float x, float y) { | |||
public void drawString(String str, float x, float y) { | |||
try { | |||
if (customTextHandler != null && !textAsShapes) { | |||
customTextHandler.drawString(s, x, y); | |||
customTextHandler.drawString(str, x, y); | |||
} else { | |||
fallbackTextHandler.drawString(s, x, y); | |||
fallbackTextHandler.drawString(str, x, y); | |||
} | |||
} catch (IOException ioe) { | |||
handleIOException(ioe); | |||
@@ -388,10 +403,6 @@ public class AFPGraphics2D extends AbstractGraphics2D { | |||
BufferedImage.TYPE_INT_ARGB); | |||
} | |||
private static final int X = 0; | |||
private static final int Y = 1; | |||
private AFPImageObjectInfo getImageObjectInfo( | |||
RenderedImage img, int x, int y, int width, int height) throws IOException { | |||
ImageInfo imageInfo = new ImageInfo(null, "image/unknown"); | |||
@@ -568,4 +579,4 @@ public class AFPGraphics2D extends AbstractGraphics2D { | |||
this.state = state; | |||
} | |||
} | |||
} |
@@ -0,0 +1,74 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp; | |||
import java.awt.Graphics2D; | |||
import java.awt.geom.Rectangle2D; | |||
import org.apache.batik.bridge.BridgeContext; | |||
import org.apache.batik.gvt.GraphicsNode; | |||
import org.apache.fop.image.loader.batik.GenericGraphics2DImagePainter; | |||
import org.apache.fop.image.loader.batik.ImageConverterSVG2G2D; | |||
import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM; | |||
import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; | |||
public class AFPImageConverterSVG2G2D extends ImageConverterSVG2G2D { | |||
/** {@inheritDoc} */ | |||
protected Graphics2DImagePainter createPainter( | |||
final ImageXMLDOM svg, final BridgeContext ctx, final GraphicsNode root) { | |||
return new AFPGraphics2DImagePainter(svg, ctx, root); | |||
} | |||
private class AFPGraphics2DImagePainter extends GenericGraphics2DImagePainter { | |||
/** | |||
* Constructor | |||
* | |||
* @param svg the svg image dom | |||
* @param ctx the bridge context | |||
* @param root the graphics node root | |||
*/ | |||
public AFPGraphics2DImagePainter(ImageXMLDOM svg, BridgeContext ctx, | |||
GraphicsNode root) { | |||
super(svg, ctx, root); | |||
} | |||
/** {@inheritDoc} */ | |||
protected void init(Graphics2D g2d, Rectangle2D area) { | |||
float iw = (float) ctx.getDocumentSize().getWidth(); | |||
float ih = (float) ctx.getDocumentSize().getHeight(); | |||
float w = (float) area.getWidth(); | |||
float h = (float) area.getHeight(); | |||
float sx = w / iw; | |||
float sy = -(h / ih); | |||
if (sx != 1.0 || sy != 1.0) { | |||
g2d.scale(sx, sy); | |||
} | |||
double tx = area.getX(); | |||
double ty = area.getY() - area.getHeight(); | |||
if (tx != 0 || ty != 0) { | |||
g2d.translate(tx, ty); | |||
} | |||
} | |||
} | |||
} |
@@ -19,11 +19,16 @@ | |||
package org.apache.fop.render.afp; | |||
import java.awt.Graphics2D; | |||
import java.awt.Rectangle; | |||
import java.awt.geom.AffineTransform; | |||
import java.awt.geom.Rectangle2D; | |||
import java.io.IOException; | |||
import org.apache.batik.bridge.BridgeContext; | |||
import org.apache.fop.image.loader.batik.GenericGraphics2DImagePainter; | |||
import org.apache.fop.svg.SVGUserAgent; | |||
import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D; | |||
import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; | |||
import org.apache.xmlgraphics.util.MimeConstants; | |||
@@ -57,15 +62,41 @@ public class AFPImageGraphics2DFactory extends AFPDataObjectInfoFactory { | |||
// set graphics 2d | |||
AFPGraphics2DAdapter g2dAdapter = afpImageInfo.g2dAdapter; | |||
AFPGraphics2D g2d = g2dAdapter.getGraphics2D(); | |||
graphicsObjectInfo.setGraphics2D(g2d); | |||
// set afp info | |||
AFPInfo afpInfo = AFPSVGHandler.getAFPInfo(afpImageInfo.rendererContext); | |||
g2d.setAFPInfo(afpInfo); | |||
// set to default graphic context | |||
g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); | |||
// translate to current location | |||
AffineTransform at = state.getData().getTransform(); | |||
g2d.translate(at.getTranslateX(), at.getTranslateY()); | |||
// set afp state | |||
g2d.setState(state); | |||
graphicsObjectInfo.setGraphics2D(g2d); | |||
// controls whether text painted by Batik is generated using text or path operations | |||
SVGUserAgent svgUserAgent | |||
= new SVGUserAgent(afpImageInfo.rendererContext.getUserAgent(), new AffineTransform()); | |||
BridgeContext ctx = new BridgeContext(svgUserAgent); | |||
if (!afpInfo.strokeText()) { | |||
AFPTextHandler textHandler = new AFPTextHandler(g2d); | |||
g2d.setCustomTextHandler(textHandler); | |||
AFPTextPainter textPainter = new AFPTextPainter(textHandler); | |||
ctx.setTextPainter(textPainter); | |||
AFPTextElementBridge textElementBridge = new AFPTextElementBridge(textPainter); | |||
ctx.putBridge(textElementBridge); | |||
} | |||
// set painter | |||
ImageGraphics2D imageG2D = (ImageGraphics2D)afpImageInfo.img; | |||
Graphics2DImagePainter painter = imageG2D.getGraphics2DImagePainter(); | |||
GenericGraphics2DImagePainter painter | |||
= (GenericGraphics2DImagePainter)imageG2D.getGraphics2DImagePainter(); | |||
painter = new AFPGraphics2DImagePainter(painter); | |||
imageG2D.setGraphics2DImagePainter(painter); | |||
graphicsObjectInfo.setPainter(painter); | |||
// set object area | |||
@@ -76,4 +107,35 @@ public class AFPImageGraphics2DFactory extends AFPDataObjectInfoFactory { | |||
return graphicsObjectInfo; | |||
} | |||
private class AFPGraphics2DImagePainter extends GenericGraphics2DImagePainter { | |||
/** | |||
* Copy constructor | |||
* | |||
* @param painter a graphics 2D image painter | |||
*/ | |||
public AFPGraphics2DImagePainter(GenericGraphics2DImagePainter painter) { | |||
super(painter.getImageXMLDOM(), painter.getBridgeContext(), painter.getRoot()); | |||
} | |||
/** {@inheritDoc} */ | |||
protected void init(Graphics2D g2d, Rectangle2D area) { | |||
double tx = area.getX(); | |||
double ty = area.getHeight() - area.getY(); | |||
if (tx != 0 || ty != 0) { | |||
g2d.translate(tx, ty); | |||
} | |||
float iw = (float) ctx.getDocumentSize().getWidth(); | |||
float ih = (float) ctx.getDocumentSize().getHeight(); | |||
float w = (float) area.getWidth(); | |||
float h = (float) area.getHeight(); | |||
float sx = w / iw; | |||
float sy = -(h / ih); | |||
if (sx != 1.0 || sy != 1.0) { | |||
g2d.scale(sx, sy); | |||
} | |||
} | |||
} | |||
} |
@@ -244,6 +244,19 @@ public final class AFPInfo { | |||
return this.paintAsBitmap; | |||
} | |||
/** | |||
* Returns true if text should be stroked when painted | |||
* | |||
* @return true if text should be stroked when painted | |||
*/ | |||
public boolean strokeText() { | |||
boolean strokeText = false; | |||
if (handlerConfiguration != null) { | |||
strokeText = handlerConfiguration.getChild("stroke-text", true).getValueAsBoolean(strokeText); | |||
} | |||
return strokeText; | |||
} | |||
/** | |||
* Sets the resource information | |||
* |
@@ -167,20 +167,12 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { | |||
AFPBatikGraphicsObjectPainter painter = new AFPBatikGraphicsObjectPainter(g2d); | |||
(graphicsObjectInfo).setPainter(painter); | |||
boolean strokeText = false; | |||
Configuration cfg = afpInfo.getHandlerConfiguration(); | |||
if (cfg != null) { | |||
strokeText = cfg.getChild("stroke-text", true).getValueAsBoolean(strokeText); | |||
} | |||
// Controls whether text painted by Batik is generated using text or path operations | |||
SVGUserAgent svgUserAgent | |||
= new SVGUserAgent(context.getUserAgent(), new AffineTransform()); | |||
BridgeContext ctx = new BridgeContext(svgUserAgent); | |||
AFPTextHandler afpTextHandler = null; | |||
//Controls whether text painted by Batik is generated using text or path operations | |||
if (!strokeText) { | |||
afpTextHandler = new AFPTextHandler(g2d); | |||
if (!afpInfo.strokeText()) { | |||
AFPTextHandler afpTextHandler = new AFPTextHandler(g2d); | |||
g2d.setCustomTextHandler(afpTextHandler); | |||
AFPTextPainter textPainter = new AFPTextPainter(afpTextHandler); | |||
ctx.setTextPainter(textPainter); |
@@ -28,7 +28,6 @@ import org.apache.fop.fonts.Font; | |||
import org.apache.fop.fonts.FontInfo; | |||
import org.apache.fop.render.afp.fonts.AFPFont; | |||
import org.apache.fop.render.afp.modca.GraphicsObject; | |||
import org.apache.xmlgraphics.java2d.TextHandler; | |||
/** | |||
@@ -41,12 +40,12 @@ public class AFPTextHandler implements TextHandler { | |||
private static Log log = LogFactory.getLog(AFPTextHandler.class); | |||
private AFPGraphics2D g2d = null; | |||
/** Overriding FontState */ | |||
protected Font overrideFont = null; | |||
/** current state */ | |||
private AFPState afpState = null; | |||
private AFPState state = null; | |||
/** | |||
* Main constructor. | |||
@@ -54,9 +53,9 @@ public class AFPTextHandler implements TextHandler { | |||
*/ | |||
public AFPTextHandler(AFPGraphics2D g2d) { | |||
this.g2d = g2d; | |||
this.afpState = g2d.getAFPInfo().getState(); | |||
this.state = g2d.getAFPInfo().getState(); | |||
} | |||
/** | |||
* Return the font information associated with this object | |||
* @return the FontInfo object | |||
@@ -64,25 +63,25 @@ public class AFPTextHandler implements TextHandler { | |||
public FontInfo getFontInfo() { | |||
return g2d.getAFPInfo().getFontInfo(); | |||
} | |||
/** | |||
* Add a text string to the current data object of the AFP datastream. | |||
* The text is painted using text operations. | |||
* {@inheritDoc} | |||
* {@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(); | |||
if (afpState.setColor(col)) { | |||
if (state.setColor(col)) { | |||
graphicsObj.setColor(col); | |||
} | |||
if (overrideFont != null) { | |||
FontInfo fontInfo = getFontInfo(); | |||
AFPPageFonts pageFonts = afpState.getPageFonts(); | |||
AFPPageFonts pageFonts = state.getPageFonts(); | |||
String internalFontName = overrideFont.getFontName(); | |||
int fontSize = overrideFont.getFontSize(); | |||
if (afpState.setFontName(internalFontName) || afpState.setFontSize(fontSize)) { | |||
if (state.setFontName(internalFontName) || state.setFontSize(fontSize)) { | |||
AFPFont font = (AFPFont)fontInfo.getFonts().get(internalFontName); | |||
AFPFontAttributes afpFontAttributes = pageFonts.registerFont( | |||
internalFontName, | |||
@@ -90,17 +89,17 @@ public class AFPTextHandler implements TextHandler { | |||
fontSize | |||
); | |||
int fontReference = afpFontAttributes.getFontReference(); | |||
graphicsObj.setCharacterSet(fontReference); | |||
graphicsObj.setCharacterSet(fontReference); | |||
} | |||
} | |||
graphicsObj.addString(str, (int)Math.round(x), (int)Math.round(y)); | |||
graphicsObj.addString(str, Math.round(x), Math.round(y)); | |||
} | |||
/** | |||
* Sets the overriding font. | |||
* @param overrideFont Overriding Font to set | |||
*/ | |||
public void setOverrideFont(Font overrideFont) { | |||
this.overrideFont = overrideFont; | |||
} | |||
this.overrideFont = overrideFont; | |||
} | |||
} |
@@ -23,22 +23,21 @@ import java.awt.Color; | |||
import java.awt.color.ColorSpace; | |||
import org.apache.fop.render.afp.modca.AbstractPreparedAFPObject; | |||
import org.apache.fop.render.afp.modca.GraphicsObject; | |||
/** | |||
* Sets the current processing color for the following GOCA structured fields | |||
*/ | |||
public class GraphicsSetProcessColor extends AbstractPreparedAFPObject { | |||
/** the color to set */ | |||
private final Color col; | |||
private final Color color; | |||
/** | |||
* Main constructor | |||
* | |||
* @param col the color to set | |||
* @param color the color to set | |||
*/ | |||
public GraphicsSetProcessColor(Color col) { | |||
this.col = col; | |||
public GraphicsSetProcessColor(Color color) { | |||
this.color = color; | |||
prepareData(); | |||
} | |||
@@ -46,18 +45,18 @@ public class GraphicsSetProcessColor extends AbstractPreparedAFPObject { | |||
protected void prepareData() { | |||
// COLSPCE | |||
byte colspace; | |||
int colSpaceType = col.getColorSpace().getType(); | |||
int colSpaceType = color.getColorSpace().getType(); | |||
if (colSpaceType == ColorSpace.TYPE_CMYK) { | |||
colspace = 0x04; | |||
} else if (colSpaceType == ColorSpace.TYPE_RGB) { | |||
colspace = 0x01; | |||
} else { | |||
GraphicsObject.log.error("unsupported colorspace " + colSpaceType); | |||
log.error("unsupported colorspace " + colSpaceType); | |||
colspace = 0x01; | |||
} | |||
// COLSIZE(S) | |||
float[] colcomp = col.getColorComponents(null); | |||
float[] colcomp = color.getColorComponents(null); | |||
byte[] colsizes = new byte[] {0x00, 0x00, 0x00, 0x00}; | |||
for (int i = 0; i < colcomp.length; i++) { | |||
colsizes[i] = (byte)8; | |||
@@ -85,6 +84,6 @@ public class GraphicsSetProcessColor extends AbstractPreparedAFPObject { | |||
/** {@inheritDoc} */ | |||
public String toString() { | |||
return "GraphicsSetProcessColor(col=" + col + ")"; | |||
return "GraphicsSetProcessColor(col=" + color + ")"; | |||
} | |||
} |
@@ -23,7 +23,6 @@ import java.io.UnsupportedEncodingException; | |||
import org.apache.fop.render.afp.AFPConstants; | |||
import org.apache.fop.render.afp.modca.AbstractPreparedAFPObject; | |||
import org.apache.fop.render.afp.modca.GraphicsObject; | |||
import org.apache.fop.render.afp.tools.BinaryUtils; | |||
/** | |||
@@ -81,7 +80,7 @@ public class GraphicsString extends AbstractPreparedAFPObject { | |||
try { | |||
strData = str.getBytes(AFPConstants.EBCIDIC_ENCODING); | |||
} catch (UnsupportedEncodingException ex) { | |||
GraphicsObject.log.error("unsupported encoding: " + ex.getMessage()); | |||
log.error("unsupported encoding: " + ex.getMessage()); | |||
} | |||
int len = strData.length; | |||
if (fromCurrentPosition) { |