keiron 01/09/18 06:06:08
Modified: src/org/apache/fop/render AbstractRenderer.java
PrintRenderer.java
src/org/apache/fop/render/awt AWTRenderer.java
src/org/apache/fop/render/mif MIFRenderer.java
src/org/apache/fop/render/ps PSRenderer.java
src/org/apache/fop/render/xml XMLRenderer.java
Log:
more refactoring of duplicate code in renderers
Revision Changes Path
1.4 +63 -3 xml-fop/src/org/apache/fop/render/AbstractRenderer.java
Index: AbstractRenderer.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/AbstractRenderer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractRenderer.java 2001/09/17 13:29:53 1.3
+++ AbstractRenderer.java 2001/09/18 13:06:07 1.4
@@ -1,5 +1,5 @@
/*
- * $Id: AbstractRenderer.java,v 1.3 2001/09/17 13:29:53 keiron Exp $
+ * $Id: AbstractRenderer.java,v 1.4 2001/09/18 13:06:07 keiron 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.
@@ -54,14 +54,74 @@
public void renderSpanArea(SpanArea area) {
Enumeration e = area.getChildren().elements();
while (e.hasMoreElements()) {
- org.apache.fop.layout.Box b =
- (org.apache.fop.layout.Box)e.nextElement();
+ Box b = (Box)e.nextElement();
b.render(this); // column areas
}
}
protected abstract void doFrame(Area area);
+
+ /**
+ * 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 abstract void addFilledRect(int x, int y, int w, int h,
+ ColorType col);
+
+ public void renderBodyAreaContainer(BodyAreaContainer area) {
+ int saveY = this.currentYPosition;
+ int saveX = this.currentAreaContainerXPosition;
+
+ if (area.getPosition() == Position.ABSOLUTE) {
+ // Y position is computed assuming positive Y axis, adjust for negative
postscript one
+ this.currentYPosition = area.getYPosition();
+ this.currentAreaContainerXPosition = area.getXPosition();
+ } else if (area.getPosition() == Position.RELATIVE) {
+ this.currentYPosition -= area.getYPosition();
+ this.currentAreaContainerXPosition += area.getXPosition();
+ }
+
+ this.currentXPosition = this.currentAreaContainerXPosition;
+ int w, h;
+ int rx = this.currentAreaContainerXPosition;
+ w = area.getContentWidth();
+ h = area.getContentHeight();
+ int ry = this.currentYPosition;
+ ColorType bg = area.getBackgroundColor();
+
+ // I'm not sure I should have to check for bg being null
+ // but I do
+ if ((bg != null) && (bg.alpha() == 0)) {
+ addFilledRect(rx, ry, w, -h, bg);
+ }
+
+ // floats & footnotes stuff
+ renderAreaContainer(area.getBeforeFloatReferenceArea());
+ renderAreaContainer(area.getFootnoteReferenceArea());
+
+ // main reference area
+ Enumeration e = area.getMainReferenceArea().getChildren().elements();
+ while (e.hasMoreElements()) {
+ Box b = (Box)e.nextElement();
+ b.render(this); // span areas
+ }
+
+
+ if (area.getPosition() != Position.STATIC) {
+ this.currentYPosition = saveY;
+ this.currentAreaContainerXPosition = saveX;
+ } else
+ this.currentYPosition -= area.getHeight();
+
+ }
/**
* render area container
1.14 +5 -46 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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- PrintRenderer.java 2001/09/17 13:29:53 1.13
+++ PrintRenderer.java 2001/09/18 13:06:07 1.14
@@ -1,5 +1,5 @@
/*
- * $Id: PrintRenderer.java,v 1.13 2001/09/17 13:29:53 keiron Exp $
+ * $Id: PrintRenderer.java,v 1.14 2001/09/18 13:06:07 keiron 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."
@@ -177,51 +177,10 @@
addRect(x, y, w, h, fill, fill);
}
- public void renderBodyAreaContainer(BodyAreaContainer area) {
- int saveY = this.currentYPosition;
- int saveX = this.currentAreaContainerXPosition;
-
- if (area.getPosition() == Position.ABSOLUTE) {
- // Y position is computed assuming positive Y axis, adjust for negative
postscript one
- this.currentYPosition = area.getYPosition();
- this.currentAreaContainerXPosition = area.getXPosition();
- } else if (area.getPosition() == Position.RELATIVE) {
- this.currentYPosition -= area.getYPosition();
- this.currentAreaContainerXPosition += area.getXPosition();
- }
-
- this.currentXPosition = this.currentAreaContainerXPosition;
- int w, h;
- int rx = this.currentAreaContainerXPosition;
- w = area.getContentWidth();
- h = area.getContentHeight();
- int ry = this.currentYPosition;
- ColorType bg = area.getBackgroundColor();
-
- // 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));
- }
-
- // floats & footnotes stuff
- renderAreaContainer(area.getBeforeFloatReferenceArea());
- renderAreaContainer(area.getFootnoteReferenceArea());
-
- // main reference area
- Enumeration e = area.getMainReferenceArea().getChildren().elements();
- while (e.hasMoreElements()) {
- Box b = (Box)e.nextElement();
- b.render(this); // span areas
- }
-
-
- if (area.getPosition() != Position.STATIC) {
- this.currentYPosition = saveY;
- this.currentAreaContainerXPosition = saveX;
- } else
- this.currentYPosition -= area.getHeight();
-
+ protected void addFilledRect(int x, int y, int w, int h,
+ ColorType col) {
+ PDFColor pdfcol = new PDFColor(col);
+ addRect(x, y, w, h, pdfcol, pdfcol);
}
protected void doFrame(Area area) {
1.35 +9 -18 xml-fop/src/org/apache/fop/render/awt/AWTRenderer.java
Index: AWTRenderer.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/awt/AWTRenderer.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- AWTRenderer.java 2001/09/17 13:29:53 1.34
+++ AWTRenderer.java 2001/09/18 13:06:07 1.35
@@ -1,5 +1,5 @@
/*
- * $Id: AWTRenderer.java,v 1.34 2001/09/17 13:29:53 keiron Exp $
+ * $Id: AWTRenderer.java,v 1.35 2001/09/18 13:06:07 keiron 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.
@@ -219,11 +219,8 @@
* @param g the green component
* @param b the blue component
*/
-
// changed by aml/rlc to use helper function that
// corrects for integer roundoff, and to remove 3D effect
-
-
protected void addRect(int x, int y, int w, int h, float r, float g,
float b) {
graphics.setColor(new Color(r, g, b));
@@ -280,6 +277,14 @@
graphics.fillRect(startx, starty, endx - startx, endy - starty);
}
+ protected void addFilledRect(int x, int y, int w, int h,
+ ColorType col) {
+ float r = col.red();
+ float g = col.green();
+ float b = col.blue();
+ addRect(x, y, w, h, r, g, b, r, g, b);
+ }
+
/**
* To configure before print.
*
@@ -390,20 +395,6 @@
* ....
* }
*/
- }
-
- public void renderBodyAreaContainer(BodyAreaContainer area) {
- renderAreaContainer(area.getBeforeFloatReferenceArea());
- renderAreaContainer(area.getFootnoteReferenceArea());
-
- // main reference area
- Enumeration e = area.getMainReferenceArea().getChildren().elements();
- while (e.hasMoreElements()) {
- org.apache.fop.layout.Box b =
- (org.apache.fop.layout.Box)e.nextElement();
- b.render(this); // span areas
- }
-
}
protected void doFrame(org.apache.fop.layout.Area area) {
1.11 +8 -131 xml-fop/src/org/apache/fop/render/mif/MIFRenderer.java
Index: MIFRenderer.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/mif/MIFRenderer.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- MIFRenderer.java 2001/09/17 13:29:53 1.10
+++ MIFRenderer.java 2001/09/18 13:06:07 1.11
@@ -1,5 +1,5 @@
/*
- * $Id: MIFRenderer.java,v 1.10 2001/09/17 13:29:53 keiron Exp $
+ * $Id: MIFRenderer.java,v 1.11 2001/09/18 13:06:07 keiron 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.
@@ -149,93 +149,11 @@
this.mifDoc.endTable();
}
- int saveY = this.currentYPosition;
- int saveX = this.currentAreaContainerXPosition;
-
- if (area.getPosition() == Position.ABSOLUTE) {
- // Y position is computed assuming positive Y axis, adjust for negative
postscript one
- this.currentYPosition = area.getYPosition()
- - 2 * area.getPaddingTop()
- - 2 * area.getBorderTopWidth();
-
- this.currentAreaContainerXPosition = area.getXPosition();
- } else if (area.getPosition() == Position.RELATIVE) {
-
- this.currentYPosition -= area.getYPosition();
- this.currentAreaContainerXPosition += area.getXPosition();
-
- } else if (area.getPosition() == Position.STATIC) {
-
- this.currentYPosition -= area.getPaddingTop()
- + area.getBorderTopWidth();
- this.currentAreaContainerXPosition += area.getPaddingLeft()
- + area.getBorderLeftWidth();
- }
-
- this.currentXPosition = this.currentAreaContainerXPosition;
- doFrame(area);
-
- Enumeration e = area.getChildren().elements();
- while (e.hasMoreElements()) {
- Box b = (Box)e.nextElement();
- b.render(this);
- }
- if (area.getPosition() != Position.STATIC) {
- this.currentYPosition = saveY;
- this.currentAreaContainerXPosition = saveX;
- } else
- this.currentYPosition -= area.getHeight();
- }
-
- public void renderBodyAreaContainer(BodyAreaContainer area) {
-
-
- int saveY = this.currentYPosition;
- int saveX = this.currentAreaContainerXPosition;
-
- if (area.getPosition() == Position.ABSOLUTE) {
- // Y position is computed assuming positive Y axis, adjust for negative
postscript one
- this.currentYPosition = area.getYPosition();
- this.currentAreaContainerXPosition = area.getXPosition();
- } else if (area.getPosition() == Position.RELATIVE) {
- this.currentYPosition -= area.getYPosition();
- this.currentAreaContainerXPosition += area.getXPosition();
- }
-
- this.currentXPosition = this.currentAreaContainerXPosition;
- int w, h;
- int rx = this.currentAreaContainerXPosition;
- w = area.getContentWidth();
- h = area.getContentHeight();
- int ry = this.currentYPosition;
- ColorType bg = area.getBackgroundColor();
-
- /*
- * // 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));
- * }
- */
- /*
- * // floats & footnotes stuff
- * renderAreaContainer(area.getBeforeFloatReferenceArea());
- * renderAreaContainer(area.getFootnoteReferenceArea());
- */
- // main reference area
- Enumeration e = area.getMainReferenceArea().getChildren().elements();
- while (e.hasMoreElements()) {
- Box b = (Box)e.nextElement();
- b.render(this); // span areas
- }
-
-
- if (area.getPosition() != Position.STATIC) {
- this.currentYPosition = saveY;
- this.currentAreaContainerXPosition = saveX;
- } else
- this.currentYPosition -= area.getHeight();
+ super.renderAreaContainer(area);
+ }
+ protected void addFilledRect(int x, int y, int w, int h,
+ ColorType col) {
}
protected void doFrame(Area area) {
@@ -293,42 +211,25 @@
}
public void renderSpanArea(SpanArea area) {
-
// A span maps to a textframe
-
-
this.mifDoc.createTextRect(area.getColumnCount());
-
- Enumeration e = area.getChildren().elements();
- while (e.hasMoreElements()) {
- Box b = (Box)e.nextElement();
- b.render(this); // column areas
- }
-
+ super.renderSpanArea(area);
}
/**
* render the given block area
*/
public void renderBlockArea(BlockArea area) {
-
this.mifDoc.setBlockProp(area.getStartIndent(), area.getEndIndent());
- Enumeration e = area.getChildren().elements();
- while (e.hasMoreElements()) {
- Box b = (Box)e.nextElement();
- b.render(this);
- }
-
+ super.renderBlockArea(area);
}
/**
* render the given display space
*/
public void renderDisplaySpace(DisplaySpace space) {
-
int d = space.getSize();
this.currentYPosition -= d;
-
}
/**
@@ -341,7 +242,6 @@
*/
public void renderForeignObjectArea(ForeignObjectArea area) {}
-
public void renderWordArea(WordArea area) {
String s;
s = area.getText();
@@ -407,32 +307,9 @@
* render the given line area
*/
public void renderLineArea(LineArea area) {
-
- int rx = this.currentAreaContainerXPosition + area.getStartIndent();
- int ry = this.currentYPosition;
- int w = area.getContentWidth();
- int h = area.getHeight();
-
- this.currentYPosition -= area.getPlacementOffset();
- this.currentXPosition = rx;
-
- int bl = this.currentYPosition;
-
// The start of a new linearea corresponds to a new para in FM
-
this.mifDoc.startLine();
-
- Enumeration e = area.getChildren().elements();
- while (e.hasMoreElements()) {
-
- Box b = (Box)e.nextElement();
- this.currentYPosition = ry - area.getPlacementOffset();
- b.render(this);
-
- }
- this.currentYPosition = ry - h;
- this.currentXPosition = rx;
-
+ super.renderLineArea(area);
}
/**
1.12 +13 -119 xml-fop/src/org/apache/fop/render/ps/PSRenderer.java
Index: PSRenderer.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/ps/PSRenderer.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- PSRenderer.java 2001/09/17 13:29:53 1.11
+++ PSRenderer.java 2001/09/18 13:06:08 1.12
@@ -1,5 +1,5 @@
/*
- * $Id: PSRenderer.java,v 1.11 2001/09/17 13:29:53 keiron Exp $
+ * $Id: PSRenderer.java,v 1.12 2001/09/18 13:06:08 keiron 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.
@@ -143,7 +143,6 @@
}
}
-
/**
* write out a comment
*/
@@ -152,7 +151,6 @@
write(comment);
}
-
protected void writeFontDict(FontInfo fontInfo) {
write("%%BeginResource: procset FOPFonts");
write("%%Title: Font setup (shortcuts) for this file");
@@ -258,123 +256,18 @@
org.apache.fop.render.pdf.FontSetup.setup(fontInfo);
this.fontInfo = fontInfo;
}
-
- /**
- * render an area container to PostScript
- *
- * @param area the area container to render
- */
- public void renderAreaContainer(AreaContainer area) {
- int saveY = this.currentYPosition;
- int saveX = this.currentAreaContainerXPosition;
- if (area.getPosition() == Position.ABSOLUTE) {
- // Y position is computed assuming positive Y axis, adjust for negative
postscript one
- this.currentYPosition = area.getYPosition()
- - 2 * area.getPaddingTop()
- - 2 * area.getBorderTopWidth();
- this.currentAreaContainerXPosition = area.getXPosition();
- } else if (area.getPosition() == Position.RELATIVE) {
- this.currentYPosition -= area.getYPosition();
- this.currentAreaContainerXPosition += area.getXPosition();
- } else if (area.getPosition() == Position.STATIC) {
- this.currentYPosition -= area.getPaddingTop()
- + area.getBorderTopWidth();
- this.currentAreaContainerXPosition += area.getPaddingLeft()
- + area.getBorderLeftWidth();
- }
-
- this.currentXPosition = this.currentAreaContainerXPosition;
-
- // comment("% --- AreaContainer begin");
- doFrame(area);
- Enumeration e = area.getChildren().elements();
- while (e.hasMoreElements()) {
- Box b = (Box)e.nextElement();
- b.render(this);
- }
- // comment("% --- AreaContainer end");
-
- if (area.getPosition() != Position.STATIC) {
- this.currentYPosition = saveY;
- this.currentAreaContainerXPosition = saveX;
- } else {
- this.currentYPosition -= area.getHeight();
- }
- }
-
- /**
- * render a body area container to PostScript
- *
- * @param area the body area container to render
- */
- public void renderBodyAreaContainer(BodyAreaContainer area) {
- int saveY = this.currentYPosition;
- int saveX = this.currentAreaContainerXPosition;
-
- if (area.getPosition() == Position.ABSOLUTE) {
- // Y position is computed assuming positive Y axis, adjust for negative
postscript one
- this.currentYPosition = area.getYPosition();
- this.currentAreaContainerXPosition = area.getXPosition();
- } else if (area.getPosition() == Position.RELATIVE) {
- this.currentYPosition -= area.getYPosition();
- this.currentAreaContainerXPosition += area.getXPosition();
- }
-
- this.currentXPosition = this.currentAreaContainerXPosition;
- int w, h;
- int rx = this.currentAreaContainerXPosition;
- w = area.getContentWidth();
- h = area.getContentHeight();
- int ry = this.currentYPosition;
-
- // comment("% --- BodyAreaContainer begin");
- doFrame(area);
- // movetoCurrPosition();
-
- Enumeration e = area.getChildren().elements();
- while (e.hasMoreElements()) {
- Box b = (Box)e.nextElement();
- b.render(this);
- }
- // comment("% --- BodyAreaContainer end");
-
- if (area.getPosition() != Position.STATIC) {
- this.currentYPosition = saveY;
- this.currentAreaContainerXPosition = saveX;
- } else {
- this.currentYPosition -= area.getHeight();
- }
- }
- /**
- * render a span area to PostScript
- *
- * @param area the span area to render
- */
- public void renderSpanArea(SpanArea area) {
- // comment("% --- SpanArea begin");
- Enumeration e = area.getChildren().elements();
- while (e.hasMoreElements()) {
- Box b = (Box)e.nextElement();
- b.render(this);
- }
- // comment("% --- SpanArea end");
- }
-
- /**
- * render a block area to PostScript
- *
- * @param area the block area to render
- */
- public void renderBlockArea(BlockArea area) {
- // comment("% --- BlockArea begin");
- doFrame(area);
- Enumeration e = area.getChildren().elements();
- while (e.hasMoreElements()) {
- Box b = (Box)e.nextElement();
- b.render(this);
- }
- // comment("% --- BlockArea end");
+ protected void addFilledRect(int x, int y, int w, int h,
+ ColorType col) {
+ write("newpath");
+ write(x + " " + y + " M");
+ write(w + " 0 rlineto");
+ write("0 " + (-h) + " rlineto");
+ write((-w) + " 0 rlineto");
+ write("0 " + h + " rlineto");
+ write("closepath");
+ useColor(col);
+ write("fill");
}
/**
@@ -699,6 +592,7 @@
this.currentXPosition = rx;
int bl = this.currentYPosition;
+ // method is identical to super method except next line
movetoCurrPosition();
String fontWeight = area.getFontState().getFontWeight();
1.27 +12 -6 xml-fop/src/org/apache/fop/render/xml/XMLRenderer.java
Index: XMLRenderer.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/xml/XMLRenderer.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- XMLRenderer.java 2001/09/17 13:29:53 1.26
+++ XMLRenderer.java 2001/09/18 13:06:08 1.27
@@ -1,5 +1,5 @@
/*
- * $Id: XMLRenderer.java,v 1.26 2001/09/17 13:29:53 keiron Exp $
+ * $Id: XMLRenderer.java,v 1.27 2001/09/18 13:06:08 keiron 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.
@@ -17,6 +17,8 @@
import org.apache.fop.pdf.*;
import org.apache.fop.fo.properties.LeaderPattern;
+import org.apache.log.Logger;
+
// Java
import java.io.IOException;
import java.io.PrintWriter;
@@ -30,8 +32,14 @@
* Modified by Mark Lillywhite [EMAIL PROTECTED] to use the
* new renderer interface. Not 100% certain that this is correct.
*/
-public class XMLRenderer extends AbstractRenderer {
+public class XMLRenderer implements Renderer {
+
+ protected Logger log;
+ public void setLogger(Logger logger) {
+ log = logger;
+ }
+
/**
* indentation to use for pretty-printing the XML
*/
@@ -55,8 +63,6 @@
public XMLRenderer() {}
- protected void doFrame(Area area) {}
-
/**
* set up renderer options
*/
@@ -444,7 +450,7 @@
*/
public void startRenderer(OutputStream outputStream)
throws IOException {
- log.info("rendering areas to XML");
+ log.debug("rendering areas to XML");
this.writer = new PrintWriter(outputStream);
this.writer.write( "<?xml version=\"1.0\"?>\n<!-- produced by " +
this.producer + " -->\n");
@@ -459,6 +465,6 @@
throws IOException {
writeEndTag("</AreaTree>");
this.writer.flush();
- log.error("written out XML");
+ log.debug("written out XML");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]