aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeiron Liddle <keiron@apache.org>2001-09-18 13:06:08 +0000
committerKeiron Liddle <keiron@apache.org>2001-09-18 13:06:08 +0000
commit7aee8f66f53bb505a7d2c6ee7df0eee90fe8f187 (patch)
tree289ebd9b66bd4a7ca4eba1cff74d5992d1c2b9e7
parent7c97252576511189ce2ba7f3dbfd414051d983e1 (diff)
downloadxmlgraphics-fop-7aee8f66f53bb505a7d2c6ee7df0eee90fe8f187.tar.gz
xmlgraphics-fop-7aee8f66f53bb505a7d2c6ee7df0eee90fe8f187.zip
more refactoring of duplicate code in renderers
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194469 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/org/apache/fop/render/AbstractRenderer.java64
-rw-r--r--src/org/apache/fop/render/PrintRenderer.java49
-rw-r--r--src/org/apache/fop/render/awt/AWTRenderer.java25
-rw-r--r--src/org/apache/fop/render/mif/MIFRenderer.java135
-rw-r--r--src/org/apache/fop/render/ps/PSRenderer.java130
-rw-r--r--src/org/apache/fop/render/xml/XMLRenderer.java16
6 files changed, 103 insertions, 316 deletions
diff --git a/src/org/apache/fop/render/AbstractRenderer.java b/src/org/apache/fop/render/AbstractRenderer.java
index 23cf0ec7a..0c203753f 100644
--- a/src/org/apache/fop/render/AbstractRenderer.java
+++ b/src/org/apache/fop/render/AbstractRenderer.java
@@ -54,8 +54,7 @@ public abstract class AbstractRenderer implements Renderer {
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
}
@@ -64,6 +63,67 @@ public abstract class AbstractRenderer implements Renderer {
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
*
* @param area the area container to render
diff --git a/src/org/apache/fop/render/PrintRenderer.java b/src/org/apache/fop/render/PrintRenderer.java
index 02fe86307..e6f4c6101 100644
--- a/src/org/apache/fop/render/PrintRenderer.java
+++ b/src/org/apache/fop/render/PrintRenderer.java
@@ -177,51 +177,10 @@ public abstract class PrintRenderer extends AbstractRenderer {
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) {
diff --git a/src/org/apache/fop/render/awt/AWTRenderer.java b/src/org/apache/fop/render/awt/AWTRenderer.java
index 9a664b5a2..aad6001b2 100644
--- a/src/org/apache/fop/render/awt/AWTRenderer.java
+++ b/src/org/apache/fop/render/awt/AWTRenderer.java
@@ -219,11 +219,8 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable
* @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 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable
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.
*
@@ -392,20 +397,6 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable
*/
}
- 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) {
int w, h;
int rx = this.currentAreaContainerXPosition;
diff --git a/src/org/apache/fop/render/mif/MIFRenderer.java b/src/org/apache/fop/render/mif/MIFRenderer.java
index 6dc9724aa..3d4a990d1 100644
--- a/src/org/apache/fop/render/mif/MIFRenderer.java
+++ b/src/org/apache/fop/render/mif/MIFRenderer.java
@@ -149,93 +149,11 @@ public class MIFRenderer extends AbstractRenderer {
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();
+ super.renderAreaContainer(area);
}
- 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) {
}
protected void doFrame(Area area) {
@@ -293,42 +211,25 @@ public class MIFRenderer extends AbstractRenderer {
}
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 class MIFRenderer extends AbstractRenderer {
*/
public void renderForeignObjectArea(ForeignObjectArea area) {}
-
public void renderWordArea(WordArea area) {
String s;
s = area.getText();
@@ -407,32 +307,9 @@ public class MIFRenderer extends AbstractRenderer {
* 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);
}
/**
diff --git a/src/org/apache/fop/render/ps/PSRenderer.java b/src/org/apache/fop/render/ps/PSRenderer.java
index e3cd72039..6785c562b 100644
--- a/src/org/apache/fop/render/ps/PSRenderer.java
+++ b/src/org/apache/fop/render/ps/PSRenderer.java
@@ -143,7 +143,6 @@ public class PSRenderer extends AbstractRenderer {
}
}
-
/**
* write out a comment
*/
@@ -152,7 +151,6 @@ public class PSRenderer extends AbstractRenderer {
write(comment);
}
-
protected void writeFontDict(FontInfo fontInfo) {
write("%%BeginResource: procset FOPFonts");
write("%%Title: Font setup (shortcuts) for this file");
@@ -259,122 +257,17 @@ public class PSRenderer extends AbstractRenderer {
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 @@ public class PSRenderer extends AbstractRenderer {
this.currentXPosition = rx;
int bl = this.currentYPosition;
+ // method is identical to super method except next line
movetoCurrPosition();
String fontWeight = area.getFontState().getFontWeight();
diff --git a/src/org/apache/fop/render/xml/XMLRenderer.java b/src/org/apache/fop/render/xml/XMLRenderer.java
index 815706091..456be9a1f 100644
--- a/src/org/apache/fop/render/xml/XMLRenderer.java
+++ b/src/org/apache/fop/render/xml/XMLRenderer.java
@@ -17,6 +17,8 @@ import org.apache.fop.layout.inline.*;
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,7 +32,13 @@ import java.util.Hashtable;
* Modified by Mark Lillywhite mark-fop@inomial.com 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 class XMLRenderer extends AbstractRenderer {
public XMLRenderer() {}
- protected void doFrame(Area area) {}
-
/**
* set up renderer options
*/
@@ -444,7 +450,7 @@ public class XMLRenderer extends AbstractRenderer {
*/
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 @@ public class XMLRenderer extends AbstractRenderer {
throws IOException {
writeEndTag("</AreaTree>");
this.writer.flush();
- log.error("written out XML");
+ log.debug("written out XML");
}
}