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 2011/04/22 09:15:44 UTC

svn commit: r1095878 - in /xmlgraphics/fop/trunk/src: documentation/content/xdocs/trunk/ java/org/apache/fop/render/intermediate/ java/org/apache/fop/render/ps/

Author: jeremias
Date: Fri Apr 22 07:15:43 2011
New Revision: 1095878

URL: http://svn.apache.org/viewvc?rev=1095878&view=rev
Log:
Added option for PostScript output to optimize for file size rather than quality.
Fixed some missing PostScript command mappings.

Added:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderingMode.java   (with props)
Modified:
    xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/output.xml
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSBorderPainter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRendererConfigurator.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderingUtil.java

Modified: xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/output.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/output.xml?rev=1095878&r1=1095877&r2=1095878&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/output.xml (original)
+++ xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/output.xml Fri Apr 22 07:15:43 2011
@@ -287,6 +287,7 @@ out = proc.getOutputStream();]]></source
   <optimize-resources>false</optimize-resources>
   <safe-set-page-device>false</safe-set-page-device>
   <dsc-compliant>true</dsc-compliant>
+  <rendering>quality</rendering>
 </renderer>]]></source>
       <p>
         The default value for the "auto-rotate-landscape" setting is "false". Setting it
@@ -319,6 +320,12 @@ out = proc.getOutputStream();]]></source
         the particular postscript implementation issuing unwanted postscript subsystem
         initgraphics/erasepage calls on each setpagedevice call.
       </p>
+      <p>
+        The default value for the "rendering" setting is "quality". Setting it to "size"
+        optimizes rendering for smaller file sizes which can involve minor compromises in
+        rendering quality. For example, solid borders are then painted as plain rectangles
+        instead of the elaborate painting instructions required for mixed-color borders.
+      </p>
     </section>
   <section id="ps-limitations">
     <title>Limitations</title>

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java?rev=1095878&r1=1095877&r2=1095878&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java Fri Apr 22 07:15:43 2011
@@ -46,6 +46,7 @@ import org.apache.xmlgraphics.image.load
 import org.apache.fop.ResourceEventProducer;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.FopFactory;
+import org.apache.fop.fo.Constants;
 import org.apache.fop.render.ImageHandler;
 import org.apache.fop.render.ImageHandlerRegistry;
 import org.apache.fop.render.ImageHandlerUtil;
@@ -342,6 +343,32 @@ public abstract class AbstractIFPainter 
         }
     }
 
+    /**
+     * Indicates whether the given border segments (if present) have only solid borders, i.e.
+     * could be painted in a simplified fashion keeping the output file smaller.
+     * @param before the border segment on the before-side (top)
+     * @param after the border segment on the after-side (bottom)
+     * @param start the border segment on the start-side (left)
+     * @param end the border segment on the end-side (right)
+     * @return true if any border segment has a non-solid border style
+     */
+    protected boolean hasOnlySolidBorders(BorderProps before, BorderProps after,
+            BorderProps start, BorderProps end) {
+        if (before != null && before.style != Constants.EN_SOLID) {
+            return false;
+        }
+        if (after != null && after.style != Constants.EN_SOLID) {
+            return false;
+        }
+        if (start != null && start.style != Constants.EN_SOLID) {
+            return false;
+        }
+        if (end != null && end.style != Constants.EN_SOLID) {
+            return false;
+        }
+        return true;
+    }
+
     /** {@inheritDoc} */
     public void drawLine(Point start, Point end, int width, Color color, RuleStyle style)
             throws IFException {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSBorderPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSBorderPainter.java?rev=1095878&r1=1095877&r2=1095878&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSBorderPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSBorderPainter.java Fri Apr 22 07:15:43 2011
@@ -62,9 +62,10 @@ public class PSBorderPainter extends Bor
     private static void drawLine(PSGenerator gen,
             float startx, float starty, float endx, float endy) throws IOException {
         gen.writeln(gen.formatDouble(startx) + " "
-                + gen.formatDouble(starty) + " M "
+                + gen.formatDouble(starty) + " " + gen.mapCommand("moveto") + " "
                 + gen.formatDouble(endx) + " "
-                + gen.formatDouble(endy) + " lineto stroke newpath");
+                + gen.formatDouble(endy) + " " + gen.mapCommand("lineto") + " "
+                + gen.mapCommand("stroke") + " " + gen.mapCommand("newpath"));
     }
 
     /**
@@ -260,7 +261,8 @@ public class PSBorderPainter extends Bor
                 lineTo(end.x, starty + 2 * half);
                 lineTo(start.x, starty + 2 * half);
                 closePath();
-                generator.writeln(" fill newpath");
+                generator.write(" " + generator.mapCommand("fill"));
+                generator.writeln(" " + generator.mapCommand("newpath"));
                 generator.useColor(color);
                 if (style == RuleStyle.GROOVE) {
                     moveTo(start.x, starty);
@@ -276,7 +278,8 @@ public class PSBorderPainter extends Bor
                     lineTo(end.x - half, starty + half);
                 }
                 closePath();
-                generator.writeln(" fill newpath");
+                generator.write(" " + generator.mapCommand("fill"));
+                generator.writeln(" " + generator.mapCommand("newpath"));
                 break;
             default:
                 throw new UnsupportedOperationException("rule style not supported");
@@ -293,13 +296,13 @@ public class PSBorderPainter extends Bor
     /** {@inheritDoc} */
     protected void moveTo(int x, int y) throws IOException {
         generator.writeln(generator.formatDouble(toPoints(x)) + " "
-                + generator.formatDouble(toPoints(y)) + " M");
+                + generator.formatDouble(toPoints(y)) + " " + generator.mapCommand("moveto"));
     }
 
     /** {@inheritDoc} */
     protected void lineTo(int x, int y) throws IOException {
         generator.writeln(generator.formatDouble(toPoints(x)) + " "
-                + generator.formatDouble(toPoints(y)) + " lineto");
+                + generator.formatDouble(toPoints(y)) + " " + generator.mapCommand("lineto"));
     }
 
     /** {@inheritDoc} */
