You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2008/01/10 11:13:23 UTC

svn commit: r610739 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/render/ps/PSRenderer.java src/java/org/apache/fop/render/ps/ResourceHandler.java status.xml

Author: jeremias
Date: Thu Jan 10 02:13:21 2008
New Revision: 610739

URL: http://svn.apache.org/viewvc?rev=610739&view=rev
Log:
PostScript output now generates the bounding box DSC comments for the whole document.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderer.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/ResourceHandler.java
    xmlgraphics/fop/trunk/status.xml

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderer.java?rev=610739&r1=610738&r2=610739&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderer.java Thu Jan 10 02:13:21 2008
@@ -35,9 +35,22 @@
 
 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.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 @@
     /** 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 @@
         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 @@
             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 @@
         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 @@
             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 @@
                     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 @@
                         "Portrait");
             }
         }
+        this.documentBoundingBox.add(pageBoundingBox);
         gen.writeDSCComment(DSCConstants.PAGE_RESOURCES,
                 new Object[] {DSCConstants.ATEND});
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/ResourceHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/ResourceHandler.java?rev=610739&r1=610738&r2=610739&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/ResourceHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/ResourceHandler.java Thu Jan 10 02:13:21 2008
@@ -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.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.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.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 @@
      * @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 @@
             {
                 //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 @@
                 //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);

Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=610739&r1=610738&r2=610739&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Thu Jan 10 02:13:21 2008
@@ -29,6 +29,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>
       <action context="Code" dev="JM" type="add" fixes-bug="44176" due-to="Patrick Jaromin">



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org