aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/java/org/apache/fop/area/AreaTreeParser.java9
-rw-r--r--src/java/org/apache/fop/area/PageViewport.java13
-rw-r--r--src/java/org/apache/fop/layoutmgr/Page.java4
-rw-r--r--src/java/org/apache/fop/pdf/PDFFactory.java37
-rw-r--r--src/java/org/apache/fop/pdf/PDFPage.java76
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFEventProducer.java7
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFRenderer.java5
-rw-r--r--src/java/org/apache/fop/render/ps/PSRenderer.java4
8 files changed, 92 insertions, 63 deletions
diff --git a/src/java/org/apache/fop/area/AreaTreeParser.java b/src/java/org/apache/fop/area/AreaTreeParser.java
index ec47d2083..aae9b5017 100644
--- a/src/java/org/apache/fop/area/AreaTreeParser.java
+++ b/src/java/org/apache/fop/area/AreaTreeParser.java
@@ -20,6 +20,7 @@
package org.apache.fop.area;
import java.awt.Color;
+import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -38,9 +39,10 @@ import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
-
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
@@ -48,9 +50,6 @@ import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.DefaultHandler;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import org.apache.xmlgraphics.image.loader.ImageException;
import org.apache.xmlgraphics.image.loader.ImageInfo;
import org.apache.xmlgraphics.image.loader.ImageManager;
@@ -403,7 +402,7 @@ public class AreaTreeParser {
if (currentPageViewport != null) {
throw new IllegalStateException("currentPageViewport must be null");
}
- Rectangle2D viewArea = XMLUtil.getAttributeAsRectangle2D(attributes, "bounds");
+ Rectangle viewArea = XMLUtil.getAttributeAsRectangle(attributes, "bounds");
int pageNumber = XMLUtil.getAttributeAsInt(attributes, "nr", -1);
String key = attributes.getValue("key");
String pageNumberString = attributes.getValue("formatted-nr");
diff --git a/src/java/org/apache/fop/area/PageViewport.java b/src/java/org/apache/fop/area/PageViewport.java
index 321ca4c03..63740386e 100644
--- a/src/java/org/apache/fop/area/PageViewport.java
+++ b/src/java/org/apache/fop/area/PageViewport.java
@@ -20,7 +20,6 @@
package org.apache.fop.area;
import java.awt.Rectangle;
-import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -48,7 +47,7 @@ import org.apache.fop.fo.pagination.SimplePageMaster;
public class PageViewport extends AreaTreeObject implements Resolvable, Cloneable {
private Page page;
- private Rectangle2D viewArea;
+ private Rectangle viewArea;
private String simplePageMasterName;
/**
@@ -100,6 +99,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
public PageViewport(SimplePageMaster spm, int pageNumber, String pageStr, boolean blank) {
this.simplePageMasterName = spm.getMasterName();
setExtensionAttachments(spm.getExtensionAttachments());
+ setForeignAttributes(spm.getForeignAttributes());
this.blank = blank;
int pageWidth = spm.getPageWidth().getValue();
int pageHeight = spm.getPageHeight().getValue();
@@ -118,11 +118,14 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
if (original.extensionAttachments != null) {
setExtensionAttachments(original.extensionAttachments);
}
+ if (original.foreignAttributes != null) {
+ setForeignAttributes(original.foreignAttributes);
+ }
this.pageIndex = original.pageIndex;
this.pageNumber = original.pageNumber;
this.pageNumberString = original.pageNumberString;
this.page = (Page)original.page.clone();
- this.viewArea = (Rectangle2D)original.viewArea.clone();
+ this.viewArea = new Rectangle(original.viewArea);
this.simplePageMasterName = original.simplePageMasterName;
this.blank = original.blank;
}
@@ -135,7 +138,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
* @param simplePageMasterName name of the original simple-page-master that generated this page
* @param blank true if this is a blank page
*/
- public PageViewport(Rectangle2D viewArea, int pageNumber, String pageStr,
+ public PageViewport(Rectangle viewArea, int pageNumber, String pageStr,
String simplePageMasterName, boolean blank) {
this.viewArea = viewArea;
this.pageNumber = pageNumber;
@@ -161,7 +164,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
* Get the view area rectangle of this viewport.
* @return the rectangle for this viewport
*/
- public Rectangle2D getViewArea() {
+ public Rectangle getViewArea() {
return viewArea;
}
diff --git a/src/java/org/apache/fop/layoutmgr/Page.java b/src/java/org/apache/fop/layoutmgr/Page.java
index 7e22cef67..b183efa01 100644
--- a/src/java/org/apache/fop/layoutmgr/Page.java
+++ b/src/java/org/apache/fop/layoutmgr/Page.java
@@ -19,7 +19,7 @@
package org.apache.fop.layoutmgr;
-import java.awt.geom.Rectangle2D;
+import java.awt.Rectangle;
import org.apache.fop.area.PageViewport;
import org.apache.fop.fo.pagination.SimplePageMaster;
@@ -54,7 +54,7 @@ public class Page {
* @param pageNumberStr the page number (as a String)
* @param blank true if this is a blank page
*/
- public Page(Rectangle2D viewArea, int pageNumber, String pageNumberStr, boolean blank) {
+ public Page(Rectangle viewArea, int pageNumber, String pageNumberStr, boolean blank) {
this.spm = null;
this.pageViewport = new PageViewport(viewArea, pageNumber, pageNumberStr, null, blank);
}
diff --git a/src/java/org/apache/fop/pdf/PDFFactory.java b/src/java/org/apache/fop/pdf/PDFFactory.java
index 0a4516ce6..a8d7a0702 100644
--- a/src/java/org/apache/fop/pdf/PDFFactory.java
+++ b/src/java/org/apache/fop/pdf/PDFFactory.java
@@ -174,21 +174,18 @@ public class PDFFactory {
* PDFDocument later using addObject().
*
* @param resources resources object to use
- * @param pageWidth width of the page in points
- * @param pageHeight height of the page in points
* @param pageIndex index of the page (zero-based)
+ * @param mediaBox the MediaBox area
+ * @param cropBox the CropBox area
+ * @param bleedBox the BleedBox area
+ * @param trimBox the TrimBox area
*
* @return the created /Page object
*/
- public PDFPage makePage(PDFResources resources,
- int pageWidth, int pageHeight, int pageIndex) {
-
- /*
- * create a PDFPage with the next object number, the given
- * resources, contents and dimensions
- */
- PDFPage page = new PDFPage(resources,
- pageWidth, pageHeight, pageIndex);
+ public PDFPage makePage(PDFResources resources, int pageIndex,
+ Rectangle2D mediaBox, Rectangle2D cropBox,
+ Rectangle2D bleedBox, Rectangle2D trimBox) {
+ PDFPage page = new PDFPage(resources, pageIndex, mediaBox, cropBox, bleedBox, trimBox);
getDocument().assignObjectNumber(page);
getDocument().getPages().addPage(page);
@@ -203,6 +200,24 @@ public class PDFFactory {
* @param resources resources object to use
* @param pageWidth width of the page in points
* @param pageHeight height of the page in points
+ * @param pageIndex index of the page (zero-based)
+ *
+ * @return the created /Page object
+ */
+ public PDFPage makePage(PDFResources resources,
+ int pageWidth, int pageHeight, int pageIndex) {
+ Rectangle2D mediaBox = new Rectangle2D.Double(0, 0, pageWidth, pageHeight);
+ return makePage(resources, pageIndex, mediaBox, mediaBox, mediaBox, mediaBox);
+ }
+
+ /**
+ * Make a /Page object. The page is assigned an object number immediately
+ * so references can already be made. The page must be added to the
+ * PDFDocument later using addObject().
+ *
+ * @param resources resources object to use
+ * @param pageWidth width of the page in points
+ * @param pageHeight height of the page in points
*
* @return the created /Page object
*/
diff --git a/src/java/org/apache/fop/pdf/PDFPage.java b/src/java/org/apache/fop/pdf/PDFPage.java
index d1472e154..4fa3b0a09 100644
--- a/src/java/org/apache/fop/pdf/PDFPage.java
+++ b/src/java/org/apache/fop/pdf/PDFPage.java
@@ -38,42 +38,42 @@ public class PDFPage extends PDFResourceContext {
* Create a /Page object
*
* @param resources the /Resources object
- * @param contents the content stream
- * @param pageWidth the page's width in points
- * @param pageHeight the page's height in points
* @param pageIndex the page's zero-based index (or -1 if the page number is auto-determined)
+ * @param mediaBox the MediaBox
+ * @param cropBox the CropBox. If null, mediaBox is used.
+ * @param bleedBox the BleedBox. If null, cropBox is used.
+ * @param trimBox the TrimBox. If null, bleedBox is used.
*/
- public PDFPage(PDFResources resources, PDFStream contents,
- int pageWidth, int pageHeight, int pageIndex) {
+ public PDFPage(PDFResources resources, int pageIndex,
+ Rectangle2D mediaBox, Rectangle2D cropBox,
+ Rectangle2D bleedBox, Rectangle2D trimBox) {
+ /* generic creation of object */
+ super(resources);
+
+ put("Type", new PDFName("Page"));
+ /* set fields using parameters */
+ setSimplePageSize(mediaBox, cropBox, bleedBox, trimBox);
+ this.pageIndex = pageIndex;
+ }
- /* generic creation of object */
- super(resources);
+ private void setSimplePageSize(Rectangle2D mediaBox, Rectangle2D cropBox,
+ Rectangle2D bleedBox, Rectangle2D trimBox) {
+ setMediaBox(mediaBox);
- put("Type", new PDFName("Page"));
- /* set fields using parameters */
- setContents(contents);
- setSimplePageSize(pageWidth, pageHeight);
- this.pageIndex = pageIndex;
- }
+ if (cropBox == null) {
+ cropBox = mediaBox;
+ }
+ setCropBox(cropBox);
- /**
- * Create a /Page object
- *
- * @param resources the /Resources object
- * @param pageWidth the page's width in points
- * @param pageHeight the page's height in points
- * @param pageIndex the page's zero-based index (or -1 if the page number is auto-determined)
- */
- public PDFPage(PDFResources resources,
- int pageWidth, int pageHeight, int pageIndex) {
- this(resources, null, pageWidth, pageHeight, pageIndex);
- }
+ if (bleedBox == null) {
+ bleedBox = cropBox;
+ }
+ setBleedBox(bleedBox); //Recommended by PDF/X
- private void setSimplePageSize(int width, int height) {
- Rectangle2D box = new Rectangle2D.Double(0, 0, width, height);
- setMediaBox(box);
- setBleedBox(box); //Recommended by PDF/X
- setTrimBox(box); //Needed for PDF/X
+ if (trimBox == null) {
+ trimBox = bleedBox;
+ }
+ setTrimBox(trimBox); //Needed for PDF/X
}
private PDFArray toPDFArray(Rectangle2D box) {
@@ -90,11 +90,11 @@ public class PDFPage extends PDFResourceContext {
}
/**
- * Sets the "TrimBox" entry
- * @param box the trim rectangle
+ * Sets the "CropBox" entry
+ * @param box the bleed rectangle
*/
- public void setTrimBox(Rectangle2D box) {
- put("TrimBox", toPDFArray(box));
+ public void setCropBox(Rectangle2D box) {
+ put("CropBox", toPDFArray(box));
}
/**
@@ -106,6 +106,14 @@ public class PDFPage extends PDFResourceContext {
}
/**
+ * Sets the "TrimBox" entry
+ * @param box the trim rectangle
+ */
+ public void setTrimBox(Rectangle2D box) {
+ put("TrimBox", toPDFArray(box));
+ }
+
+ /**
* set this page contents
*
* @param contents the contents of the page
diff --git a/src/java/org/apache/fop/render/pdf/PDFEventProducer.java b/src/java/org/apache/fop/render/pdf/PDFEventProducer.java
index 2c3be9736..d70409870 100644
--- a/src/java/org/apache/fop/render/pdf/PDFEventProducer.java
+++ b/src/java/org/apache/fop/render/pdf/PDFEventProducer.java
@@ -30,7 +30,12 @@ import org.apache.fop.events.model.EventModel;
public interface PDFEventProducer extends EventProducer {
/** Provider class for the event producer. */
- class Provider {
+ final class Provider {
+
+ /**
+ * Utility classes should not have a public or default constructor.
+ */
+ private Provider() { }
/**
* Returns an event producer.
diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
index c40c94fc4..3b737150b 100644
--- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java
+++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
@@ -457,9 +457,8 @@ public class PDFRenderer extends AbstractPathOrientedRenderer implements PDFConf
}
currentPageRef = currentPage.referencePDF();
- Rectangle2D bounds = page.getViewArea();
- double h = bounds.getHeight();
- pageHeight = (int) h;
+ Rectangle bounds = page.getViewArea();
+ pageHeight = bounds.height;
this.generator = new PDFContentGenerator(this.pdfDoc, this.ostream, this.currentPage);
this.borderPainter = new PDFBorderPainter(this.generator);
diff --git a/src/java/org/apache/fop/render/ps/PSRenderer.java b/src/java/org/apache/fop/render/ps/PSRenderer.java
index 09ea800f8..14924996e 100644
--- a/src/java/org/apache/fop/render/ps/PSRenderer.java
+++ b/src/java/org/apache/fop/render/ps/PSRenderer.java
@@ -815,8 +815,8 @@ public class PSRenderer extends AbstractPathOrientedRenderer
{page.getPageNumberString(),
new Integer(this.currentPageNumber)});
- double pageWidth = Math.round(page.getViewArea().getWidth()) / 1000f;
- double pageHeight = Math.round(page.getViewArea().getHeight()) / 1000f;
+ double pageWidth = page.getViewArea().width / 1000f;
+ double pageHeight = page.getViewArea().height / 1000f;
boolean rotate = false;
List pageSizes = new java.util.ArrayList();
if (getPSUtil().isAutoRotateLandscape() && (pageHeight < pageWidth)) {