aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2006-01-20 13:09:05 +0000
committerJeremias Maerki <jeremias@apache.org>2006-01-20 13:09:05 +0000
commit1d584c0578e207f856a557a3a583b6be273012f6 (patch)
tree4dd1f3a3a7e620dafa05e67510bbc1778a4cf632 /src/java/org/apache
parent5a9b73f0742d64a486e69d9713c3304232ea4492 (diff)
downloadxmlgraphics-fop-1d584c0578e207f856a557a3a583b6be273012f6.tar.gz
xmlgraphics-fop-1d584c0578e207f856a557a3a583b6be273012f6.zip
(Re?)added integer page number to the PageViewport.
Serializing both the integer and the formatted value to the area tree XML. In the XML "nr" is now "formatted-nr" and "nr" is now the integer value. This doesn't have any impact on our layout engine tests as we don't seem to use a non-default for page numbers. Make the current PageViewport available to XMLHandler through the RenderContext. I need this for Barcode4J so the current page number can be used as part of a barcode message. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@370801 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/area/AreaTreeParser.java4
-rw-r--r--src/java/org/apache/fop/area/PageViewport.java25
-rw-r--r--src/java/org/apache/fop/layoutmgr/Page.java5
-rw-r--r--src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java2
-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
10 files changed, 118 insertions, 74 deletions
diff --git a/src/java/org/apache/fop/area/AreaTreeParser.java b/src/java/org/apache/fop/area/AreaTreeParser.java
index ad1017505..a05b83f05 100644
--- a/src/java/org/apache/fop/area/AreaTreeParser.java
+++ b/src/java/org/apache/fop/area/AreaTreeParser.java
@@ -218,7 +218,9 @@ public class AreaTreeParser {
throw new IllegalStateException("currentPageViewport must be null");
}
Rectangle2D viewArea = parseRect(attributes.getValue("bounds"));
- currentPageViewport = new PageViewport(viewArea, attributes.getValue("nr"));
+ int pageNumber = getAttributeAsInteger(attributes, "nr", -1);
+ String pageNumberString = attributes.getValue("formatted-nr");
+ currentPageViewport = new PageViewport(viewArea, pageNumber, pageNumberString);
} else if ("page".equals(localName)) {
Page p = new Page();
currentPageViewport.setPage(p);
diff --git a/src/java/org/apache/fop/area/PageViewport.java b/src/java/org/apache/fop/area/PageViewport.java
index fedc4284f..51c354b4d 100644
--- a/src/java/org/apache/fop/area/PageViewport.java
+++ b/src/java/org/apache/fop/area/PageViewport.java
@@ -48,6 +48,7 @@ public class PageViewport implements Resolvable, Cloneable {
private Page page;
private Rectangle2D viewArea;
private String simplePageMasterName;
+ private int pageNumber = -1;
private String pageNumberString = null;
private int pageIndex = -1; //-1 = undetermined
private boolean blank;
@@ -82,18 +83,20 @@ public class PageViewport implements Resolvable, Cloneable {
/**
* Create a page viewport.
* @param spm SimplePageMaster indicating the page and region dimensions
+ * @param pageNumber the page number
* @param pageStr String representation of the page number
* @param blank true if this is a blank page
*/
- public PageViewport(SimplePageMaster spm, String pageStr, boolean blank) {
+ public PageViewport(SimplePageMaster spm, int pageNumber, String pageStr, boolean blank) {
this.simplePageMasterName = spm.getMasterName();
this.extensionAttachments = spm.getExtensionAttachments();
this.blank = blank;
int pageWidth = spm.getPageWidth().getValue();
int pageHeight = spm.getPageHeight().getValue();
- pageNumberString = pageStr;
- viewArea = new Rectangle(0, 0, pageWidth, pageHeight);
- page = new Page(spm);
+ this.pageNumber = pageNumber;
+ this.pageNumberString = pageStr;
+ this.viewArea = new Rectangle(0, 0, pageWidth, pageHeight);
+ this.page = new Page(spm);
createSpan(false);
}
@@ -103,6 +106,7 @@ public class PageViewport implements Resolvable, Cloneable {
*/
public PageViewport(PageViewport original) {
this.extensionAttachments = new java.util.ArrayList(original.extensionAttachments);
+ this.pageNumber = original.pageNumber;
this.pageNumberString = original.pageNumberString;
this.page = (Page)original.page.clone();
this.viewArea = (Rectangle2D)original.viewArea.clone();
@@ -111,10 +115,12 @@ public class PageViewport implements Resolvable, Cloneable {
/**
* Constructor used by the area tree parser.
* @param viewArea the view area
+ * @param pageNumber the page number
* @param pageStr String representation of the page number
*/
- public PageViewport(Rectangle2D viewArea, String pageStr) {
+ public PageViewport(Rectangle2D viewArea, int pageNumber, String pageStr) {
this.viewArea = viewArea;
+ this.pageNumber = pageNumber;
this.pageNumberString = pageStr;
}
@@ -144,6 +150,14 @@ public class PageViewport implements Resolvable, Cloneable {
/**
* Get the page number of this page.
+ * @return the integer value that represents this page
+ */
+ public int getPageNumber() {
+ return pageNumber;
+ }
+
+ /**
+ * Get the page number of this page.
* @return the string that represents this page
*/
public String getPageNumberString() {
@@ -152,6 +166,7 @@ public class PageViewport implements Resolvable, Cloneable {
/**
* Sets the page index of the page in this rendering run.
+ * (This is not the same as the page number!)
* @param index the page index (zero-based), -1 if it is undetermined
*/
public void setPageIndex(int index) {
diff --git a/src/java/org/apache/fop/layoutmgr/Page.java b/src/java/org/apache/fop/layoutmgr/Page.java
index e33230c68..70eab62ac 100644
--- a/src/java/org/apache/fop/layoutmgr/Page.java
+++ b/src/java/org/apache/fop/layoutmgr/Page.java
@@ -35,12 +35,13 @@ public class Page {
/**
* Main constructor
* @param spm the simple-page-master used for this page
+ * @param pageNumber the page number (as an int)
* @param pageNumberStr the page number (as a String)
* @param blank true if this is a blank page
*/
- public Page(SimplePageMaster spm, String pageNumberStr, boolean blank) {
+ public Page(SimplePageMaster spm, int pageNumber, String pageNumberStr, boolean blank) {
this.spm = spm;
- this.pageViewport = new PageViewport(spm, pageNumberStr, blank);
+ this.pageViewport = new PageViewport(spm, pageNumber, pageNumberStr, blank);
}
/** @return the simple-page-master that created this page */
diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
index 71b319f7e..52d14ad96 100644
--- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
@@ -882,7 +882,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
+ spm.getMasterName() + "'. FOP presently "
+ "does not support this.");
}
- Page page = new Page(spm, pageNumberString, bIsBlank);
+ Page page = new Page(spm, index, pageNumberString, bIsBlank);
cachedPages.add(page);
} catch (FOPException e) {
//TODO Maybe improve. It'll mean to propagate this exception up several
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");