You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by je...@apache.org on 2007/06/20 10:28:53 UTC

svn commit: r548990 - in /xmlgraphics/commons/trunk: src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java src/java/org/apache/xmlgraphics/ps/PSGenerator.java src/java/org/apache/xmlgraphics/ps/PSState.java status.xml

Author: jeremias
Date: Wed Jun 20 01:28:52 2007
New Revision: 548990

URL: http://svn.apache.org/viewvc?view=rev&rev=548990
Log:
Bugzilla #42507:
Added support for CMYK and GRAY color spaces for PSGenerator
Submitted by: Adrian Cumiskey <dev.at.cumiskey.com>

Patch modified:
color selection code moved from PSGraphics2D to PSGenerator in order not to generate a circular dependency.

Modified:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSGenerator.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSState.java
    xmlgraphics/commons/trunk/status.xml

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java?view=diff&rev=548990&r1=548989&r2=548990
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java Wed Jun 20 01:28:52 2007
@@ -598,46 +598,7 @@
      * @throws IOException In case of an I/O problem
      */
     public void establishColor(Color c) throws IOException {
-        StringBuffer p = new StringBuffer();
-        float[] comps = c.getColorComponents(null);
-        
-        if (c.getColorSpace().getType() == ColorSpace.TYPE_RGB) {
-            // according to pdfspec 12.1 p.399
-            // if the colors are the same then just use the g or G operator
-            boolean same = (comps[0] == comps[1] 
-                        && comps[0] == comps[2]);
-            // output RGB
-            if (same) {
-                p.append(gen.formatDouble(comps[0]));
-            } else {
-                for (int i = 0; i < c.getColorSpace().getNumComponents(); i++) {
-                    if (i > 0) {
-                        p.append(" ");
-                    }
-                    p.append(gen.formatDouble(comps[i]));
-                }
-            }
-            if (same) {
-                p.append(" setgray");
-            } else {
-                p.append(" setrgbcolor");
-            }
-        } else if (c.getColorSpace().getType() == ColorSpace.TYPE_CMYK) {
-            // colorspace is CMYK
-            for (int i = 0; i < c.getColorSpace().getNumComponents(); i++) {
-                if (i > 0) {
-                    p.append(" ");
-                }
-                p.append(gen.formatDouble(comps[i]));
-            }
-            p.append(" setcmykcolor");
-        } else {
-            // means we're in DeviceGray or Unknown.
-            // assume we're in DeviceGray, because otherwise we're screwed.
-            p.append(gen.formatDouble(comps[0]));
-            p.append(" setgray");
-        }
-        gen.writeln(p.toString());
+        gen.useColor(c);
     }
 
     /**

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSGenerator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSGenerator.java?view=diff&rev=548990&r1=548989&r2=548990
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSGenerator.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSGenerator.java Wed Jun 20 01:28:52 2007
@@ -20,6 +20,7 @@
 package org.apache.xmlgraphics.ps;
 
 import java.awt.Color;
+import java.awt.color.ColorSpace;
 import java.awt.geom.AffineTransform;
 import java.io.OutputStream;
 import java.io.IOException;
@@ -41,6 +42,9 @@
  */
 public class PSGenerator {
 
+    /**
+     * Default postscript language level
+     */
     public static final int DEFAULT_LANGUAGE_LEVEL = 3;
     
     /** 
@@ -495,23 +499,69 @@
             writeln(pattern + " setdash");
         }
     }
-                                
+
     /**
      * Establishes the specified color (RGB).
      * @param col the color as defined by the setrgbcolor command.
      * @exception IOException In case of an I/O problem
+     * @deprecated use useColor method instead
      */
     public void useRGBColor(Color col) throws IOException {
-        if (col == null) {
-            col = PSState.DEFAULT_RGB_COLOR;
-        }
+        useColor(col);
+    }        
+
+    /**
+     * Establishes the specified color.
+     * @param col the color.
+     * @exception IOException In case of an I/O problem
+     */
+    public void useColor(Color col) throws IOException {
         if (getCurrentState().useColor(col)) {
-            float[] comps = col.getColorComponents(null);
-            writeln(formatDouble(comps[0])
-                    + " " + formatDouble(comps[1])
-                    + " " + formatDouble(comps[2])
-                    + " setrgbcolor");
+            writeln(convertColorToPS(col));
+        }
+    }
+    
+    private String convertColorToPS(Color col) {
+        StringBuffer p = new StringBuffer();
+        float[] comps = col.getColorComponents(null);
+        
+        if (col.getColorSpace().getType() == ColorSpace.TYPE_RGB) {
+            // according to pdfspec 12.1 p.399
+            // if the colors are the same then just use the g or G operator
+            boolean same = (comps[0] == comps[1] 
+                        && comps[0] == comps[2]);
+            // output RGB
+            if (same) {
+                p.append(formatDouble(comps[0]));
+            } else {
+                for (int i = 0; i < col.getColorSpace().getNumComponents(); i++) {
+                    if (i > 0) {
+                        p.append(" ");
+                    }
+                    p.append(formatDouble(comps[i]));
+                }
+            }
+            if (same) {
+                p.append(" setgray");
+            } else {
+                p.append(" setrgbcolor");
+            }
+        } else if (col.getColorSpace().getType() == ColorSpace.TYPE_CMYK) {
+            // colorspace is CMYK
+            for (int i = 0; i < col.getColorSpace().getNumComponents(); i++) {
+                if (i > 0) {
+                    p.append(" ");
+                }
+                p.append(formatDouble(comps[i]));
+            }
+            p.append(" setcmykcolor");
+        } else {
+            // means we're in DeviceGray or Unknown.
+            // assume we're in DeviceGray, because otherwise we're screwed.
+            p.append(formatDouble(comps[0]));
+            p.append(" setgray");
         }
+        return p.toString();
     }
     
     /**

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSState.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSState.java?view=diff&rev=548990&r1=548989&r2=548990
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSState.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSState.java Wed Jun 20 01:28:52 2007
@@ -43,7 +43,7 @@
     private int linecap = 0;
     private double linewidth = 1.0f;
     private String dashpattern = DEFAULT_DASH;
-    private Color rgbColor = DEFAULT_RGB_COLOR;
+    private Color color = DEFAULT_RGB_COLOR;
     
     //Font state
     private String fontname;
@@ -69,7 +69,7 @@
         this.linecap = org.linecap;
         this.linewidth = org.linewidth;
         this.dashpattern = org.dashpattern;
-        this.rgbColor = org.rgbColor;
+        this.color = org.color;
         this.fontname = org.fontname;
         this.fontsize = org.fontsize;
     }
@@ -152,8 +152,8 @@
      * @return true if the color changed compared to the previous setting
      */
     public boolean useColor(Color value) {
-        if (!rgbColor.equals(value)) {
-            rgbColor = value;
+        if (!color.equals(value)) {
+            color = value;
             return true;
         } else {
             return false;
@@ -192,7 +192,7 @@
         gen.useLineCap(linecap);
         gen.useLineWidth(linewidth);
         gen.useDash(dashpattern);
-        gen.useRGBColor(rgbColor);
+        gen.useColor(color);
         if (fontname != null) {
             gen.useFont(fontname, fontsize);
         }

Modified: xmlgraphics/commons/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/status.xml?view=diff&rev=548990&r1=548989&r2=548990
==============================================================================
--- xmlgraphics/commons/trunk/status.xml (original)
+++ xmlgraphics/commons/trunk/status.xml Wed Jun 20 01:28:52 2007
@@ -28,6 +28,10 @@
 
   <changes>
     <release version="Trunk" date="n/a">
+      <action context="Code" dev="JM" type="add" fixes-bug="42507" due-to="Adrian Cumiskey">
+        Added support for CMYK and GRAY color spaces for PSGenerator
+        (moved there from PSGraphics2D).
+      </action>
       <action context="Code" dev="JM" type="fix">
         Fixed the PDF/A namespace according to ISO-19005-1:2005/Cor.1:2007 and deprecated the
         use of the draft PDF/A namespace used by Adobe Acrobat 7.x.



---------------------------------------------------------------------
Apache XML Graphics Project URL: http://xmlgraphics.apache.org/
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org