From: Adrian Cumiskey Date: Fri, 10 Oct 2008 09:19:46 +0000 (+0000) Subject: * Block-container positioning fix. X-Git-Tag: fop-1_0~376^2~69 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a1f8514b3b863a2716ce60cb102b9aea50f27319;p=xmlgraphics-fop.git * Block-container positioning fix. * Reference orientation fix. * Multi-column document fix. fox:conversion-mode="bitmap GOCA fallback still needs work. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@703362 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java b/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java index e402e8a9b..38f532b4e 100644 --- a/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java +++ b/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java @@ -26,13 +26,7 @@ import java.awt.geom.Rectangle2D; 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; @@ -48,7 +42,10 @@ import org.apache.fop.fo.Constants; 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 @@ -282,12 +279,12 @@ public abstract class AbstractPathOrientedRenderer extends PrintRenderer { * @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; @@ -518,9 +515,10 @@ public abstract class AbstractPathOrientedRenderer extends PrintRenderer { positionTransform.concatenate(freeTransform); } - saveGraphicsState(); //Viewport position - concatenateTransformationMatrix(UnitConv.mptToPt(positionTransform)); + if (!positionTransform.isIdentity()) { + establishTransformationMatrix(positionTransform); + } //Background and borders float bpwidth = (borderPaddingStart + bv.getBorderAndPaddingWidthEnd()) / 1000f; @@ -537,17 +535,23 @@ public abstract class AbstractPathOrientedRenderer extends PrintRenderer { 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); @@ -603,8 +607,7 @@ public abstract class AbstractPathOrientedRenderer extends PrintRenderer { at.translate(0, block.getSpaceBefore()); if (!at.isIdentity()) { - saveGraphicsState(); - concatenateTransformationMatrix(UnitConv.mptToPt(at)); + establishTransformationMatrix(at); } currentIPPosition = 0; @@ -636,8 +639,7 @@ public abstract class AbstractPathOrientedRenderer extends PrintRenderer { at.translate(currentIPPosition, currentBPPosition); if (!at.isIdentity()) { - saveGraphicsState(); - concatenateTransformationMatrix(UnitConv.mptToPt(at)); + establishTransformationMatrix(at); } currentIPPosition = 0; @@ -849,4 +851,16 @@ public abstract class AbstractPathOrientedRenderer extends PrintRenderer { 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)); + } + } diff --git a/src/java/org/apache/fop/render/AbstractState.java b/src/java/org/apache/fop/render/AbstractState.java index 51f831011..04409390f 100644 --- a/src/java/org/apache/fop/render/AbstractState.java +++ b/src/java/org/apache/fop/render/AbstractState.java @@ -251,10 +251,10 @@ public abstract class AbstractState implements Cloneable, Serializable { /** * 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); } /** @@ -382,6 +382,30 @@ public abstract class AbstractState implements Cloneable, Serializable { // 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(); diff --git a/src/java/org/apache/fop/render/afp/AFPAbstractGraphicsObjectPainter.java b/src/java/org/apache/fop/render/afp/AFPAbstractGraphicsObjectPainter.java new file mode 100644 index 000000000..101d28b61 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/AFPAbstractGraphicsObjectPainter.java @@ -0,0 +1,62 @@ +/* + * 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 diff --git a/src/java/org/apache/fop/render/afp/AFPBatikGraphicsObjectPainter.java b/src/java/org/apache/fop/render/afp/AFPBatikGraphicsObjectPainter.java new file mode 100644 index 000000000..94da16d71 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/AFPBatikGraphicsObjectPainter.java @@ -0,0 +1,70 @@ +/* + * 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; + } + +} diff --git a/src/java/org/apache/fop/render/afp/AFPBorderPainter.java b/src/java/org/apache/fop/render/afp/AFPBorderPainter.java index db2b8681b..e8fa4d83e 100644 --- a/src/java/org/apache/fop/render/afp/AFPBorderPainter.java +++ b/src/java/org/apache/fop/render/afp/AFPBorderPainter.java @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Id: $ */ +/* $Id$ */ package org.apache.fop.render.afp; @@ -35,12 +35,6 @@ public class AFPBorderPainter { /** 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; @@ -52,176 +46,156 @@ public class AFPBorderPainter { */ 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); } } diff --git a/src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java b/src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java index d31b79cc4..3acac7e6e 100644 --- a/src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java @@ -15,10 +15,12 @@ * 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; @@ -35,6 +37,7 @@ import org.apache.fop.render.afp.modca.ResourceObject; 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) @@ -121,8 +124,11 @@ public class AFPDataObjectFactory { */ 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; } @@ -170,13 +176,16 @@ public class AFPDataObjectFactory { 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); diff --git a/src/java/org/apache/fop/render/afp/AFPDataObjectInfoFactory.java b/src/java/org/apache/fop/render/afp/AFPDataObjectInfoFactory.java index 1aaa89d00..a4979eb89 100644 --- a/src/java/org/apache/fop/render/afp/AFPDataObjectInfoFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPDataObjectInfoFactory.java @@ -62,17 +62,28 @@ public abstract class AFPDataObjectInfoFactory { // 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; } diff --git a/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java b/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java index 525c3487f..b54479e53 100644 --- a/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java +++ b/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Id: $ */ +/* $Id$ */ package org.apache.fop.render.afp; @@ -23,6 +23,7 @@ import java.util.Iterator; 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; @@ -31,7 +32,8 @@ 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/**/ factoryMap + = new java.util.HashMap/**/(); private final AFPState state; /** @@ -54,6 +56,8 @@ public class AFPDataObjectInfoProvider { ImageRawCCITTFax.class, new AFPRawCCITTFaxFactory(state)); factoryMap.put( ImageRawStream.class, new AFPImageRawStreamFactory(state)); + factoryMap.put( + ImageGraphics2D.class, new AFPImageGraphics2DFactory(state)); }; /** diff --git a/src/java/org/apache/fop/render/afp/AFPGraphics2D.java b/src/java/org/apache/fop/render/afp/AFPGraphics2D.java index cb33e5a5a..ea98fe18e 100644 --- a/src/java/org/apache/fop/render/afp/AFPGraphics2D.java +++ b/src/java/org/apache/fop/render/afp/AFPGraphics2D.java @@ -85,8 +85,6 @@ public class AFPGraphics2D extends AbstractGraphics2D { /** Current AFP state */ private AFPState state = null; - private AFPUnitConverter unitConv; - /** * Main constructor * @@ -122,7 +120,6 @@ public class AFPGraphics2D extends AbstractGraphics2D { public void setAFPInfo(AFPInfo afpInfo) { this.info = afpInfo; this.state = info.getState(); - this.unitConv = state.getUnitConverter(); } /** @@ -400,6 +397,7 @@ public class AFPGraphics2D extends AbstractGraphics2D { 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); @@ -425,10 +423,6 @@ public class AFPGraphics2D extends AbstractGraphics2D { ImageRendered imgRend = new ImageRendered(imageInfo, buf, null); RenderedImage ri = imgRend.getRenderedImage(); - - - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { // Serialize image @@ -536,4 +530,13 @@ public class AFPGraphics2D extends AbstractGraphics2D { 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 diff --git a/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java b/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java index 0f891c03b..f9759676f 100644 --- a/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java +++ b/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java @@ -37,6 +37,8 @@ public class AFPGraphics2DAdapter extends AbstractGraphics2DAdapter { private final AFPRenderer renderer; + private final AFPGraphics2D g2d; + /** * Main constructor * @@ -44,6 +46,18 @@ public class AFPGraphics2DAdapter extends AbstractGraphics2DAdapter { */ 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} */ @@ -54,8 +68,6 @@ public class AFPGraphics2DAdapter extends AbstractGraphics2DAdapter { // 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); @@ -90,7 +102,6 @@ public class AFPGraphics2DAdapter extends AbstractGraphics2DAdapter { at.scale(scale, scale); } - AffineTransform trans = state.getData().getTransform(); trans.concatenate(at); @@ -101,8 +112,15 @@ public class AFPGraphics2DAdapter extends AbstractGraphics2DAdapter { // 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(); diff --git a/src/java/org/apache/fop/render/afp/AFPGraphicsObjectInfo.java b/src/java/org/apache/fop/render/afp/AFPGraphicsObjectInfo.java index c01e266fe..b4c651574 100644 --- a/src/java/org/apache/fop/render/afp/AFPGraphicsObjectInfo.java +++ b/src/java/org/apache/fop/render/afp/AFPGraphicsObjectInfo.java @@ -5,9 +5,9 @@ * 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. @@ -19,6 +19,9 @@ package org.apache.fop.render.afp; +import java.awt.geom.Rectangle2D; + +import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; import org.apache.xmlgraphics.util.MimeConstants; /** @@ -26,26 +29,69 @@ 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() + "}"; @@ -55,4 +101,5 @@ public class AFPGraphicsObjectInfo extends AFPDataObjectInfo { public String getMimeType() { return MimeConstants.MIME_SVG; } + } diff --git a/src/java/org/apache/fop/render/afp/AFPGraphicsObjectPainter.java b/src/java/org/apache/fop/render/afp/AFPGraphicsObjectPainter.java deleted file mode 100644 index b794ff93c..000000000 --- a/src/java/org/apache/fop/render/afp/AFPGraphicsObjectPainter.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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 diff --git a/src/java/org/apache/fop/render/afp/AFPImageGraphics2DFactory.java b/src/java/org/apache/fop/render/afp/AFPImageGraphics2DFactory.java new file mode 100644 index 000000000..0433d25b3 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/AFPImageGraphics2DFactory.java @@ -0,0 +1,70 @@ +/* + * 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; + } + +} diff --git a/src/java/org/apache/fop/render/afp/AFPImageInfo.java b/src/java/org/apache/fop/render/afp/AFPImageInfo.java index 0ab4f6493..9acc87b3f 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageInfo.java +++ b/src/java/org/apache/fop/render/afp/AFPImageInfo.java @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Id: $ */ +/* $Id$ */ package org.apache.fop.render.afp; @@ -23,6 +23,7 @@ import java.awt.Point; 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; @@ -49,6 +50,12 @@ public class AFPImageInfo { /** the image */ protected final Image img; + /** the AFP graphics 2d adapter */ + protected AFPGraphics2DAdapter g2dAdapter; + + /** the renderer context */ + protected RendererContext rendererContext; + /** * Main constructor * @@ -69,4 +76,22 @@ public class AFPImageInfo { 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; + } + } diff --git a/src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java b/src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java index c4b901b7c..711e135d0 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java +++ b/src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java @@ -128,7 +128,7 @@ public class AFPImageObjectInfo extends AFPDataObjectInfo { /** {@inheritDoc} */ public String toString() { return "AFPImageObjectInfo{" + super.toString() - + "compression=" + compression + + ", compression=" + compression + ", color=" + color + ", bitsPerPixel=" + bitsPerPixel + "}"; diff --git a/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java b/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java index 43e678aab..172b67038 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Id: $ */ +/* $Id$ */ package org.apache.fop.render.afp; @@ -25,7 +25,7 @@ import java.io.InputStream; 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 { diff --git a/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java b/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java index 4ce6b27b0..df806a4d9 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Id: $ */ +/* $Id$ */ package org.apache.fop.render.afp; @@ -28,7 +28,7 @@ import org.apache.xmlgraphics.image.loader.impl.ImageRendered; import org.apache.xmlgraphics.ps.ImageEncodingHelper; /** - * A buffered image configurator + * A buffered image data object info factory */ public class AFPImageRenderedFactory extends AFPDataObjectInfoFactory { diff --git a/src/java/org/apache/fop/render/afp/AFPLineDataInfo.java b/src/java/org/apache/fop/render/afp/AFPLineDataInfo.java new file mode 100644 index 000000000..618cf21ae --- /dev/null +++ b/src/java/org/apache/fop/render/afp/AFPLineDataInfo.java @@ -0,0 +1,192 @@ +/* + * 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 + + "}"; + } + +} diff --git a/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java b/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java index 6700f263d..2f090b0ba 100644 --- a/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Id: $ */ +/* $Id$ */ package org.apache.fop.render.afp; @@ -24,7 +24,7 @@ import java.io.IOException; 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 { diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java index 9a7fa7515..1f080b38a 100644 --- a/src/java/org/apache/fop/render/afp/AFPRenderer.java +++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java @@ -36,7 +36,6 @@ import java.util.Map; 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; @@ -66,7 +65,6 @@ import org.apache.xmlgraphics.image.loader.ImageFlavor; 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; @@ -186,15 +184,16 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { /** {@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} */ @@ -220,7 +219,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { /** {@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(); @@ -298,12 +297,15 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { 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); @@ -419,6 +421,14 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { 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); @@ -429,14 +439,6 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { 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(), @@ -546,28 +548,55 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { 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 { @@ -579,43 +608,17 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { + 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 @@ -769,11 +772,11 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { } /** - * Returns the AFPDataStream + * Returns the AFP DataStream * - * @return the AFPDataStream + * @return the AFP DataStream */ - public DataStream getAFPDocumentStream() { + public DataStream getDataStream() { return this.dataStream; } @@ -813,40 +816,11 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { 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); } } diff --git a/src/java/org/apache/fop/render/afp/AFPResourceManager.java b/src/java/org/apache/fop/render/afp/AFPResourceManager.java index 5a28efe26..58f65524d 100644 --- a/src/java/org/apache/fop/render/afp/AFPResourceManager.java +++ b/src/java/org/apache/fop/render/afp/AFPResourceManager.java @@ -69,10 +69,11 @@ public class AFPResourceManager { /** * 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); } @@ -105,7 +106,7 @@ public class AFPResourceManager { } /** - * Creates and returns a new data object + * Creates a new data object in the AFP datastream * * @param dataObjectInfo the data object info * @@ -119,17 +120,14 @@ public class AFPResourceManager { 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; @@ -140,6 +138,7 @@ public class AFPResourceManager { } 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(); @@ -172,7 +171,7 @@ public class AFPResourceManager { // 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 @@ -186,4 +185,4 @@ public class AFPResourceManager { } } -} +} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/AFPSVGHandler.java b/src/java/org/apache/fop/render/afp/AFPSVGHandler.java index 5d9fcdb7d..508c13efb 100644 --- a/src/java/org/apache/fop/render/afp/AFPSVGHandler.java +++ b/src/java/org/apache/fop/render/afp/AFPSVGHandler.java @@ -126,12 +126,12 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { // 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]); @@ -146,18 +146,21 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { 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(); @@ -172,8 +175,8 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { //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); @@ -184,7 +187,7 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { = (Map/**/)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; @@ -214,15 +217,18 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { // 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} */ diff --git a/src/java/org/apache/fop/render/afp/AFPState.java b/src/java/org/apache/fop/render/afp/AFPState.java index 2f01e8371..8209f3153 100644 --- a/src/java/org/apache/fop/render/afp/AFPState.java +++ b/src/java/org/apache/fop/render/afp/AFPState.java @@ -19,8 +19,6 @@ 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; @@ -44,7 +42,7 @@ public class AFPState extends org.apache.fop.render.AbstractState implements Clo 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; @@ -55,10 +53,12 @@ public class AFPState extends org.apache.fop.render.AbstractState implements Clo /** 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. @@ -289,6 +289,15 @@ public class AFPState extends org.apache.fop.render.AbstractState implements Clo return pageState.getHeight(); } + /** + * Returns the page rotation + * + * @return the page rotation + */ + public int getPageRotation() { + return pageState.getOrientation(); + } + /** * Sets the uri of the current image * @@ -308,24 +317,12 @@ public class AFPState extends org.apache.fop.render.AbstractState implements Clo } /** - * 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(); } /** @@ -365,18 +362,21 @@ public class AFPState extends org.apache.fop.render.AbstractState implements Clo * 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 * @@ -440,12 +440,31 @@ public class AFPState extends org.apache.fop.render.AbstractState implements Clo 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; } @@ -454,6 +473,7 @@ public class AFPState extends org.apache.fop.render.AbstractState implements Clo public String toString() { return "AFPPageState{width=" + width + ", height=" + height + + ", orientation=" + orientation + ", fonts=" + fonts + ", fontCount=" + fontCount + "}"; @@ -487,4 +507,5 @@ public class AFPState extends org.apache.fop.render.AbstractState implements Clo + "}"; } } + } \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/AFPStreamer.java b/src/java/org/apache/fop/render/afp/AFPStreamer.java index 0759b85fc..be68caab2 100644 --- a/src/java/org/apache/fop/render/afp/AFPStreamer.java +++ b/src/java/org/apache/fop/render/afp/AFPStreamer.java @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Id: $ */ +/* $Id$ */ package org.apache.fop.render.afp; @@ -84,16 +84,17 @@ public class AFPStreamer implements Streamable { /** * 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()); } diff --git a/src/java/org/apache/fop/render/afp/AFPTextDataInfo.java b/src/java/org/apache/fop/render/afp/AFPTextDataInfo.java index dc507580a..7cc90c589 100644 --- a/src/java/org/apache/fop/render/afp/AFPTextDataInfo.java +++ b/src/java/org/apache/fop/render/afp/AFPTextDataInfo.java @@ -5,9 +5,9 @@ * 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. @@ -27,142 +27,142 @@ import java.awt.Color; 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) { @@ -171,22 +171,22 @@ public class AFPTextDataInfo { /** * 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 @@ -195,7 +195,7 @@ public class AFPTextDataInfo { + ", color=" + color + ", vsci=" + variableSpaceCharacterIncrement + ", ica=" + interCharacterAdjustment - + ", orientation=" + orientation + + ", orientation=" + rotation + ", data=" + data + "}"; } diff --git a/src/java/org/apache/fop/render/afp/LineDataInfo.java b/src/java/org/apache/fop/render/afp/LineDataInfo.java deleted file mode 100644 index 4926f79e6..000000000 --- a/src/java/org/apache/fop/render/afp/LineDataInfo.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * 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 - + "}"; - } - -} diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java index 3ce108bfc..6b03adee0 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java @@ -23,7 +23,7 @@ import java.io.IOException; 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; @@ -128,6 +128,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { String name, int width, int height, int rotation, int widthRes, int heightRes) { super(name); + this.factory = factory; this.width = width; this.height = height; @@ -158,7 +159,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { * * @param lineDataInfo the line data information. */ - public void createLine(LineDataInfo lineDataInfo) { + public void createLine(AFPLineDataInfo lineDataInfo) { getPresentationTextObject().createLineData(lineDataInfo); } @@ -269,9 +270,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { */ 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); @@ -343,5 +342,4 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { public void addObject(Object obj) { objects.add(obj); } - } diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java index dee0366cb..89b7f8cdb 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java @@ -84,6 +84,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writeObjects(triplets, baos); this.tripletData = baos.toByteArray(); + triplets = null; // gc } return this.tripletData; } @@ -99,6 +100,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { os.write(tripletData); } else if (triplets != null) { writeObjects(triplets, os); + triplets = null; // gc } } diff --git a/src/java/org/apache/fop/render/afp/modca/DataStream.java b/src/java/org/apache/fop/render/afp/modca/DataStream.java index 129a2bfbb..2f5336f20 100644 --- a/src/java/org/apache/fop/render/afp/modca/DataStream.java +++ b/src/java/org/apache/fop/render/afp/modca/DataStream.java @@ -20,6 +20,7 @@ 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; @@ -28,9 +29,10 @@ import java.util.Map; 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; @@ -76,14 +78,11 @@ public class DataStream { /** 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 @@ -93,13 +92,18 @@ public class DataStream { 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; } @@ -293,31 +297,6 @@ public class DataStream { } } - /** - * 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 * @@ -350,6 +329,37 @@ public class DataStream { 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. @@ -358,7 +368,13 @@ public class DataStream { * 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); } @@ -367,8 +383,7 @@ public class DataStream { * * @param lineDataInfo the line data information. */ - public void createLine(LineDataInfo lineDataInfo) { - lineDataInfo.setOrientation(orientation); + public void createLine(AFPLineDataInfo lineDataInfo) { currentPage.createLine(lineDataInfo); } @@ -400,7 +415,7 @@ public class DataStream { * 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); } @@ -427,6 +442,7 @@ public class DataStream { 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; @@ -547,38 +563,6 @@ public class DataStream { } } - /** - * 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 * @@ -615,4 +599,38 @@ public class DataStream { 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) { + } + } diff --git a/src/java/org/apache/fop/render/afp/modca/Factory.java b/src/java/org/apache/fop/render/afp/modca/Factory.java index d45684a70..468912b50 100644 --- a/src/java/org/apache/fop/render/afp/modca/Factory.java +++ b/src/java/org/apache/fop/render/afp/modca/Factory.java @@ -23,6 +23,7 @@ import java.io.OutputStream; 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; @@ -359,13 +360,14 @@ public class Factory { } /** - * 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; } @@ -424,9 +426,9 @@ public class Factory { /** * 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, diff --git a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java b/src/java/org/apache/fop/render/afp/modca/IncludeObject.java index 336f2700f..9e5216f6f 100644 --- a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java +++ b/src/java/org/apache/fop/render/afp/modca/IncludeObject.java @@ -42,59 +42,38 @@ import org.apache.fop.render.afp.tools.BinaryUtils; */ 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; /** diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationTextData.java b/src/java/org/apache/fop/render/afp/modca/PresentationTextData.java index 57a45f99d..05ea1ebf2 100644 --- a/src/java/org/apache/fop/render/afp/modca/PresentationTextData.java +++ b/src/java/org/apache/fop/render/afp/modca/PresentationTextData.java @@ -24,7 +24,7 @@ import java.io.IOException; 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; @@ -277,22 +277,25 @@ public class PresentationTextData extends AbstractAFPObject { 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 @@ -362,43 +365,43 @@ public class PresentationTextData extends AbstractAFPObject { * @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; } @@ -425,36 +428,36 @@ public class PresentationTextData extends AbstractAFPObject { * * @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; } } @@ -467,10 +470,10 @@ public class PresentationTextData extends AbstractAFPObject { * * @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 @@ -489,7 +492,7 @@ public class PresentationTextData extends AbstractAFPObject { (byte) (col.getBlue()), // Blue intensity }; - afpdata.write(colorData, 0, colorData.length); + os.write(colorData, 0, colorData.length); } /** @@ -497,14 +500,14 @@ public class PresentationTextData extends AbstractAFPObject { * * @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] }, @@ -516,12 +519,12 @@ public class PresentationTextData extends AbstractAFPObject { * * @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 diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java b/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java index cbfad326d..4071ebb9d 100644 --- a/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java +++ b/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java @@ -23,7 +23,7 @@ import java.io.IOException; 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; /** @@ -87,7 +87,7 @@ public class PresentationTextObject extends AbstractNamedAFPObject { * * @param lineDataInfo the line data information. */ - public void createLineData(LineDataInfo lineDataInfo) { + public void createLineData(AFPLineDataInfo lineDataInfo) { if (currentPresentationTextData == null) { startPresentationTextData(); }