]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
PostScript output now generates the bounding box DSC comments for the whole document.
authorJeremias Maerki <jeremias@apache.org>
Thu, 10 Jan 2008 10:13:21 +0000 (10:13 +0000)
committerJeremias Maerki <jeremias@apache.org>
Thu, 10 Jan 2008 10:13:21 +0000 (10:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@610739 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/render/ps/PSRenderer.java
src/java/org/apache/fop/render/ps/ResourceHandler.java
status.xml

index 3befb0738ab863105ad0b9543a350a7d2ed47568..7580bd0d5d3e9c7f95c222774acf540d1584e297 100644 (file)
@@ -35,9 +35,22 @@ import java.util.Map;
 
 import javax.xml.transform.Source;
 
+import org.w3c.dom.Document;
+
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.ps.DSCConstants;
+import org.apache.xmlgraphics.ps.PSGenerator;
+import org.apache.xmlgraphics.ps.PSProcSets;
+import org.apache.xmlgraphics.ps.PSResource;
+import org.apache.xmlgraphics.ps.PSState;
+import org.apache.xmlgraphics.ps.dsc.DSCException;
+import org.apache.xmlgraphics.ps.dsc.ResourceTracker;
+import org.apache.xmlgraphics.ps.dsc.events.DSCCommentBoundingBox;
+import org.apache.xmlgraphics.ps.dsc.events.DSCCommentHiResBoundingBox;
+
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.area.Area;
@@ -75,14 +88,6 @@ import org.apache.fop.render.ps.extensions.PSExtensionAttachment;
 import org.apache.fop.render.ps.extensions.PSSetPageDevice;
 import org.apache.fop.render.ps.extensions.PSSetupCode;
 import org.apache.fop.util.CharUtilities;
-import org.apache.xmlgraphics.ps.DSCConstants;
-import org.apache.xmlgraphics.ps.PSGenerator;
-import org.apache.xmlgraphics.ps.PSProcSets;
-import org.apache.xmlgraphics.ps.PSResource;
-import org.apache.xmlgraphics.ps.PSState;
-import org.apache.xmlgraphics.ps.dsc.DSCException;
-import org.apache.xmlgraphics.ps.dsc.ResourceTracker;
-import org.w3c.dom.Document;
 
 /**
  * Renderer that renders to PostScript.
@@ -152,6 +157,9 @@ public class PSRenderer extends AbstractPathOrientedRenderer implements ImageAda
     /** Whether or not Dublin Core Standard (dsc) compliant output is enforced */
     private boolean dscCompliant = true;
 
+    /** Is used to determine the document's bounding box */
+    private Rectangle2D documentBoundingBox;
+    
     /** This is a collection holding all document header comments */
     private Collection headerComments;
 
@@ -776,6 +784,9 @@ public class PSRenderer extends AbstractPathOrientedRenderer implements ImageAda
         gen.writeDSCComment(DSCConstants.CREATION_DATE, new Object[] {new java.util.Date()});
         gen.writeDSCComment(DSCConstants.LANGUAGE_LEVEL, new Integer(gen.getPSLevel()));
         gen.writeDSCComment(DSCConstants.PAGES, new Object[] {DSCConstants.ATEND});
+        gen.writeDSCComment(DSCConstants.BBOX, DSCConstants.ATEND);
+        gen.writeDSCComment(DSCConstants.HIRES_BBOX, DSCConstants.ATEND);
+        this.documentBoundingBox = new Rectangle2D.Double();
         gen.writeDSCComment(DSCConstants.DOCUMENT_SUPPLIED_RESOURCES, 
                 new Object[] {DSCConstants.ATEND});
         if (headerComments != null) {
@@ -833,6 +844,8 @@ public class PSRenderer extends AbstractPathOrientedRenderer implements ImageAda
             footerComments.clear();
         }
         gen.writeDSCComment(DSCConstants.PAGES, new Integer(this.currentPageNumber));
+        new DSCCommentBoundingBox(this.documentBoundingBox).generate(gen);
+        new DSCCommentHiResBoundingBox(this.documentBoundingBox).generate(gen);
         gen.getResourceTracker().writeResources(false, gen);
         gen.writeDSCComment(DSCConstants.EOF);
         gen.flush();
@@ -863,7 +876,8 @@ public class PSRenderer extends AbstractPathOrientedRenderer implements ImageAda
         try {
             try {
                 ResourceHandler.process(this.userAgent, in, this.outputStream, 
-                        this.fontInfo, resTracker, this.formResources, this.currentPageNumber);
+                        this.fontInfo, resTracker, this.formResources,
+                        this.currentPageNumber, this.documentBoundingBox);
                 this.outputStream.flush();
             } catch (DSCException e) {
                 throw new RuntimeException(e.getMessage());
@@ -1031,7 +1045,9 @@ public class PSRenderer extends AbstractPathOrientedRenderer implements ImageAda
             log.error(e.getMessage());
         }
         final Integer zero = new Integer(0);
+        Rectangle2D pageBoundingBox = new Rectangle2D.Double();
         if (rotate) {
+            pageBoundingBox.setRect(0, 0, pageHeight, pageWidth);
             gen.writeDSCComment(DSCConstants.PAGE_BBOX, new Object[] {
                     zero, zero, new Long(Math.round(pageHeight)),
                     new Long(Math.round(pageWidth)) });
@@ -1040,6 +1056,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer implements ImageAda
                     new Double(pageWidth) });
             gen.writeDSCComment(DSCConstants.PAGE_ORIENTATION, "Landscape");
         } else {
+            pageBoundingBox.setRect(0, 0, pageWidth, pageHeight);
             gen.writeDSCComment(DSCConstants.PAGE_BBOX, new Object[] {
                     zero, zero, new Long(Math.round(pageWidth)),
                     new Long(Math.round(pageHeight)) });
@@ -1051,6 +1068,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer implements ImageAda
                         "Portrait");
             }
         }
