diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/java/org/apache/fop/traits/BorderPropsTestCase.java | 6 | ||||
-rw-r--r-- | test/java/org/apache/fop/util/ColorUtilTestCase.java | 161 | ||||
-rw-r--r-- | test/resources/color/ncp-example.icc | bin | 0 -> 532 bytes |
3 files changed, 127 insertions, 40 deletions
diff --git a/test/java/org/apache/fop/traits/BorderPropsTestCase.java b/test/java/org/apache/fop/traits/BorderPropsTestCase.java index e142a4358..6eb41daac 100644 --- a/test/java/org/apache/fop/traits/BorderPropsTestCase.java +++ b/test/java/org/apache/fop/traits/BorderPropsTestCase.java @@ -27,7 +27,6 @@ import org.apache.xmlgraphics.java2d.color.ColorSpaces; import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace; import org.apache.fop.fo.Constants; -import org.apache.fop.util.ColorExt; import org.apache.fop.util.ColorUtil; /** @@ -51,10 +50,7 @@ public class BorderPropsTestCase extends TestCase { assertEquals(b1, b2); float[] cmyk = new float[] {1.0f, 1.0f, 0.5f, 1.0f}; - DeviceCMYKColorSpace cmykCs = ColorSpaces.getDeviceCMYKColorSpace(); - float[] rgb = cmykCs.toRGB(cmyk); - col = ColorExt.createFromFoRgbIcc(rgb[0], rgb[1], rgb[2], - "#CMYK", null, cmykCs, cmyk); + col = DeviceCMYKColorSpace.createCMYKColor(cmyk); b1 = new BorderProps(Constants.EN_INSET, 9999, col, BorderProps.SEPARATE); ser = b1.toString(); diff --git a/test/java/org/apache/fop/util/ColorUtilTestCase.java b/test/java/org/apache/fop/util/ColorUtilTestCase.java index c2fb0fbc9..bc871794c 100644 --- a/test/java/org/apache/fop/util/ColorUtilTestCase.java +++ b/test/java/org/apache/fop/util/ColorUtilTestCase.java @@ -21,10 +21,14 @@ package org.apache.fop.util; import java.awt.Color; import java.awt.color.ColorSpace; +import java.net.URI; import junit.framework.TestCase; import org.apache.xmlgraphics.java2d.color.ColorSpaces; +import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives; +import org.apache.xmlgraphics.java2d.color.NamedColorSpace; +import org.apache.xmlgraphics.java2d.color.RenderingIntent; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FopFactory; @@ -79,11 +83,14 @@ public class ColorUtilTestCase extends TestCase { 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)"); + /* The following doesn't work since java.awt.Color from Sun doesn't round consistently 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)); + assertTrue(col1.equals(col2)); + assertFalse(org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor(col1, col2)); } /** @@ -109,31 +116,35 @@ public class ColorUtilTestCase extends TestCase { */ public void testRGBICC() throws Exception { FopFactory fopFactory = FopFactory.newInstance(); - ColorSpace cs = fopFactory.getColorSpace(null, - "src/java/org/apache/fop/pdf/sRGB Color Space Profile.icm"); - assertNotNull(cs); - + URI sRGBLoc = new URI( + "file:src/java/org/apache/fop/pdf/sRGB%20Color%20Space%20Profile.icm"); + ColorSpace cs = fopFactory.getColorSpace("sRGBAlt", null, sRGBLoc.toASCIIString(), + RenderingIntent.AUTO); + assertNotNull("Color profile not found", cs); FOUserAgent ua = fopFactory.newFOUserAgent(); - ColorExt colActual; + ColorWithFallback colActual; //fop-rgb-icc() is used instead of rgb-icc() inside FOP! String colSpec = "fop-rgb-icc(1.0,0.0,0.0,sRGBAlt," - + "\"src/java/org/apache/fop/pdf/sRGB Color Space Profile.icm\",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(0, colActual.getBlue()); + + "\"" + sRGBLoc.toASCIIString() + "\",1.0,0.0,0.0)"; + colActual = (ColorWithFallback)ColorUtil.parseColorString(ua, colSpec); assertEquals(cs, colActual.getColorSpace()); + assertEquals(255, colActual.getRed()); + assertEquals(0, colActual.getGreen()); + assertEquals(0, colActual.getBlue()); float[] comps = colActual.getColorComponents(null); assertEquals(3, comps.length); assertEquals(1f, comps[0], 0); assertEquals(0f, comps[1], 0); assertEquals(0f, comps[2], 0); + assertEquals(0, colActual.getAlternativeColors().length); + + Color fallback = colActual.getFallbackColor(); + assertTrue(fallback.getColorSpace().isCS_sRGB()); + assertEquals(255, colActual.getRed()); + assertEquals(0, colActual.getGreen()); + assertEquals(0, colActual.getBlue()); assertEquals(colSpec, ColorUtil.colorToString(colActual)); @@ -148,16 +159,17 @@ public class ColorUtilTestCase extends TestCase { * @throws Exception if an error occurs */ public void testCMYK() throws Exception { - ColorExt colActual; + ColorWithAlternatives colActual; String colSpec; colSpec = "cmyk(0.0, 0.0, 1.0, 0.0)"; - colActual = (ColorExt)ColorUtil.parseColorString(null, colSpec); + colActual = (ColorWithAlternatives)ColorUtil.parseColorString(null, colSpec); assertEquals(255, colActual.getRed()); assertEquals(255, colActual.getGreen()); assertEquals(0, colActual.getBlue()); - assertEquals(ColorSpaces.getDeviceCMYKColorSpace(), colActual.getColorSpace()); - float[] comps = colActual.getColorComponents(null); + Color alt = colActual.getAlternativeColors()[0]; + assertEquals(ColorSpaces.getDeviceCMYKColorSpace(), alt.getColorSpace()); + float[] comps = alt.getColorComponents(null); assertEquals(4, comps.length); assertEquals(0f, comps[0], 0); assertEquals(0f, comps[1], 0); @@ -167,26 +179,28 @@ public class ColorUtilTestCase extends TestCase { ColorUtil.colorToString(colActual)); colSpec = "cmyk(0.0274, 0.2196, 0.3216, 0.0)"; - colActual = (ColorExt)ColorUtil.parseColorString(null, colSpec); - assertEquals(248, colActual.getRed()); - assertEquals(199, colActual.getGreen()); - assertEquals(172, colActual.getBlue()); - assertEquals(ColorSpaces.getDeviceCMYKColorSpace(), colActual.getColorSpace()); - comps = colActual.getColorComponents(null); + colActual = (ColorWithAlternatives)ColorUtil.parseColorString(null, colSpec); + assertEquals(248, colActual.getRed(), 1); + assertEquals(199, colActual.getGreen(), 1); + assertEquals(172, colActual.getBlue(), 1); + alt = colActual.getAlternativeColors()[0]; + assertEquals(ColorSpaces.getDeviceCMYKColorSpace(), alt.getColorSpace()); + comps = alt.getColorComponents(null); assertEquals(0.0274f, comps[0], 0.001); assertEquals(0.2196f, comps[1], 0.001); assertEquals(0.3216f, comps[2], 0.001); assertEquals(0f, comps[3], 0); - assertEquals("fop-rgb-icc(0.9726,0.7804,0.67840004,#CMYK,,0.0274,0.2196,0.3216,0.0)", + assertEquals("fop-rgb-icc(0.972549,0.78039217,0.6745098,#CMYK,,0.0274,0.2196,0.3216,0.0)", ColorUtil.colorToString(colActual)); colSpec = "fop-rgb-icc(1.0,1.0,0.0,#CMYK,,0.0,0.0,1.0,0.0)"; - colActual = (ColorExt)ColorUtil.parseColorString(null, colSpec); + colActual = (ColorWithAlternatives)ColorUtil.parseColorString(null, colSpec); assertEquals(255, colActual.getRed()); assertEquals(255, colActual.getGreen()); assertEquals(0, colActual.getBlue()); - assertEquals(ColorSpaces.getDeviceCMYKColorSpace(), colActual.getColorSpace()); - comps = colActual.getColorComponents(null); + alt = colActual.getAlternativeColors()[0]; + assertEquals(ColorSpaces.getDeviceCMYKColorSpace(), alt.getColorSpace()); + comps = alt.getColorComponents(null); assertEquals(4, comps.length); assertEquals(0f, comps[0], 0); assertEquals(0f, comps[1], 0); @@ -196,12 +210,13 @@ public class ColorUtilTestCase extends TestCase { 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(ColorSpaces.getDeviceCMYKColorSpace(), colActual.getColorSpace()); - comps = colActual.getColorComponents(null); + colActual = (ColorWithAlternatives)ColorUtil.parseColorString(null, colSpec); + assertEquals(127, colActual.getRed(), 1); + assertEquals(127, colActual.getGreen(), 1); + assertEquals(127, colActual.getBlue(), 1); + alt = colActual.getAlternativeColors()[0]; + assertEquals(ColorSpaces.getDeviceCMYKColorSpace(), alt.getColorSpace()); + comps = alt.getColorComponents(null); assertEquals(4, comps.length); assertEquals(0f, comps[0], 0); assertEquals(0f, comps[1], 0); @@ -211,4 +226,80 @@ public class ColorUtilTestCase extends TestCase { ColorUtil.colorToString(colActual)); } + /** + * Tests color for the #Separation pseudo-colorspace. + * @throws Exception if an error occurs + */ + public void testSeparationColor() throws Exception { + ColorWithFallback colActual; + String colSpec; + + colSpec = "fop-rgb-icc(1.0,0.8,0.0,#Separation,,Postgelb)"; + colActual = (ColorWithFallback)ColorUtil.parseColorString(null, colSpec); + assertEquals(255, colActual.getRed(), 1); + assertEquals(204, colActual.getGreen(), 1); + assertEquals(0, colActual.getBlue()); + + Color fallback = colActual.getFallbackColor(); + assertEquals(255, fallback.getRed()); + assertEquals(204, fallback.getGreen()); + assertEquals(0, fallback.getBlue()); + + assertFalse(colActual.hasAlternativeColors()); + + assertTrue(colActual.getColorSpace() instanceof NamedColorSpace); + NamedColorSpace ncs; + ncs = (NamedColorSpace)colActual.getColorSpace(); + assertEquals("Postgelb", ncs.getColorName()); + float[] comps = colActual.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("NCP", null, ncpLoc.toASCIIString(), + RenderingIntent.AUTO); + assertNotNull("Color profile not found", cs); + + FOUserAgent ua = fopFactory.newFOUserAgent(); + ColorWithFallback 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 = (ColorWithFallback)ColorUtil.parseColorString(ua, colSpec); + assertEquals(255, colActual.getRed()); + assertEquals(193, colActual.getGreen()); + assertEquals(0, colActual.getBlue()); + + Color fallback = colActual.getFallbackColor(); + assertEquals(255, fallback.getRed()); + assertEquals(204, fallback.getGreen()); + assertEquals(0, fallback.getBlue()); + assertEquals(ColorSpace.getInstance(ColorSpace.CS_sRGB), fallback.getColorSpace()); + + float[] comps = fallback.getColorComponents(null); + assertEquals(3, comps.length); + assertEquals(1f, comps[0], 0); + assertEquals(0.8f, comps[1], 0); + assertEquals(0f, comps[2], 0); + + assertTrue(colActual.getColorSpace() instanceof NamedColorSpace); + NamedColorSpace ncs; + ncs = (NamedColorSpace)colActual.getColorSpace(); + assertEquals("Postgelb", ncs.getColorName()); + comps = colActual.getColorComponents(null); + assertEquals(1, comps.length); + assertEquals(1f, comps[0], 0); + + assertEquals(colSpec, ColorUtil.colorToString(colActual)); + } } diff --git a/test/resources/color/ncp-example.icc b/test/resources/color/ncp-example.icc Binary files differnew file mode 100644 index 000000000..7afb2d8fc --- /dev/null +++ b/test/resources/color/ncp-example.icc |