diff options
Diffstat (limited to 'src/java/org/apache/fop/render/afp/AFPBorderPainter.java')
-rw-r--r-- | src/java/org/apache/fop/render/afp/AFPBorderPainter.java | 169 |
1 files changed, 81 insertions, 88 deletions
diff --git a/src/java/org/apache/fop/render/afp/AFPBorderPainter.java b/src/java/org/apache/fop/render/afp/AFPBorderPainter.java index d73154997..5fbb91abc 100644 --- a/src/java/org/apache/fop/render/afp/AFPBorderPainter.java +++ b/src/java/org/apache/fop/render/afp/AFPBorderPainter.java @@ -19,11 +19,8 @@ package org.apache.fop.render.afp; -import java.awt.Color; import java.awt.geom.AffineTransform; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.fop.fo.Constants; import org.apache.fop.render.afp.modca.DataStream; import org.apache.fop.util.ColorUtil; @@ -31,12 +28,7 @@ import org.apache.fop.util.ColorUtil; /** * Handles the drawing of borders/lines in AFP */ -public class AFPBorderPainter { - /** Static logging instance */ - protected static Log log = LogFactory.getLog("org.apache.fop.render.afp"); - - private final DataStream dataStream; - private final AFPState state; +public class AFPBorderPainter extends AbstractAFPPainter { /** * Main constructor @@ -45,59 +37,14 @@ public class AFPBorderPainter { * @param dataStream the afp datastream */ public AFPBorderPainter(AFPState state, DataStream dataStream) { - this.state = state; - this.dataStream = dataStream; + super(state, 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(); - - 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()) + Math.round(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() - y); - lineDataInfo.x2 = pageWidth - Math.round((float)at.getTranslateX() - x - width); - break; - case 270: - lineDataInfo.x1 = pageHeight - Math.round((float)at.getTranslateY() - 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 isHorizontal, boolean startOrBefore, int style, Color color) { - float w = x2 - x1; - float h = y2 - y1; + public void paint(PaintInfo paintInfo) { + BorderPaintInfo borderPaintInfo = (BorderPaintInfo)paintInfo; + float w = borderPaintInfo.getX2() - borderPaintInfo.getX1(); + float h = borderPaintInfo.getY2() - borderPaintInfo.getY1(); if ((w < 0) || (h < 0)) { log.error("Negative extent received. Border won't be painted."); return; @@ -108,10 +55,10 @@ public class AFPBorderPainter { 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); + float x1 = unitConv.pt2units(borderPaintInfo.getX1()); + float y1 = unitConv.pt2units(borderPaintInfo.getY1()); + float x2 = unitConv.pt2units(borderPaintInfo.getX2()); + float y2 = unitConv.pt2units(borderPaintInfo.getY2()); switch (state.getRotation()) { case 0: @@ -141,49 +88,90 @@ public class AFPBorderPainter { } AFPLineDataInfo lineDataInfo = new AFPLineDataInfo(); - lineDataInfo.setThickness(Math.round(y2 - y1)); - lineDataInfo.setColor(color); + lineDataInfo.setColor(borderPaintInfo.getColor()); lineDataInfo.setRotation(state.getRotation()); - lineDataInfo.x1 = Math.round(x1); lineDataInfo.y1 = Math.round(y1); + if (borderPaintInfo.isHorizontal()) { + lineDataInfo.setThickness(Math.round(y2 - y1)); + } else { + lineDataInfo.setThickness(Math.round(x2 - x1)); + } // handle border-*-style - switch (style) { + switch (borderPaintInfo.getStyle()) { case Constants.EN_DOUBLE: - 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); + if (borderPaintInfo.isHorizontal()) { + lineDataInfo.x2 = Math.round(x2); + lineDataInfo.y2 = lineDataInfo.y1; + dataStream.createLine(lineDataInfo); + lineDataInfo.y1 += Math.round((lineDataInfo.thickness / 3) * 2); + dataStream.createLine(lineDataInfo); + } else { + lineDataInfo.x2 = lineDataInfo.x1; + lineDataInfo.y2 = Math.round(y2); + dataStream.createLine(lineDataInfo); + lineDataInfo.x1 += Math.round((lineDataInfo.thickness / 3) * 2); + dataStream.createLine(lineDataInfo); + } break; case Constants.EN_DASHED: - case Constants.EN_DOTTED: - 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; + int thick = lineDataInfo.thickness * 3; + if (borderPaintInfo.isHorizontal()) { 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; + } + } else { + lineDataInfo.x2 = lineDataInfo.x1; + lineDataInfo.y2 = lineDataInfo.y1 + thick; + int ey2 = Math.round(y2); + while (lineDataInfo.y1 + thick < ey2) { + dataStream.createLine(lineDataInfo); + lineDataInfo.y1 += 2 * thick; + lineDataInfo.y2 = lineDataInfo.y1 + thick; + } + } + break; + case Constants.EN_DOTTED: + if (borderPaintInfo.isHorizontal()) { + lineDataInfo.x2 = lineDataInfo.x1 + lineDataInfo.thickness; + lineDataInfo.y2 = lineDataInfo.y1; + int ex2 = Math.round(x2); + while (lineDataInfo.x1 + lineDataInfo.thickness < ex2) { + dataStream.createLine(lineDataInfo); + lineDataInfo.x1 += 3 * lineDataInfo.thickness; + lineDataInfo.x2 = lineDataInfo.x1 + lineDataInfo.thickness; + } + } else { + lineDataInfo.x2 = lineDataInfo.x1; + lineDataInfo.y2 = lineDataInfo.y1 + lineDataInfo.thickness; + int ey2 = Math.round(y2); + while (lineDataInfo.y1 + lineDataInfo.thickness < ey2) { + dataStream.createLine(lineDataInfo); + lineDataInfo.y1 += 3 * lineDataInfo.thickness; + lineDataInfo.y2 = lineDataInfo.y1 + lineDataInfo.thickness; + } } break; case Constants.EN_GROOVE: case Constants.EN_RIDGE: + //TODO lineDataInfo.x2 = Math.round(x2); - float colFactor = (style == Constants.EN_GROOVE ? 0.4f : -0.4f); + float colFactor = (borderPaintInfo.getStyle() == Constants.EN_GROOVE ? 0.4f : -0.4f); float h3 = (y2 - y1) / 3; - lineDataInfo.color = ColorUtil.lightenColor(color, -colFactor); + lineDataInfo.color = ColorUtil.lightenColor(borderPaintInfo.getColor(), -colFactor); lineDataInfo.thickness = Math.round(h3); lineDataInfo.y1 = lineDataInfo.y2 = Math.round(y1); dataStream.createLine(lineDataInfo); - lineDataInfo.color = color; + lineDataInfo.color = borderPaintInfo.getColor(); lineDataInfo.y1 = lineDataInfo.y2 = Math.round(y1 + h3); dataStream.createLine(lineDataInfo); - lineDataInfo.color = ColorUtil.lightenColor(color, colFactor); + lineDataInfo.color = ColorUtil.lightenColor(borderPaintInfo.getColor(), colFactor); lineDataInfo.y1 = lineDataInfo.y2 = Math.round(y1 + h3 + h3); dataStream.createLine(lineDataInfo); break; @@ -193,8 +181,13 @@ public class AFPBorderPainter { case Constants.EN_OUTSET: case Constants.EN_SOLID: default: - lineDataInfo.x2 = Math.round(x2); - lineDataInfo.y2 = lineDataInfo.y1; + if (borderPaintInfo.isHorizontal()) { + lineDataInfo.x2 = Math.round(x2); + lineDataInfo.y2 = lineDataInfo.y1; + } else { + lineDataInfo.x2 = lineDataInfo.x1; + lineDataInfo.y2 = Math.round(y2); + } dataStream.createLine(lineDataInfo); } } |