diff options
-rw-r--r-- | src/java/org/apache/fop/apps/FopFactory.java | 31 | ||||
-rw-r--r-- | src/java/org/apache/fop/util/ColorUtil.java | 18 | ||||
-rw-r--r-- | test/java/org/apache/fop/traits/BorderPropsTestCase.java | 5 | ||||
-rw-r--r-- | test/java/org/apache/fop/util/ColorUtilTestCase.java | 24 |
4 files changed, 40 insertions, 38 deletions
diff --git a/src/java/org/apache/fop/apps/FopFactory.java b/src/java/org/apache/fop/apps/FopFactory.java index a85b2d305..2aca8bf99 100644 --- a/src/java/org/apache/fop/apps/FopFactory.java +++ b/src/java/org/apache/fop/apps/FopFactory.java @@ -19,7 +19,6 @@ package org.apache.fop.apps; -import java.awt.color.ColorSpace; import java.io.File; import java.io.IOException; import java.io.OutputStream; @@ -43,7 +42,6 @@ import org.apache.commons.logging.LogFactory; import org.apache.xmlgraphics.image.loader.ImageContext; import org.apache.xmlgraphics.image.loader.ImageManager; -import org.apache.xmlgraphics.java2d.color.RenderingIntent; import org.apache.xmlgraphics.util.UnitConv; import org.apache.fop.fo.ElementMapping; @@ -152,7 +150,7 @@ public class FopFactory implements ImageContext { /** Optional overriding LayoutManagerMaker */ private LayoutManagerMaker lmMakerOverride = null; - private Set ignoredNamespaces; + private Set<String> ignoredNamespaces; private FOURIResolver foURIResolver; @@ -177,7 +175,7 @@ public class FopFactory implements ImageContext { this.rendererFactory = new RendererFactory(); this.xmlHandlers = new XMLHandlerRegistry(); this.imageHandlers = new ImageHandlerRegistry(); - this.ignoredNamespaces = new java.util.HashSet(); + this.ignoredNamespaces = new java.util.HashSet<String>(); } /** @@ -658,7 +656,7 @@ public class FopFactory implements ImageContext { * namespace is in the ignored set. * @param namespaceURIs the namespace URIs */ - public void ignoreNamespaces(Collection namespaceURIs) { + public void ignoreNamespaces(Collection<String> namespaceURIs) { this.ignoredNamespaces.addAll(namespaceURIs); } @@ -672,7 +670,7 @@ public class FopFactory implements ImageContext { } /** @return the set of namespaces that are ignored by FOP */ - public Set getIgnoredNamespace() { + public Set<String> getIgnoredNamespace() { return Collections.unmodifiableSet(this.ignoredNamespaces); } @@ -802,24 +800,13 @@ public class FopFactory implements ImageContext { } /** - * Create (if needed) and return an ICC ColorSpace instance. - * <p> - * The ICC profile source is taken from the src attribute of the color-profile FO element. - * If the ICC ColorSpace is not yet in the cache a new one is created and stored in the cache. - * <p> - * The FOP URI resolver is used to try and locate the ICC file. - * If that fails null is returned. + * Returns the color space cache for this instance. * <p> * Note: this method should not be considered as part of FOP's external API. - * @param profileName the profile name - * @param baseUri a base URI to resolve relative URIs - * @param iccProfileSrc ICC Profile source to return a ColorSpace for - * @param renderingIntent overriding rendering intent - * @return ICC ColorSpace object or null if ColorSpace could not be created - */ - public ColorSpace getColorSpace(String profileName, String baseUri, String iccProfileSrc, - RenderingIntent renderingIntent) { - return colorSpaceCache.get(profileName, baseUri, iccProfileSrc, renderingIntent); + * @return the color space cache + */ + public ColorSpaceCache getColorSpaceCache() { + return this.colorSpaceCache; } } diff --git a/src/java/org/apache/fop/util/ColorUtil.java b/src/java/org/apache/fop/util/ColorUtil.java index 3c456dbbc..1b15c599a 100644 --- a/src/java/org/apache/fop/util/ColorUtil.java +++ b/src/java/org/apache/fop/util/ColorUtil.java @@ -410,7 +410,8 @@ public final class ColorUtil { assert colorSpace == null; RenderingIntent renderingIntent = RenderingIntent.AUTO; //TODO connect to fo:color-profile/@rendering-intent - colorSpace = foUserAgent.getFactory().getColorSpace(iccProfileName, + colorSpace = foUserAgent.getFactory().getColorSpaceCache().get( + iccProfileName, foUserAgent.getBaseURL(), iccProfileSrc, renderingIntent); } @@ -421,7 +422,7 @@ public final class ColorUtil { //sRGB is the primary color with the CMYK as the alternative Color deviceColor = new ColorWithAlternatives( colorSpace, iccComponents, 1.0f, null); - float[] rgbComps = sRGB.getColorComponents(null); + float[] rgbComps = sRGB.getRGBColorComponents(null); parsedColor = new ColorWithAlternatives( rgbComps[0], rgbComps[1], rgbComps[2], new Color[] {deviceColor}); @@ -499,7 +500,7 @@ public final class ColorUtil { if (foUserAgent != null && iccProfileSrc != null) { RenderingIntent renderingIntent = RenderingIntent.AUTO; //TODO connect to fo:color-profile/@rendering-intent - colorSpace = (ICC_ColorSpace)foUserAgent.getFactory().getColorSpace( + colorSpace = (ICC_ColorSpace)foUserAgent.getFactory().getColorSpaceCache().get( iccProfileName, foUserAgent.getBaseURL(), iccProfileSrc, renderingIntent); @@ -632,7 +633,8 @@ public final class ColorUtil { float black = parseComponent1(args[3], value); float[] comps = new float[] {cyan, magenta, yellow, black}; Color cmykColor = DeviceCMYKColorSpace.createCMYKColor(comps); - parsedColor = new ColorWithAlternatives(cmykColor.getRGB(), + float[] rgbComps = cmykColor.getRGBColorComponents(null); + parsedColor = new ColorWithAlternatives(rgbComps[0], rgbComps[1], rgbComps[2], new Color[] {cmykColor}); } catch (PropertyException pe) { throw pe; @@ -714,13 +716,9 @@ public final class ColorUtil { private static Color toSRGBColor(Color color) { float[] comps; ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB); - if (color.getColorSpace().isCS_sRGB()) { - comps = color.getColorComponents(null); - } else { - comps = color.getColorComponents(sRGB, null); - } + comps = color.getRGBColorComponents(null); float[] allComps = color.getComponents(null); - float alpha = allComps[comps.length - 1]; //Alpha is on last component + float alpha = allComps[allComps.length - 1]; //Alpha is on last component return new Color(sRGB, comps, alpha); } diff --git a/test/java/org/apache/fop/traits/BorderPropsTestCase.java b/test/java/org/apache/fop/traits/BorderPropsTestCase.java index 6eb41daac..07e4cd68c 100644 --- a/test/java/org/apache/fop/traits/BorderPropsTestCase.java +++ b/test/java/org/apache/fop/traits/BorderPropsTestCase.java @@ -23,7 +23,7 @@ import java.awt.Color; import junit.framework.TestCase; -import org.apache.xmlgraphics.java2d.color.ColorSpaces; +import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives; import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace; import org.apache.fop.fo.Constants; @@ -51,6 +51,9 @@ public class BorderPropsTestCase extends TestCase { float[] cmyk = new float[] {1.0f, 1.0f, 0.5f, 1.0f}; col = DeviceCMYKColorSpace.createCMYKColor(cmyk); + //Convert to sRGB with CMYK alternative as constructed by the cmyk() function + float[] rgb = col.getRGBColorComponents(null); + col = new ColorWithAlternatives(rgb[0], rgb[1], rgb[2], new Color[] {col}); 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 d0b6cc79a..c466b6cc6 100644 --- a/test/java/org/apache/fop/util/ColorUtilTestCase.java +++ b/test/java/org/apache/fop/util/ColorUtilTestCase.java @@ -118,8 +118,8 @@ public class ColorUtilTestCase extends TestCase { FopFactory fopFactory = FopFactory.newInstance(); 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); + ColorSpace cs = fopFactory.getColorSpaceCache().get( + "sRGBAlt", null, sRGBLoc.toASCIIString(), RenderingIntent.AUTO); assertNotNull("Color profile not found", cs); FOUserAgent ua = fopFactory.newFOUserAgent(); @@ -194,7 +194,7 @@ public class ColorUtilTestCase extends TestCase { assertEquals(0.2196f, comps[1], 0.001); assertEquals(0.3216f, comps[2], 0.001); assertEquals(0f, comps[3], 0); - assertEquals("fop-rgb-icc(0.972549,0.78039217,0.6745098,#CMYK,,0.0274,0.2196,0.3216,0.0)", + assertEquals("fop-rgb-icc(0.9726,0.7804,0.67840004,#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)"; @@ -228,6 +228,20 @@ public class ColorUtilTestCase extends TestCase { 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)); + + //Verify that the cmyk() and fop-rgb-icc(#CMYK) functions have the same results + ColorWithAlternatives colCMYK = (ColorWithAlternatives)ColorUtil.parseColorString( + null, "cmyk(0,0,0,0.5)"); + assertEquals(colCMYK.getAlternativeColors()[0], colActual.getAlternativeColors()[0]); + //The following doesn't work: + //assertEquals(colCMYK, colActual); + //java.awt.Color does not consistenly calculate the int RGB values: + //Color(ColorSpace cspace, float components[], float alpha): 0.5 --> 127 + //Color(float r, float g, float b): 0.5 --> 128 + if (!colCMYK.equals(colActual)) { + System.out.println("Info: java.awt.Color does not consistently calculate" + + " int RGB values from float RGB values."); + } } /** @@ -270,8 +284,8 @@ public class ColorUtilTestCase extends TestCase { 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); + ColorSpace cs = fopFactory.getColorSpaceCache().get( + "NCP", null, ncpLoc.toASCIIString(), RenderingIntent.AUTO); assertNotNull("Color profile not found", cs); FOUserAgent ua = fopFactory.newFOUserAgent(); |