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 2010/06/29 18:52:06 UTC

svn commit: r959028 - in /xmlgraphics/fop/branches/Temp_Color: src/java/org/apache/fop/util/ColorUtil.java test/java/org/apache/fop/util/ColorUtilTestCase.java test/resources/color/ test/resources/color/ncp-example.icc

Author: jeremias
Date: Tue Jun 29 16:52:06 2010
New Revision: 959028

URL: http://svn.apache.org/viewvc?rev=959028&view=rev
Log:
Round-trip for fop-rgb-named-color() function.

Added:
    xmlgraphics/fop/branches/Temp_Color/test/resources/color/
    xmlgraphics/fop/branches/Temp_Color/test/resources/color/ncp-example.icc   (with props)
Modified:
    xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/util/ColorUtil.java
    xmlgraphics/fop/branches/Temp_Color/test/java/org/apache/fop/util/ColorUtilTestCase.java

Modified: xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/util/ColorUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/util/ColorUtil.java?rev=959028&r1=959027&r2=959028&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/util/ColorUtil.java (original)
+++ xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/util/ColorUtil.java Tue Jun 29 16:52:06 2010
@@ -660,31 +660,50 @@ public final class ColorUtil {
      */
     public static String toFunctionCall(ColorExt color) {
         Color[] alt = color.getAlternateColors();
-        if (alt.length == 0) {
+        ICCColor icc = null;
+        for (int i = 0, c = alt.length; i < c; i++) {
+            if (alt[i] instanceof ICCColor) {
+                //Find first ICCColor in alternatives
+                icc = (ICCColor)alt[i];
+                break;
+            }
+        }
+        if (icc == null) {
             return toRGBFunctionCall(color);
-        } else if (alt.length != 1) {
-            throw new IllegalStateException(
-                    "Cannot convert to function call: the number of alternate colors is not one.");
         }
         StringBuffer sb = new StringBuffer(40);
-        sb.append("fop-rgb-icc(");
+
+        String functionName;
         float[] rgb = color.getColorComponents(null);
         assert rgb.length == 3;
+        sb.append("(");
         sb.append(rgb[0]).append(",");
         sb.append(rgb[1]).append(",");
         sb.append(rgb[2]).append(",");
-        ICCColor icc = (ICCColor)alt[0];
-        sb.append(icc.getColorProfileName()).append(",");
+        String profileName = icc.getColorProfileName();
+        sb.append(profileName).append(",");
         if (icc.getColorProfileSource() != null) {
             sb.append("\"").append(icc.getColorProfileSource()).append("\"");
         }
-        float[] colorComponents = icc.getColorComponents(null);
-        for (int ix = 0; ix < colorComponents.length; ix++) {
-            sb.append(",");
-            sb.append(colorComponents[ix]);
+
+        if (icc.getColorSpace() instanceof NamedColorSpace) {
+            NamedColorSpace ncs = (NamedColorSpace)icc.getColorSpace();
+            if (SEPARATION_PSEUDO_PROFILE.equalsIgnoreCase(profileName)) {
+                functionName = "fop-rgb-icc";
+            } else {
+                functionName = "fop-rgb-named-color";
+            }
+            sb.append(",").append(ncs.getColorName());
+        } else {
+            functionName = "fop-rgb-icc";
+            float[] colorComponents = icc.getColorComponents(null);
+            for (int ix = 0; ix < colorComponents.length; ix++) {
+                sb.append(",");
+                sb.append(colorComponents[ix]);
+            }
         }
         sb.append(")");
-        return sb.toString();
+        return functionName + sb.toString();
     }
 
     private static Color createColor(int r, int g, int b) {

Modified: xmlgraphics/fop/branches/Temp_Color/test/java/org/apache/fop/util/ColorUtilTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Color/test/java/org/apache/fop/util/ColorUtilTestCase.java?rev=959028&r1=959027&r2=959028&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Color/test/java/org/apache/fop/util/ColorUtilTestCase.java (original)
+++ xmlgraphics/fop/branches/Temp_Color/test/java/org/apache/fop/util/ColorUtilTestCase.java Tue Jun 29 16:52:06 2010
@@ -27,6 +27,7 @@ import junit.framework.TestCase;
 
 import org.apache.xmlgraphics.java2d.color.ColorExt;
 import org.apache.xmlgraphics.java2d.color.ColorSpaces;
+import org.apache.xmlgraphics.java2d.color.NamedColorSpace;
 
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.FopFactory;
@@ -124,12 +125,8 @@ public class ColorUtilTestCase extends T
         String colSpec = "fop-rgb-icc(1.0,0.0,0.0,sRGBAlt,"
             + "\"" + sRGBLoc.toASCIIString() + "\",1.0,0.0,0.0)";
         colActual = (ColorExt)ColorUtil.parseColorString(ua, colSpec);
-        //assertEquals(255, colActual.getRed()); //253 is returned
-        //assertEquals(24, colActual.getGreen()); //24 is returned
-        //I don't understand the difference. Maybe Java's sRGB and HP's sRGB are somehow not
-        //equivalent. This is only going to be a problem if anyone actually makes use of the
-        //RGB fallback in any renderer.
-        //TODO Anyone know what's going on here?
+        assertEquals(255, colActual.getRed());
+        assertEquals(0, colActual.getGreen());
         assertEquals(0, colActual.getBlue());
         assertEquals(ColorSpace.getInstance(ColorSpace.CS_sRGB), colActual.getColorSpace());
         float[] comps = colActual.getColorComponents(null);
@@ -226,4 +223,67 @@ public class ColorUtilTestCase extends T
                 ColorUtil.colorToString(colActual));
     }
 
+    /**
+     * Tests color for the #Separation pseudo-colorspace.
+     * @throws Exception if an error occurs
+     */
+    public void testSeparationColor() throws Exception {
+        ColorExt colActual;
+        String colSpec;
+
+        colSpec = "fop-rgb-icc(1.0,0.8,0.0,#Separation,,Postgelb)";
+        colActual = (ColorExt)ColorUtil.parseColorString(null, colSpec);
+        assertEquals(255, colActual.getRed());
+        assertEquals(204, colActual.getGreen());
+        assertEquals(0, colActual.getBlue());
+
+        Color alt = colActual.getAlternateColors()[0];
+        assertTrue(alt.getColorSpace() instanceof NamedColorSpace);
+        NamedColorSpace ncs;
+        ncs = (NamedColorSpace)alt.getColorSpace();
+        assertEquals("Postgelb", ncs.getColorName());
+        float[] comps = alt.getColorComponents(null);
+        assertEquals(1, comps.length);
+        assertEquals(1f, comps[0], 0);
+        assertEquals(colSpec, ColorUtil.colorToString(colActual));
+    }
+
+    /**
+     * Tests the fop-rgb-named-color() function.
+     * @throws Exception if an error occurs
+     */
+    public void testNamedColorProfile() throws Exception {
+        FopFactory fopFactory = FopFactory.newInstance();
+        URI ncpLoc = new URI("file:test/resources/color/ncp-example.icc");
+        ColorSpace cs = fopFactory.getColorSpace(null, ncpLoc.toASCIIString());
+        assertNotNull(cs);
+
+        FOUserAgent ua = fopFactory.newFOUserAgent();
+        ColorExt colActual;
+
+        //fop-rgb-named-color() is used instead of rgb-named-color() inside FOP!
+        String colSpec = "fop-rgb-named-color(1.0,0.8,0.0,NCP,"
+            + "\"" + ncpLoc.toASCIIString() + "\",Postgelb)";
+        colActual = (ColorExt)ColorUtil.parseColorString(ua, colSpec);
+        assertEquals(255, colActual.getRed());
+        assertEquals(204, colActual.getGreen());
+        assertEquals(0, colActual.getBlue());
+        assertEquals(ColorSpace.getInstance(ColorSpace.CS_sRGB), colActual.getColorSpace());
+        float[] comps = colActual.getColorComponents(null);
+        assertEquals(3, comps.length);
+        assertEquals(1f, comps[0], 0);
+        assertEquals(0.8f, comps[1], 0);
+        assertEquals(0f, comps[2], 0);
+
+        Color alt = colActual.getAlternateColors()[0];
+        assertTrue(alt.getColorSpace() instanceof NamedColorSpace);
+        NamedColorSpace ncs;
+        ncs = (NamedColorSpace)alt.getColorSpace();
+        assertEquals("Postgelb", ncs.getColorName());
+        comps = alt.getColorComponents(null);
+        assertEquals(1, comps.length);
+        assertEquals(1f, comps[0], 0);
+
+        assertEquals(colSpec, ColorUtil.colorToString(colActual));
+    }
 }

Added: xmlgraphics/fop/branches/Temp_Color/test/resources/color/ncp-example.icc
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Color/test/resources/color/ncp-example.icc?rev=959028&view=auto
==============================================================================
Binary file - no diff available.

Propchange: xmlgraphics/fop/branches/Temp_Color/test/resources/color/ncp-example.icc
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



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