xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r1045060 - /xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/ps/PSGenerator.java
Date Mon, 13 Dec 2010 11:05:42 GMT
Author: jeremias
Date: Mon Dec 13 11:05:41 2010
New Revision: 1045060

URL: http://svn.apache.org/viewvc?rev=1045060&view=rev
Log:
Fixed behaviour for establishing color and added a note how the various colors are handled.
(partly automatic) adjustments for J2SE 1.5.

Modified:
    xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/ps/PSGenerator.java

Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/ps/PSGenerator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/ps/PSGenerator.java?rev=1045060&r1=1045059&r2=1045060&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/ps/PSGenerator.java
(original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/ps/PSGenerator.java
Mon Dec 13 11:05:41 2010
@@ -59,6 +59,7 @@ public class PSGenerator implements PSCo
      * later in the document (mostly in the %%Trailer section).
      * @deprecated Please use DSCConstants.ATEND. This constant was in the wrong place.
      */
+    @Deprecated
     public static final Object ATEND = DSCConstants.ATEND;
 
     /** Line feed used by PostScript */
@@ -71,7 +72,7 @@ public class PSGenerator implements PSCo
     private boolean compactMode = true;
     private PSCommandMap commandMap = PSProcSets.STD_COMMAND_MAP;
 
-    private Stack graphicsStateStack = new Stack();
+    private Stack<PSState> graphicsStateStack = new Stack<PSState>();
     private PSState currentState;
     //private DecimalFormat df3 = new DecimalFormat("0.000", new DecimalFormatSymbols(Locale.US));
     private DecimalFormat df3 = new DecimalFormat("0.###", new DecimalFormatSymbols(Locale.US));
@@ -455,7 +456,7 @@ public class PSGenerator implements PSCo
     public boolean restoreGraphicsState() throws IOException {
         if (this.graphicsStateStack.size() > 0) {
             writeln(mapCommand("grestore"));
-            this.currentState = (PSState)this.graphicsStateStack.pop();
+            this.currentState = this.graphicsStateStack.pop();
             return true;
         } else {
             return false;
@@ -628,6 +629,7 @@ public class PSGenerator implements PSCo
      * @exception IOException In case of an I/O problem
      * @deprecated use useColor method instead
      */
+    @Deprecated
     public void useRGBColor(Color col) throws IOException {
         useColor(col);
     }
@@ -646,10 +648,15 @@ public class PSGenerator implements PSCo
     private String convertColorToPS(Color color) {
         StringBuffer codeBuffer = new StringBuffer();
 
+        //Important: Right now, CMYK colors are treated as device colors (DeviceCMYK) irrespective
+        //of any associated color profile. All other colors are converted to sRGB (if necessary)
+        //and the resulting RGB components are treated as DeviceRGB colors.
+        //If all three RGB components are the same, DeviceGray is used.
+
         boolean established = false;
         if (color instanceof ColorWithAlternatives) {
             ColorWithAlternatives colExt = (ColorWithAlternatives)color;
-            //Alternate colors have priority
+            //Alternative colors have priority
             Color[] alt = colExt.getAlternativeColors();
             for (int i = 0, c = alt.length; i < c; i++) {
                 Color col = alt[i];
@@ -669,30 +676,34 @@ public class PSGenerator implements PSCo
             established = establishColorFromColor(codeBuffer, color);
         }
         if (!established) {
-            establishDeviceRGB(codeBuffer, color);
+            establishFallbackRGB(codeBuffer, color);
         }
 
         return codeBuffer.toString();
     }
 
     private boolean establishColorFromColor(StringBuffer codeBuffer, Color color) {
+        //Important: see above note about color handling!
         float[] comps = color.getColorComponents(null);
         if (color.getColorSpace().getType() == ColorSpace.TYPE_CMYK) {
             // colorspace is CMYK
-            for (int i = 0; i < color.getColorSpace().getNumComponents(); i++) {
-                if (i > 0) {
-                    codeBuffer.append(" ");
-                }
-                codeBuffer.append(formatDouble(comps[i]));
+            writeSetColor(codeBuffer, comps, "setcmykcolor");
+            return true;
+        }
+        return false;
+    }
+
+    private void writeSetColor(StringBuffer codeBuffer, float[] comps, String command) {
+        for (int i = 0, c = comps.length; i < c; i++) {
+            if (i > 0) {
+                codeBuffer.append(" ");
             }
-            codeBuffer.append(" ").append(mapCommand("setcmykcolor"));
-        } else {
-            establishDeviceRGB(codeBuffer, color);
+            codeBuffer.append(formatDouble(comps[i]));
         }
-        return true;
+        codeBuffer.append(" ").append(mapCommand(command));
     }
 
-    private void establishDeviceRGB(StringBuffer codeBuffer, Color color) {
+    private void establishFallbackRGB(StringBuffer codeBuffer, Color color) {
         float[] comps;
         if (color.getColorSpace().isCS_sRGB()) {
             comps = color.getColorComponents(null);
@@ -707,17 +718,7 @@ public class PSGenerator implements PSCo
         if (gray) {
             codeBuffer.append(formatDouble(comps[0]));
         } else {
-            for (int i = 0, c = comps.length; i < c; i++) {
-                if (i > 0) {
-                    codeBuffer.append(" ");
-                }
-                codeBuffer.append(formatDouble(comps[i]));
-            }
-        }
-        if (gray) {
-            codeBuffer.append(" ").append(mapCommand("setgray"));
-        } else {
-            codeBuffer.append(" ").append(mapCommand("setrgbcolor"));
+            writeSetColor(codeBuffer, comps, gray ? "setgray" : "setrgbcolor");
         }
     }
 
@@ -756,6 +757,7 @@ public class PSGenerator implements PSCo
      * set can be cleared.
      * @deprecated Use the notifyStartNewPage() on ResourceTracker instead.
      */
+    @Deprecated
     public void notifyStartNewPage() {
         getResourceTracker().notifyStartNewPage();
     }
@@ -766,6 +768,7 @@ public class PSGenerator implements PSCo
      * @param needed true if this is a needed resource, false for a supplied resource
      * @deprecated Use the notifyResourceUsageOnPage() on ResourceTracker instead
      */
+    @Deprecated
     public void notifyResourceUsage(PSResource res, boolean needed) {
         getResourceTracker().notifyResourceUsageOnPage(res);
     }
@@ -778,6 +781,7 @@ public class PSGenerator implements PSCo
      * @exception IOException In case of an I/O problem
      * @deprecated Use the writeResources() on ResourceTracker instead.
      */
+    @Deprecated
     public void writeResources(boolean pageLevel) throws IOException {
         getResourceTracker().writeResources(pageLevel, this);
     }
@@ -788,6 +792,7 @@ public class PSGenerator implements PSCo
      * @return true if the resource is registered as being supplied.
      * @deprecated Use the isResourceSupplied() on ResourceTracker instead.
      */
+    @Deprecated
     public boolean isResourceSupplied(PSResource res) {
         return getResourceTracker().isResourceSupplied(res);
     }



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


Mime
View raw message