aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/fop/render')
-rw-r--r--src/java/org/apache/fop/render/AbstractRenderer.java17
-rw-r--r--src/java/org/apache/fop/render/RendererContextConstants.java3
-rw-r--r--src/java/org/apache/fop/render/java2d/Java2DRenderer.java127
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFRenderer.java4
-rw-r--r--src/java/org/apache/fop/render/ps/PSRenderer.java2
-rw-r--r--src/java/org/apache/fop/render/xml/XMLRenderer.java3
6 files changed, 91 insertions, 65 deletions
diff --git a/src/java/org/apache/fop/render/AbstractRenderer.java b/src/java/org/apache/fop/render/AbstractRenderer.java
index bb84fde27..850190aab 100644
--- a/src/java/org/apache/fop/render/AbstractRenderer.java
+++ b/src/java/org/apache/fop/render/AbstractRenderer.java
@@ -111,6 +111,9 @@ public abstract class AbstractRenderer
*/
protected int containingIPPosition = 0;
+ /** the currently active PageViewport */
+ protected PageViewport currentPageViewport;
+
private Set warnedXMLHandlers;
/**
@@ -161,6 +164,11 @@ public abstract class AbstractRenderer
return null;
}
+ /** @return the current PageViewport or null, if none is active */
+ protected PageViewport getCurrentPageViewport() {
+ return this.currentPageViewport;
+ }
+
/**
* Prepare a page for rendering. This is called if the renderer supports
* out of order rendering. The renderer should prepare the page so that a
@@ -216,8 +224,13 @@ public abstract class AbstractRenderer
public void renderPage(PageViewport page)
throws IOException, FOPException {
- Page p = page.getPage();
- renderPageAreas(p);
+ this.currentPageViewport = page;
+ try {
+ Page p = page.getPage();
+ renderPageAreas(p);
+ } finally {
+ this.currentPageViewport = null;
+ }
}
/**
diff --git a/src/java/org/apache/fop/render/RendererContextConstants.java b/src/java/org/apache/fop/render/RendererContextConstants.java
index 1d219cab2..c744a82a1 100644
--- a/src/java/org/apache/fop/render/RendererContextConstants.java
+++ b/src/java/org/apache/fop/render/RendererContextConstants.java
@@ -26,6 +26,9 @@ public interface RendererContextConstants {
/** The output stream that the document is being sent to. */
String OUTPUT_STREAM = "outputStream";
+ /** The current PageViewport being rendered. */
+ String PAGE_VIEWPORT = "pageViewport";
+
/** The target width of the image being painted. */
String WIDTH = "width";
diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
index 6bff76bb4..173595cce 100644
--- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
+++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
@@ -263,67 +263,72 @@ public abstract class Java2DRenderer extends AbstractRenderer implements Printab
*/
public BufferedImage getPageImage(PageViewport pageViewport) {
- Rectangle2D bounds = pageViewport.getViewArea();
- pageWidth = (int) Math.round(bounds.getWidth() / 1000f);
- pageHeight = (int) Math.round(bounds.getHeight() / 1000f);
-
- log.info(
- "Rendering Page " + pageViewport.getPageNumberString()
- + " (pageWidth " + pageWidth + ", pageHeight "
- + pageHeight + ")");
-
- double scaleX = scaleFactor
- * (25.4 / FOUserAgent.DEFAULT_TARGET_RESOLUTION)
- / userAgent.getTargetPixelUnitToMillimeter();
- double scaleY = scaleFactor
- * (25.4 / FOUserAgent.DEFAULT_TARGET_RESOLUTION)
- / userAgent.getTargetPixelUnitToMillimeter();
- int bitmapWidth = (int) ((pageWidth * scaleX) + 0.5);
- int bitmapHeight = (int) ((pageHeight * scaleY) + 0.5);
-
-
- BufferedImage currentPageImage = new BufferedImage(
- bitmapWidth, bitmapHeight, BufferedImage.TYPE_INT_ARGB);
- // FIXME TYPE_BYTE_BINARY ?
-
- Graphics2D graphics = currentPageImage.createGraphics();
- graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
- RenderingHints.VALUE_FRACTIONALMETRICS_ON);
- if (antialiasing) {
- graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
- RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
- }
- if (qualityRendering) {
- graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
- RenderingHints.VALUE_RENDER_QUALITY);
- }
+ this.currentPageViewport = pageViewport;
+ try {
+ Rectangle2D bounds = pageViewport.getViewArea();
+ pageWidth = (int) Math.round(bounds.getWidth() / 1000f);
+ pageHeight = (int) Math.round(bounds.getHeight() / 1000f);
+
+ log.info(
+ "Rendering Page " + pageViewport.getPageNumberString()
+ + " (pageWidth " + pageWidth + ", pageHeight "
+ + pageHeight + ")");
+
+ double scaleX = scaleFactor
+ * (25.4 / FOUserAgent.DEFAULT_TARGET_RESOLUTION)
+ / userAgent.getTargetPixelUnitToMillimeter();
+ double scaleY = scaleFactor
+ * (25.4 / FOUserAgent.DEFAULT_TARGET_RESOLUTION)
+ / userAgent.getTargetPixelUnitToMillimeter();
+ int bitmapWidth = (int) ((pageWidth * scaleX) + 0.5);
+ int bitmapHeight = (int) ((pageHeight * scaleY) + 0.5);
+
+
+ BufferedImage currentPageImage = new BufferedImage(
+ bitmapWidth, bitmapHeight, BufferedImage.TYPE_INT_ARGB);
+ // FIXME TYPE_BYTE_BINARY ?
+
+ Graphics2D graphics = currentPageImage.createGraphics();
+ graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
+ RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+ if (antialiasing) {
+ graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+ graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
+ RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+ }
+ if (qualityRendering) {
+ graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
+ RenderingHints.VALUE_RENDER_QUALITY);
+ }
+
+ // transform page based on scale factor supplied
+ AffineTransform at = graphics.getTransform();
+ at.scale(scaleX, scaleY);
+ graphics.setTransform(at);
- // transform page based on scale factor supplied
- AffineTransform at = graphics.getTransform();
- at.scale(scaleX, scaleY);
- graphics.setTransform(at);
-
- // draw page frame
- graphics.setColor(Color.white);
- graphics.fillRect(0, 0, pageWidth, pageHeight);
- graphics.setColor(Color.black);
- graphics.drawRect(-1, -1, pageWidth + 2, pageHeight + 2);
- graphics.drawLine(pageWidth + 2, 0, pageWidth + 2, pageHeight + 2);
- graphics.drawLine(pageWidth + 3, 1, pageWidth + 3, pageHeight + 3);
- graphics.drawLine(0, pageHeight + 2, pageWidth + 2, pageHeight + 2);
- graphics.drawLine(1, pageHeight + 3, pageWidth + 3, pageHeight + 3);
-
- state = new Java2DGraphicsState(graphics, this.fontInfo, at);
-
- // reset the current Positions
- currentBPPosition = 0;
- currentIPPosition = 0;
-
- // this toggles the rendering of all areas
- renderPageAreas(pageViewport.getPage());
- return currentPageImage;
+ // draw page frame
+ graphics.setColor(Color.white);
+ graphics.fillRect(0, 0, pageWidth, pageHeight);
+ graphics.setColor(Color.black);
+ graphics.drawRect(-1, -1, pageWidth + 2, pageHeight + 2);
+ graphics.drawLine(pageWidth + 2, 0, pageWidth + 2, pageHeight + 2);
+ graphics.drawLine(pageWidth + 3, 1, pageWidth + 3, pageHeight + 3);
+ graphics.drawLine(0, pageHeight + 2, pageWidth + 2, pageHeight + 2);
+ graphics.drawLine(1, pageHeight + 3, pageWidth + 3, pageHeight + 3);
+
+ state = new Java2DGraphicsState(graphics, this.fontInfo, at);
+
+ // reset the current Positions
+ currentBPPosition = 0;
+ currentIPPosition = 0;
+
+ // this toggles the rendering of all areas
+ renderPageAreas(pageViewport.getPage());
+ return currentPageImage;
+ } finally {
+ this.currentPageViewport = null;
+ }
}
@@ -1169,6 +1174,8 @@ public abstract class Java2DRenderer extends AbstractRenderer implements Printab
new Integer((int)pos.getWidth()));
context.setProperty(Java2DRendererContextConstants.HEIGHT,
new Integer((int) pos.getHeight()));
+ context.setProperty(Java2DRendererContextConstants.PAGE_VIEWPORT,
+ getCurrentPageViewport());
renderXML(context, doc, ns);
}
diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
index 3328ad247..ab2ae245b 100644
--- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java
+++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
@@ -470,8 +470,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
currentFontName = "";
- Page p = page.getPage();
- renderPageAreas(p);
+ super.renderPage(page);
this.pdfDoc.registerObject(currentStream);
currentPage.setContents(currentStream);
@@ -1353,6 +1352,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
context.setProperty(PDFRendererContextConstants.PDF_DOCUMENT, pdfDoc);
context.setProperty(PDFRendererContextConstants.OUTPUT_STREAM, ostream);
+ context.setProperty(PDFRendererContextConstants.PAGE_VIEWPORT, getCurrentPageViewport());
context.setProperty(PDFRendererContextConstants.PDF_STATE, currentState);
context.setProperty(PDFRendererContextConstants.PDF_PAGE, currentPage);
context.setProperty(PDFRendererContextConstants.PDF_CONTEXT,
diff --git a/src/java/org/apache/fop/render/ps/PSRenderer.java b/src/java/org/apache/fop/render/ps/PSRenderer.java
index 71a948949..fcee2e94d 100644
--- a/src/java/org/apache/fop/render/ps/PSRenderer.java
+++ b/src/java/org/apache/fop/render/ps/PSRenderer.java
@@ -1079,6 +1079,8 @@ public class PSRenderer extends AbstractPathOrientedRenderer {
new Integer(currentIPPosition + (int) pos.getX()));
context.setProperty(PSRendererContextConstants.YPOS,
new Integer(currentBPPosition + (int) pos.getY()));
+ context.setProperty(PSRendererContextConstants.PAGE_VIEWPORT,
+ getCurrentPageViewport());
renderXML(context, doc, ns);
}
diff --git a/src/java/org/apache/fop/render/xml/XMLRenderer.java b/src/java/org/apache/fop/render/xml/XMLRenderer.java
index 982d138bc..d231569d5 100644
--- a/src/java/org/apache/fop/render/xml/XMLRenderer.java
+++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java
@@ -442,7 +442,8 @@ public class XMLRenderer extends PrintRenderer {
public void renderPage(PageViewport page) throws IOException, FOPException {
atts.clear();
addAttribute("bounds", page.getViewArea());
- addAttribute("nr", page.getPageNumberString());
+ addAttribute("nr", page.getPageNumber());
+ addAttribute("formatted-nr", page.getPageNumberString());
startElement("pageViewport", atts);
startElement("page");