@@ -314,7 +317,7 @@ public class PSBorderPainter extends Bor
 
     /** {@inheritDoc} */
     protected void clip() throws IOException {
-        generator.writeln("clip newpath");
+        generator.writeln(generator.mapCommand("clip") + " " + generator.mapCommand("newpath"));
     }
 
     /** {@inheritDoc} */

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java?rev=1095878&r1=1095877&r2=1095878&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java Fri Apr 22 07:15:43 2011
@@ -202,7 +202,7 @@ public class PSPainter extends AbstractI
             endTextObject();
             generator.defineRect(rect.x / 1000.0, rect.y / 1000.0,
                     rect.width / 1000.0, rect.height / 1000.0);
-            generator.writeln("clip newpath");
+            generator.writeln(generator.mapCommand("clip") + " " + generator.mapCommand("newpath"));
         } catch (IOException ioe) {
             throw new IFException("I/O error in clipRect()", ioe);
         }
@@ -226,7 +226,7 @@ public class PSPainter extends AbstractI
                 }
                 generator.defineRect(rect.x / 1000.0, rect.y / 1000.0,
                         rect.width / 1000.0, rect.height / 1000.0);
-                generator.writeln("fill");
+                generator.writeln(generator.mapCommand("fill"));
             } catch (IOException ioe) {
                 throw new IFException("I/O error in fillRect()", ioe);
             }
@@ -239,7 +239,12 @@ public class PSPainter extends AbstractI
         if (before != null || after != null || start != null || end != null) {
             try {
                 endTextObject();
-                this.borderPainter.drawBorders(rect, before, after, start, end);
+                if (getPSUtil().getRenderingMode() == PSRenderingMode.SIZE
+                    && hasOnlySolidBorders(before, after, start, end)) {
+                    super.drawBorderRect(rect, before, after, start, end);
+                } else {
+                    this.borderPainter.drawBorders(rect, before, after, start, end);
+                }
             } catch (IOException ioe) {
                 throw new IFException("I/O error in drawBorderRect()", ioe);
             }
@@ -478,9 +483,9 @@ public class PSPainter extends AbstractI
                 spb.append(formatMptAsPt(generator, letterSpacing))
                     .append(" 0 ");
                 sb.insert(0, spb.toString());
-                sb.append(" ashow");
+                sb.append(" " + generator.mapCommand("ashow"));
             } else {
-                sb.append(" show");
+                sb.append(" " + generator.mapCommand("show"));
             }
         }
         generator.writeln(sb.toString());

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRendererConfigurator.java?rev=1095878&r1=1095877&r2=1095878&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRendererConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRendererConfigurator.java Fri Apr 22 07:15:43 2011
@@ -66,6 +66,11 @@ public class PSRendererConfigurator exte
         if (child != null) {
             psUtil.setOptimizeResources(child.getValueAsBoolean(false));
         }
+        child = cfg.getChild("rendering");
+        if (child != null) {
+            psUtil.setRenderingMode(PSRenderingMode.valueOf(
+                    child.getValue(psUtil.getRenderingMode().toString()).toUpperCase()));
+        }
         psUtil.setSafeSetPageDevice(
             cfg.getChild("safe-set-page-device").getValueAsBoolean(false));
         psUtil.setDSCComplianceEnabled(

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderingMode.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderingMode.java?rev=1095878&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderingMode.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderingMode.java Fri Apr 22 07:15:43 2011
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps;
+
+/**
+ * Enumeration that specifies the rendering mode for PostScript output. {@link #SIZE} tries
+ * to produce smaller files at the expense of quality, whereas {@link #QUALITY} tries to
+ * produce the best possible quality.
+ */
+enum PSRenderingMode {
+
+    SIZE, QUALITY;
+
+}

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderingMode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderingMode.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderingUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderingUtil.java?rev=1095878&r1=1095877&r2=1095878&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderingUtil.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderingUtil.java Fri Apr 22 07:15:43 2011
@@ -56,6 +56,12 @@ public class PSRenderingUtil implements 
     /** Determines whether the PS file is generated in two passes to minimize file size */
     private boolean optimizeResources = false;
 
+    /**
+     * Determines whether the generated PostScript code is optimized for minimum file size
+     * of best quality.
+     */
+    private PSRenderingMode renderingMode = PSRenderingMode.QUALITY;
+
     PSRenderingUtil(FOUserAgent userAgent) {
         this.userAgent = userAgent;
         initialize();
@@ -287,5 +293,19 @@ public class PSRenderingUtil implements 
         return optimizeResources;
     }
 
+    /**
+     * Sets the rendering mode.
+     * @param renderingMode the rendering mode
+     */
+    public void setRenderingMode(PSRenderingMode renderingMode) {
+        this.renderingMode = renderingMode;
+    }
 
+    /**
+     * Returns the rendering mode.
+     * @return the rendering mode
+     */
+    public PSRenderingMode getRenderingMode() {
+        return this.renderingMode;
+    }
 }



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