import java.util.List;
import java.util.Map;
-import org.w3c.dom.Document;
-
import org.apache.batik.parser.AWTTransformProducer;
-
-import org.apache.xmlgraphics.image.loader.ImageSize;
-import org.apache.xmlgraphics.util.QName;
-
import org.apache.fop.area.Area;
import org.apache.fop.area.Block;
import org.apache.fop.area.BlockViewport;
import org.apache.fop.fo.extensions.ExtensionElementMapping;
import org.apache.fop.fonts.FontMetrics;
import org.apache.fop.traits.BorderProps;
+import org.apache.xmlgraphics.image.loader.ImageSize;
+import org.apache.xmlgraphics.util.QName;
import org.apache.xmlgraphics.util.UnitConv;
+import org.w3c.dom.Document;
/**
* Abstract base class for renderers like PDF and PostScript where many painting operations
* @param bpsAfter the border specification on the after side
* @param bpsStart the border specification on the start side
* @param bpsEnd the border specification on the end side
- */
+ */
protected void drawBorders(Rectangle2D.Float borderRect,
BorderProps bpsBefore, BorderProps bpsAfter, BorderProps bpsStart, BorderProps bpsEnd) {
//TODO generalize each of the four conditions into using a parameterized drawBorder()
boolean[] border = new boolean[] {
- (bpsBefore != null), (bpsEnd != null),
+ (bpsBefore != null), (bpsEnd != null),
(bpsAfter != null), (bpsStart != null)};
float startx = borderRect.x;
float starty = borderRect.y;
positionTransform.concatenate(freeTransform);
}
- saveGraphicsState();
//Viewport position
- concatenateTransformationMatrix(UnitConv.mptToPt(positionTransform));
+ if (!positionTransform.isIdentity()) {
+ establishTransformationMatrix(positionTransform);
+ }
//Background and borders
float bpwidth = (borderPaddingStart + bv.getBorderAndPaddingWidthEnd()) / 1000f;
clipRect(0f, 0f, width, height);
}
- saveGraphicsState();
//Set up coordinate system for content rectangle
AffineTransform contentTransform = ctm.toAffineTransform();
- concatenateTransformationMatrix(UnitConv.mptToPt(contentTransform));
+ if (!contentTransform.isIdentity()) {
+ establishTransformationMatrix(contentTransform);
+ }
currentIPPosition = 0;
currentBPPosition = 0;
renderBlocks(bv, children);
- restoreGraphicsState();
- restoreGraphicsState();
+ if (!positionTransform.isIdentity()) {
+ restoreGraphicsState();
+ }
+
+ if (!contentTransform.isIdentity()) {
+ restoreGraphicsState();
+ }
if (breakOutList != null) {
restoreStateStackAfterBreakOut(breakOutList);
at.translate(0, block.getSpaceBefore());
if (!at.isIdentity()) {
- saveGraphicsState();
- concatenateTransformationMatrix(UnitConv.mptToPt(at));
+ establishTransformationMatrix(at);
}
currentIPPosition = 0;
at.translate(currentIPPosition, currentBPPosition);
if (!at.isIdentity()) {
- saveGraphicsState();
- concatenateTransformationMatrix(UnitConv.mptToPt(at));
+ establishTransformationMatrix(at);
}
currentIPPosition = 0;
renderDocument(doc, ns, pos, fo.getForeignAttributes());
}
+ /**
+ * Establishes a new coordinate system with the given transformation matrix.
+ * The current graphics state is saved and the new coordinate system is concatenated.
+ * @param block
+ *
+ * @param at the transformation matrix
+ */
+ protected void establishTransformationMatrix(AffineTransform at) {
+ saveGraphicsState();
+ concatenateTransformationMatrix(UnitConv.mptToPt(at));
+ }
+
}
/**
* Concatenates the given AffineTransform to the current one.
*
- * @param tf the transform to concatenate to the current level transform
+ * @param at the transform to concatenate to the current level transform
*/
- public void concatenate(AffineTransform tf) {
- getData().concatenate(tf);
+ public void concatenate(AffineTransform at) {
+ getData().concatenate(at);
}
/**
// transform = new AffineTransform();
}
+ /**
+ * Returns the derived rotation from the current transform
+ *
+ * @return the derived rotation from the current transform
+ */
+ public int getDerivedRotation() {
+ AffineTransform at = getTransform();
+ double sx = at.getScaleX();
+ double sy = at.getScaleY();
+ double shx = at.getShearX();
+ double shy = at.getShearY();
+ int rotation = 0;
+ if (sx == 0 && sy == 0 && shx > 0 && shy < 0) {
+ rotation = 270;
+ } else if (sx < 0 && sy < 0 && shx == 0 && shy == 0) {
+ rotation = 180;
+ } else if (sx == 0 && sy == 0 && shx < 0 && shy > 0) {
+ rotation = 90;
+ } else {
+ rotation = 0;
+ }
+ return rotation;
+ }
+
/** {@inheritDoc} */
public Object clone() {
AbstractData data = instantiateData();
--- /dev/null
+/*
+ * 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 org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.render.afp.modca.GraphicsObject;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+
+/**
+ * A simple AFP Graphics 2D painter
+ */
+public abstract class AFPAbstractGraphicsObjectPainter implements Graphics2DImagePainter {
+ /** Static logging instance */
+ protected static Log log = LogFactory.getLog(AFPAbstractGraphicsObjectPainter.class);
+
+ private final AFPGraphics2D graphics2D;
+
+ /**
+ * Default constructor
+ */
+ public AFPAbstractGraphicsObjectPainter() {
+ final boolean textAsShapes = false;
+ this.graphics2D = new AFPGraphics2D(textAsShapes);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param graphics the afp graphics 2d implementation
+ */
+ public AFPAbstractGraphicsObjectPainter(AFPGraphics2D graphics) {
+ this.graphics2D = graphics;
+ }
+
+ /**
+ * Sets the GOCA Graphics Object
+ *
+ * @param graphicsObject the GOCA Graphics Object
+ */
+ public void setGraphicsObject(GraphicsObject graphicsObject) {
+ this.graphics2D.setGraphicsObject(graphicsObject);
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.Dimension;
+import java.awt.Graphics2D;
+import java.awt.geom.Rectangle2D;
+
+import org.apache.batik.gvt.GraphicsNode;
+
+/**
+ * Paints SVG as a GOCA Graphics Object using Batik
+ */
+public class AFPBatikGraphicsObjectPainter extends AFPAbstractGraphicsObjectPainter {
+
+ /** the batik root node of the svg document */
+ private GraphicsNode root;
+
+ /**
+ * Main constructor
+ *
+ * @param graphics an AFP graphics 2D implementation
+ */
+ public AFPBatikGraphicsObjectPainter(AFPGraphics2D graphics) {
+ super(graphics);
+ }
+
+ /**
+ * Sets the graphics node
+ *
+ * @param rootNode the graphics root node
+ */
+ public void setGraphicsNode(GraphicsNode rootNode) {
+ this.root = rootNode;
+ }
+
+ /** {@inheritDoc} */
+ public void paint(Graphics2D g2d, Rectangle2D area) {
+ log.debug("Painting SVG using GOCA");
+
+ // tell batik to paint the graphics object
+ root.paint(g2d);
+
+ // dispose of the graphics 2d implementation
+ g2d.dispose();
+ }
+
+ /** {@inheritDoc} */
+ public Dimension getImageSize() {
+ return null;
+ }
+
+}
* limitations under the License.
*/
-/* $Id: $ */
+/* $Id$ */
package org.apache.fop.render.afp;
/** Static logging instance */
protected static Log log = LogFactory.getLog("org.apache.fop.render.afp");
- private static final int X1 = 0;
- private static final int Y1 = 1;
- private static final int X2 = 2;
- private static final int Y2 = 3;
-
- private final AFPUnitConverter unitConv;
private final DataStream dataStream;
private final AFPState state;
*/
public AFPBorderPainter(AFPState state, DataStream dataStream) {
this.state = state;
- this.unitConv = state.getUnitConverter();
this.dataStream = dataStream;
}
/** {@inheritDoc} */
public void fillRect(float x, float y, float width, float height) {
+ int pageWidth = dataStream.getCurrentPage().getWidth();
+ int pageHeight = dataStream.getCurrentPage().getHeight();
+
+ AFPUnitConverter unitConv = state.getUnitConverter();
+ width = unitConv.pt2units(width);
+ height = unitConv.pt2units(height);
+ x = unitConv.pt2units(x);
+ y = unitConv.pt2units(y);
+
AffineTransform at = state.getData().getTransform();
- float transX = (float)at.getTranslateX();
- float transY = (float)at.getTranslateY();
- int x1 = Math.round(transX + unitConv.pt2units(x));
- int y1 = Math.round(transY + unitConv.pt2units(y));
- int x2 = Math.round(transX + unitConv.pt2units(x) + unitConv.pt2units(width));
- LineDataInfo lineDataInfo = new LineDataInfo();
- lineDataInfo.x1 = x1;
- lineDataInfo.y1 = y1;
- lineDataInfo.x2 = x2;
- lineDataInfo.y2 = y1;
- lineDataInfo.thickness = Math.round(unitConv.pt2units(height));
+
+ AFPLineDataInfo lineDataInfo = new AFPLineDataInfo();
lineDataInfo.color = state.getColor();
+ lineDataInfo.rotation = state.getRotation();
+ lineDataInfo.thickness = Math.round(height);
+
+ switch (lineDataInfo.rotation) {
+ case 0:
+ lineDataInfo.x1 = Math.round((float)at.getTranslateX() + x);
+ lineDataInfo.y1 = lineDataInfo.y2 = Math.round((float)at.getTranslateY() + y);
+ lineDataInfo.x2 = Math.round((float)at.getTranslateX() + x + width);
+ break;
+ case 90:
+ lineDataInfo.x1 = Math.round((float)at.getTranslateY() + x);
+ lineDataInfo.y1 = lineDataInfo.y2
+ = pageWidth - Math.round((float)at.getTranslateX() + y);
+ lineDataInfo.x2 = Math.round(width + (float)at.getTranslateY() + x);
+ break;
+ case 180:
+ lineDataInfo.x1 = pageWidth - Math.round((float)at.getTranslateX() - x);
+ lineDataInfo.y1 = lineDataInfo.y2 = pageHeight - Math.round((float)at.getTranslateY() - x);
+ lineDataInfo.x2 = pageWidth - Math.round((float)at.getTranslateX() - x - width);
+ break;
+ case 270:
+ lineDataInfo.x1 = pageHeight - Math.round((float)at.getTranslateY() + y - x);
+ lineDataInfo.y1 = lineDataInfo.y2 = Math.round((float)at.getTranslateX() + y);
+ lineDataInfo.x2 = lineDataInfo.x1 + Math.round(width - x);
+ break;
+ }
dataStream.createLine(lineDataInfo);
}
/** {@inheritDoc} */
public void drawBorderLine(float x1, float y1, float x2, float y2,
- boolean horz, boolean startOrBefore, int style, Color col) {
- float[] srcPts = new float[] {x1 * 1000, y1 * 1000, x2 * 1000, y2 * 1000};
- float[] dstPts = new float[srcPts.length];
- int[] coords = unitConv.mpts2units(srcPts, dstPts);
-
- float width = dstPts[X2] - dstPts[X1];
- float height = dstPts[Y2] - dstPts[Y1];
- if ((width < 0) || (height < 0)) {
+ boolean isHorizontal, boolean startOrBefore, int style, Color color) {
+ float w = x2 - x1;
+ float h = y2 - y1;
+ if ((w < 0) || (h < 0)) {
log.error("Negative extent received. Border won't be painted.");
return;
}
- LineDataInfo lineDataInfo = new LineDataInfo();
- lineDataInfo.color = col;
+ int pageWidth = dataStream.getCurrentPage().getWidth();
+ int pageHeight = dataStream.getCurrentPage().getHeight();
+ AFPUnitConverter unitConv = state.getUnitConverter();
+ AffineTransform at = state.getData().getTransform();
+ x1 = unitConv.pt2units(x1);
+ y1 = unitConv.pt2units(y1);
+ x2 = unitConv.pt2units(x2);
+ y2 = unitConv.pt2units(y2);
+
+ switch (state.getRotation()) {
+ case 0:
+ x1 += at.getTranslateX();
+ y1 += at.getTranslateY();
+ x2 += at.getTranslateX();
+ y2 += at.getTranslateY();
+ break;
+ case 90:
+ x1 += at.getTranslateY();
+ y1 += (float) (pageWidth - at.getTranslateX());
+ x2 += at.getTranslateY();
+ y2 += (float) (pageWidth - at.getTranslateX());
+ break;
+ case 180:
+ x1 += (float) (pageWidth - at.getTranslateX());
+ y1 += (float) (pageHeight - at.getTranslateY());
+ x2 += (float) (pageWidth - at.getTranslateX());
+ y2 += (float) (pageHeight - at.getTranslateY());
+ break;
+ case 270:
+ x1 = (float) (pageHeight - at.getTranslateY());
+ y1 += (float) at.getTranslateX();
+ x2 += x1;
+ y2 += (float) at.getTranslateX();
+ break;
+ }
+
+ AFPLineDataInfo lineDataInfo = new AFPLineDataInfo();
+ lineDataInfo.setThickness(Math.round(y2 - y1));
+ lineDataInfo.setColor(color);
+ lineDataInfo.setRotation(state.getRotation());
+
+ lineDataInfo.x1 = Math.round(x1);
+ lineDataInfo.y1 = Math.round(y1);
+
+ // handle border-*-style
switch (style) {
case Constants.EN_DOUBLE:
- lineDataInfo.x1 = coords[X1];
- lineDataInfo.y1 = coords[Y1];
- if (horz) {
- float h3 = height / 3;
- lineDataInfo.thickness = Math.round(h3);
- lineDataInfo.x2 = coords[X2];
- lineDataInfo.y2 = coords[Y1];
- dataStream.createLine(lineDataInfo);
- int ym2 = Math.round(dstPts[Y1] + h3 + h3);
- lineDataInfo.y1 = ym2;
- lineDataInfo.y2 = ym2;
- dataStream.createLine(lineDataInfo);
- } else {
- float w3 = width / 3;
- lineDataInfo.thickness = Math.round(w3);
- lineDataInfo.x2 = coords[X1];
- lineDataInfo.y2 = coords[Y2];
- dataStream.createLine(lineDataInfo);
- int xm2 = Math.round(dstPts[X1] + w3 + w3);
- lineDataInfo.x1 = xm2;
- lineDataInfo.x2 = xm2;
- dataStream.createLine(lineDataInfo);
- }
+ lineDataInfo.x2 = Math.round(x2);
+ lineDataInfo.y2 = lineDataInfo.y1;
+ dataStream.createLine(lineDataInfo);
+ float w3 = lineDataInfo.thickness / 3;
+ lineDataInfo.y1 += Math.round(w3 * 2);
+ dataStream.createLine(lineDataInfo);
break;
-
case Constants.EN_DASHED:
- lineDataInfo.x1 = coords[X1];
- if (horz) {
- float w2 = 2 * height;
- lineDataInfo.y1 = coords[Y1];
- lineDataInfo.x2 = coords[X1] + Math.round(w2);
- lineDataInfo.y2 = coords[Y1];
- lineDataInfo.thickness = Math.round(height);
- while (lineDataInfo.x1 + w2 < coords[X2]) {
- dataStream.createLine(lineDataInfo);
- lineDataInfo.x1 += 2 * w2;
- }
- } else {
- float h2 = 2 * width;
- lineDataInfo.y1 = coords[Y2];
- lineDataInfo.x2 = coords[X1];
- lineDataInfo.y2 = coords[Y1] + Math.round(h2);
- lineDataInfo.thickness = Math.round(width);
- while (lineDataInfo.y2 < coords[Y2]) {
- dataStream.createLine(lineDataInfo);
- lineDataInfo.y2 += 2 * h2;
- }
- }
- break;
-
case Constants.EN_DOTTED:
- lineDataInfo.x1 = coords[X1];
- lineDataInfo.y1 = coords[Y1];
- if (horz) {
- lineDataInfo.thickness = Math.round(height);
- lineDataInfo.x2 = coords[X1] + lineDataInfo.thickness;
- lineDataInfo.y2 = coords[Y1];
- while (lineDataInfo.x2 < coords[X2]) {
- dataStream.createLine(lineDataInfo);
- coords[X1] += 2 * height;
- lineDataInfo.x1 = coords[X1];
- lineDataInfo.x2 = coords[X1] + lineDataInfo.thickness;
- }
- } else {
- lineDataInfo.thickness = Math.round(width);
- lineDataInfo.x2 = coords[X1];
- lineDataInfo.y2 = coords[Y1] + lineDataInfo.thickness;
- while (lineDataInfo.y2 < coords[Y2]) {
- dataStream.createLine(lineDataInfo);
- coords[Y1] += 2 * width;
- lineDataInfo.y1 = coords[Y1];
- lineDataInfo.y2 = coords[Y1] + lineDataInfo.thickness;
- }
+ int factor = style == Constants.EN_DASHED ? 3 : 2;
+ int thick = lineDataInfo.thickness * factor;
+ lineDataInfo.x2 = lineDataInfo.x1 + thick;
+ lineDataInfo.y2 = lineDataInfo.y1;
+ int ex2 = Math.round(x2);
+ while (lineDataInfo.x1 + thick < ex2) {
+ dataStream.createLine(lineDataInfo);
+ lineDataInfo.x1 += 2 * thick;
+ lineDataInfo.x2 = lineDataInfo.x1 + thick;
}
break;
case Constants.EN_GROOVE:
case Constants.EN_RIDGE:
+ lineDataInfo.x2 = Math.round(x2);
float colFactor = (style == Constants.EN_GROOVE ? 0.4f : -0.4f);
- if (horz) {
- lineDataInfo.x1 = coords[X1];
- lineDataInfo.x2 = coords[X2];
- float h3 = height / 3;
- lineDataInfo.color = ColorUtil.lightenColor(col, -colFactor);
- lineDataInfo.thickness = Math.round(h3);
- lineDataInfo.y1 = lineDataInfo.y2 = coords[Y1];
- dataStream.createLine(lineDataInfo);
- lineDataInfo.color = col;
- lineDataInfo.y1 = lineDataInfo.y2 = Math.round(dstPts[Y1] + h3);
- dataStream.createLine(lineDataInfo);
- lineDataInfo.color = ColorUtil.lightenColor(col, colFactor);
- lineDataInfo.y1 = lineDataInfo.y2 = Math.round(dstPts[Y1] + h3 + h3);
- dataStream.createLine(lineDataInfo);
- } else {
- lineDataInfo.y1 = coords[Y1];
- lineDataInfo.y2 = coords[Y2];
- float w3 = width / 3;
- float xm1 = dstPts[X1] + (w3 / 2);
- lineDataInfo.color = ColorUtil.lightenColor(col, -colFactor);
- lineDataInfo.x1 = lineDataInfo.x2 = Math.round(xm1);
- dataStream.createLine(lineDataInfo);
- lineDataInfo.color = col;
- lineDataInfo.x1 = lineDataInfo.x2 = Math.round(xm1 + w3);
- dataStream.createLine(lineDataInfo);
- lineDataInfo.color = ColorUtil.lightenColor(col, colFactor);
- lineDataInfo.x1 = lineDataInfo.x2 = Math.round(xm1 + w3 + w3);
- dataStream.createLine(lineDataInfo);
- }
+ float h3 = (y2 - y1) / 3;
+ lineDataInfo.color = ColorUtil.lightenColor(color, -colFactor);
+ lineDataInfo.thickness = Math.round(h3);
+ lineDataInfo.y1 = lineDataInfo.y2 = Math.round(y1);
+ dataStream.createLine(lineDataInfo);
+ lineDataInfo.color = color;
+ lineDataInfo.y1 = lineDataInfo.y2 = Math.round(y1 + h3);
+ dataStream.createLine(lineDataInfo);
+ lineDataInfo.color = ColorUtil.lightenColor(color, colFactor);
+ lineDataInfo.y1 = lineDataInfo.y2 = Math.round(y1 + h3 + h3);
+ dataStream.createLine(lineDataInfo);
break;
-
case Constants.EN_HIDDEN:
break;
-
case Constants.EN_INSET:
case Constants.EN_OUTSET:
+ case Constants.EN_SOLID:
default:
- lineDataInfo.x1 = coords[X1];
- lineDataInfo.y1 = coords[Y1];
- if (horz) {
- lineDataInfo.thickness = Math.round(height);
- lineDataInfo.x2 = coords[X2];
- lineDataInfo.y2 = coords[Y1];
- } else {
- lineDataInfo.thickness = Math.round(width);
- lineDataInfo.x2 = coords[X1];
- lineDataInfo.y2 = coords[Y2];
- }
- lineDataInfo.x2 = (horz ? coords[X2] : coords[X1]);
- lineDataInfo.y2 = (horz ? coords[Y1] : coords[Y2]);
- dataStream.createLine(lineDataInfo);
+ lineDataInfo.x2 = Math.round(x2);
+ lineDataInfo.y2 = lineDataInfo.y1;
+ dataStream.createLine(lineDataInfo);
}
}
* limitations under the License.
*/
-/* $Id: $ */
+/* $Id$ */
package org.apache.fop.render.afp;
+import java.awt.geom.Rectangle2D;
+
import org.apache.fop.render.afp.ioca.ImageContent;
import org.apache.fop.render.afp.modca.AbstractDataObject;
import org.apache.fop.render.afp.modca.AbstractNamedAFPObject;
import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet;
import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet;
import org.apache.xmlgraphics.image.codec.tiff.TIFFImage;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
/**
* Factory for high level data objects (Image/Graphics etc)
*/
public GraphicsObject createGraphic(AFPGraphicsObjectInfo graphicsObjectInfo) {
GraphicsObject graphicsObj = factory.createGraphicsObject();
- // paint the graphic using batik
- graphicsObjectInfo.getPainter().paint(graphicsObj);
+ AFPGraphics2D g2d = graphicsObjectInfo.getGraphics2D();
+ g2d.setGraphicsObject(graphicsObj);
+ Graphics2DImagePainter painter = graphicsObjectInfo.getPainter();
+ Rectangle2D area = graphicsObjectInfo.getArea();
+ painter.paint(g2d, area);
return graphicsObj;
}
int yOffset = objectAreaInfo.getY();
includeObj.setObjectAreaOffset(xOffset, yOffset);
- includeObj.setObjectAreaSize(
- objectAreaInfo.getWidth(), objectAreaInfo.getHeight());
+ int width = objectAreaInfo.getWidth();
+ int height = objectAreaInfo.getHeight();
+ includeObj.setObjectAreaSize(width, height);
- includeObj.setObjectAreaOrientation(objectAreaInfo.getRotation());
+ int rotation = objectAreaInfo.getRotation();
+ includeObj.setObjectAreaOrientation(rotation);
- includeObj.setMeasurementUnits(
- objectAreaInfo.getWidthRes(), objectAreaInfo.getHeightRes());
+ int widthRes = objectAreaInfo.getWidthRes();
+ int heightRes = objectAreaInfo.getHeightRes();
+ includeObj.setMeasurementUnits(widthRes, heightRes);
includeObj.setMappingOption(MappingOptionTriplet.SCALE_TO_FIT);
// set object area
AFPObjectAreaInfo objectAreaInfo = new AFPObjectAreaInfo();
+
float srcX = afpImageInfo.origin.x + (float)afpImageInfo.pos.getX();
float srcY = afpImageInfo.origin.y + (float)afpImageInfo.pos.getY();
AFPUnitConverter unitConv = state.getUnitConverter();
int[] coords = unitConv.mpts2units(new float[] {srcX, srcY});
objectAreaInfo.setX(coords[X]);
objectAreaInfo.setY(coords[Y]);
+
int width = Math.round(unitConv.mpt2units((float)afpImageInfo.pos.getWidth()));
objectAreaInfo.setWidth(width);
+
int height = Math.round(unitConv.mpt2units((float)afpImageInfo.pos.getHeight()));
objectAreaInfo.setHeight(height);
+
+ int resolution = state.getResolution();
+ objectAreaInfo.setHeightRes(resolution);
+ objectAreaInfo.setWidthRes(resolution);
+
+ objectAreaInfo.setRotation(state.getRotation());
+
dataObjectInfo.setObjectAreaInfo(objectAreaInfo);
+
return dataObjectInfo;
}
* limitations under the License.
*/
-/* $Id: $ */
+/* $Id$ */
package org.apache.fop.render.afp;
import java.util.Map;
import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
* AFP data object info factory provider
*/
public class AFPDataObjectInfoProvider {
- private final Map factoryMap = new java.util.HashMap();
+ private final Map/*<AbstractImage,AFPDataObjectInfoFactory>*/ factoryMap
+ = new java.util.HashMap/*<AbstractImage,AFPDataObjectInfoFactory>*/();
private final AFPState state;
/**
ImageRawCCITTFax.class, new AFPRawCCITTFaxFactory(state));
factoryMap.put(
ImageRawStream.class, new AFPImageRawStreamFactory(state));
+ factoryMap.put(
+ ImageGraphics2D.class, new AFPImageGraphics2DFactory(state));
};
/**
/** Current AFP state */
private AFPState state = null;
- private AFPUnitConverter unitConv;
-
/**
* Main constructor
*
public void setAFPInfo(AFPInfo afpInfo) {
this.info = afpInfo;
this.state = info.getState();
- this.unitConv = state.getUnitConverter();
}
/**
ImageObserver observer) {
// draw with AWT Graphics2D
+ AFPUnitConverter unitConv = state.getUnitConverter();
int w = Math.round(unitConv.pt2units(width));
int h = Math.round(unitConv.pt2units(height));
Dimension size = new Dimension(w, h);
ImageRendered imgRend = new ImageRendered(imageInfo, buf, null);
RenderedImage ri = imgRend.getRenderedImage();
-
-
-
-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
// Serialize image
this.graphicsObj = obj;
}
+ /**
+ * Sets the AFP state
+ *
+ * @param state the AFP state
+ */
+ protected void setState(AFPState state) {
+ this.state = state;
+ }
+
}
\ No newline at end of file
private final AFPRenderer renderer;
+ private final AFPGraphics2D g2d;
+
/**
* Main constructor
*
*/
public AFPGraphics2DAdapter(AFPRenderer renderer) {
this.renderer = renderer;
+
+ final boolean textAsShapes = false;
+ this.g2d = new AFPGraphics2D(textAsShapes);
+ }
+
+ /**
+ * Returns the AFP graphics 2D implementation
+ *
+ * @return the AFP graphics 2D implementation
+ */
+ protected AFPGraphics2D getGraphics2D() {
+ return g2d;
}
/** {@inheritDoc} */
// get the 'width' and 'height' attributes of the SVG document
Dimension dim = painter.getImageSize();
- final boolean textAsShapes = false;
- AFPGraphics2D g2d = new AFPGraphics2D(textAsShapes);
AFPInfo afpInfo = AFPSVGHandler.getAFPInfo(context);
g2d.setAFPInfo(afpInfo);
at.scale(scale, scale);
}
-
AffineTransform trans = state.getData().getTransform();
trans.concatenate(at);
// at = state.getData().getTransform();
g2d.drawImage(bi, trans, null);
} else {
+ AFPGraphicsObjectInfo graphicsObjectInfo = new AFPGraphicsObjectInfo();
+ graphicsObjectInfo.setPainter(painter);
+ graphicsObjectInfo.setGraphics2D(g2d);
+
Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
- painter.paint(g2d, area);
+ graphicsObjectInfo.setArea(area);
+ AFPResourceManager resourceManager = (AFPResourceManager)context.getProperty(
+ AFPRendererContextConstants.AFP_RESOURCE_MANAGER);
+ resourceManager.createObject(graphicsObjectInfo);
}
renderer.restoreGraphicsState();
* 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.
package org.apache.fop.render.afp;
+import java.awt.geom.Rectangle2D;
+
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
import org.apache.xmlgraphics.util.MimeConstants;
/**
*/
public class AFPGraphicsObjectInfo extends AFPDataObjectInfo {
- private AFPGraphicsObjectPainter painter;
+ /** the graphics object painter implementation */
+ private Graphics2DImagePainter painter;
+
+ /** the graphics object area */
+ private Rectangle2D area;
+
+ /** the AFP graphics 2d implementation */
+ private AFPGraphics2D g2d;
/**
* Returns the graphics painter
- *
+ *
* @return the graphics painter
*/
- public AFPGraphicsObjectPainter getPainter() {
- return painter;
+ public Graphics2DImagePainter getPainter() {
+ return this.painter;
}
/**
* Sets the graphics painter
- *
+ *
* @param graphicsPainter the graphics painter
*/
- public void setPainter(AFPGraphicsObjectPainter graphicsPainter) {
+ public void setPainter(Graphics2DImagePainter graphicsPainter) {
this.painter = graphicsPainter;
}
-
+
+ /**
+ * Returns the graphics area
+ *
+ * @return the graphics area
+ */
+ public Rectangle2D getArea() {
+ return this.area;
+ }
+
+ /**
+ * Sets the graphics area area
+ *
+ * @param area the graphics object area
+ */
+ public void setArea(Rectangle2D area) {
+ this.area = area;
+ }
+
+ /**
+ * Sets the AFP graphics 2D implementation
+ *
+ * @param g2d the AFP graphics 2D implementation
+ */
+ public void setGraphics2D(AFPGraphics2D g2d) {
+ this.g2d = g2d;
+ }
+
+ /**
+ * Returns the AFP graphics 2D implementation
+ *
+ * @return the AFP graphics 2D implementation
+ */
+ public AFPGraphics2D getGraphics2D() {
+ return this.g2d;
+ }
+
/** {@inheritDoc} */
public String toString() {
return "GraphicsObjectInfo{" + super.toString() + "}";
public String getMimeType() {
return MimeConstants.MIME_SVG;
}
+
}
+++ /dev/null
-/*
- * 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 org.apache.batik.gvt.GraphicsNode;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.fop.render.afp.modca.GraphicsObject;
-
-/**
- * A simple AFP Graphics 2D painter
- */
-public class AFPGraphicsObjectPainter {
- /** Static logging instance */
- protected static Log log = LogFactory.getLog(AFPGraphicsObjectPainter.class);
-
- private final AFPGraphics2D graphics2D;
-
- private GraphicsNode root;
-
- /**
- * Default constructor
- *
- * @param graphics the afp graphics 2d implementation
- */
- public AFPGraphicsObjectPainter(AFPGraphics2D graphics) {
- this.graphics2D = graphics;
- }
-
- /**
- * Sets the graphics node
- *
- * @param rootNode the graphics root node
- */
- public void setGraphicsNode(GraphicsNode rootNode) {
- this.root = rootNode;
- }
-
- /**
- * Paints the graphics object
- *
- * @param graphicsObj the graphics object
- */
- public void paint(GraphicsObject graphicsObj) {
- log.debug("Painting SVG using GOCA " + graphicsObj.getName());
-
- // set the graphics object
- graphics2D.setGraphicsObject(graphicsObj);
-
- // tell batik to paint the graphics object
- root.paint(graphics2D);
-
- // dispose of the graphics 2d implementation
- graphics2D.dispose();
- }
-}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.Rectangle;
+import java.io.IOException;
+
+import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+
+
+/**
+ * An AFP image graphics 2d factory
+ */
+public class AFPImageGraphics2DFactory extends AFPDataObjectInfoFactory {
+
+ /**
+ * Main constructor
+ *
+ * @param state the afp state
+ */
+ public AFPImageGraphics2DFactory(AFPState state) {
+ super(state);
+ }
+
+ /** {@inheritDoc} */
+ protected AFPDataObjectInfo createDataObjectInfo() {
+ return new AFPGraphicsObjectInfo();
+ }
+
+ /** {@inheritDoc} */
+ public AFPDataObjectInfo create(AFPImageInfo afpImageInfo) throws IOException {
+ AFPGraphicsObjectInfo graphicsObjectInfo
+ = (AFPGraphicsObjectInfo)super.create(afpImageInfo);
+
+ AFPGraphics2DAdapter g2dAdapter = afpImageInfo.g2dAdapter;
+ AFPGraphics2D g2d = g2dAdapter.getGraphics2D();
+ g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
+ g2d.setState(state);
+ graphicsObjectInfo.setGraphics2D(g2d);
+
+ ImageGraphics2D imageG2D = (ImageGraphics2D)afpImageInfo.img;
+ Graphics2DImagePainter painter = imageG2D.getGraphics2DImagePainter();
+ graphicsObjectInfo.setPainter(painter);
+
+ AFPObjectAreaInfo objectAreaInfo = graphicsObjectInfo.getObjectAreaInfo();
+ Rectangle area = new Rectangle(objectAreaInfo.getWidth(), objectAreaInfo.getHeight());
+ graphicsObjectInfo.setArea(area);
+
+ return graphicsObjectInfo;
+ }
+
+}
* limitations under the License.
*/
-/* $Id: $ */
+/* $Id$ */
package org.apache.fop.render.afp;
import java.awt.geom.Rectangle2D;
import java.util.Map;
+import org.apache.fop.render.RendererContext;
import org.apache.xmlgraphics.image.loader.Image;
import org.apache.xmlgraphics.image.loader.ImageInfo;
/** the image */
protected final Image img;
+ /** the AFP graphics 2d adapter */
+ protected AFPGraphics2DAdapter g2dAdapter;
+
+ /** the renderer context */
+ protected RendererContext rendererContext;
+
/**
* Main constructor
*
this.foreignAttributes = foreignAttributes;
}
+ /**
+ * Sets the renderer context
+ *
+ * @param rendererContext the renderer context
+ */
+ public void setRendererContext(RendererContext rendererContext) {
+ this.rendererContext = rendererContext;
+ }
+
+ /**
+ * Sets the graphics 2d adapter
+ *
+ * @param adapter the graphics 2d adapter
+ */
+ public void setGraphics2DAdapter(AFPGraphics2DAdapter adapter) {
+ this.g2dAdapter = adapter;
+ }
+
}
/** {@inheritDoc} */
public String toString() {
return "AFPImageObjectInfo{" + super.toString()
- + "compression=" + compression
+ + ", compression=" + compression
+ ", color=" + color
+ ", bitsPerPixel=" + bitsPerPixel
+ "}";
* limitations under the License.
*/
-/* $Id: $ */
+/* $Id$ */
package org.apache.fop.render.afp;
import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
/**
- * A raw stream image configurator
+ * A raw stream image data object info factory
*/
public class AFPImageRawStreamFactory extends AFPDataObjectInfoFactory {
* limitations under the License.
*/
-/* $Id: $ */
+/* $Id$ */
package org.apache.fop.render.afp;
import org.apache.xmlgraphics.ps.ImageEncodingHelper;
/**
- * A buffered image configurator
+ * A buffered image data object info factory
*/
public class AFPImageRenderedFactory extends AFPDataObjectInfoFactory {
--- /dev/null
+/*
+ * 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.Color;
+
+/** Line data information */
+public class AFPLineDataInfo {
+
+ /** the x1 coordinate */
+ int x1;
+
+ /** the y1 coordinate */
+ int y1;
+
+ /** the x2 coordinate */
+ int x2;
+
+ /** the y2 coordinate */
+ int y2;
+
+ /** the thickness */
+ int thickness;
+
+ /** the painting color */
+ Color color;
+
+ /** the rotation */
+ int rotation = 0;
+
+ /**
+ * Default constructor
+ */
+ public AFPLineDataInfo() {
+ }
+
+ /**
+ * Returns the X1 coordinate
+ *
+ * @return the X1 coordinate
+ */
+ public int getX1() {
+ return x1;
+ }
+
+ /**
+ * Sets the X1 coordinate
+ *
+ * @param x1 the X1 coordinate
+ */
+ public void setX1(int x1) {
+ this.x1 = x1;
+ }
+
+ /**
+ * Returns the Y1 coordinate
+ *
+ * @return the Y1 coordinate
+ */
+ public int getY1() {
+ return y1;
+ }
+
+ /**
+ * Sets the Y1 coordinate
+ *
+ * @param y1 the Y1 coordinate
+ */
+ public void setY1(int y1) {
+ this.y1 = y1;
+ }
+
+ /**
+ * Returns the X2 coordinate
+ *
+ * @return the X2 coordinate
+ */
+ public int getX2() {
+ return x2;
+ }
+
+ /**
+ * Sets the X2 coordinate
+ *
+ * @param x2 the X2 coordinate
+ */
+ public void setX2(int x2) {
+ this.x2 = x2;
+ }
+
+ /**
+ * Returns the Y2 coordinate
+ *
+ * @return the Y2 coordinate
+ */
+ public int getY2() {
+ return y2;
+ }
+
+ /**
+ * Sets the Y2 coordinate
+ *
+ * @param y2 the Y2 coordinate
+ */
+ public void setY2(int y2) {
+ this.y2 = y2;
+ }
+
+ /**
+ * Returns the line thickness
+ *
+ * @return the line thickness
+ */
+ public int getThickness() {
+ return thickness;
+ }
+
+ /**
+ * Sets the line thickness
+ *
+ * @param thickness the line thickness
+ */
+ public void setThickness(int thickness) {
+ this.thickness = thickness;
+ }
+
+ /**
+ * Returns line color
+ *
+ * @return the line color
+ */
+ public Color getColor() {
+ return color;
+ }
+
+ /**
+ * Sets the line color
+ *
+ * @param color the line color
+ */
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+ /**
+ * Returns line rotation
+ *
+ * @return the line rotation
+ */
+ public int getRotation() {
+ return rotation;
+ }
+
+ /**
+ * Sets the line rotation
+ *
+ * @param rotation the line rotation
+ */
+ public void setRotation(int rotation) {
+ this.rotation = rotation;
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return "AFPLineDataInfo{x1=" + x1
+ + ", y1=" + y1
+ + ", x2=" + x2
+ + ", y2=" + y2
+ + ", thickness=" + thickness
+ + ", color=" + color
+ + ", rotation=" + rotation
+ + "}";
+ }
+
+}
* limitations under the License.
*/
-/* $Id: $ */
+/* $Id$ */
package org.apache.fop.render.afp;
import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
/**
- * An CITT fax image configurator
+ * An CITT fax image data object info factory
*/
public class AFPRawCCITTFaxFactory extends AFPDataObjectInfoFactory {
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.area.Block;
import org.apache.fop.area.CTM;
import org.apache.fop.area.LineArea;
import org.apache.fop.area.OffDocumentItem;
import org.apache.xmlgraphics.image.loader.ImageInfo;
import org.apache.xmlgraphics.image.loader.ImageManager;
import org.apache.xmlgraphics.image.loader.ImageSessionContext;
-import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
import org.apache.xmlgraphics.image.loader.util.ImageUtil;
import org.apache.xmlgraphics.ps.ImageEncodingHelper;
/** {@inheritDoc} */
public void startRenderer(OutputStream outputStream) throws IOException {
- state.setColor(new Color(255, 255, 255));
- resourceManager.setOutputStream(outputStream);
+ state.setColor(Color.WHITE);
- this.dataStream = resourceManager.getDataStream();
- dataStream.setPortraitRotation(state.getPortraitRotation());
- dataStream.setLandscapeRotation(state.getLandscapeRotation());
- dataStream.startDocument();
+ resourceManager.createDataStream(state, outputStream);
+ this.dataStream = resourceManager.getDataStream();
this.borderPainter = new AFPBorderPainter(state, dataStream);
+
+// dataStream.setPortraitRotation(state.getPortraitRotation());
+// dataStream.setLandscapeRotation(state.getLandscapeRotation());
+ dataStream.startDocument();
}
/** {@inheritDoc} */
/** {@inheritDoc} */
public void preparePage(PageViewport page) {
- final int pageRotation = 0;
+ int pageRotation = state.getPageRotation();
int pageWidth = state.getPageWidth();
int pageHeight = state.getPageHeight();
int resolution = state.getResolution();
int pageWidth
= Math.round(unitConv.mpt2units((float)bounds.getWidth()));
state.setPageWidth(pageWidth);
+
int pageHeight
= Math.round(unitConv.mpt2units((float)bounds.getHeight()));
state.setPageHeight(pageHeight);
- final int pageRotation = 0;
+ int pageRotation = state.getPageRotation();
+
int resolution = state.getResolution();
+
dataStream.startPage(pageWidth, pageHeight, pageRotation,
resolution, resolution);
if (factory != null) {
AFPImageInfo afpImageInfo
= new AFPImageInfo(uri, pos, origin, info, img, foreignAttributes);
+ if (factory instanceof AFPImageGraphics2DFactory) {
+ RendererContext rendererContext = createRendererContext(
+ x, y, posInt.width, posInt.height, foreignAttributes);
+ afpImageInfo.setRendererContext(rendererContext);
+ AFPGraphics2DAdapter g2dAdapter
+ = (AFPGraphics2DAdapter)getGraphics2DAdapter();
+ afpImageInfo.setGraphics2DAdapter(g2dAdapter);
+ }
AFPDataObjectInfo dataObjectInfo = null;
try {
dataObjectInfo = factory.create(afpImageInfo);
throw ioe;
}
resourceManager.createObject(dataObjectInfo);
- } else if (img instanceof ImageGraphics2D) { // ...and process the image
- ImageGraphics2D imageG2D = (ImageGraphics2D) img;
- RendererContext rendererContext = createRendererContext(
- x, y, posInt.width, posInt.height, foreignAttributes);
- getGraphics2DAdapter().paintImage(
- imageG2D.getGraphics2DImagePainter(), rendererContext,
- origin.x + posInt.x, origin.y + posInt.y, posInt.width,
- posInt.height);
} else if (img instanceof ImageXMLDOM) {
ImageXMLDOM imgXML = (ImageXMLDOM) img;
renderDocument(imgXML.getDocument(), imgXML.getRootNamespace(),
public void renderText(TextArea text) {
renderInlineAreaBackAndBorders(text);
- String name = getInternalFontNameForArea(text);
int fontSize = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue();
state.setFontSize(fontSize);
+
+ String name = getInternalFontNameForArea(text);
AFPFont font = (AFPFont)fontInfo.getFonts().get(name);
// Set letterSpacing
// float ls = fs.getLetterSpacing() / this.currentFontSize;
// Create an AFPFontAttributes object from the current font details
- AFPFontAttributes afpFontAttributes
+ AFPFontAttributes fontAttributes
= new AFPFontAttributes(name, font, fontSize);
AFPPageFonts pageFonts = state.getPageFonts();
- if (!pageFonts.containsKey(afpFontAttributes.getFontKey())) {
+ if (!pageFonts.containsKey(fontAttributes.getFontKey())) {
// Font not found on current page, so add the new one
- afpFontAttributes.setFontReference(state.incrementPageFontCount());
- pageFonts.put(afpFontAttributes.getFontKey(), afpFontAttributes);
+ fontAttributes.setFontReference(state.incrementPageFontCount());
+ pageFonts.put(fontAttributes.getFontKey(), fontAttributes);
} else {
// Use the previously stored font attributes
- afpFontAttributes = (AFPFontAttributes) pageFonts.get(afpFontAttributes.getFontKey());
+ fontAttributes = (AFPFontAttributes)pageFonts.get(fontAttributes.getFontKey());
}
+ AFPTextDataInfo textDataInfo = new AFPTextDataInfo();
+
+ int fontReference = fontAttributes.getFontReference();
+ textDataInfo.setFontReference(fontReference);
+
+ int x = (currentIPPosition + text.getBorderAndPaddingWidthStart());
+ int y = (currentBPPosition + text.getOffset() + text.getBaselineOffset());
+
+ int[] coords = unitConv.mpts2units(new float[] {x, y} );
+ textDataInfo.setX(coords[X]);
+ textDataInfo.setY(coords[Y]);
+
+ Color color = (Color) text.getTrait(Trait.COLOR);
+ textDataInfo.setColor(color);
+
+ int variableSpaceCharacterIncrement = font.getWidth(' ', fontSize) / 1000
+ + text.getTextWordSpaceAdjust()
+ + text.getTextLetterSpaceAdjust();
+ variableSpaceCharacterIncrement
+ = Math.round(unitConv.mpt2units(variableSpaceCharacterIncrement));
+ textDataInfo.setVariableSpaceCharacterIncrement(variableSpaceCharacterIncrement);
+
+ int interCharacterAdjustment
+ = Math.round(unitConv.mpt2units(text.getTextLetterSpaceAdjust()));
+ textDataInfo.setInterCharacterAdjustment(interCharacterAdjustment);
+
// Try and get the encoding to use for the font
String encoding = null;
try {
+ encoding);
}
+ String textString = text.getText();
byte[] data = null;
try {
- String worddata = text.getText();
- data = worddata.getBytes(encoding);
+ data = textString.getBytes(encoding);
+ textDataInfo.setData(data);
} catch (UnsupportedEncodingException usee) {
- log.error("renderText:: Font " + afpFontAttributes.getFontKey()
+ log.error("renderText:: Font " + fontAttributes.getFontKey()
+ " caused UnsupportedEncodingException");
return;
}
- int fontReference = afpFontAttributes.getFontReference();
-
- int x = (currentIPPosition + text.getBorderAndPaddingWidthStart());
- int y = (currentBPPosition + text.getOffset() + text.getBaselineOffset());
- float[] srcPts = new float[] {x, y};
- int[] coords = unitConv.mpts2units(srcPts);
-
- Color color = (Color) text.getTrait(Trait.COLOR);
-
- int variableSpaceCharacterIncrement = font.getWidth(' ', fontSize) / 1000
- + text.getTextWordSpaceAdjust()
- + text.getTextLetterSpaceAdjust();
- variableSpaceCharacterIncrement
- = Math.round(unitConv.mpt2units(variableSpaceCharacterIncrement));
-
- int interCharacterAdjustment
- = Math.round(unitConv.mpt2units(text.getTextLetterSpaceAdjust()));
-
- AFPTextDataInfo textDataInfo = new AFPTextDataInfo();
- textDataInfo.setFontReference(fontReference);
- textDataInfo.setX(coords[X]);
- textDataInfo.setY(coords[Y]);
- textDataInfo.setColor(color);
- textDataInfo.setVariableSpaceCharacterIncrement(variableSpaceCharacterIncrement);
- textDataInfo.setInterCharacterAdjustment(interCharacterAdjustment);
- textDataInfo.setData(data);
- textDataInfo.setOrientation(state.getOrientation());
dataStream.createText(textDataInfo);
// word.getOffset() = only height of text itself
// currentBlockIPPosition: 0 for beginning of line; nonzero
}
/**
- * Returns the AFPDataStream
+ * Returns the AFP DataStream
*
- * @return the AFPDataStream
+ * @return the AFP DataStream
*/
- public DataStream getAFPDocumentStream() {
+ public DataStream getDataStream() {
return this.dataStream;
}
resourceManager.setDefaultResourceGroupFilePath(filePath);
}
- // TODO: remove this and use the superclass implementation
/** {@inheritDoc} */
- protected void renderReferenceArea(Block block) {
- // save position and offset
- int saveIP = currentIPPosition;
- int saveBP = currentBPPosition;
-
- //Establish a new coordinate system
- AffineTransform at = new AffineTransform();
- at.translate(currentIPPosition, currentBPPosition);
- at.translate(block.getXOffset(), block.getYOffset());
- at.translate(0, block.getSpaceBefore());
-
- if (!at.isIdentity()) {
- saveGraphicsState();
- concatenateTransformationMatrix(at);
- }
-
- currentIPPosition = 0;
- currentBPPosition = 0;
- handleBlockTraits(block);
-
- List children = block.getChildAreas();
- if (children != null) {
- renderBlocks(block, children);
- }
-
- if (!at.isIdentity()) {
- restoreGraphicsState();
- }
-
- // stacked and relative blocks effect stacking
- currentIPPosition = saveIP;
- currentBPPosition = saveBP;
+ protected void establishTransformationMatrix(AffineTransform at) {
+ saveGraphicsState();
+ //state.resetTransform(); // reset to base transform (scale)
+ concatenateTransformationMatrix(at);
}
}
/**
* Sets the outputstream
*
+ * @param state the afp state
* @param outputStream the outputstream
*/
- public void setOutputStream(OutputStream outputStream) {
- this.dataStream = streamer.createDataStream();
+ public void createDataStream(AFPState state, OutputStream outputStream) {
+ this.dataStream = streamer.createDataStream(state);
streamer.setOutputStream(outputStream);
}
}
/**
- * Creates and returns a new data object
+ * Creates a new data object in the AFP datastream
*
* @param dataObjectInfo the data object info
*
if (uri == null) {
uri = "/";
}
- // if this is an instream data object adjust uri to ensure that it is
- // unique
+ // if this is an instream data object adjust the uri to ensure that its unique
if (uri.endsWith("/")) {
uri += "#" + (++instreamObjectCount);
resourceInfo.setUri(uri);
}
- // try and find an include name for the same resource
String objectName = (String)includeNameMap.get(resourceInfo);
if (objectName == null) {
-
boolean useInclude = true;
Registry.ObjectType objectType = null;
} else if (dataObjectInfo instanceof AFPGraphicsObjectInfo) {
namedObj = dataObjectFactory.createGraphic((AFPGraphicsObjectInfo)dataObjectInfo);
} else {
+ // natively embedded object
namedObj = dataObjectFactory.createObjectContainer(dataObjectInfo);
objectType = dataObjectInfo.getObjectType();
useInclude = objectType != null && objectType.isIncludable();
// add an include to the current page
dataStream.getCurrentPage().addObject(includeObject);
- // record name of data object for the resource
+ // record mapping of resource info to data object resource name
includeNameMap.put(resourceInfo, objectName);
} else {
// not to be included so inline data object directly into the current page
}
}
-}
+}
\ No newline at end of file
// set the data object parameters
AFPObjectAreaInfo objectAreaInfo = new AFPObjectAreaInfo();
- AFPUnitConverter unitConv = state.getUnitConverter();
-
RendererContextWrapper rctx = RendererContext.wrapRendererContext(context);
int currx = rctx.getCurrentXPosition();
int curry = rctx.getCurrentYPosition();
float[] srcPts = {currx, curry};
+
+ AFPUnitConverter unitConv = state.getUnitConverter();
int[] coords = unitConv.mpts2units(srcPts);
objectAreaInfo.setX(coords[X]);
objectAreaInfo.setY(coords[Y]);
int height = Math.round(unitConv.mpt2units(afpInfo.getHeight()));
objectAreaInfo.setHeight(height);
- AFPDataObjectInfo dataObjectInfo = new AFPGraphicsObjectInfo();
- dataObjectInfo.setUri(uri);
+ int rotation = state.getRotation();
+ objectAreaInfo.setRotation(rotation);
+
+ AFPGraphicsObjectInfo graphicsObjectInfo = new AFPGraphicsObjectInfo();
+ graphicsObjectInfo.setUri(uri);
// Configure Graphics2D implementation
final boolean textAsShapes = false;
- AFPGraphics2D graphics = new AFPGraphics2D(textAsShapes);
- graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
- graphics.setAFPInfo(afpInfo);
+ AFPGraphics2D g2d = new AFPGraphics2D(textAsShapes);
+ g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
+ g2d.setAFPInfo(afpInfo);
// Configure GraphicsObjectPainter with the Graphics2D implementation
- AFPGraphicsObjectPainter painter = new AFPGraphicsObjectPainter(graphics);
- ((AFPGraphicsObjectInfo)dataObjectInfo).setPainter(painter);
+ AFPBatikGraphicsObjectPainter painter = new AFPBatikGraphicsObjectPainter(g2d);
+ (graphicsObjectInfo).setPainter(painter);
boolean strokeText = false;
Configuration cfg = afpInfo.getHandlerConfiguration();
//Controls whether text painted by Batik is generated using text or path operations
if (!strokeText) {
- afpTextHandler = new AFPTextHandler(graphics);
- graphics.setCustomTextHandler(afpTextHandler);
+ afpTextHandler = new AFPTextHandler(g2d);
+ g2d.setCustomTextHandler(afpTextHandler);
AFPTextPainter textPainter = new AFPTextPainter(afpTextHandler);
ctx.setTextPainter(textPainter);
AFPTextElementBridge tBridge = new AFPTextElementBridge(textPainter);
= (Map/*<QName, String>*/)context.getProperty(
RendererContextConstants.FOREIGN_ATTRIBUTES);
AFPResourceInfo resourceInfo = foreignAttributeReader.getResourceInfo(foreignAttributes);
- dataObjectInfo.setResourceInfo(resourceInfo);
+ graphicsObjectInfo.setResourceInfo(resourceInfo);
// Build the SVG DOM and provide the painter with it
GraphicsNode root;
// for the SVG graphic in relation to the current coordinate system
// (note: y axis is inverted)
AffineTransform trans = new AffineTransform(scaleX, 0, 0, -scaleY, xOffset, yOffset);
- graphics.setTransform(trans);
+ g2d.setTransform(trans);
+
+ // Set the afp graphics 2d implementation
+ graphicsObjectInfo.setGraphics2D(g2d);
// Set the object area info
- dataObjectInfo.setObjectAreaInfo(objectAreaInfo);
+ graphicsObjectInfo.setObjectAreaInfo(objectAreaInfo);
AFPResourceManager resourceManager = afpInfo.getAFPResourceManager();
// Create the graphics object
- resourceManager.createObject(dataObjectInfo);
+ resourceManager.createObject(graphicsObjectInfo);
}
/** {@inheritDoc} */
package org.apache.fop.render.afp;
-import java.awt.geom.AffineTransform;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.render.AbstractState;
private boolean colorImages = false;
/** images are supported in this AFP environment */
- private boolean nativeImages;
+ private boolean nativeImages = false;
/** default value for image depth */
private int bitsPerPixel = 8;
/** the current page */
private AFPPageState pageState = new AFPPageState();
+// /** reference orientation */
+// private int orientation = 0;
+
/** a unit converter */
private final transient AFPUnitConverter unitConv = new AFPUnitConverter(this);
-
/**
* Sets the rotation to be used for portrait pages, valid values are 0
* (default), 90, 180, 270.
return pageState.getHeight();
}
+ /**
+ * Returns the page rotation
+ *
+ * @return the page rotation
+ */
+ public int getPageRotation() {
+ return pageState.getOrientation();
+ }
+
/**
* Sets the uri of the current image
*
}
/**
- * Returns the current orientation
+ * Returns the currently derived rotation
*
- * @return the current orientation
+ * @return the currently derived rotation
*/
- public int getOrientation() {
- AffineTransform at = getData().getTransform();
- int orientation = 0;
- if (at.getScaleX() == 0 && at.getScaleY() == 0
- && at.getShearX() == 1 && at.getShearY() == -1) {
- orientation = 90;
- } else if (at.getScaleX() == -1 && at.getScaleY() == -1
- && at.getShearX() == 0 && at.getShearY() == 0) {
- orientation = 180;
- } else if (at.getScaleX() == 0 && at.getScaleY() == 0
- && at.getShearX() == -1 && at.getShearY() == 1) {
- orientation = 270;
- }
- return orientation;
+ public int getRotation() {
+ return getData().getDerivedRotation();
}
/**
* Page level state data
*/
private class AFPPageState implements Cloneable {
- /** The current page width */
+ /** page width */
private int width = 0;
- /** The current page height */
+ /** page height */
private int height = 0;
- /** The current page fonts */
+ /** page fonts */
private AFPPageFonts fonts = new AFPPageFonts();
- /** The current page font count */
+ /** page font count */
private int fontCount = 0;
+ /** page orientation */
+ private int orientation = 0;
+
/**
* Returns the page width
*
return ++fontCount;
}
+ /**
+ * Returns the current page orientation
+ *
+ * @return the current page orientation
+ */
+ protected int getOrientation() {
+ return orientation;
+ }
+
+ /**
+ * Sets the current page orientation
+ *
+ * @param orientation the current page orientation
+ */
+ protected void setOrientation(int orientation) {
+ this.orientation = orientation;
+ }
+
/** {@inheritDoc} */
public Object clone() {
AFPPageState state = new AFPPageState();
- state.fonts = new AFPPageFonts(this.fonts);
- state.height = this.height;
state.width = this.width;
+ state.height = this.height;
+ state.orientation = this.orientation;
+ state.fonts = new AFPPageFonts(this.fonts);
state.fontCount = this.fontCount;
return state;
}
public String toString() {
return "AFPPageState{width=" + width
+ ", height=" + height
+ + ", orientation=" + orientation
+ ", fonts=" + fonts
+ ", fontCount=" + fontCount
+ "}";
+ "}";
}
}
+
}
\ No newline at end of file
* limitations under the License.
*/
-/* $Id: $ */
+/* $Id$ */
package org.apache.fop.render.afp;
/**
* Creates a new DataStream
+ * @param state the afp state
*
* @return a new {@link DataStream}
*/
- public DataStream createDataStream() {
+ public DataStream createDataStream(AFPState state) {
try {
this.tempFile = File.createTempFile(AFPDATASTREAM_TEMP_FILE_PREFIX, null);
this.documentFile = new RandomAccessFile(tempFile, "rw");
this.documentOutputStream = new BufferedOutputStream(
new FileOutputStream(documentFile.getFD()));
- this.dataStream = factory.createDataStream(documentOutputStream);
+ this.dataStream = factory.createDataStream(state, documentOutputStream);
} catch (IOException e) {
log.error(e.getMessage());
}
* 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.
public class AFPTextDataInfo {
private int fontReference;
-
+
private int x;
-
+
private int y;
-
+
private Color color;
-
+
private int variableSpaceCharacterIncrement;
-
+
private int interCharacterAdjustment;
-
+
private byte[] data;
-
- private int orientation;
-
+
+ private int rotation;
+
/**
* Returns the font reference
- *
+ *
* @return the font reference
*/
public int getFontReference() {
return fontReference;
}
-
+
/**
* Sets the font reference
- *
+ *
* @param fontReference the font reference
*/
protected void setFontReference(int fontReference) {
this.fontReference = fontReference;
}
-
+
/**
* Returns the x coordinate
- *
+ *
* @return the x coordinate
*/
public int getX() {
return x;
}
-
+
/**
* Sets the X coordinate
- *
+ *
* @param x the X coordinate
*/
- protected void setX(int x) {
+ public void setX(int x) {
this.x = x;
}
-
+
/**
* Returns the y coordinate
- *
+ *
* @return the y coordinate
*/
public int getY() {
return y;
}
-
+
/**
* Sets the Y coordinate
- *
+ *
* @param y the Y coordinate
*/
- protected void setY(int y) {
+ public void setY(int y) {
this.y = y;
}
-
+
/**
* Returns the color
- *
+ *
* @return the color
*/
public Color getColor() {
return color;
}
-
+
/**
* Sets the color
- *
+ *
* @param color the color
*/
protected void setColor(Color color) {
this.color = color;
}
-
+
/**
* Return the variable space character increment
- *
+ *
* @return the variable space character increment
*/
public int getVariableSpaceCharacterIncrement() {
return variableSpaceCharacterIncrement;
}
-
+
/**
* Sets the variable space character increment
- *
+ *
* @param variableSpaceCharacterIncrement the variable space character increment
*/
protected void setVariableSpaceCharacterIncrement(
int variableSpaceCharacterIncrement) {
this.variableSpaceCharacterIncrement = variableSpaceCharacterIncrement;
}
-
+
/**
* Return the inter character adjustment
- *
+ *
* @return the inter character adjustment
*/
public int getInterCharacterAdjustment() {
return interCharacterAdjustment;
}
-
+
/**
* Sets the inter character adjustment
- *
+ *
* @param interCharacterAdjustment the inter character adjustment
*/
protected void setInterCharacterAdjustment(int interCharacterAdjustment) {
this.interCharacterAdjustment = interCharacterAdjustment;
}
-
+
/**
* Return the text data
- *
+ *
* @return the text data
*/
public byte[] getData() {
return data;
}
-
+
/**
* Sets the text data
- *
+ *
* @param data the text orientation
*/
protected void setData(byte[] data) {
/**
* Sets the text orientation
- *
- * @param orientation the text orientation
+ *
+ * @param rotation the text rotation
*/
- public void setOrientation(int orientation) {
- this.orientation = orientation;
+ public void setRotation(int rotation) {
+ this.rotation = rotation;
}
-
+
/**
- * Returns the text orientation
- *
- * @return the text orientation
+ * Returns the text rotation
+ *
+ * @return the text rotation
*/
- public int getOrientation() {
- return this.orientation;
+ public int getRotation() {
+ return this.rotation;
}
-
+
/** {@inheritDoc} */
public String toString() {
return "TextDataInfo{fontReference=" + fontReference
+ ", color=" + color
+ ", vsci=" + variableSpaceCharacterIncrement
+ ", ica=" + interCharacterAdjustment
- + ", orientation=" + orientation
+ + ", orientation=" + rotation
+ ", data=" + data
+ "}";
}
+++ /dev/null
-/*
- * 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.Color;
-
-/** Line data information */
-public class LineDataInfo {
-
- /** the x1 coordinate */
- int x1;
-
- /** the y1 coordinate */
- int y1;
-
- /** the x2 coordinate */
- int x2;
-
- /** the y2 coordinate */
- int y2;
-
- /** the thickness */
- int thickness;
-
- /** the painting color */
- Color color;
-
- /** the orientation */
- int orientation;
-
- /**
- * Default constructor
- */
- public LineDataInfo() {
- }
-
- /**
- * Returns the X1 coordinate
- *
- * @return the X1 coordinate
- */
- public int getX1() {
- return x1;
- }
-
- /**
- * Sets the X1 coordinate
- *
- * @param x1 the X1 coordinate
- */
- public void setX1(int x1) {
- this.x1 = x1;
- }
-
- /**
- * Returns the Y1 coordinate
- *
- * @return the Y1 coordinate
- */
- public int getY1() {
- return y1;
- }
-
- /**
- * Sets the Y1 coordinate
- *
- * @param y1 the Y1 coordinate
- */
- public void setY1(int y1) {
- this.y1 = y1;
- }
-
- /**
- * Returns the X2 coordinate
- *
- * @return the X2 coordinate
- */
- public int getX2() {
- return x2;
- }
-
- /**
- * Sets the X2 coordinate
- *
- * @param x2 the X2 coordinate
- */
- public void setX2(int x2) {
- this.x2 = x2;
- }
-
- /**
- * Returns the Y2 coordinate
- *
- * @return the Y2 coordinate
- */
- public int getY2() {
- return y2;
- }
-
- /**
- * Sets the Y2 coordinate
- *
- * @param y2 the Y2 coordinate
- */
- public void setY2(int y2) {
- this.y2 = y2;
- }
-
- /**
- * Returns the line thickness
- *
- * @return the line thickness
- */
- public int getThickness() {
- return thickness;
- }
-
- /**
- * Sets the line thickness
- *
- * @param thickness the line thickness
- */
- public void setThickness(int thickness) {
- this.thickness = thickness;
- }
-
- /**
- * Returns line color
- *
- * @return the line color
- */
- public Color getColor() {
- return color;
- }
-
- /**
- * Sets the line color
- *
- * @param color the line color
- */
- public void setColor(Color color) {
- this.color = color;
- }
-
- /**
- * Returns line orientation
- *
- * @return the line orientation
- */
- public int getOrientation() {
- return orientation;
- }
-
- /**
- * Sets the orientation
- *
- * @param orientation the orientation
- */
- public void setOrientation(int orientation) {
- this.orientation = orientation;
- }
-
- /** {@inheritDoc} */
- public String toString() {
- return "LineDataInfo{x1=" + x1
- + ", y1=" + y1
- + ", x2=" + x2
- + ", y2=" + y2
- + ", thickness=" + thickness
- + ", color=" + color
- + ", orientation=" + orientation
- + "}";
- }
-
-}
import java.io.OutputStream;
import java.util.List;
-import org.apache.fop.render.afp.LineDataInfo;
+import org.apache.fop.render.afp.AFPLineDataInfo;
import org.apache.fop.render.afp.AFPTextDataInfo;
import org.apache.fop.render.afp.fonts.AFPFont;
String name, int width, int height, int rotation,
int widthRes, int heightRes) {
super(name);
+
this.factory = factory;
this.width = width;
this.height = height;
*
* @param lineDataInfo the line data information.
*/
- public void createLine(LineDataInfo lineDataInfo) {
+ public void createLine(AFPLineDataInfo lineDataInfo) {
getPresentationTextObject().createLineData(lineDataInfo);
}
*/
public ActiveEnvironmentGroup getActiveEnvironmentGroup() {
if (activeEnvironmentGroup == null) {
- /**
- * Every page object must have an ActiveEnvironmentGroup
- */
+ // every page object must have an ActiveEnvironmentGroup
this.activeEnvironmentGroup
= factory.createActiveEnvironmentGroup(width, height, widthRes, heightRes);
public void addObject(Object obj) {
objects.add(obj);
}
-
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writeObjects(triplets, baos);
this.tripletData = baos.toByteArray();
+ triplets = null; // gc
}
return this.tripletData;
}
os.write(tripletData);
} else if (triplets != null) {
writeObjects(triplets, os);
+ triplets = null; // gc
}
}
package org.apache.fop.render.afp.modca;
import java.awt.Color;
+import java.awt.Point;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.render.afp.AFPFontAttributes;
+import org.apache.fop.render.afp.AFPLineDataInfo;
import org.apache.fop.render.afp.AFPResourceLevel;
+import org.apache.fop.render.afp.AFPState;
import org.apache.fop.render.afp.AFPTextDataInfo;
-import org.apache.fop.render.afp.LineDataInfo;
import org.apache.fop.render.afp.fonts.AFPFont;
import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet;
/** The current page */
private AbstractPageObject currentPage = null;
- /** The portrait rotation */
- private int portraitRotation = 0;
-
- /** The landscape rotation */
- private int landscapeRotation = 270;
-
- /** The rotation */
- private int orientation;
+// /** The portrait rotation */
+// private int portraitRotation = 0;
+//
+// /** The landscape rotation */
+// private int landscapeRotation = 270;
/** The MO:DCA interchange set in use (default to MO:DCA-P IS/2 set) */
private InterchangeSet interchangeSet
private OutputStream outputStream;
+ /** the afp state */
+ private final AFPState state;
+
/**
* Default constructor for the AFPDocumentStream.
*
* @param factory the resource factory
+ * @param state the afp state
* @param outputStream the outputstream to write to
*/
- public DataStream(Factory factory, OutputStream outputStream) {
+ public DataStream(Factory factory, AFPState state, OutputStream outputStream) {
+ this.state = state;
this.factory = factory;
this.outputStream = outputStream;
}
}
}
- /**
- * Sets the offsets to be used for element positioning
- *
- * @param xOff
- * the offset in the x direction
- * @param yOff
- * the offset in the y direction
- * @param orientation
- * the rotation
- * @deprecated offsets are no longer used, use setOrientation() for setting the orientation
- */
- public void setOffsets(int xOff, int yOff, int orientation) {
- setOrientation(orientation);
- }
-
- /**
- * Sets the orientation to be used for element positioning
- *
- * @param orientation
- * the orientation used for element positioning
- */
- public void setOrientation(int orientation) {
- this.orientation = orientation;
- }
-
/**
* Creates the given page fonts in the current page
*
currentPage.createFont(fontReference, font, size);
}
+ /**
+ * Returns a point on the current page
+ *
+ * @param x the X-coordinate
+ * @param y the Y-coordinate
+ * @return a point on the current page
+ */
+ private Point getPoint(int x, int y) {
+ Point p = new Point();
+ int rotation = state.getRotation();
+ switch (rotation) {
+ case 90:
+ p.x = y;
+ p.y = currentPage.getWidth() - x;
+ break;
+ case 180:
+ p.x = currentPage.getWidth() - x;
+ p.y = currentPage.getHeight() - y;
+ break;
+ case 270:
+ p.x = currentPage.getHeight() - y;
+ p.y = x;
+ break;
+ default:
+ p.x = x;
+ p.y = y;
+ break;
+ }
+ return p;
+ }
+
/**
* Helper method to create text on the current page, this method delegates
* to the current presentation text object in order to construct the text.
* the afp text data
*/
public void createText(AFPTextDataInfo textDataInfo) {
- textDataInfo.setOrientation(orientation);
+ int rotation = state.getRotation();
+ if (rotation != 0) {
+ textDataInfo.setRotation(rotation);
+ Point p = getPoint(textDataInfo.getX(), textDataInfo.getY());
+ textDataInfo.setX(p.x);
+ textDataInfo.setY(p.y);
+ }
currentPage.createText(textDataInfo);
}
*
* @param lineDataInfo the line data information.
*/
- public void createLine(LineDataInfo lineDataInfo) {
- lineDataInfo.setOrientation(orientation);
+ public void createLine(AFPLineDataInfo lineDataInfo) {
currentPage.createLine(lineDataInfo);
}
* the name of the static overlay
*/
public void createIncludePageOverlay(String name) {
- currentPageObject.createIncludePageOverlay(name, 0, 0, orientation);
+ currentPageObject.createIncludePageOverlay(name, 0, 0, state.getRotation());
currentPageObject.getActiveEnvironmentGroup().createOverlay(name);
}
public void createIncludePageSegment(String name, int x, int y) {
int xOrigin;
int yOrigin;
+ int orientation = state.getRotation();
switch (orientation) {
case 90:
xOrigin = currentPage.getWidth() - y;
}
}
- /**
- * Sets the rotation to be used for portrait pages, valid values are 0
- * (default), 90, 180, 270.
- *
- * @param pageRotation the rotation in degrees.
- */
- public void setPortraitRotation(int pageRotation) {
- if (pageRotation == 0 || pageRotation == 90 || pageRotation == 180
- || pageRotation == 270) {
- this.portraitRotation = pageRotation;
- } else {
- throw new IllegalArgumentException(
- "The portrait rotation must be one of the values 0, 90, 180, 270");
- }
- }
-
- /**
- * Sets the rotation to be used for landscape pages, valid values are 0, 90,
- * 180, 270 (default).
- *
- * @param pageRotation the rotation in degrees.
- */
- public void setLandscapeRotation(int pageRotation) {
- if (pageRotation == 0 || pageRotation == 90 || pageRotation == 180
- || pageRotation == 270) {
- this.landscapeRotation = pageRotation;
- } else {
- throw new IllegalArgumentException(
- "The landscape rotation must be one of the values 0, 90, 180, 270");
- }
- }
-
/**
* Sets the MO:DCA interchange set to use
*
return resourceGroup;
}
+ /**
+ * Sets the rotation to be used for portrait pages, valid values are 0
+ * (default), 90, 180, 270.
+ *
+ * @param pageRotation the rotation in degrees.
+ * @deprecated not used
+ */
+ public void setPortraitRotation(int pageRotation) {
+ }
+
+ /**
+ * Sets the rotation to be used for landscape pages, valid values are 0, 90,
+ * 180, 270 (default).
+ *
+ * @param pageRotation the rotation in degrees.
+ * @deprecated not used
+ */
+ public void setLandscapeRotation(int pageRotation) {
+ }
+
+ /**
+ * Sets the offsets to be used for element positioning
+ *
+ * @param xOff
+ * the offset in the x direction
+ * @param yOff
+ * the offset in the y direction
+ * @param orientation
+ * the orientation
+ * @deprecated not used
+ */
+ public void setOffsets(int xOff, int yOff, int orientation) {
+ }
+
}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.fop.render.afp.AFPState;
import org.apache.fop.render.afp.goca.GraphicsData;
import org.apache.fop.render.afp.ioca.ImageContent;
import org.apache.fop.render.afp.ioca.ImageRasterData;
}
/**
- * Creates an {@link DataStream}
+ * Creates a new {@link DataStream}
*
+ * @param state the afp state
* @param outputStream an outputstream to write to
* @return a new {@link DataStream}
*/
- public DataStream createDataStream(OutputStream outputStream) {
- DataStream dataStream = new DataStream(this, outputStream);
+ public DataStream createDataStream(AFPState state, OutputStream outputStream) {
+ DataStream dataStream = new DataStream(this, state, outputStream);
return dataStream;
}
/**
* Creates a new {@link ObjectAreaPosition}
*
- * @param x The x coordinate.
- * @param y The y coordinate.
- * @param rotation The coordinate system rotation (must be 0, 90, 180, 270).
+ * @param x the x coordinate.
+ * @param y the y coordinate.
+ * @param rotation the coordinate system rotation (must be 0, 90, 180, 270).
* @return a new {@link ObjectAreaPosition}
*/
public ObjectAreaPosition createObjectAreaPosition(int x, int y,
*/
public class IncludeObject extends AbstractNamedAFPObject {
- /**
- * the include object is of type page segment
- */
+ /** the object referenced is of type page segment */
public static final byte TYPE_PAGE_SEGMENT = (byte)0x5F;
- /**
- * the include object is of type other
- */
+ /** the object referenced is of type other */
public static final byte TYPE_OTHER = (byte)0x92;
- /**
- * the include object is of type graphic
- */
+ /** the object referenced is of type graphic */
public static final byte TYPE_GRAPHIC = (byte)0xBB;
- /**
- * the included object is of type barcode
- */
+ /** the object referenced is of type barcode */
public static final byte TYPE_BARCODE = (byte)0xEB;
- /**
- * the included object is of type image
- */
+ /** the object referenced is of type image */
public static final byte TYPE_IMAGE = (byte)0xFB;
- /**
- * The object type (default is other)
- */
+
+ /** the object type referenced (default is other) */
private byte objectType = TYPE_OTHER;
- /**
- * The X-axis origin of the object area
- */
+ /** the X-axis origin of the object area */
private int xoaOset = 0;
- /**
- * The Y-axis origin of the object area
- */
+ /** the Y-axis origin of the object area */
private int yoaOset = 0;
- /**
- * The orientation on the include object
- */
+ /** the orientation of the referenced object */
private int oaOrent = 0;
- /**
- * The X-axis origin defined in the object
- */
+ /** the X-axis origin defined in the object */
private int xocaOset = -1;
- /**
- * The Y-axis origin defined in the object
- */
+ /** the Y-axis origin defined in the object */
private int yocaOset = -1;
/**
import java.io.OutputStream;
import org.apache.commons.io.output.ByteArrayOutputStream;
-import org.apache.fop.render.afp.LineDataInfo;
+import org.apache.fop.render.afp.AFPLineDataInfo;
import org.apache.fop.render.afp.AFPTextDataInfo;
import org.apache.fop.render.afp.tools.BinaryUtils;
ByteArrayOutputStream afpdata = new ByteArrayOutputStream();
- if (currentOrientation != textDataInfo.getOrientation()) {
- setTextOrientation(textDataInfo.getOrientation(), afpdata);
- currentOrientation = textDataInfo.getOrientation();
+ int rotation = textDataInfo.getRotation();
+ if (currentOrientation != rotation) {
+ setTextOrientation(rotation, afpdata);
+ currentOrientation = rotation;
currentX = -1;
currentY = -1;
}
- // Avoid unnecessary specification of the Y co-ordinate
- if (textDataInfo.getY() != currentY) {
- absoluteMoveBaseline(textDataInfo.getY(), afpdata);
+ // Avoid unnecessary specification of the Y coordinate
+ int y = textDataInfo.getY();
+ if (currentY != y) {
+ absoluteMoveBaseline(y, afpdata);
currentX = -1;
}
- // Avoid unnecessary specification of the X co-ordinate
- if (textDataInfo.getX() != currentX) {
- absoluteMoveInline(textDataInfo.getX(), afpdata);
+ // Avoid unnecessary specification of the X coordinate
+ int x = textDataInfo.getX();
+ if (currentX != x) {
+ absoluteMoveInline(x, afpdata);
}
// Avoid unnecessary specification of the variable space increment
* @throws MaximumSizeExceededException
* thrown if the maximum number of line data has been exceeded
*/
- public void createLineData(LineDataInfo lineDataInfo) throws MaximumSizeExceededException {
+ public void createLineData(AFPLineDataInfo lineDataInfo) throws MaximumSizeExceededException {
ByteArrayOutputStream afpdata = new ByteArrayOutputStream();
- int thickness = lineDataInfo.getThickness();
- int orientation = lineDataInfo.getOrientation();
- int x1 = lineDataInfo.getX1();
- int y1 = lineDataInfo.getY1();
- int x2 = lineDataInfo.getX2();
- int y2 = lineDataInfo.getY2();
- Color col = lineDataInfo.getColor();
-
+ int orientation = lineDataInfo.getRotation();
if (currentOrientation != orientation) {
setTextOrientation(orientation, afpdata);
currentOrientation = orientation;
}
// Avoid unnecessary specification of the Y coordinate
+ int y1 = lineDataInfo.getY1();
if (y1 != currentY) {
absoluteMoveBaseline(y1, afpdata);
}
// Avoid unnecessary specification of the X coordinate
+ int x1 = lineDataInfo.getX1();
if (x1 != currentX) {
absoluteMoveInline(x1, afpdata);
}
+ Color col = lineDataInfo.getColor();
if (!col.equals(currentColor)) {
setExtendedTextColor(col, afpdata);
currentColor = col;
}
+ int x2 = lineDataInfo.getX2();
+ int y2 = lineDataInfo.getY2();
+ int thickness = lineDataInfo.getThickness();
if (y1 == y2) {
drawIaxisRule(x2 - x1, thickness, afpdata);
} else if (x1 == x2) {
drawBaxisRule(y2 - y1, thickness, afpdata);
} else {
+ log.error("Invalid axis rule unable to draw line");
return;
}
*
* @param orientation
* The text orientation (0, 90, 180, 270).
- * @param afpdata
+ * @param os
* The output stream to which data should be written.
*/
private void setTextOrientation(int orientation,
- ByteArrayOutputStream afpdata) {
- afpdata.write(new byte[] {0x06, (byte) 0xF7, }, 0, 2);
+ ByteArrayOutputStream os) {
+ os.write(new byte[] {0x06, (byte) 0xF7, }, 0, 2);
switch (orientation) {
case 90:
- afpdata.write(0x2D);
- afpdata.write(0x00);
- afpdata.write(0x5A);
- afpdata.write(0x00);
+ os.write(0x2D);
+ os.write(0x00);
+ os.write(0x5A);
+ os.write(0x00);
break;
case 180:
- afpdata.write(0x5A);
- afpdata.write(0x00);
- afpdata.write(0x87);
- afpdata.write(0x00);
+ os.write(0x5A);
+ os.write(0x00);
+ os.write(0x87);
+ os.write(0x00);
break;
case 270:
- afpdata.write(0x87);
- afpdata.write(0x00);
- afpdata.write(0x00);
- afpdata.write(0x00);
+ os.write(0x87);
+ os.write(0x00);
+ os.write(0x00);
+ os.write(0x00);
break;
default:
- afpdata.write(0x00);
- afpdata.write(0x00);
- afpdata.write(0x2D);
- afpdata.write(0x00);
+ os.write(0x00);
+ os.write(0x00);
+ os.write(0x2D);
+ os.write(0x00);
break;
}
}
*
* @param col
* The color to be set.
- * @param afpdata
+ * @param os
* The output stream to which data should be written.
*/
- private void setExtendedTextColor(Color col, ByteArrayOutputStream afpdata) {
+ private void setExtendedTextColor(Color col, ByteArrayOutputStream os) {
byte[] colorData = new byte[] {
15, // Control sequence length
(byte) 0x81, // Control sequence function type
(byte) (col.getBlue()), // Blue intensity
};
- afpdata.write(colorData, 0, colorData.length);
+ os.write(colorData, 0, colorData.length);
}
/**
*
* @param incr
* The increment to be set.
- * @param afpdata
+ * @param os
* The output stream to which data should be written.
*/
private void setVariableSpaceCharacterIncrement(int incr,
- ByteArrayOutputStream afpdata) {
+ ByteArrayOutputStream os) {
byte[] b = BinaryUtils.convert(incr, 2);
- afpdata.write(new byte[] {
+ os.write(new byte[] {
4, // Control sequence length
(byte) 0xC5, // Control sequence function type
b[0], b[1] },
*
* @param incr
* The increment to be set.
- * @param afpdata
+ * @param os
* The output stream to which data should be written.
*/
- private void setInterCharacterAdjustment(int incr, ByteArrayOutputStream afpdata) {
+ private void setInterCharacterAdjustment(int incr, ByteArrayOutputStream os) {
byte[] b = BinaryUtils.convert(Math.abs(incr), 2);
- afpdata.write(new byte[] {
+ os.write(new byte[] {
5, // Control sequence length
(byte) 0xC3, // Control sequence function type
b[0], b[1], (byte) (incr >= 0 ? 0 : 1) // Direction
import java.io.OutputStream;
import java.util.List;
-import org.apache.fop.render.afp.LineDataInfo;
+import org.apache.fop.render.afp.AFPLineDataInfo;
import org.apache.fop.render.afp.AFPTextDataInfo;
/**
*
* @param lineDataInfo the line data information.
*/
- public void createLineData(LineDataInfo lineDataInfo) {
+ public void createLineData(AFPLineDataInfo lineDataInfo) {
if (currentPresentationTextData == null) {
startPresentationTextData();
}