From 12b81dc08427e0c512acc3b47d4af935632c5097 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Thu, 17 Apr 2003 15:35:20 +0000 Subject: [PATCH] Moved all procsets out to PSProcSets. 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 --- .../apache/fop/render/ps/DSCConstants.java | 4 + .../org/apache/fop/render/ps/PSGenerator.java | 4 + .../org/apache/fop/render/ps/PSProcSets.java | 43 ++++++++ .../org/apache/fop/render/ps/PSRenderer.java | 102 +++++++++--------- 4 files changed, 101 insertions(+), 52 deletions(-) diff --git a/src/java/org/apache/fop/render/ps/DSCConstants.java b/src/java/org/apache/fop/render/ps/DSCConstants.java index fcaee2ac9..40da71313 100644 --- a/src/java/org/apache/fop/render/ps/DSCConstants.java +++ b/src/java/org/apache/fop/render/ps/DSCConstants.java @@ -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"; diff --git a/src/java/org/apache/fop/render/ps/PSGenerator.java b/src/java/org/apache/fop/render/ps/PSGenerator.java index 2b0622d96..988d53bd6 100644 --- a/src/java/org/apache/fop/render/ps/PSGenerator.java +++ b/src/java/org/apache/fop/render/ps/PSGenerator.java @@ -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) { diff --git a/src/java/org/apache/fop/render/ps/PSProcSets.java b/src/java/org/apache/fop/render/ps/PSProcSets.java index 566328733..d8ddf97e3 100644 --- a/src/java/org/apache/fop/render/ps/PSProcSets.java +++ b/src/java/org/apache/fop/render/ps/PSProcSets.java @@ -51,6 +51,11 @@ 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"); + } + } + + } diff --git a/src/java/org/apache/fop/render/ps/PSRenderer.java b/src/java/org/apache/fop/render/ps/PSRenderer.java index 5071d86e8..1f249c975 100644 --- a/src/java/org/apache/fop/render/ps/PSRenderer.java +++ b/src/java/org/apache/fop/render/ps/PSRenderer.java @@ -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; *
* 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 Apache XML FOP Development Team * @author Jeremias Maerki @@ -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) */ -- 2.39.5