klease 01/07/20 13:57:23
Modified: src/org/apache/fop/render PrintRenderer.java
src/org/apache/fop/render/pdf PDFRenderer.java
Log:
Add new addFilledRect method to make it possible to draw filled rectangles without
any stroke in PDF; in doFrame, use rectangles instead of lines for borders to
eliminate pixel errors
Revision Changes Path
1.7 +52 -18 xml-fop/src/org/apache/fop/render/PrintRenderer.java
Index: PrintRenderer.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/PrintRenderer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PrintRenderer.java 2001/05/17 07:46:12 1.6
+++ PrintRenderer.java 2001/07/20 20:57:22 1.7
@@ -1,4 +1,4 @@
-/* $Id: PrintRenderer.java,v 1.6 2001/05/17 07:46:12 keiron Exp $
+/* $Id: PrintRenderer.java,v 1.7 2001/07/20 20:57:22 klease Exp $
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources."
@@ -142,7 +142,7 @@
PDFPathPaint stroke);
/**
- * add a filled rectangle to the current stream
+ * add a filled and stroked rectangle to the current stream
*
* @param x the x position of left edge in millipoints
* @param y the y position of top edge in millipoints
@@ -155,6 +155,22 @@
PDFPathPaint stroke, PDFPathPaint fill);
/**
+ * Add a filled rectangle to the current stream
+ * This default implementation calls addRect
+ * using the same color for fill and border.
+ *
+ * @param x the x position of left edge in millipoints
+ * @param y the y position of top edge in millipoints
+ * @param w the width in millipoints
+ * @param h the height in millipoints
+ * @param fill the fill color/gradient
+ */
+ protected void addFilledRect(int x, int y, int w, int h,
+ PDFPathPaint fill) {
+ addRect(x,y,w,h,fill,fill);
+ }
+
+ /**
* render area container
*
* @param area the area container to render
@@ -174,8 +190,8 @@
} else if (area.getPosition() == Position.STATIC) {
this.currentYPosition -=
area.getPaddingTop() + area.getBorderTopWidth();
- this.currentAreaContainerXPosition +=
- area.getPaddingLeft() + area.getBorderLeftWidth();
+ /* this.currentAreaContainerXPosition +=
+ area.getPaddingLeft() + area.getBorderLeftWidth();*/
}
this.currentXPosition = this.currentAreaContainerXPosition;
@@ -274,7 +290,7 @@
// I'm not sure I should have to check for bg being null
// but I do
if ((bg != null) && (bg.alpha() == 0)) {
- this.addRect(rx, ry, w, -h, new PDFColor(bg), new PDFColor(bg));
+ this.addFilledRect(rx, ry, w, -h, new PDFColor(bg));
}
//rx = rx - area.getBorderLeftWidth();
@@ -285,23 +301,41 @@
// Handle line style
// Offset for haft the line width!
BorderAndPadding bp = area.getBorderAndPadding();
- int left = rx - area.getBorderLeftWidth() / 2;
- int right = rx + w + area.getBorderRightWidth() / 2;
- int top = ry + area.getBorderTopWidth() / 2;
- int bottom = ry - h - area.getBorderBottomWidth() / 2;
- if (area.getBorderTopWidth() != 0)
- addLine(left, top, right, top, area.getBorderTopWidth(),
+// int left = rx - area.getBorderLeftWidth() / 2;
+// int right = rx + w + area.getBorderRightWidth() / 2;
+// int top = ry + area.getBorderTopWidth() / 2;
+// int bottom = ry - h - area.getBorderBottomWidth() / 2;
+// if (area.getBorderTopWidth() != 0)
+// addLine(left, top, right, top, area.getBorderTopWidth(),
+// new PDFColor(bp.getBorderColor(BorderAndPadding.TOP)));
+// if (area.getBorderLeftWidth() != 0)
+// addLine(left, ry + area.getBorderTopWidth(), left, bottom,
area.getBorderLeftWidth(),
+// new PDFColor(bp.getBorderColor(BorderAndPadding.LEFT)));
+// if (area.getBorderRightWidth() != 0)
+// addLine(right, ry + area.getBorderTopWidth(), right, bottom,
area.getBorderRightWidth(),
+// new PDFColor(bp.getBorderColor(BorderAndPadding.RIGHT)));
+// if (area.getBorderBottomWidth() != 0)
+// addLine(rx - area.getBorderLeftWidth(), bottom, rx + w +
area.getBorderRightWidth(), bottom, area.getBorderBottomWidth(),
+// new PDFColor(bp.getBorderColor(BorderAndPadding.BOTTOM)));
+ // Try using rectangles instead of lines. Line style will be a
+ // problem though?
+ int left = area.getBorderLeftWidth();
+ int right = area.getBorderRightWidth();
+ int top = area.getBorderTopWidth();
+ int bottom = area.getBorderBottomWidth() ;
+ // If style is solid, use filled rectangles
+ if (top != 0)
+ addFilledRect(rx, ry, w, top,
new PDFColor(bp.getBorderColor(BorderAndPadding.TOP)));
- if (area.getBorderLeftWidth() != 0)
- addLine(left, ry + area.getBorderTopWidth(), left, bottom,
area.getBorderLeftWidth(),
+ if (left != 0)
+ addFilledRect(rx-left, ry-h-bottom, left, h+top+bottom,
new PDFColor(bp.getBorderColor(BorderAndPadding.LEFT)));
- if (area.getBorderRightWidth() != 0)
- addLine(right, ry + area.getBorderTopWidth(), right, bottom,
area.getBorderRightWidth(),
+ if (right != 0)
+ addFilledRect(rx+w, ry-h-bottom, right, h+top+bottom,
new PDFColor(bp.getBorderColor(BorderAndPadding.RIGHT)));
- if (area.getBorderBottomWidth() != 0)
- addLine(rx - area.getBorderLeftWidth(), bottom, rx + w +
area.getBorderRightWidth(), bottom, area.getBorderBottomWidth(),
+ if (bottom != 0)
+ addFilledRect(rx, ry-h-bottom, w, bottom,
new PDFColor(bp.getBorderColor(BorderAndPadding.BOTTOM)));
-
}
1.73 +20 -2 xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
Index: PDFRenderer.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -r1.72 -r1.73
--- PDFRenderer.java 2001/07/12 13:03:29 1.72
+++ PDFRenderer.java 2001/07/20 20:57:22 1.73
@@ -1,4 +1,4 @@
-/* $Id: PDFRenderer.java,v 1.72 2001/07/12 13:03:29 keiron Exp $
+/* $Id: PDFRenderer.java,v 1.73 2001/07/20 20:57:22 klease Exp $
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources."
@@ -218,10 +218,28 @@
protected void addRect(int x, int y, int w, int h,
PDFPathPaint stroke, PDFPathPaint fill) {
closeText();
- currentStream.add("ET\nq\n" + fill.getColorSpaceOut(true) +
+ currentStream.add("ET\nq\n" + fill.getColorSpaceOut(true) +
stroke.getColorSpaceOut(false) + (x / 1000f) + " " +
(y / 1000f) + " " + (w / 1000f) + " " + (h / 1000f) +
" re b\n" + "Q\nBT\n");
+ }
+
+ /**
+ * add a filled rectangle to the current stream
+ *
+ * @param x the x position of left edge in millipoints
+ * @param y the y position of top edge in millipoints
+ * @param w the width in millipoints
+ * @param h the height in millipoints
+ * @param fill the fill color/gradient
+ */
+ protected void addFilledRect(int x, int y, int w, int h,
+ PDFPathPaint fill) {
+ closeText();
+ currentStream.add("ET\nq\n" + fill.getColorSpaceOut(true) +
+ (x / 1000f) + " " +
+ (y / 1000f) + " " + (w / 1000f) + " " + (h / 1000f) +
+ " re f\n" + "Q\nBT\n");
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]