xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r1060457 - in /xmlgraphics/fop/branches/Temp_Color: src/java/org/apache/fop/apps/ src/java/org/apache/fop/util/ test/java/org/apache/fop/traits/ test/java/org/apache/fop/util/
Date Tue, 18 Jan 2011 16:40:14 GMT
Author: jeremias
Date: Tue Jan 18 16:40:13 2011
New Revision: 1060457

URL: http://svn.apache.org/viewvc?rev=1060457&view=rev
Log:
Removed FopFactory.getColorSpace() in favor of FopFactory.getColorSpaceCache() to better follow
the pattern we use for the FontManager and ImageManager.
Increased accuracy for sRGB derivation.
Fixed some tests.
Fixed bug in ColorUtil.toSRGBColor().
Documented inconsistency inside java.awt.Color in ColorUtilTest.

Modified:
    xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/apps/FopFactory.java
    xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/util/ColorUtil.java
    xmlgraphics/fop/branches/Temp_Color/test/java/org/apache/fop/traits/BorderPropsTestCase.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/apps/FopFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/apps/FopFactory.java?rev=1060457&r1=1060456&r2=1060457&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/apps/FopFactory.java (original)
+++ xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/apps/FopFactory.java Tue Jan
18 16:40:13 2011
@@ -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.LogFac
 
 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 Image
     /** 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 Image
         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 Image
      * 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 Image
     }
 
     /** @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 Image
     }
 
     /**
-     * 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;
     }
 
 }

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=1060457&r1=1060456&r2=1060457&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 Jan
18 16:40:13 2011
@@ -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);
     }
 

Modified: xmlgraphics/fop/branches/Temp_Color/test/java/org/apache/fop/traits/BorderPropsTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Color/test/java/org/apache/fop/traits/BorderPropsTestCase.java?rev=1060457&r1=1060456&r2=1060457&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Color/test/java/org/apache/fop/traits/BorderPropsTestCase.java
(original)
+++ xmlgraphics/fop/branches/Temp_Color/test/java/org/apache/fop/traits/BorderPropsTestCase.java
Tue Jan 18 16:40:13 2011
@@ -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
 
         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();

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=1060457&r1=1060456&r2=1060457&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 Jan 18 16:40:13 2011
@@ -118,8 +118,8 @@ public class ColorUtilTestCase extends T
         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 T
         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 T
         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 T
     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();



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


Mime
View raw message