]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Bugfix: Added equals() method to ColorExt because the base class only compares the...
authorJeremias Maerki <jeremias@apache.org>
Wed, 25 Nov 2009 14:42:48 +0000 (14:42 +0000)
committerJeremias Maerki <jeremias@apache.org>
Wed, 25 Nov 2009 14:42:48 +0000 (14:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@884117 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/util/ColorExt.java
test/java/org/apache/fop/util/ColorUtilTestCase.java

index 22c2dcc36d3d88939a400ad957ae1f8883523940..e8f929ad1a4f0bd9699673bbad9ea74a5831008c 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.fop.util;
 
 import java.awt.Color;
 import java.awt.color.ColorSpace;
+import java.util.Arrays;
 
 /**
  * Color helper class.
@@ -120,6 +121,7 @@ public final class ColorExt extends Color {
     public static ColorExt createFromSvgIccColor(float red, float green,
             float blue, float opacity, String profileName, String profileHref,
             ColorSpace profileCS, float[] colorValues) {
+        //TODO this method is not referenced by FOP, can it be deleted?
         ColorExt ce = new ColorExt(red, green, blue, opacity);
         ce.rgbReplacementRed = -1;
         ce.rgbReplacementGreen = -1;
@@ -132,6 +134,57 @@ public final class ColorExt extends Color {
 
     }
 
+    /** {@inheritDoc} */
+    public int hashCode() {
+        //implementation from the superclass should be good enough for our purposes
+        return super.hashCode();
+    }
+
+    /** {@inheritDoc} */
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        ColorExt other = (ColorExt)obj;
+        //TODO maybe use super.getColorComponents() instead
+        if (!Arrays.equals(colorValues, other.colorValues)) {
+            return false;
+        }
+        if (iccProfileName == null) {
+            if (other.iccProfileName != null) {
+                return false;
+            }
+        } else if (!iccProfileName.equals(other.iccProfileName)) {
+            return false;
+        }
+        if (iccProfileSrc == null) {
+            if (other.iccProfileSrc != null) {
+                return false;
+            }
+        } else if (!iccProfileSrc.equals(other.iccProfileSrc)) {
+            return false;
+        }
+        if (Float.floatToIntBits(rgbReplacementBlue)
+                != Float.floatToIntBits(other.rgbReplacementBlue)) {
+            return false;
+        }
+        if (Float.floatToIntBits(rgbReplacementGreen)
+                != Float.floatToIntBits(other.rgbReplacementGreen)) {
+            return false;
+        }
+        if (Float.floatToIntBits(rgbReplacementRed)
+                != Float.floatToIntBits(other.rgbReplacementRed)) {
+            return false;
+        }
+        return true;
+    }
+
     /**
      * Get ICC profile name
      *
@@ -154,14 +207,19 @@ public final class ColorExt extends Color {
      * @return the original ColorSpace
      */
     public ColorSpace getOrigColorSpace() {
+        //TODO this method is probably unnecessary due to super.cs and getColorSpace()
         return this.colorSpace;
     }
 
     /**
+     * Returns the original color values.
      * @return the original color values
      */
     public float[] getOriginalColorComponents() {
-        return this.colorValues;
+        //TODO this method is probably unnecessary due to super.fvalue and getColorComponents()
+        float[] copy = new float[this.colorValues.length];
+        System.arraycopy(this.colorValues, 0, copy, 0, copy.length);
+        return copy;
     }
 
     /**
index 9b905dd42e31bcee666e625426c4b607ffa69421..79cb0d02c0ff84e0bb81ebf005fce24fea6a600b 100644 (file)
@@ -75,6 +75,13 @@ public class ColorUtilTestCase extends TestCase {
         Color col1 = ColorUtil.parseColorString(null, "#ff0000cc");
         Color col2 = ColorUtil.parseColorString(null, "#ff0000cc");
         assertEquals(col1, col2);
+
+        col1 = ColorUtil.parseColorString(null, "fop-rgb-icc(0.5,0.5,0.5,#CMYK,,0.0,0.0,0.0,0.5)");
+        col2 = ColorUtil.parseColorString(null, "cmyk(0.0,0.0,0.0,0.5)");
+        assertEquals(col1, col2);
+
+        col2 = ColorUtil.parseColorString(null, "fop-rgb-icc(0.5,0.5,0.5,#CMYK,,0.5,0.5,0.5,0.0)");
+        assertFalse(col1.equals(col2));
     }
 
     /**
@@ -120,7 +127,7 @@ public class ColorUtilTestCase extends TestCase {
         //TODO Anyone know what's going on here?
         assertEquals(0, colActual.getBlue());
         assertEquals(cs, colActual.getColorSpace());
-        float[] comps = colActual.getOriginalColorComponents();
+        float[] comps = colActual.getColorComponents(null);
         assertEquals(3, comps.length);
         assertEquals(1f, comps[0], 0);
         assertEquals(0f, comps[1], 0);
@@ -148,7 +155,7 @@ public class ColorUtilTestCase extends TestCase {
         assertEquals(255, colActual.getGreen());
         assertEquals(0, colActual.getBlue());
         assertEquals(CMYKColorSpace.getInstance(), colActual.getColorSpace());
-        float[] comps = colActual.getOriginalColorComponents();
+        float[] comps = colActual.getColorComponents(null);
         assertEquals(4, comps.length);
         assertEquals(0f, comps[0], 0);
         assertEquals(0f, comps[1], 0);
@@ -163,7 +170,7 @@ public class ColorUtilTestCase extends TestCase {
         assertEquals(199, colActual.getGreen());
         assertEquals(172, colActual.getBlue());
         assertEquals(CMYKColorSpace.getInstance(), colActual.getColorSpace());
-        comps = colActual.getOriginalColorComponents();
+        comps = colActual.getColorComponents(null);
         assertEquals(0.0274f, comps[0], 0.001);
         assertEquals(0.2196f, comps[1], 0.001);
         assertEquals(0.3216f, comps[2], 0.001);
@@ -177,7 +184,7 @@ public class ColorUtilTestCase extends TestCase {
         assertEquals(255, colActual.getGreen());
         assertEquals(0, colActual.getBlue());
         assertEquals(CMYKColorSpace.getInstance(), colActual.getColorSpace());
-        comps = colActual.getOriginalColorComponents();
+        comps = colActual.getColorComponents(null);
         assertEquals(4, comps.length);
         assertEquals(0f, comps[0], 0);
         assertEquals(0f, comps[1], 0);
@@ -185,6 +192,21 @@ public class ColorUtilTestCase extends TestCase {
         assertEquals(0f, comps[3], 0);
         assertEquals("fop-rgb-icc(1.0,1.0,0.0,#CMYK,,0.0,0.0,1.0,0.0)",
                 ColorUtil.colorToString(colActual));
+
+        colSpec = "fop-rgb-icc(0.5,0.5,0.5,#CMYK,,0.0,0.0,0.0,0.5)";
+        colActual = (ColorExt)ColorUtil.parseColorString(null, colSpec);
+        assertEquals(127, colActual.getRed());
+        assertEquals(127, colActual.getGreen());
+        assertEquals(127, colActual.getBlue());
+        assertEquals(CMYKColorSpace.getInstance(), colActual.getColorSpace());
+        comps = colActual.getColorComponents(null);
+        assertEquals(4, comps.length);
+        assertEquals(0f, comps[0], 0);
+        assertEquals(0f, comps[1], 0);
+        assertEquals(0f, comps[2], 0);
+        assertEquals(0.5f, comps[3], 0);
+        assertEquals("fop-rgb-icc(0.5,0.5,0.5,#CMYK,,0.0,0.0,0.0,0.5)",
+                ColorUtil.colorToString(colActual));
     }
 
 }