]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Moved all procsets out to PSProcSets.
authorJeremias Maerki <jeremias@apache.org>
Thu, 17 Apr 2003 15:35:20 +0000 (15:35 +0000)
committerJeremias Maerki <jeremias@apache.org>
Thu, 17 Apr 2003 15:35:20 +0000 (15:35 +0000)
Cleaned up PSRenderer a bit
Add configurable auto-rotate-landscape behaviour (default is false)
Added PageHiResBoundingBox
Fixed BoundingBox values

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196272 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/render/ps/DSCConstants.java
src/java/org/apache/fop/render/ps/PSGenerator.java
src/java/org/apache/fop/render/ps/PSProcSets.java
src/java/org/apache/fop/render/ps/PSRenderer.java

index fcaee2ac9c38ce3555b860bbb8a6f72a89e1d234..40da7131350b78a628b139a475ddbb2de44f2536 100644 (file)
@@ -66,6 +66,8 @@ public class DSCConstants {
     
     /** Bounding box for the document */
     public static final String BBOX              = "BoundingBox";
+    /** High-resolution bounding box for the document */
+    public static final String HIRES_BBOX        = "HiResBoundingBox";
     /** Copyright information associated with the document or resource */
     public static final String COPYRIGHT         = "Copyright";
     /** Creator of the document */
@@ -151,6 +153,8 @@ public class DSCConstants {
     public static final String PAGE              = "Page";
     /** Bounding box for a page */
     public static final String PAGE_BBOX         = "PageBoundingBox";
+    /** High-resolution bounding box for a page */
+    public static final String PAGE_HIRES_BBOX   = "PageHiResBoundingBox";
     /** Bounding box for a page */
     public static final String PAGE_ORIENTATION  = "PageOrientation";
 
index 2b0622d9665d9401f9940c859c8a312de2bac1e0..988d53bd698425987cb3a221f1852126de7d7d67 100644 (file)
@@ -53,6 +53,7 @@ package org.apache.fop.render.ps;
 import java.io.OutputStream;
 import java.io.IOException;
 import java.text.DateFormat;
+import java.text.DecimalFormat;
 import java.text.NumberFormat;
 import java.util.Date;
 import java.util.Stack;
@@ -76,6 +77,7 @@ public class PSGenerator {
     
     private Stack graphicsStateStack = new Stack();
     private PSState currentState;
+    private DecimalFormat df = new DecimalFormat("0.000");
 
     private StringBuffer tempBuffer = new StringBuffer(256);
 
@@ -287,6 +289,8 @@ public class PSGenerator {
                     tempBuffer.append(convertStringToDSC((String)params[i]));
                 } else if (params[i] instanceof AtendIndicator) {
                     tempBuffer.append("(atend)");
+                } else if (params[i] instanceof Double) {
+                    tempBuffer.append(df.format(params[i]));
                 } else if (params[i] instanceof Number) {
                     tempBuffer.append(params[i].toString());
                 } else if (params[i] instanceof Date) {
index 566328733b80fbad51cc45a082a203c41aa977e3..d8ddf97e3dd405829cefb9e39340e55d67fc94ee 100644 (file)
 package org.apache.fop.render.ps;
 
 import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.fop.fonts.Font;
+import org.apache.fop.layout.FontInfo;
 
 /**
  * This class defines the basic resources (procsets) used by FOP's PostScript
@@ -197,4 +202,42 @@ public final class PSProcSets {
         gen.writeln("%%EndResource");
     }
 
+    /**
+     * Generates the PostScript code for the font dictionary.
+     * @param gen PostScript generator to use for output
+     * @param fontInfo available fonts
+     * @throws IOException in case of an I/O problem
+     */
+    public static void writeFontDict(PSGenerator gen, FontInfo fontInfo) 
+                throws IOException {
+        gen.writeln("%%BeginResource: procset FOPFonts");
+        gen.writeln("%%Title: Font setup (shortcuts) for this file");
+        gen.writeln("/FOPFonts 100 dict dup begin");
+
+        // write("/gfF1{/Helvetica findfont} bd");
+        // write("/gfF3{/Helvetica-Bold findfont} bd");
+        Map fonts = fontInfo.getFonts();
+        Iterator enum = fonts.keySet().iterator();
+        while (enum.hasNext()) {
+            String key = (String)enum.next();
+            Font fm = (Font)fonts.get(key);
+            gen.writeln("/" + key + " /" + fm.getFontName() + " def");
+        }
+        gen.writeln("end def");
+        gen.writeln("%%EndResource");
+        enum = fonts.keySet().iterator();
+        while (enum.hasNext()) {
+            String key = (String)enum.next();
+            Font fm = (Font)fonts.get(key);
+            gen.writeln("/" + fm.getFontName() + " findfont");
+            gen.writeln("dup length dict begin");
+            gen.writeln("  {1 index /FID ne {def} {pop pop} ifelse} forall");
+            gen.writeln("  /Encoding ISOLatin1Encoding def");
+            gen.writeln("  currentdict");
+            gen.writeln("end");
+            gen.writeln("/" + fm.getFontName() + " exch definefont pop");
+        }
+    }
+
+
 }
index 5071d86e8a5e1f80515705ce024a9c3ff44a4b0f..1f249c975e504be135065e53da0787f459d62b3e 100644 (file)
@@ -54,11 +54,11 @@ package org.apache.fop.render.ps;
 import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 // FOP
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.fop.fo.properties.BackgroundRepeat;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.RegionViewport;
@@ -96,7 +96,6 @@ import org.w3c.dom.Document;
  * <br>
  * The PS renderer operates in millipoints as the layout engine. Since PostScript
  * initially uses points, scaling is applied as needed.
- * @todo Rebuild the PostScript renderer
  * 
  * @author <a href="mailto:fop-dev@xml.apache.org">Apache XML FOP Development Team</a>
  * @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a>
@@ -112,6 +111,7 @@ public class PSRenderer extends AbstractRenderer {
     private int currentPageNumber = 0;
 
     private boolean enableComments = true;
+    private boolean autoRotateLandscape = false;
 
     /** The PostScript generator used to output the PostScript */
     protected PSGenerator gen;
@@ -119,14 +119,20 @@ public class PSRenderer extends AbstractRenderer {
 
     private String currentFontName;
     private int currentFontSize;
-    private int pageHeight;
-    private int pageWidth;
     private float currRed;
     private float currGreen;
     private float currBlue;
 
     private FontInfo fontInfo;
 
+    /**
+     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
+     */
+    public void configure(Configuration cfg) throws ConfigurationException {
+        super.configure(cfg);
+        this.autoRotateLandscape = cfg.getChild("auto-rotate-landscape").getValueAsBoolean(false);
+    }
+    
     /**
      * Set the document's producer
      *
@@ -180,43 +186,6 @@ public class PSRenderer extends AbstractRenderer {
         }
     }
 
-    /**
-     * Generates the PostScript code for the font dictionary.
-     * @param gen PostScript generator to use for output
-     * @param fontInfo available fonts
-     * @throws IOException in case of an I/O problem
-     */
-    public static void writeFontDict(PSGenerator gen, FontInfo fontInfo) 
-                throws IOException {
-        gen.writeln("%%BeginResource: procset FOPFonts");
-        gen.writeln("%%Title: Font setup (shortcuts) for this file");
-        gen.writeln("/FOPFonts 100 dict dup begin");
-
-        // write("/gfF1{/Helvetica findfont} bd");
-        // write("/gfF3{/Helvetica-Bold findfont} bd");
-        Map fonts = fontInfo.getFonts();
-        Iterator enum = fonts.keySet().iterator();
-        while (enum.hasNext()) {
-            String key = (String)enum.next();
-            Font fm = (Font)fonts.get(key);
-            gen.writeln("/" + key + " /" + fm.getFontName() + " def");
-        }
-        gen.writeln("end def");
-        gen.writeln("%%EndResource");
-        enum = fonts.keySet().iterator();
-        while (enum.hasNext()) {
-            String key = (String)enum.next();
-            Font fm = (Font)fonts.get(key);
-            gen.writeln("/" + fm.getFontName() + " findfont");
-            gen.writeln("dup length dict begin");
-            gen.writeln("  {1 index /FID ne {def} {pop pop} ifelse} forall");
-            gen.writeln("  /Encoding ISOLatin1Encoding def");
-            gen.writeln("  currentdict");
-            gen.writeln("end");
-            gen.writeln("/" + fm.getFontName() + " exch definefont pop");
-        }
-    }
-
     /**
      * Make sure the cursor is in the right place.
      */
@@ -399,7 +368,7 @@ public class PSRenderer extends AbstractRenderer {
         gen.writeDSCComment(DSCConstants.BEGIN_SETUP);
         PSProcSets.writeFOPStdProcSet(gen);
         PSProcSets.writeFOPEPSProcSet(gen);
-        writeFontDict(gen, fontInfo);
+        PSProcSets.writeFontDict(gen, fontInfo);
         gen.writeDSCComment(DSCConstants.END_SETUP);
     }
 
@@ -425,14 +394,47 @@ public class PSRenderer extends AbstractRenderer {
                 {page.getPageNumber(),
                  new Integer(this.currentPageNumber)});
         final Integer zero = new Integer(0);
-        final Long pagewidth = new Long(Math.round(page.getViewArea().getWidth()));
-        final Long pageheight = new Long(Math.round(page.getViewArea().getHeight()));
-        gen.writeDSCComment(DSCConstants.PAGE_BBOX, new Object[]
-                {zero, zero, pagewidth, pageheight});
+        final long pagewidth = Math.round(page.getViewArea().getWidth());
+        final long pageheight = Math.round(page.getViewArea().getHeight());
+        final double pspagewidth = pagewidth / 1000f;
+        final double pspageheight = pageheight / 1000f;
+        boolean rotate = false;
+        if (this.autoRotateLandscape && (pageheight < pagewidth)) {
+            rotate = true;
+            gen.writeDSCComment(DSCConstants.PAGE_BBOX, new Object[]
+                    {zero,
+                     zero,
+                     new Long(Math.round(pspageheight)),
+                     new Long(Math.round(pspagewidth))});
+            gen.writeDSCComment(DSCConstants.PAGE_HIRES_BBOX, new Object[]
+                    {zero,
+                     zero,
+                     new Double(pspageheight),
+                     new Double(pspagewidth)});
+            gen.writeDSCComment(DSCConstants.PAGE_ORIENTATION, "Landscape");
+        } else {
+            gen.writeDSCComment(DSCConstants.PAGE_BBOX, new Object[]
+                    {zero,
+                     zero,
+                     new Long(Math.round(pspagewidth)),
+                     new Long(Math.round(pspageheight))});
+            gen.writeDSCComment(DSCConstants.PAGE_HIRES_BBOX, new Object[]
+                    {zero,
+                     zero,
+                     new Double(pspagewidth),
+                     new Double(pspageheight)});
+            if (this.autoRotateLandscape) {
+                gen.writeDSCComment(DSCConstants.PAGE_ORIENTATION, "Portrait");
+            }                
+        }
         gen.writeDSCComment(DSCConstants.BEGIN_PAGE_SETUP);         
         gen.writeln("FOPFonts begin");
+        if (rotate) {
+            gen.writeln(Math.round(pspageheight) + " 0 translate");
+            gen.writeln("90 rotate");
+        }
         gen.writeln("0.001 0.001 scale");
-        concatMatrix(1, 0, 0, -1, 0, pageheight.doubleValue());
+        concatMatrix(1, 0, 0, -1, 0, pageheight);
         
         gen.writeDSCComment(DSCConstants.END_PAGE_SETUP);         
         
@@ -836,10 +838,6 @@ public class PSRenderer extends AbstractRenderer {
                         + gen.formatDouble(col.getBlue()) + " setrgbcolor");
     }
 
-    private void updateFont(String name, int size, StringBuffer pdf) {
-
-    }
-   
     /**
      * @see org.apache.fop.render.AbstractRenderer#renderForeignObject(ForeignObject, Rectangle2D)
      */