aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2008-08-20 20:47:34 +0000
committerJeremias Maerki <jeremias@apache.org>2008-08-20 20:47:34 +0000
commit0864f618dc60cfe3dde181a06ae82b12a0f32931 (patch)
treeebaa65f4a62cc9f529f6c10c60b0be23e6251295 /src/java/org/apache/fop/render
parentb639554f837e39f0984d0585d7effad7093a03d7 (diff)
downloadxmlgraphics-fop-0864f618dc60cfe3dde181a06ae82b12a0f32931.tar.gz
xmlgraphics-fop-0864f618dc60cfe3dde181a06ae82b12a0f32931.zip
Added support for painting leaders (implemented as drawLine in IFPainter).
Removed unused "stroke" parameter in drawRect and renamed the method to fillRect. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@687455 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render')
-rw-r--r--src/java/org/apache/fop/render/intermediate/BorderPainter.java7
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFConstants.java1
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFPainter.java21
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFParser.java25
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFRenderer.java30
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFSerializer.java33
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFBorderPainter.java62
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFContentGenerator.java14
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFPainter.java26
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFRenderer.java79
10 files changed, 199 insertions, 99 deletions
diff --git a/src/java/org/apache/fop/render/intermediate/BorderPainter.java b/src/java/org/apache/fop/render/intermediate/BorderPainter.java
index fdde321a9..e8874dc69 100644
--- a/src/java/org/apache/fop/render/intermediate/BorderPainter.java
+++ b/src/java/org/apache/fop/render/intermediate/BorderPainter.java
@@ -20,9 +20,11 @@
package org.apache.fop.render.intermediate;
import java.awt.Color;
+import java.awt.Point;
import java.awt.Rectangle;
import org.apache.fop.traits.BorderProps;
+import org.apache.fop.traits.RuleStyle;
/**
* This is an abstract base class for handling border painting.
@@ -198,7 +200,10 @@ public abstract class BorderPainter {
protected abstract void drawBorderLine(int x1, int y1, int x2, int y2,
- boolean horz, boolean startOrBefore, int style, Color col);
+ boolean horz, boolean startOrBefore, int style, Color color);
+
+ public abstract void drawLine(Point start, Point end,
+ int width, Color color, RuleStyle style);
protected abstract void moveTo(int x, int y);
diff --git a/src/java/org/apache/fop/render/intermediate/IFConstants.java b/src/java/org/apache/fop/render/intermediate/IFConstants.java
index f101ad363..e7f7e1a00 100644
--- a/src/java/org/apache/fop/render/intermediate/IFConstants.java
+++ b/src/java/org/apache/fop/render/intermediate/IFConstants.java
@@ -46,6 +46,7 @@ public interface IFConstants extends XMLConstants {
String EL_IMAGE = "image";
String EL_CLIP_RECT = "clip-rect";
String EL_RECT = "rect";
+ String EL_LINE = "line";
String EL_BORDER_RECT = "border-rect";
String EL_FONT = "font";
String EL_TEXT = "text";
diff --git a/src/java/org/apache/fop/render/intermediate/IFPainter.java b/src/java/org/apache/fop/render/intermediate/IFPainter.java
index 4722a02ac..b354510f8 100644
--- a/src/java/org/apache/fop/render/intermediate/IFPainter.java
+++ b/src/java/org/apache/fop/render/intermediate/IFPainter.java
@@ -22,6 +22,7 @@ package org.apache.fop.render.intermediate;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Paint;
+import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.util.Map;
@@ -33,6 +34,7 @@ import org.w3c.dom.Document;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.traits.BorderProps;
+import org.apache.fop.traits.RuleStyle;
/**
* Interface used to paint whole documents layouted by Apache FOP.
@@ -277,13 +279,12 @@ public interface IFPainter {
//TODO clipRect() shall be considered temporary until verified with SVG and PCL
/**
- * Draws a rectangle. Either fill or stroke has to be specified.
+ * Fills a rectangular area.
* @param rect the rectangle's coordinates and extent
- * @param fill the fill paint (may be null)
- * @param stroke the stroke color (may be null)
+ * @param fill the fill paint
* @throws IFException if an error occurs while handling this event
*/
- void drawRect(Rectangle rect, Paint fill, Color stroke) throws IFException;
+ void fillRect(Rectangle rect, Paint fill) throws IFException;
/**
* Draws a border rectangle. The border segments are specified through {@code BorderProps}
@@ -300,6 +301,18 @@ public interface IFPainter {
BorderProps start, BorderProps end) throws IFException;
/**
+ * Draws a line. NOTE: Currently, only horizontal lines are implemented!
+ * @param start the start point of the line
+ * @param end the end point of the line
+ * @param width the line width
+ * @param color the line color
+ * @param style the line style (using the Constants.EN_* constants for the rule-style property)
+ * @throws IFException if an error occurs while handling this event
+ */
+ void drawLine(Point start, Point end, int width, Color color, RuleStyle style)
+ throws IFException;
+
+ /**
* Draws an image identified by a URI inside a given rectangle. This is the equivalent to
* an fo:external-graphic in XSL-FO.
* @param uri the image's URI
diff --git a/src/java/org/apache/fop/render/intermediate/IFParser.java b/src/java/org/apache/fop/render/intermediate/IFParser.java
index 50c061ff4..cc125a6f7 100644
--- a/src/java/org/apache/fop/render/intermediate/IFParser.java
+++ b/src/java/org/apache/fop/render/intermediate/IFParser.java
@@ -21,6 +21,7 @@ package org.apache.fop.render.intermediate;
import java.awt.Color;
import java.awt.Dimension;
+import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.util.Map;
@@ -50,6 +51,7 @@ import org.apache.fop.fo.ElementMapping;
import org.apache.fop.fo.ElementMappingRegistry;
import org.apache.fop.fo.expr.PropertyException;
import org.apache.fop.traits.BorderProps;
+import org.apache.fop.traits.RuleStyle;
import org.apache.fop.util.ColorUtil;
import org.apache.fop.util.ContentHandlerFactory;
import org.apache.fop.util.ContentHandlerFactoryRegistry;
@@ -138,6 +140,7 @@ public class IFParser implements IFConstants {
elementHandlers.put(EL_TEXT, new TextHandler());
elementHandlers.put(EL_CLIP_RECT, new ClipRectHandler());
elementHandlers.put(EL_RECT, new RectHandler());
+ elementHandlers.put(EL_LINE, new LineHandler());
elementHandlers.put(EL_BORDER_RECT, new BorderRectHandler());
elementHandlers.put(EL_IMAGE, new ImageHandler());
}
@@ -467,13 +470,27 @@ public class IFParser implements IFConstants {
} catch (PropertyException pe) {
throw new IFException("Error parsing the fill attribute", pe);
}
- Color strokeColor;
+ painter.fillRect(new Rectangle(x, y, width, height), fillColor);
+ }
+
+ }
+
+ private class LineHandler extends AbstractElementHandler {
+
+ public void startElement(Attributes attributes) throws IFException {
+ int x1 = Integer.parseInt(attributes.getValue("x1"));
+ int y1 = Integer.parseInt(attributes.getValue("y1"));
+ int x2 = Integer.parseInt(attributes.getValue("x2"));
+ int y2 = Integer.parseInt(attributes.getValue("y2"));
+ int width = Integer.parseInt(attributes.getValue("stroke-width"));
+ Color color;
try {
- strokeColor = getAttributeAsColor(attributes, "stroke");
+ color = getAttributeAsColor(attributes, "color");
} catch (PropertyException pe) {
- throw new IFException("Error parsing the stroke attribute", pe);
+ throw new IFException("Error parsing the fill attribute", pe);
}
- painter.drawRect(new Rectangle(x, y, width, height), fillColor, strokeColor);
+ RuleStyle style = RuleStyle.valueOf(attributes.getValue("style"));
+ painter.drawLine(new Point(x1, y1), new Point(x2, y2), width, color, style);
}
}
diff --git a/src/java/org/apache/fop/render/intermediate/IFRenderer.java b/src/java/org/apache/fop/render/intermediate/IFRenderer.java
index 0b74987b5..1ea3f9592 100644
--- a/src/java/org/apache/fop/render/intermediate/IFRenderer.java
+++ b/src/java/org/apache/fop/render/intermediate/IFRenderer.java
@@ -67,6 +67,7 @@ import org.apache.fop.area.inline.AbstractTextArea;
import org.apache.fop.area.inline.ForeignObject;
import org.apache.fop.area.inline.Image;
import org.apache.fop.area.inline.InlineArea;
+import org.apache.fop.area.inline.Leader;
import org.apache.fop.area.inline.SpaceArea;
import org.apache.fop.area.inline.TextArea;
import org.apache.fop.area.inline.Viewport;
@@ -87,6 +88,7 @@ import org.apache.fop.render.intermediate.extensions.GoToXYAction;
import org.apache.fop.render.intermediate.extensions.NamedDestination;
import org.apache.fop.render.pdf.PDFEventProducer;
import org.apache.fop.traits.BorderProps;
+import org.apache.fop.traits.RuleStyle;
/**
* This renderer implementation is an adapter to the {@code IFPainter} interface. It is used
@@ -993,6 +995,30 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
}
/** {@inheritDoc} */
+ public void renderLeader(Leader area) {
+ renderInlineAreaBackAndBorders(area);
+
+ int style = area.getRuleStyle();
+ int ruleThickness = area.getRuleThickness();
+ int startx = currentIPPosition + area.getBorderAndPaddingWidthStart();
+ int starty = currentBPPosition + area.getOffset() + (ruleThickness / 2);
+ int endx = currentIPPosition
+ + area.getBorderAndPaddingWidthStart()
+ + area.getIPD();
+ Color col = (Color)area.getTrait(Trait.COLOR);
+
+ Point start = new Point(startx, starty);
+ Point end = new Point(endx, starty);
+ try {
+ painter.drawLine(start, end, ruleThickness, col, RuleStyle.valueOf(style));
+ } catch (IFException ife) {
+ handleIFException(ife);
+ }
+
+ super.renderLeader(area);
+ }
+
+ /** {@inheritDoc} */
protected void clip() {
throw new IllegalStateException("Not used");
}
@@ -1048,9 +1074,9 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
/** {@inheritDoc} */
protected void fillRect(float x, float y, float width, float height) {
try {
- painter.drawRect(
+ painter.fillRect(
toMillipointRectangle(x, y, width, height),
- this.graphicContext.getPaint(), null);
+ this.graphicContext.getPaint());
} catch (IFException e) {
handleIFException(e);
}
diff --git a/src/java/org/apache/fop/render/intermediate/IFSerializer.java b/src/java/org/apache/fop/render/intermediate/IFSerializer.java
index 4eb7f0713..20db35c6a 100644
--- a/src/java/org/apache/fop/render/intermediate/IFSerializer.java
+++ b/src/java/org/apache/fop/render/intermediate/IFSerializer.java
@@ -22,6 +22,7 @@ package org.apache.fop.render.intermediate;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Paint;
+import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.util.Iterator;
@@ -37,6 +38,7 @@ import org.apache.xmlgraphics.util.XMLizable;
import org.apache.fop.render.RenderingContext;
import org.apache.fop.traits.BorderProps;
+import org.apache.fop.traits.RuleStyle;
import org.apache.fop.util.ColorUtil;
import org.apache.fop.util.DOM2SAX;
import org.apache.fop.util.XMLUtil;
@@ -364,8 +366,8 @@ public class IFSerializer extends AbstractXMLWritingIFPainter implements IFConst
}
/** {@inheritDoc} */
- public void drawRect(Rectangle rect, Paint fill, Color stroke) throws IFException {
- if (fill == null && stroke == null) {
+ public void fillRect(Rectangle rect, Paint fill) throws IFException {
+ if (fill == null) {
return;
}
try {
@@ -374,15 +376,10 @@ public class IFSerializer extends AbstractXMLWritingIFPainter implements IFConst
addAttribute(atts, "y", Integer.toString(rect.y));
addAttribute(atts, "width", Integer.toString(rect.width));
addAttribute(atts, "height", Integer.toString(rect.height));
- if (fill != null) {
- addAttribute(atts, "fill", toString(fill));
- }
- if (stroke != null) {
- addAttribute(atts, "stroke", toString(stroke));
- }
+ addAttribute(atts, "fill", toString(fill));
element(EL_RECT, atts);
} catch (SAXException e) {
- throw new IFException("SAX error in drawRect()", e);
+ throw new IFException("SAX error in fillRect()", e);
}
}
@@ -417,6 +414,24 @@ public class IFSerializer extends AbstractXMLWritingIFPainter implements IFConst
}
/** {@inheritDoc} */
+ public void drawLine(Point start, Point end, int width, Color color, RuleStyle style)
+ throws IFException {
+ try {
+ AttributesImpl atts = new AttributesImpl();
+ addAttribute(atts, "x1", Integer.toString(start.x));
+ addAttribute(atts, "y1", Integer.toString(start.y));
+ addAttribute(atts, "x2", Integer.toString(end.x));
+ addAttribute(atts, "y2", Integer.toString(end.y));
+ addAttribute(atts, "stroke-width", Integer.toString(width));
+ addAttribute(atts, "color", Integer.toString(width));
+ addAttribute(atts, "style", style.getName());
+ element(EL_LINE, atts);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in drawLine()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
public void drawText(int x, int y, int[] dx, int[] dy, String text) throws IFException {
try {
AttributesImpl atts = new AttributesImpl();
diff --git a/src/java/org/apache/fop/render/pdf/PDFBorderPainter.java b/src/java/org/apache/fop/render/pdf/PDFBorderPainter.java
index ab34e36c9..309307a51 100644
--- a/src/java/org/apache/fop/render/pdf/PDFBorderPainter.java
+++ b/src/java/org/apache/fop/render/pdf/PDFBorderPainter.java
@@ -20,6 +20,8 @@
package org.apache.fop.render.pdf;
import java.awt.Color;
+import java.awt.Point;
+import java.awt.Rectangle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -27,6 +29,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.fop.fo.Constants;
import org.apache.fop.render.PrintRenderer;
import org.apache.fop.render.intermediate.BorderPainter;
+import org.apache.fop.traits.RuleStyle;
/**
* PDF-specific implementation of the {@code BorderPainter}.
@@ -221,6 +224,65 @@ public class PDFBorderPainter extends BorderPainter {
}
}
+ /** {@inheritDoc} */
+ public void drawLine(Point start, Point end,
+ int width, Color color, RuleStyle style) {
+ if (start.y != end.y) {
+ //TODO Support arbitrary lines if necessary
+ throw new UnsupportedOperationException(
+ "Can only deal with horizontal lines right now");
+ }
+
+ saveGraphicsState();
+ int half = width / 2;
+ int starty = start.y - half;
+ Rectangle boundingRect = new Rectangle(start.x, start.y - half, end.x - start.x, width);
+ switch (style.getEnumValue()) {
+ case Constants.EN_SOLID:
+ case Constants.EN_DASHED:
+ case Constants.EN_DOUBLE:
+ drawBorderLine(start.x, start.y - half, end.x, end.y + half,
+ true, true, style.getEnumValue(), color);
+ break;
+ case Constants.EN_DOTTED:
+ generator.clipRect(boundingRect);
+ //This displaces the dots to the right by half a dot's width
+ //TODO There's room for improvement here
+ generator.add("1 0 0 1 " + format(half) + " 0 cm\n");
+ drawBorderLine(start.x, start.y - half, end.x, end.y + half,
+ true, true, style.getEnumValue(), color);
+ break;
+ case Constants.EN_GROOVE:
+ case Constants.EN_RIDGE:
+ generator.setColor(PrintRenderer.lightenColor(color, 0.6f), true);
+ generator.add(format(start.x) + " " + format(starty) + " m\n");
+ generator.add(format(end.x) + " " + format(starty) + " l\n");
+ generator.add(format(end.x) + " " + format(starty + 2 * half) + " l\n");
+ generator.add(format(start.x) + " " + format(starty + 2 * half) + " l\n");
+ generator.add("h\n");
+ generator.add("f\n");
+ generator.setColor(color, true);
+ if (style == RuleStyle.GROOVE) {
+ generator.add(format(start.x) + " " + format(starty) + " m\n");
+ generator.add(format(end.x) + " " + format(starty) + " l\n");
+ generator.add(format(end.x) + " " + format(starty + half) + " l\n");
+ generator.add(format(start.x + half) + " " + format(starty + half) + " l\n");
+ generator.add(format(start.x) + " " + format(starty + 2 * half) + " l\n");
+ } else {
+ generator.add(format(end.x) + " " + format(starty) + " m\n");
+ generator.add(format(end.x) + " " + format(starty + 2 * half) + " l\n");
+ generator.add(format(start.x) + " " + format(starty + 2 * half) + " l\n");
+ generator.add(format(start.x) + " " + format(starty + half) + " l\n");
+ generator.add(format(end.x - half) + " " + format(starty + half) + " l\n");
+ }
+ generator.add("h\n");
+ generator.add("f\n");
+ break;
+ default:
+ throw new UnsupportedOperationException("rule style not supported");
+ }
+ restoreGraphicsState();
+ }
static final String format(int coordinate) {
return format(coordinate / 1000f);
diff --git a/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java b/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java
index da1bf728e..35dc0960a 100644
--- a/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java
+++ b/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java
@@ -20,6 +20,7 @@
package org.apache.fop.render.pdf;
import java.awt.Color;
+import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.io.IOException;
import java.io.OutputStream;
@@ -210,6 +211,19 @@ public class PDFContentGenerator {
}
/**
+ * Intersects the current clip region with the given rectangle.
+ * @param rect the clip rectangle
+ */
+ public void clipRect(Rectangle rect) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(format(rect.x / 1000f)).append(' ');
+ sb.append(format(rect.y / 1000f)).append(' ');
+ sb.append(format(rect.width / 1000f)).append(' ');
+ sb.append(format(rect.height / 1000f)).append(" re W n\n");
+ add(sb.toString());
+ }
+
+ /**
* Adds content to the stream.
* @param content the PDF content
*/
diff --git a/src/java/org/apache/fop/render/pdf/PDFPainter.java b/src/java/org/apache/fop/render/pdf/PDFPainter.java
index 0ddfd8324..e4418bb99 100644
--- a/src/java/org/apache/fop/render/pdf/PDFPainter.java
+++ b/src/java/org/apache/fop/render/pdf/PDFPainter.java
@@ -22,6 +22,7 @@ package org.apache.fop.render.pdf;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Paint;
+import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
@@ -65,6 +66,7 @@ import org.apache.fop.render.intermediate.extensions.BookmarkTree;
import org.apache.fop.render.intermediate.extensions.GoToXYAction;
import org.apache.fop.render.intermediate.extensions.NamedDestination;
import org.apache.fop.traits.BorderProps;
+import org.apache.fop.traits.RuleStyle;
import org.apache.fop.util.CharUtilities;
/**
@@ -327,17 +329,12 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter {
/** {@inheritDoc} */
public void clipRect(Rectangle rect) throws IFException {
generator.endTextObject();
- StringBuffer sb = new StringBuffer();
- sb.append(format(rect.x)).append(' ');
- sb.append(format(rect.y)).append(' ');
- sb.append(format(rect.width)).append(' ');
- sb.append(format(rect.height)).append(" re W n\n");
- generator.add(sb.toString());
+ generator.clipRect(rect);
}
/** {@inheritDoc} */
- public void drawRect(Rectangle rect, Paint fill, Color stroke) throws IFException {
- if (fill == null && stroke == null) {
+ public void fillRect(Rectangle rect, Paint fill) throws IFException {
+ if (fill == null) {
return;
}
generator.endTextObject();
@@ -349,9 +346,6 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter {
throw new UnsupportedOperationException("Non-Color paints NYI");
}
}
- if (stroke != null) {
- throw new UnsupportedOperationException("stroke NYI");
- }
StringBuffer sb = new StringBuffer();
sb.append(format(rect.x)).append(' ');
sb.append(format(rect.y)).append(' ');
@@ -360,9 +354,10 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter {
if (fill != null) {
sb.append(" f");
}
+ /* Removed from method signature as it is currently not used
if (stroke != null) {
sb.append(" S");
- }
+ }*/
sb.append('\n');
generator.add(sb.toString());
}
@@ -377,6 +372,13 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter {
}
}
+ /** {@inheritDoc} */
+ public void drawLine(Point start, Point end, int width, Color color, RuleStyle style)
+ throws IFException {
+ generator.endTextObject();
+ this.borderPainter.drawLine(start, end, width, color, style);
+ }
+
private Typeface getTypeface(String fontName) {
if (fontName == null) {
throw new NullPointerException("fontName must not be null");
diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
index 325cc79fe..9567c5306 100644
--- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java
+++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
@@ -91,6 +91,7 @@ import org.apache.fop.pdf.PDFXObject;
import org.apache.fop.render.AbstractPathOrientedRenderer;
import org.apache.fop.render.Graphics2DAdapter;
import org.apache.fop.render.RendererContext;
+import org.apache.fop.traits.RuleStyle;
import org.apache.fop.util.CharUtilities;
/**
@@ -167,6 +168,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer implements PDFConf
/** The current content generator to produce PDF commands with */
protected PDFContentGenerator generator;
+ private PDFBorderPainter borderPainter;
/**
* the current annotation list to add annotations to
@@ -189,6 +191,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer implements PDFConf
/** Image handler registry */
private PDFImageHandlerRegistry imageHandlerRegistry = new PDFImageHandlerRegistry();
+
/**
* create the PDF renderer
*/
@@ -460,17 +463,8 @@ public class PDFRenderer extends AbstractPathOrientedRenderer implements PDFConf
pageHeight = (int) h;
this.generator = new PDFContentGenerator(this.pdfDoc, this.ostream, this.currentPage);
- /*
- currentStream = this.pdfDoc.getFactory()
- .makeStream(PDFFilterList.CONTENT_FILTER, false);
- this.textutil = new PDFTextUtil() {
- protected void write(String code) {
- currentStream.add(code);
- }
- };
+ this.borderPainter = new PDFBorderPainter(this.generator);
- currentState = new PDFState();
- */
// Transform the PDF's default coordinate system (0,0 at lower left) to the PDFRenderer's
AffineTransform basicPageTransform = new AffineTransform(1, 0, 0, -1, 0,
pageHeight / 1000f);
@@ -1223,66 +1217,17 @@ public class PDFRenderer extends AbstractPathOrientedRenderer implements PDFConf
public void renderLeader(Leader area) {
renderInlineAreaBackAndBorders(area);
- getState().push();
- saveGraphicsState();
int style = area.getRuleStyle();
- float startx = (currentIPPosition + area.getBorderAndPaddingWidthStart()) / 1000f;
- float starty = (currentBPPosition + area.getOffset()) / 1000f;
- float endx = (currentIPPosition + area.getBorderAndPaddingWidthStart()
- + area.getIPD()) / 1000f;
- float ruleThickness = area.getRuleThickness() / 1000f;
+ int ruleThickness = area.getRuleThickness();
+ int startx = currentIPPosition + area.getBorderAndPaddingWidthStart();
+ int starty = currentBPPosition + area.getOffset() + (ruleThickness / 2);
+ int endx = currentIPPosition
+ + area.getBorderAndPaddingWidthStart()
+ + area.getIPD();
Color col = (Color)area.getTrait(Trait.COLOR);
- switch (style) {
- case EN_SOLID:
- case EN_DASHED:
- case EN_DOUBLE:
- drawBorderLine(startx, starty, endx, starty + ruleThickness,
- true, true, style, col);
- break;
- case EN_DOTTED:
- clipRect(startx, starty, endx - startx, ruleThickness);
- //This displaces the dots to the right by half a dot's width
- //TODO There's room for improvement here
- generator.add("1 0 0 1 " + format(ruleThickness / 2) + " 0 cm\n");
- drawBorderLine(startx, starty, endx, starty + ruleThickness,
- true, true, style, col);
- break;
- case EN_GROOVE:
- case EN_RIDGE:
- float half = area.getRuleThickness() / 2000f;
-
- generator.setColor(lightenColor(col, 0.6f), true);
- generator.add(format(startx) + " " + format(starty) + " m\n");
- generator.add(format(endx) + " " + format(starty) + " l\n");
- generator.add(format(endx) + " " + format(starty + 2 * half) + " l\n");
- generator.add(format(startx) + " " + format(starty + 2 * half) + " l\n");
- generator.add("h\n");
- generator.add("f\n");
- generator.setColor(col, true);
- if (style == EN_GROOVE) {
- generator.add(format(startx) + " " + format(starty) + " m\n");
- generator.add(format(endx) + " " + format(starty) + " l\n");
- generator.add(format(endx) + " " + format(starty + half) + " l\n");
- generator.add(format(startx + half) + " " + format(starty + half) + " l\n");
- generator.add(format(startx) + " " + format(starty + 2 * half) + " l\n");
- } else {
- generator.add(format(endx) + " " + format(starty) + " m\n");
- generator.add(format(endx) + " " + format(starty + 2 * half) + " l\n");
- generator.add(format(startx) + " " + format(starty + 2 * half) + " l\n");
- generator.add(format(startx) + " " + format(starty + half) + " l\n");
- generator.add(format(endx - half) + " " + format(starty + half) + " l\n");
- }
- generator.add("h\n");
- generator.add("f\n");
- break;
- default:
- throw new UnsupportedOperationException("rule style not supported");
- }
-
- restoreGraphicsState();
- getState().pop();
- beginTextObject();
+ borderPainter.drawLine(new Point(startx, starty), new Point(endx, starty),
+ ruleThickness, col, RuleStyle.valueOf(style));
super.renderLeader(area);
}