+        this.documentBoundingBox.add(pageBoundingBox);
         gen.writeDSCComment(DSCConstants.PAGE_RESOURCES,
                 new Object[] {DSCConstants.ATEND});
 
index f187e619a80243c81101fae7aae8178d7994521b..a0762e6e0b0462bb046247522c5655f6f32759dd 100644 (file)
@@ -19,6 +19,7 @@
 
 package org.apache.fop.render.ps;
 
+import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -26,10 +27,6 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.image.FopImage;
-import org.apache.fop.image.ImageFactory;
 import org.apache.xmlgraphics.ps.DSCConstants;
 import org.apache.xmlgraphics.ps.PSGenerator;
 import org.apache.xmlgraphics.ps.dsc.DSCException;
@@ -39,8 +36,10 @@ import org.apache.xmlgraphics.ps.dsc.DSCParserConstants;
 import org.apache.xmlgraphics.ps.dsc.DefaultNestedDocumentHandler;
 import org.apache.xmlgraphics.ps.dsc.ResourceTracker;
 import org.apache.xmlgraphics.ps.dsc.events.DSCComment;
+import org.apache.xmlgraphics.ps.dsc.events.DSCCommentBoundingBox;
 import org.apache.xmlgraphics.ps.dsc.events.DSCCommentDocumentNeededResources;
 import org.apache.xmlgraphics.ps.dsc.events.DSCCommentDocumentSuppliedResources;
+import org.apache.xmlgraphics.ps.dsc.events.DSCCommentHiResBoundingBox;
 import org.apache.xmlgraphics.ps.dsc.events.DSCCommentLanguageLevel;
 import org.apache.xmlgraphics.ps.dsc.events.DSCCommentPage;
 import org.apache.xmlgraphics.ps.dsc.events.DSCCommentPages;
@@ -49,6 +48,11 @@ import org.apache.xmlgraphics.ps.dsc.events.DSCHeaderComment;
 import org.apache.xmlgraphics.ps.dsc.events.PostScriptComment;
 import org.apache.xmlgraphics.ps.dsc.tools.DSCTools;
 
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.image.FopImage;
+import org.apache.fop.image.ImageFactory;
+
 /**
  * This class is used when two-pass production is used to generate the PostScript file (setting
  * "optimize-resources"). It uses the DSC parser from XML Graphics Commons to go over the
@@ -67,11 +71,14 @@ public class ResourceHandler implements DSCParserConstants {
      * @param resTracker the resource tracker to use
      * @param formResources Contains all forms used by this document (maintained by PSRenderer)
      * @param pageCount the number of pages (given here because PSRenderer writes an "(atend)")
+     * @param documentBoundingBox the document's bounding box
+     *                                  (given here because PSRenderer writes an "(atend)")
      * @throws DSCException If there's an error in the DSC structure of the PS file
      * @throws IOException In case of an I/O error
      */
     public static void process(FOUserAgent userAgent, InputStream in, OutputStream out, 
-            FontInfo fontInfo, ResourceTracker resTracker, Map formResources, int pageCount)
+            FontInfo fontInfo, ResourceTracker resTracker, Map formResources,
+            int pageCount, Rectangle2D documentBoundingBox)
                     throws DSCException, IOException {
         DSCParser parser = new DSCParser(in);
         PSGenerator gen = new PSGenerator(out);
@@ -86,6 +93,8 @@ public class ResourceHandler implements DSCParserConstants {
             {
                 //We rewrite those as part of the processing
                 filtered.add(DSCConstants.PAGES);
+                filtered.add(DSCConstants.BBOX);
+                filtered.add(DSCConstants.HIRES_BBOX);
                 filtered.add(DSCConstants.DOCUMENT_NEEDED_RESOURCES);
                 filtered.add(DSCConstants.DOCUMENT_SUPPLIED_RESOURCES);
             }
@@ -109,6 +118,8 @@ public class ResourceHandler implements DSCParserConstants {
                 //Set number of pages
                 DSCCommentPages pages = new DSCCommentPages(pageCount);
                 pages.generate(gen);
+                new DSCCommentBoundingBox(documentBoundingBox).generate(gen);
+                new DSCCommentHiResBoundingBox(documentBoundingBox).generate(gen);
 
                 PSFontUtils.determineSuppliedFonts(resTracker, fontInfo, fontInfo.getUsedFonts());
                 registerSuppliedForms(resTracker, formResources);
index 3b88812115011f241dde0a7175b6c066834ea166..829a76a6642e5a8dbe69801338d9083e2f8608c2 100644 (file)
@@ -28,6 +28,9 @@
 
   <changes>
     <release version="FOP Trunk">
+      <action context="Code" dev="JM" type="add">
+        PostScript output now generates the bounding box DSC comments for the whole document.
+      </action>
       <action context="Code" dev="JM" type="add">
         Added support for PDF page labels.
       </action>