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 2003/04/17 17:35:20 UTC

cvs commit: xml-fop/src/java/org/apache/fop/render/ps PSProcSets.java PSGenerator.java PSRenderer.java DSCConstants.java

jeremias    2003/04/17 08:35:20

  Modified:    src/java/org/apache/fop/render/ps PSProcSets.java
                        PSGenerator.java PSRenderer.java DSCConstants.java
  Log:
  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
  
  Revision  Changes    Path
  1.2       +43 -0     xml-fop/src/java/org/apache/fop/render/ps/PSProcSets.java
  
  Index: PSProcSets.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/ps/PSProcSets.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PSProcSets.java	11 Mar 2003 13:05:22 -0000	1.1
  +++ PSProcSets.java	17 Apr 2003 15:35:20 -0000	1.2
  @@ -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
  @@ -196,5 +201,43 @@
           
           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");
  +        }
  +    }
  +
   
   }
  
  
  
  1.2       +4 -0      xml-fop/src/java/org/apache/fop/render/ps/PSGenerator.java
  
  Index: PSGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/ps/PSGenerator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PSGenerator.java	11 Mar 2003 13:05:22 -0000	1.1
  +++ PSGenerator.java	17 Apr 2003 15:35:20 -0000	1.2
  @@ -53,6 +53,7 @@
   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 @@
       
       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 @@
                       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) {
  
  
  
  1.3       +50 -52    xml-fop/src/java/org/apache/fop/render/ps/PSRenderer.java
  
  Index: PSRenderer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/ps/PSRenderer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PSRenderer.java	12 Mar 2003 15:33:03 -0000	1.2
  +++ PSRenderer.java	17 Apr 2003 15:35:20 -0000	1.3
  @@ -54,11 +54,11 @@
   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 @@
    * <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 @@
       private int currentPageNumber = 0;
   
       private boolean enableComments = true;
  +    private boolean autoRotateLandscape = false;
   
       /** The PostScript generator used to output the PostScript */
       protected PSGenerator gen;
  @@ -119,8 +119,6 @@
   
       private String currentFontName;
       private int currentFontSize;
  -    private int pageHeight;
  -    private int pageWidth;
       private float currRed;
       private float currGreen;
       private float currBlue;
  @@ -128,6 +126,14 @@
       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
        *
        * @param producer string indicating application producing the PostScript
  @@ -181,43 +187,6 @@
       }
   
       /**
  -     * 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.
        */
       protected void movetoCurrPosition() {
  @@ -399,7 +368,7 @@
           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 @@
                   {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 @@
                           + gen.formatDouble(col.getBlue()) + " setrgbcolor");
       }
   
  -    private void updateFont(String name, int size, StringBuffer pdf) {
  -
  -    }
  -   
       /**
        * @see org.apache.fop.render.AbstractRenderer#renderForeignObject(ForeignObject, Rectangle2D)
        */
  
  
  
  1.2       +4 -0      xml-fop/src/java/org/apache/fop/render/ps/DSCConstants.java
  
  Index: DSCConstants.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/ps/DSCConstants.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DSCConstants.java	11 Mar 2003 13:05:22 -0000	1.1
  +++ DSCConstants.java	17 Apr 2003 15:35:20 -0000	1.2
  @@ -66,6 +66,8 @@
       
       /** 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 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";
   
  
  
  

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