import java.awt.Color;
import java.awt.color.ColorSpace;
+import java.util.Arrays;
/**
* Color helper class.
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;
}
+ /** {@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
*
* @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;
}
/**
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));
}
/**
//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);
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);
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);
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);
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));
}
}