]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Bugzilla #49403:
authorJeremias Maerki <jeremias@apache.org>
Fri, 25 Jun 2010 12:17:58 +0000 (12:17 +0000)
committerJeremias Maerki <jeremias@apache.org>
Fri, 25 Jun 2010 12:17:58 +0000 (12:17 +0000)
Initial support for PDF Separation color spaces (aka spot colors). This is still unfinished but produces valid PDF with Separation colors in simple cases.
Based on work by: Patrick Jaromin <Patrick.at.Jaromin.com>

Note: PDFColor is broken right now, as I'm planning to phase that class out. Squeezing separation colors and what else comes later into that class isn't such a good idea IMO. Instead, PDFColorHandler tries to do all that in a better way based on the new color support classes from XGC.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_Color@957913 13f79535-47bb-0310-9956-ffa450edef68

18 files changed:
src/java/org/apache/fop/fo/expr/PropertyTokenizer.java
src/java/org/apache/fop/pdf/PDFColor.java
src/java/org/apache/fop/pdf/PDFColorHandler.java [new file with mode: 0644]
src/java/org/apache/fop/pdf/PDFDeviceColorSpace.java
src/java/org/apache/fop/pdf/PDFFactory.java
src/java/org/apache/fop/pdf/PDFName.java
src/java/org/apache/fop/pdf/PDFResources.java
src/java/org/apache/fop/pdf/PDFSeparationColorSpace.java [new file with mode: 0644]
src/java/org/apache/fop/render/intermediate/IFState.java
src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java
src/java/org/apache/fop/render/pdf/PDFContentGenerator.java
src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
src/java/org/apache/fop/svg/PDFGraphics2D.java
src/java/org/apache/fop/util/AbstractPaintingState.java
src/java/org/apache/fop/util/ColorUtil.java
status.xml
test/java/org/apache/fop/traits/BorderPropsTestCase.java
test/java/org/apache/fop/util/ColorUtilTestCase.java

index 5baa0c4d8b8c81a64b2006e8c4b6bf2765177ef8..7d846eefc22a51ce246e40b081949d504fa47cdb 100644 (file)
@@ -80,10 +80,9 @@ class PropertyTokenizer {
     void next() throws PropertyException {
         currentTokenValue = null;
         currentTokenStartIndex = exprIndex;
-        boolean currentMaybeOperator = recognizeOperator;
         boolean bSawDecimal;
         recognizeOperator = true;
-        for (; ;) {
+        for (;;) {
             if (exprIndex >= exprLength) {
                 currentToken = TOK_EOF;
                 return;
@@ -244,14 +243,14 @@ class PropertyTokenizer {
 
 
     private void nextColor() throws PropertyException {
-        if (exprIndex < exprLength
-                && isHexDigit(expr.charAt(exprIndex))) {
+        if (exprIndex < exprLength) {
             ++exprIndex;
             scanHexDigits();
             int len = exprIndex - currentTokenStartIndex - 1;
             if (len % 3 == 0) {
                 currentToken = TOK_COLORSPEC;
             } else {
+                //Actually not a color at all, but an NCNAME starting with "#"
                 scanRestOfName();
                 currentToken = TOK_NCNAME;
             }
@@ -320,8 +319,8 @@ class PropertyTokenizer {
     }
 
 
-    private static final String NAME_START_CHARS =
-        "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+    private static final String NAME_START_CHARS
+        "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
     private static final String NAME_CHARS = ".-0123456789";
     private static final String DIGITS = "0123456789";
     private static final String HEX_CHARS = DIGITS + "abcdefABCDEF";
index 42a9c722386d992d1f380544e06f42c44fc43ee9..c51bc639b6c37bce20618264033fd8e635c0687b 100644 (file)
@@ -26,8 +26,8 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.xmlgraphics.java2d.color.CMYKColorSpace;
 import org.apache.xmlgraphics.java2d.color.ColorExt;
+import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace;
 
 /**
  * PDF Color object.
@@ -122,7 +122,7 @@ public class PDFColor extends PDFPathPaint {
             ce = (ColorExt)col;
             cs = ce.getOrigColorSpace();
         }
-        if (cs != null && cs instanceof CMYKColorSpace) {
+        if (cs != null && cs instanceof DeviceCMYKColorSpace) {
             // CMYK case
             this.colorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_CMYK);
             float[] cmyk = (ce == null
diff --git a/src/java/org/apache/fop/pdf/PDFColorHandler.java b/src/java/org/apache/fop/pdf/PDFColorHandler.java
new file mode 100644 (file)
index 0000000..4a5908a
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import java.awt.Color;
+import java.awt.color.ColorSpace;
+import java.awt.color.ICC_ColorSpace;
+import java.awt.color.ICC_Profile;
+import java.text.DecimalFormat;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.java2d.color.ColorExt;
+import org.apache.xmlgraphics.java2d.color.ColorUtil;
+import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace;
+import org.apache.xmlgraphics.java2d.color.NamedColorSpace;
+
+import org.apache.fop.util.ColorProfileUtil;
+import org.apache.fop.util.DecimalFormatCache;
+
+/**
+ * This class handles the registration of color spaces and the generation of PDF code to select
+ * the right colors given a {@link Color} instance.
+ */
+public class PDFColorHandler {
+
+    private Log log = LogFactory.getLog(PDFColorHandler.class);
+
+    private PDFResources resources;
+
+    public PDFColorHandler(PDFResources resources) {
+        this.resources = resources;
+    }
+
+    private PDFDocument getDocument() {
+        return this.resources.getDocumentSafely();
+    }
+
+    /**
+     * Generates code to select the given color and handles the registration of color spaces in
+     * PDF where necessary.
+     * @param codeBuffer the target buffer to receive the color selection code
+     * @param color the color
+     * @param fill true for fill color, false for stroke color
+     */
+    public void establishColor(StringBuffer codeBuffer, Color color, boolean fill) {
+        if (color instanceof ColorExt) {
+            ColorExt colExt = (ColorExt)color;
+            //Alternate colors have priority
+            Color[] alt = colExt.getAlternateColors();
+            for (int i = 0, c = alt.length; i < c; i++) {
+                Color col = alt[i];
+                boolean established = establishColorFromColor(codeBuffer, col, fill);
+                if (established) {
+                    return;
+                }
+            }
+        }
+
+        //Fallback
+        establishColorFromColor(codeBuffer, color, fill);
+    }
+
+    private boolean establishColorFromColor(StringBuffer codeBuffer, Color color, boolean fill) {
+        ColorSpace cs = color.getColorSpace();
+        if (cs instanceof DeviceCMYKColorSpace) {
+            establishDeviceCMYK(codeBuffer, color, fill);
+            return true;
+        } else if (!cs.isCS_sRGB()) {
+            if (cs instanceof ICC_ColorSpace) {
+                PDFICCBasedColorSpace pdfcs = getICCBasedColorSpace((ICC_ColorSpace)cs);
+                establishColor(codeBuffer, pdfcs, color, fill);
+                return true;
+            } else if (cs instanceof NamedColorSpace) {
+                PDFSeparationColorSpace sepcs = getSeparationColorSpace((NamedColorSpace)cs);
+                establishColor(codeBuffer, sepcs, color, fill);
+                return true;
+            }
+        }
+        //Fallback (RGB) Color
+        establishDeviceRGB(codeBuffer, color, fill);
+        return true;
+    }
+
+    private PDFICCBasedColorSpace getICCBasedColorSpace(ICC_ColorSpace cs) {
+        ICC_Profile profile = cs.getProfile();
+        String desc = ColorProfileUtil.getICCProfileDescription(profile);
+        if (log.isDebugEnabled()) {
+            log.trace("ICC profile encountered: " + desc);
+        }
+        PDFICCBasedColorSpace pdfcs = this.resources.getICCColorSpaceByProfileName(desc);
+        if (pdfcs == null) {
+            //color space is not in the PDF, yet
+            PDFFactory factory = getDocument().getFactory();
+            PDFICCStream pdfICCStream = factory.makePDFICCStream();
+            PDFDeviceColorSpace altSpace = PDFDeviceColorSpace.toPDFColorSpace(cs);
+            pdfICCStream.setColorSpace(profile, altSpace);
+            pdfcs = factory.makeICCBasedColorSpace(null, desc, pdfICCStream);
+        }
+        return pdfcs;
+    }
+
+    private PDFSeparationColorSpace getSeparationColorSpace(NamedColorSpace cs) {
+        PDFName colorName = new PDFName(cs.getColorName());
+        PDFSeparationColorSpace sepcs = (PDFSeparationColorSpace)this.resources.getColorSpace(
+                colorName);
+        if (sepcs == null) {
+            //color space is not in the PDF, yet
+            PDFFactory factory = getDocument().getFactory();
+            sepcs = factory.makeSeparationColorSpace(null, cs);
+        }
+        return sepcs;
+    }
+
+    private void establishColor(StringBuffer codeBuffer,
+            PDFColorSpace pdfcs, Color color, boolean fill) {
+        codeBuffer.append(new PDFName(pdfcs.getName()));
+        if (fill)  {
+            codeBuffer.append(" cs ");
+        } else {
+            codeBuffer.append(" CS ");
+        }
+        writeColor(codeBuffer, color, pdfcs.getNumComponents(), (fill ? "sc" : "SC"));
+    }
+
+    private void establishDeviceRGB(StringBuffer codeBuffer, Color color, boolean fill) {
+        float[] comps;
+        if (color.getColorSpace().isCS_sRGB()) {
+            comps = color.getColorComponents(null);
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug("Converting color to sRGB as a fallback: " + color);
+            }
+            ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+            comps = color.getColorComponents(sRGB, null);
+        }
+        if (ColorUtil.isGray(color)) {
+            comps = new float[] {comps[0]}; //assuming that all components are the same
+            writeColor(codeBuffer, comps, 1, (fill ? "g" : "G"));
+        } else {
+            writeColor(codeBuffer, comps, 3, (fill ? "rg" : "RG"));
+        }
+    }
+
+    private void establishDeviceCMYK(StringBuffer codeBuffer, Color color, boolean fill) {
+        writeColor(codeBuffer, color, 4, (fill ? "k" : "K"));
+    }
+
+    private void writeColor(StringBuffer codeBuffer, Color color, int componentCount,
+            String command) {
+        float[] comps = color.getColorComponents(null);
+        writeColor(codeBuffer, comps, componentCount, command);
+    }
+
+    private void writeColor(StringBuffer codeBuffer, float[] comps, int componentCount,
+            String command) {
+        if (comps.length != componentCount) {
+            throw new IllegalStateException("Color with unexpected component count encountered");
+        }
+        DecimalFormat df = DecimalFormatCache.getDecimalFormat(4);
+        for (int i = 0, c = comps.length; i < c; i++) {
+            codeBuffer.append(df.format(comps[i])).append(" ");
+        }
+        codeBuffer.append(command).append("\n");
+    }
+
+}
index 6ccfd39f5c0cd9cda0e6ef6b79fa2aeb5b1dcec5..b18c3ac9eb98bf0b6729a03c762cc213384f7369 100644 (file)
@@ -19,6 +19,8 @@
 
 package org.apache.fop.pdf;
 
+import java.awt.color.ColorSpace;
+
 /**
  * Represents a device-specific color space. Used for mapping DeviceRGB, DeviceCMYK and DeviceGray.
  */
@@ -137,4 +139,28 @@ public class PDFDeviceColorSpace implements PDFColorSpace {
         return getColorSpace() == DEVICE_GRAY;
     }
 
+    /**
+     * Returns a suitable {@link PDFDeviceColorSpace} object given a {@link ColorSpace} object.
+     * @param cs ColorSpace instance
+     * @return a PDF-based color space
+     */
+    public static PDFDeviceColorSpace toPDFColorSpace(ColorSpace cs) {
+        if (cs == null) {
+            return null;
+        }
+
+        PDFDeviceColorSpace pdfCS = new PDFDeviceColorSpace(0);
+        switch (cs.getType()) {
+            case ColorSpace.TYPE_CMYK:
+                pdfCS.setColorSpace(PDFDeviceColorSpace.DEVICE_CMYK);
+            break;
+            case ColorSpace.TYPE_GRAY:
+                pdfCS.setColorSpace(PDFDeviceColorSpace.DEVICE_GRAY);
+                break;
+            default:
+                pdfCS.setColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
+        }
+        return pdfCS;
+    }
+
 }
index bf3399b09c16b308591799c17924b9e9704b91c4..152f75285320ea40e3917a408e95229d38dc7d3d 100644 (file)
@@ -20,6 +20,7 @@
 package org.apache.fop.pdf;
 
 // Java
+import java.awt.Color;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 import java.io.FileNotFoundException;
@@ -27,6 +28,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.BitSet;
 import java.util.Iterator;
 import java.util.List;
@@ -40,6 +42,7 @@ import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.xmlgraphics.java2d.color.NamedColorSpace;
 import org.apache.xmlgraphics.xmp.Metadata;
 
 import org.apache.fop.fonts.CIDFont;
@@ -770,23 +773,21 @@ public class PDFFactory {
 
         for (currentPosition = 0; currentPosition < lastPosition;
                 currentPosition++) {    // for every consecutive color pair
-            PDFColor currentColor = (PDFColor)theColors.get(currentPosition);
-            PDFColor nextColor = (PDFColor)theColors.get(currentPosition
-                                 + 1);
+            Color currentColor = (Color)theColors.get(currentPosition);
+            Color nextColor = (Color)theColors.get(currentPosition + 1);
+
             // colorspace must be consistant
-            if (getDocument().getColorSpace() != currentColor.getColorSpace()) {
-                currentColor.setColorSpace(
-                    getDocument().getColorSpace());
+            if (!currentColor.getColorSpace().isCS_sRGB()) {
+                //Convert to sRGB
+                theColors.set(currentPosition, new Color(currentColor.getRGB()));
             }
-
-            if (getDocument().getColorSpace()
-                    != nextColor.getColorSpace()) {
-                nextColor.setColorSpace(
-                    getDocument().getColorSpace());
+            if (!nextColor.getColorSpace().isCS_sRGB()) {
+                //Convert to sRGB
+                theColors.set(currentPosition + 1, new Color(nextColor.getRGB()));
             }
 
-            theCzero = currentColor.getVector();
-            theCone = nextColor.getVector();
+            theCzero = toColorVector(currentColor);
+            theCone = toColorVector(nextColor);
 
             myfunc = makeFunction(2, null, null, theCzero, theCone,
                                        interpolation);
@@ -834,6 +835,15 @@ public class PDFFactory {
         return (myPattern);
     }
 
+    private List toColorVector(Color nextColor) {
+        List vector = new java.util.ArrayList();
+        float[] comps = nextColor.getColorComponents(null);
+        for (int i = 0, c = comps.length; i < c; i++) {
+            vector.add(new Double(comps[i]));
+        }
+        return vector;
+    }
+
     /* ============= named destinations and the name dictionary ============ */
 
     /**
@@ -1713,6 +1723,38 @@ public class PDFFactory {
         return cs;
     }
 
+    /**
+     * Create a new Separation color space.
+     * @param res the resource context (may be null)
+     * @param ncs the named color space to map to a separation color space
+     * @return the newly created Separation color space
+     */
+    public PDFSeparationColorSpace makeSeparationColorSpace(PDFResourceContext res,
+            NamedColorSpace ncs) {
+        String colorName = ncs.getColorName();
+        final Double zero = new Double(0d);
+        final Double one = new Double(1d);
+        List theDomain = Arrays.asList(new Double[] {zero, one});
+        List theRange = Arrays.asList(new Double[] {zero, one, zero, one, zero, one});
+        List theCZero = Arrays.asList(new Double[] {one, one, one});
+        List theCOne = new ArrayList();
+        float[] comps = ncs.getRGBColor().getColorComponents(null);
+        for (int i = 0, c = comps.length; i < c; i++) {
+            theCOne.add(new Double(comps[i]));
+        }
+        PDFFunction tintFunction = makeFunction(2, theDomain, theRange,
+                theCZero, theCOne, 1.0d);
+        PDFSeparationColorSpace cs = new PDFSeparationColorSpace(colorName, tintFunction);
+        getDocument().registerObject(cs);
+        if (res != null) {
+            res.getPDFResources().addColorSpace(cs);
+        } else {
+            getDocument().getResources().addColorSpace(cs);
+        }
+
+        return cs;
+    }
+
     /**
      * Make an Array object (ex. Widths array for a font).
      *
index 19db917c8c87b9c9f4c314b7c8eedb22bd1e8825..42c39ef529afc3fb22b1e24d041f9ec518ad29ef 100644 (file)
@@ -82,6 +82,21 @@ public class PDFName extends PDFObject {
         return this.name;
     }
 
+    /** {@inheritDoc} */
+    public boolean equals(Object obj) {
+        if (!(obj instanceof PDFName)) {
+            return false;
+        }
+        PDFName other = (PDFName)obj;
+        return this.name.equals(other.name);
+    }
+
+    /** {@inheritDoc} */
+    public int hashCode() {
+        return name.hashCode();
+    }
+
+
     /** {@inheritDoc} */
     protected int output(OutputStream stream) throws IOException {
         CountingOutputStream cout = new CountingOutputStream(stream);
index cbfc9d53a891ae459a72b506c842190bbd6dccce..6d994a73d3f24084ce3d93a9b1b2e3cff72a96f4 100644 (file)
@@ -19,6 +19,8 @@
 
 package org.apache.fop.pdf;
 
+import java.io.IOException;
+import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -33,12 +35,12 @@ import org.apache.fop.fonts.base14.ZapfDingbats;
 import org.apache.fop.util.ColorProfileUtil;
 
 /**
- * class representing a /Resources object.
+ * Class representing a /Resources object.
  *
  * /Resources object contain a list of references to the fonts for the
  * document
  */
-public class PDFResources extends PDFObject {
+public class PDFResources extends PDFDictionary {
 
     /**
      * /Font objects keyed by their internal name
@@ -161,11 +163,14 @@ public class PDFResources extends PDFObject {
      * Add a ColorSpace dictionary to the resources.
      * @param colorSpace the color space
      */
-    public void addColorSpace(PDFICCBasedColorSpace colorSpace) {
-        this.colorSpaces.put(colorSpace.getName(), colorSpace);
-        String desc = ColorProfileUtil.getICCProfileDescription(
-                colorSpace.getICCStream().getICCProfile());
-        this.iccColorSpaces.put(desc, colorSpace);
+    public void addColorSpace(PDFColorSpace colorSpace) {
+        this.colorSpaces.put(new PDFName(colorSpace.getName()), colorSpace);
+        if (colorSpace instanceof PDFICCBasedColorSpace) {
+            PDFICCBasedColorSpace icc = (PDFICCBasedColorSpace)colorSpace;
+            String desc = ColorProfileUtil.getICCProfileDescription(
+                    icc.getICCStream().getICCProfile());
+            this.iccColorSpaces.put(desc, colorSpace);
+        }
     }
 
     /**
@@ -183,105 +188,80 @@ public class PDFResources extends PDFObject {
      * @param name the name of the color space
      * @return the requested color space or null if it wasn't found
      */
-    public PDFICCBasedColorSpace getColorSpace(String name) {
-        PDFICCBasedColorSpace cs = (PDFICCBasedColorSpace)this.colorSpaces.get(name);
+    public PDFColorSpace getColorSpace(PDFName name) {
+        PDFColorSpace cs = (PDFColorSpace)this.colorSpaces.get(name);
         return cs;
     }
 
-    /**
-     * represent the object in PDF
-     * This adds the references to all the objects in the current
-     * resource context.
-     *
-     * @return the PDF
-     * {@inheritDoc}
-     */
-    public String toPDFString() {
-        StringBuffer p = new StringBuffer(128);
-        p.append(getObjectID() + "<<\n");
-        if (!this.fonts.isEmpty()) {
-            p.append("/Font <<\n");
+    /** {@inheritDoc} */
+    protected int output(OutputStream stream) throws IOException {
+        populateDictionary();
+        return super.output(stream);
+    }
 
+    private void populateDictionary() {
+        if (!this.fonts.isEmpty()) {
+            PDFDictionary dict = new PDFDictionary(this);
             /* construct PDF dictionary of font object references */
             Iterator fontIterator = this.fonts.keySet().iterator();
             while (fontIterator.hasNext()) {
                 String fontName = (String)fontIterator.next();
-                p.append("  /" + fontName + " "
-                         + ((PDFFont)this.fonts.get(fontName)).referencePDF()
-                         + "\n");
+                dict.put(fontName, (PDFFont)this.fonts.get(fontName));
             }
-
-            p.append(">>\n");
+            put("Font", dict);
         }
 
-        PDFShading currentShading = null;
         if (!this.shadings.isEmpty()) {
-            p.append("/Shading <<\n");
-
+            PDFDictionary dict = new PDFDictionary(this);
             for (Iterator iter = shadings.iterator(); iter.hasNext();) {
-                currentShading = (PDFShading)iter.next();
-                p.append("  /" + currentShading.getName() + " "
-                         + currentShading.referencePDF() + " ");    // \n ??????
+                PDFShading currentShading = (PDFShading)iter.next();
+                dict.put(currentShading.getName(), currentShading);
             }
-
-            p.append(">>\n");
+            put("Shading", dict);
         }
-        // "free" the memory. Sorta.
-        currentShading = null;
 
-        PDFPattern currentPattern = null;
         if (!this.patterns.isEmpty()) {
-            p.append("/Pattern <<\n");
-
+            PDFDictionary dict = new PDFDictionary(this);
             for (Iterator iter = patterns.iterator(); iter.hasNext();) {
-                currentPattern = (PDFPattern)iter.next();
-                p.append("  /" + currentPattern.getName() + " "
-                         + currentPattern.referencePDF() + " ");
+                PDFPattern currentPattern = (PDFPattern)iter.next();
+                dict.put(currentPattern.getName(), currentPattern);
             }
-
-            p.append(">>\n");
+            put("Pattern", dict);
         }
-        // "free" the memory. Sorta.
-        currentPattern = null;
 
-        p.append("/ProcSet [ /PDF /ImageB /ImageC /Text ]\n");
+        PDFArray procset = new PDFArray(this);
+        procset.add(new PDFName("PDF"));
+        procset.add(new PDFName("ImageB"));
+        procset.add(new PDFName("ImageC"));
+        procset.add(new PDFName("Text"));
+        put("ProcSet", procset);
 
         if (this.xObjects != null && !this.xObjects.isEmpty()) {
-            p = p.append("/XObject <<\n");
+            PDFDictionary dict = new PDFDictionary(this);
             for (Iterator iter = xObjects.iterator(); iter.hasNext();) {
                 PDFXObject xobj = (PDFXObject)iter.next();
-                p = p.append("  " + xobj.getName() + " "
-                             + xobj.referencePDF()
-                             + "\n");
+                dict.put(xobj.getName().toString(), xobj);
             }
-            p = p.append(">>\n");
+            put("XObject", dict);
         }
 
         if (!this.gstates.isEmpty()) {
-            p = p.append("/ExtGState <<\n");
+            PDFDictionary dict = new PDFDictionary(this);
             for (Iterator iter = gstates.iterator(); iter.hasNext();) {
                 PDFGState gs = (PDFGState)iter.next();
-                p = p.append("  /" + gs.getName() + " "
-                             + gs.referencePDF()
-                             + "\n");
+                dict.put(gs.getName(), gs);
             }
-            p = p.append(">>\n");
+            put("ExtGState", dict);
         }
 
         if (!this.colorSpaces.isEmpty()) {
-            p = p.append("/ColorSpace <<\n");
+            PDFDictionary dict = new PDFDictionary(this);
             for (Iterator iter = colorSpaces.values().iterator(); iter.hasNext();) {
-                PDFICCBasedColorSpace colorSpace = (PDFICCBasedColorSpace)iter.next();
-                p = p.append("  /" + colorSpace.getName() + " "
-                             + colorSpace.referencePDF()
-                             + "\n");
+                PDFColorSpace colorSpace = (PDFColorSpace)iter.next();
+                dict.put(colorSpace.getName(), colorSpace);
             }
-            p = p.append(">>\n");
+            put("ColorSpace", dict);
         }
-
-        p = p.append(">>\nendobj\n");
-
-        return p.toString();
     }
 
 }
diff --git a/src/java/org/apache/fop/pdf/PDFSeparationColorSpace.java b/src/java/org/apache/fop/pdf/PDFSeparationColorSpace.java
new file mode 100644 (file)
index 0000000..d364ecc
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+/**
+ * This class represents a "Separation" color space. It is used in FOP to map named colors.
+ */
+public class PDFSeparationColorSpace extends PDFArray implements PDFColorSpace {
+
+    /**
+     * Creates a new "Separation" color space.
+     * @param colorName the name of the colorant
+     * @param tintFunction the tint function used as fallback
+     */
+    public PDFSeparationColorSpace(String colorName, PDFFunction tintFunction) {
+        super();
+        add(new PDFName("Separation"));
+        add(new PDFName(colorName));
+        add(new PDFName("DeviceRGB"));
+        add(new PDFReference(tintFunction));
+    }
+
+    /** {@inheritDoc} */
+    public String getName() {
+        //return "CS" + this.getObjectNumber();
+        return getColorName().toString();
+    }
+
+    /**
+     * Returns the name of the colorant.
+     * @return the name of the colorant
+     */
+    public PDFName getColorName() {
+        return (PDFName)get(1);
+    }
+
+    /**
+     * Returns a reference to the tint function that is used as a fallback if the colorant is
+     * not available.
+     * @return a reference to the tint function
+     */
+    public PDFReference getTintFunction() {
+        return (PDFReference)get(2);
+    }
+
+    /** {@inheritDoc} */
+    public int getNumComponents() {
+        return 1;
+    }
+
+    /** {@inheritDoc} */
+    public boolean isCMYKColorSpace() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    public boolean isDeviceColorSpace() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    public boolean isGrayColorSpace() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    public boolean isRGBColorSpace() {
+        return false;
+    }
+
+}
index aa073d03c782eb77bc553fe548637e8189302b4e..5d669d3ef7881eb1d6937377943624e0fdf3818f 100644 (file)
@@ -178,7 +178,8 @@ public class IFState {
      * @param color the new text color
      */
     public void setTextColor(Color color) {
-        if (!color.equals(this.textColor)) {
+        //Check in both directions due to limitations of java.awt.Color
+        if (!color.equals(this.textColor) || !this.textColor.equals(color)) {
             this.fontChanged = true;
         }
         this.textColor = color;
index 165236359abfe42c85f1f774af9ef9f671ab92a3..ff7532639cd64228c9ef667d8912fd3f0659c0d3 100644 (file)
@@ -34,6 +34,7 @@ import org.apache.fop.pdf.PDFDocument;
 import org.apache.fop.pdf.PDFICCBasedColorSpace;
 import org.apache.fop.pdf.PDFICCStream;
 import org.apache.fop.pdf.PDFImage;
+import org.apache.fop.pdf.PDFName;
 import org.apache.fop.pdf.PDFReference;
 import org.apache.fop.util.ColorProfileUtil;
 
@@ -128,13 +129,14 @@ public abstract class AbstractImageAdapter implements PDFImage {
         } else {
             if (cs == null && desc.startsWith("sRGB")) {
                 //It's the default sRGB profile which we mapped to DefaultRGB in PDFRenderer
-                cs = doc.getResources().getColorSpace("DefaultRGB");
+                cs = (PDFICCBasedColorSpace)doc.getResources().getColorSpace(
+                        new PDFName("DefaultRGB"));
             }
             if (cs == null) {
                 // sRGB hasn't been set up for the PDF document
                 // so install but don't set to DefaultRGB
                 cs = PDFICCBasedColorSpace.setupsRGBColorSpace(doc);
-            }            
+            }
             pdfICCStream = cs.getICCStream();
         }
         return pdfICCStream;
index fb5fc4e8d05937a59f4ae4b8cfef0d1e98a1878c..634551baa23c1b567915a8cd88784ce27e437b1d 100644 (file)
@@ -25,7 +25,7 @@ import java.awt.geom.AffineTransform;
 import java.io.IOException;
 import java.io.OutputStream;
 
-import org.apache.fop.pdf.PDFColor;
+import org.apache.fop.pdf.PDFColorHandler;
 import org.apache.fop.pdf.PDFDocument;
 import org.apache.fop.pdf.PDFFilterList;
 import org.apache.fop.pdf.PDFNumber;
@@ -51,6 +51,8 @@ public class PDFContentGenerator {
     /** the current stream to add PDF commands to */
     private PDFStream currentStream;
 
+    private PDFColorHandler colorHandler;
+
     /** drawing state */
     protected PDFPaintingState currentState = null;
     /** Text generation utility holding the current font status */
@@ -80,6 +82,7 @@ public class PDFContentGenerator {
         };
 
         this.currentState = new PDFPaintingState();
+        this.colorHandler = new PDFColorHandler(document.getResources());
     }
 
     /**
@@ -340,8 +343,9 @@ public class PDFContentGenerator {
      */
     public void setColor(Color col, boolean fill, PDFStream stream) {
         assert stream != null;
-        PDFColor color = new PDFColor(this.document, col);
-        stream.add(color.getColorSpaceOut(fill));
+        StringBuffer sb = new StringBuffer();
+        setColor(col, fill, sb);
+        stream.add(sb.toString());
     }
 
     /**
@@ -363,8 +367,7 @@ public class PDFContentGenerator {
      */
     protected void setColor(Color col, boolean fill, StringBuffer pdf) {
         if (pdf != null) {
-            PDFColor color = new PDFColor(this.document, col);
-            pdf.append(color.getColorSpaceOut(fill));
+            colorHandler.establishColor(pdf, col, fill);
         } else {
             setColor(col, fill, this.currentStream);
         }
index cf3053e19c44c521560f962fe6fd5f360fa0ce7c..c38b753bacfa0ac2c495da2c3e26978645fcd2ac 100644 (file)
@@ -34,7 +34,6 @@ import org.apache.fop.Version;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontSetup;
 import org.apache.fop.pdf.PDFAnnotList;
-import org.apache.fop.pdf.PDFColor;
 import org.apache.fop.pdf.PDFDocument;
 import org.apache.fop.pdf.PDFFilterList;
 import org.apache.fop.pdf.PDFNumber;
@@ -230,15 +229,15 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D {
      * @param col the background colour to fill
      */
     public void setBackgroundColor(Color col) {
-        Color c = col;
-        PDFColor currentColour = new PDFColor(c.getRed(), c.getGreen(), c.getBlue());
-        currentStream.write("q\n");
-        currentStream.write(currentColour.getColorSpaceOut(true));
+        StringBuffer sb = new StringBuffer();
+        sb.append("q\n");
+        this.colorHandler.establishColor(sb, col, true);
 
-        currentStream.write("0 0 " + width + " " + height + " re\n");
+        sb.append("0 0 ").append(width).append(" ").append(height).append(" re\n");
 
-        currentStream.write("f\n");
-        currentStream.write("Q\n");
+        sb.append("f\n");
+        sb.append("Q\n");
+        currentStream.write(sb.toString());
     }
 
     /**
index f0084da0956fc8a1c6b6cff7276293370095fdea..fee91bbf82ad039895c538b1ab4d9e2aa43e0c31 100644 (file)
@@ -67,7 +67,6 @@ import org.apache.xmlgraphics.image.loader.impl.ImageRawJPEG;
 import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
 import org.apache.xmlgraphics.java2d.AbstractGraphics2D;
 import org.apache.xmlgraphics.java2d.GraphicContext;
-import org.apache.xmlgraphics.java2d.color.ColorExt;
 
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontInfo;
@@ -75,6 +74,7 @@ import org.apache.fop.fonts.FontSetup;
 import org.apache.fop.pdf.BitmapImage;
 import org.apache.fop.pdf.PDFAnnotList;
 import org.apache.fop.pdf.PDFColor;
+import org.apache.fop.pdf.PDFColorHandler;
 import org.apache.fop.pdf.PDFConformanceException;
 import org.apache.fop.pdf.PDFDeviceColorSpace;
 import org.apache.fop.pdf.PDFDocument;
@@ -131,6 +131,9 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
      */
     protected PDFPaintingState paintingState;
 
+    /** the PDF color handler */
+    protected PDFColorHandler colorHandler;
+
     /**
      * The PDF graphics state level that this svg is being drawn into.
      */
@@ -193,6 +196,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
                          PDFResourceContext page, String pref, String font, float size) {
         this(textAsShapes);
         pdfDoc = doc;
+        this.colorHandler = new PDFColorHandler(doc.getResources());
         resourceContext = page;
         currentFontName = font;
         currentFontSize = size;
@@ -219,6 +223,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
     public PDFGraphics2D(PDFGraphics2D g) {
         super(g);
         this.pdfDoc = g.pdfDoc;
+        this.colorHandler = g.colorHandler;
         this.resourceContext = g.resourceContext;
         this.currentFontName = g.currentFontName;
         this.currentFontSize = g.currentFontSize;
@@ -731,39 +736,20 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
     protected void applyColor(Color col, boolean fill) {
         preparePainting();
 
-        Color c = col;
-        if (col instanceof ColorExt) {
-            PDFColor currentColour = new PDFColor(this.pdfDoc, col);
-            currentStream.write(currentColour.getColorSpaceOut(fill));
-        } else if (c.getColorSpace().getType()
-                == ColorSpace.TYPE_RGB) {
-            PDFColor currentColour = new PDFColor(c.getRed(), c.getGreen(),
-                                         c.getBlue());
-            currentStream.write(currentColour.getColorSpaceOut(fill));
-        } else if (c.getColorSpace().getType()
-                   == ColorSpace.TYPE_CMYK) {
-            if (pdfDoc.getProfile().getPDFAMode().isPDFA1LevelB()) {
-                //See PDF/A-1, ISO 19005:1:2005(E), 6.2.3.3
-                //FOP is currently restricted to DeviceRGB if PDF/A-1 is active.
-                throw new PDFConformanceException(
-                        "PDF/A-1 does not allow mixing DeviceRGB and DeviceCMYK.");
-            }
-            PDFColor currentColour = new PDFColor(c);
-            currentStream.write(currentColour.getColorSpaceOut(fill));
-        } else if (c.getColorSpace().getType()
-                   == ColorSpace.TYPE_2CLR) {
-            // used for black/magenta
-            float[] cComps = c.getColorComponents(new float[1]);
-            double[] blackMagenta = new double[1];
-            for (int i = 0; i < 1; i++) {
-                blackMagenta[i] = cComps[i];
-            }
-            //PDFColor  currentColour = new PDFColor(blackMagenta[0], blackMagenta[1]);
-            //currentStream.write(currentColour.getColorSpaceOut(fill));
-        } else {
-            throw new UnsupportedOperationException(
-                    "Color Space not supported by PDFGraphics2D: " + c.getColorSpace());
+        //TODO Handle this in PDFColorHandler by automatically converting the color.
+        //This won't work properly anyway after the redesign of ColorExt
+        if (col.getColorSpace().getType() == ColorSpace.TYPE_CMYK) {
+             if (pdfDoc.getProfile().getPDFAMode().isPDFA1LevelB()) {
+                 //See PDF/A-1, ISO 19005:1:2005(E), 6.2.3.3
+                 //FOP is currently restricted to DeviceRGB if PDF/A-1 is active.
+                 throw new PDFConformanceException(
+                         "PDF/A-1 does not allow mixing DeviceRGB and DeviceCMYK.");
+             }
         }
+
+        StringBuffer sb = new StringBuffer();
+        colorHandler.establishColor(sb, col, fill);
+        currentStream.write(sb.toString());
     }
 
     /**
@@ -857,14 +843,15 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
                     return false;  // PDF can't do alpha
                 }
 
-                PDFColor color1 = new PDFColor(c1.getRed(), c1.getGreen(),
-                                               c1.getBlue());
-                someColors.add(color1);
+                //PDFColor color1 = new PDFColor(c1.getRed(), c1.getGreen(),
+                //                               c1.getBlue());
+                someColors.add(c1);
                 if (count > 0 && count < cols.length - 1) {
                     theBounds.add(new Double(fractions[count]));
                 }
             }
 
+            //Gradients are currently restricted to sRGB
             PDFDeviceColorSpace aColorSpace;
             aColorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
             PDFPattern myPat = pdfDoc.getFactory().makeGradient(
@@ -932,8 +919,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
                     return false;  // PDF can't do alpha
                 }
 
-                someColors.add(new PDFColor(cc.getRed(), cc.getGreen(),
-                                            cc.getBlue()));
+                someColors.add(cc);
             }
 
             float[] fractions = rgp.getFractions();
index c0c3c7fc805966ef16e55696750ba70ed88804b0..a5280c3613f8b7deb330e5c1e79620b615d7680a 100644 (file)
@@ -75,7 +75,9 @@ public abstract class AbstractPaintingState implements Cloneable, Serializable {
      * @return true if the color has changed
      */
     public boolean setColor(Color col) {
-        if (!col.equals(getData().color)) {
+        Color other = getData().color;
+        //Check in both directions due to limitations of java.awt.Color
+        if (!col.equals(other) || !other.equals(col)) {
             getData().color = col;
             return true;
         }
@@ -114,7 +116,9 @@ public abstract class AbstractPaintingState implements Cloneable, Serializable {
      * @return true if the color has changed
      */
     public boolean setBackColor(Color col) {
-        if (!col.equals(getData().backColor)) {
+        Color other = getData().backColor;
+        //Check in both directions due to limitations of java.awt.Color
+        if (!col.equals(other) || !other.equals(col)) {
             getData().backColor = col;
             return true;
         }
index 656d9ef98c29014200efb390c722ec8f74aa5b02..5b72027759754946f7d46f0e01078aee428b9daa 100644 (file)
@@ -27,8 +27,11 @@ import java.util.Map;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.apache.xmlgraphics.java2d.color.CMYKColorSpace;
 import org.apache.xmlgraphics.java2d.color.ColorExt;
+import org.apache.xmlgraphics.java2d.color.ColorSpaces;
+import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace;
+import org.apache.xmlgraphics.java2d.color.ICCColor;
+import org.apache.xmlgraphics.java2d.color.NamedColorSpace;
 
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.fo.expr.PropertyException;
@@ -41,9 +44,16 @@ import org.apache.fop.fo.expr.PropertyException;
  */
 public final class ColorUtil {
 
+    //Implementation note: this class should ALWAYS create ColorExt instances instead of using
+    //java.awt.Color since the latter has an equals() method that can't detect two different
+    //colors using the same sRGB fallback.
+
     /** The name for the uncalibrated CMYK pseudo-profile */
     public static final String CMYK_PSEUDO_PROFILE = "#CMYK";
 
+    /** The name for the Separation pseudo-profile used for spot colors */
+    public static final String SEPARATION_PSEUDO_PROFILE = "#Separation";
+
     /**
      *
      * keeps all the predefined and parsed colors.
@@ -194,7 +204,7 @@ public final class ColorUtil {
         } catch (Exception e) {
             throw new PropertyException(e);
         }
-        return new Color(red, green, blue);
+        return new ColorExt(red, green, blue, null);
     }
 
     /**
@@ -245,7 +255,7 @@ public final class ColorUtil {
                         || (blue < 0.0 || blue > 1.0)) {
                     throw new PropertyException("Color values out of range");
                 }
-                parsedColor = new Color(red, green, blue);
+                parsedColor = new ColorExt(red, green, blue, null);
             } catch (PropertyException pe) {
                 //simply re-throw
                 throw pe;
@@ -293,7 +303,7 @@ public final class ColorUtil {
             } else {
                 throw new NumberFormatException();
             }
-            parsedColor = new Color(red, green, blue, alpha);
+            parsedColor = new ColorExt(red, green, blue, alpha, null);
         } catch (Exception e) {
             throw new PropertyException("Unknown color format: " + value
                     + ". Must be #RGB. #RGBA, #RRGGBB, or #RRGGBBAA");
@@ -320,6 +330,21 @@ public final class ColorUtil {
                 if (args.length < 5) {
                     throw new PropertyException("Too few arguments for rgb-icc() function");
                 }
+
+                //Set up fallback sRGB value
+                float red = 0, green = 0, blue = 0;
+                red = Float.parseFloat(args[0].trim());
+                green = Float.parseFloat(args[1].trim());
+                blue = Float.parseFloat(args[2].trim());
+                /* Verify rgb replacement arguments */
+                if ((red < 0 || red > 1)
+                        || (green < 0 || green > 1)
+                        || (blue < 0 || blue > 1)) {
+                    throw new PropertyException("Color values out of range. "
+                            + "Fallback RGB arguments to fop-rgb-icc() must be [0..1]");
+                }
+                Color sRGB = new ColorExt(red, green, blue, null);
+
                 /* Get and verify ICC profile name */
                 String iccProfileName = args[3].trim();
                 if (iccProfileName == null || "".equals(iccProfileName)) {
@@ -329,7 +354,9 @@ public final class ColorUtil {
                 String iccProfileSrc = null;
                 if (isPseudoProfile(iccProfileName)) {
                     if (CMYK_PSEUDO_PROFILE.equalsIgnoreCase(iccProfileName)) {
-                        colorSpace = CMYKColorSpace.getInstance();
+                        colorSpace = ColorSpaces.getDeviceCMYKColorSpace();
+                    } else if (SEPARATION_PSEUDO_PROFILE.equalsIgnoreCase(iccProfileName)) {
+                        colorSpace = new NamedColorSpace(args[5], sRGB);
                     } else {
                         assert false : "Incomplete implementation";
                     }
@@ -347,21 +374,16 @@ public final class ColorUtil {
                     }
                 }
                 /* ICC profile arguments */
-                float[] iccComponents = new float[args.length - 5];
-                for (int ix = 4; ++ix < args.length;) {
-                    iccComponents[ix - 5] = Float.parseFloat(args[ix].trim());
+                int componentStart = 4;
+                if (colorSpace instanceof NamedColorSpace) {
+                    componentStart++;
                 }
-
-                float red = 0, green = 0, blue = 0;
-                red = Float.parseFloat(args[0].trim());
-                green = Float.parseFloat(args[1].trim());
-                blue = Float.parseFloat(args[2].trim());
-                /* Verify rgb replacement arguments */
-                if ((red < 0 || red > 1)
-                        || (green < 0 || green > 1)
-                        || (blue < 0 || blue > 1)) {
-                    throw new PropertyException("Color values out of range. "
-                            + "Fallback RGB arguments to fop-rgb-icc() must be [0..1]");
+                float[] iccComponents = new float[args.length - componentStart - 1];
+                for (int ix = componentStart; ++ix < args.length;) {
+                    iccComponents[ix - componentStart - 1] = Float.parseFloat(args[ix].trim());
+                }
+                if (colorSpace instanceof NamedColorSpace && iccComponents.length == 0) {
+                    iccComponents = new float[] {1.0f}; //full tint if not specified
                 }
 
                 /* Ask FOP factory to get ColorSpace for the specified ICC profile source */
@@ -372,14 +394,14 @@ public final class ColorUtil {
                 if (colorSpace != null) {
                     // ColorSpace available - create ColorExt (keeps track of replacement rgb
                     // values for possible later colorTOsRGBString call
-                    parsedColor = ColorExt.createFromFoRgbIcc(red, green, blue,
-                            iccProfileName, iccProfileSrc, colorSpace, iccComponents);
+                    ICCColor iccColor = new ICCColor(colorSpace, iccProfileName, iccProfileSrc,
+                            iccComponents, 1.0f);
+                    parsedColor = new ColorExt(red, green, blue, new Color[] {iccColor});
                 } else {
                     // ICC profile could not be loaded - use rgb replacement values */
                     log.warn("Color profile '" + iccProfileSrc
-                            + "' not found. Using rgb replacement values.");
-                    parsedColor = new Color(Math.round(red * 255),
-                            Math.round(green * 255), Math.round(blue * 255));
+                            + "' not found. Using sRGB replacement values.");
+                    parsedColor = sRGB;
                 }
             } catch (PropertyException pe) {
                 //simply re-throw
@@ -453,11 +475,8 @@ public final class ColorUtil {
                     throw new PropertyException("Color values out of range"
                             + "Arguments to cmyk() must be in the range [0%-100%] or [0.0-1.0]");
                 }
-                float[] cmyk = new float[] {cyan, magenta, yellow, black};
-                CMYKColorSpace cmykCs = CMYKColorSpace.getInstance();
-                float[] rgb = cmykCs.toRGB(cmyk);
-                parsedColor = ColorExt.createFromFoRgbIcc(rgb[0], rgb[1], rgb[2],
-                        CMYK_PSEUDO_PROFILE, null, cmykCs, cmyk);
+                float[] comps = new float[] {cyan, magenta, yellow, black};
+                parsedColor = DeviceCMYKColorSpace.createColorExt(comps);
             } catch (PropertyException pe) {
                 throw pe;
             } catch (Exception e) {
@@ -483,39 +502,82 @@ public final class ColorUtil {
     public static String colorToString(Color color) {
         ColorSpace cs = color.getColorSpace();
         if (color instanceof ColorExt) {
-            return ((ColorExt)color).toFunctionCall();
+            return toFunctionCall((ColorExt)color);
         } else if (cs != null && cs.getType() == ColorSpace.TYPE_CMYK) {
             StringBuffer sbuf = new StringBuffer(24);
             float[] cmyk = color.getColorComponents(null);
             sbuf.append("cmyk(" + cmyk[0] + "," + cmyk[1] + "," + cmyk[2] + "," +  cmyk[3] + ")");
             return sbuf.toString();
         } else {
-            StringBuffer sbuf = new StringBuffer();
-            sbuf.append('#');
-            String s = Integer.toHexString(color.getRed());
-            if (s.length() == 1) {
-                sbuf.append('0');
-            }
-            sbuf.append(s);
-            s = Integer.toHexString(color.getGreen());
-            if (s.length() == 1) {
-                sbuf.append('0');
-            }
-            sbuf.append(s);
-            s = Integer.toHexString(color.getBlue());
+            return toRGBFunctionCall(color);
+        }
+    }
+
+    private static String toRGBFunctionCall(Color color) {
+        StringBuffer sbuf = new StringBuffer();
+        sbuf.append('#');
+        String s = Integer.toHexString(color.getRed());
+        if (s.length() == 1) {
+            sbuf.append('0');
+        }
+        sbuf.append(s);
+        s = Integer.toHexString(color.getGreen());
+        if (s.length() == 1) {
+            sbuf.append('0');
+        }
+        sbuf.append(s);
+        s = Integer.toHexString(color.getBlue());
+        if (s.length() == 1) {
+            sbuf.append('0');
+        }
+        sbuf.append(s);
+        if (color.getAlpha() != 255) {
+            s = Integer.toHexString(color.getAlpha());
             if (s.length() == 1) {
                 sbuf.append('0');
             }
             sbuf.append(s);
-            if (color.getAlpha() != 255) {
-                s = Integer.toHexString(color.getAlpha());
-                if (s.length() == 1) {
-                    sbuf.append('0');
-                }
-                sbuf.append(s);
-            }
-            return sbuf.toString();
         }
+        return sbuf.toString();
+    }
+
+    /**
+     * Create string representation of fop-rgb-icc function call to map this
+     * ColorExt settings.
+     * @param color the color to turn into a function call
+     * @return the string representing the internal fop-rgb-icc() function call
+     */
+    public static String toFunctionCall(ColorExt color) {
+        Color[] alt = color.getAlternateColors();
+        if (alt.length == 0) {
+            return toRGBFunctionCall(color);
+        } else if (alt.length != 1) {
+            throw new IllegalStateException(
+                    "Cannot convert to function call: the number of alternate colors is not one.");
+        }
+        StringBuffer sb = new StringBuffer(40);
+        sb.append("fop-rgb-icc(");
+        float[] rgb = color.getColorComponents(null);
+        assert rgb.length == 3;
+        sb.append(rgb[0]).append(",");
+        sb.append(rgb[1]).append(",");
+        sb.append(rgb[2]).append(",");
+        ICCColor icc = (ICCColor)alt[0];
+        sb.append(icc.getColorProfileName()).append(",");
+        if (icc.getColorProfileSource() != null) {
+            sb.append("\"").append(icc.getColorProfileSource()).append("\"");
+        }
+        float[] colorComponents = icc.getColorComponents(null);
+        for (int ix = 0; ix < colorComponents.length; ix++) {
+            sb.append(",");
+            sb.append(colorComponents[ix]);
+        }
+        sb.append(")");
+        return sb.toString();
+    }
+
+    private static Color createColor(int r, int g, int b) {
+        return new ColorExt(r, g, b, null);
     }
 
     /**
@@ -524,155 +586,155 @@ public final class ColorUtil {
     private static void initializeColorMap() {
         colorMap = Collections.synchronizedMap(new java.util.HashMap());
 
-        colorMap.put("aliceblue", new Color(240, 248, 255));
-        colorMap.put("antiquewhite", new Color(250, 235, 215));
-        colorMap.put("aqua", new Color(0, 255, 255));
-        colorMap.put("aquamarine", new Color(127, 255, 212));
-        colorMap.put("azure", new Color(240, 255, 255));
-        colorMap.put("beige", new Color(245, 245, 220));
-        colorMap.put("bisque", new Color(255, 228, 196));
-        colorMap.put("black", new Color(0, 0, 0));
-        colorMap.put("blanchedalmond", new Color(255, 235, 205));
-        colorMap.put("blue", new Color(0, 0, 255));
-        colorMap.put("blueviolet", new Color(138, 43, 226));
-        colorMap.put("brown", new Color(165, 42, 42));
-        colorMap.put("burlywood", new Color(222, 184, 135));
-        colorMap.put("cadetblue", new Color(95, 158, 160));
-        colorMap.put("chartreuse", new Color(127, 255, 0));
-        colorMap.put("chocolate", new Color(210, 105, 30));
-        colorMap.put("coral", new Color(255, 127, 80));
-        colorMap.put("cornflowerblue", new Color(100, 149, 237));
-        colorMap.put("cornsilk", new Color(255, 248, 220));
-        colorMap.put("crimson", new Color(220, 20, 60));
-        colorMap.put("cyan", new Color(0, 255, 255));
-        colorMap.put("darkblue", new Color(0, 0, 139));
-        colorMap.put("darkcyan", new Color(0, 139, 139));
-        colorMap.put("darkgoldenrod", new Color(184, 134, 11));
-        colorMap.put("darkgray", new Color(169, 169, 169));
-        colorMap.put("darkgreen", new Color(0, 100, 0));
-        colorMap.put("darkgrey", new Color(169, 169, 169));
-        colorMap.put("darkkhaki", new Color(189, 183, 107));
-        colorMap.put("darkmagenta", new Color(139, 0, 139));
-        colorMap.put("darkolivegreen", new Color(85, 107, 47));
-        colorMap.put("darkorange", new Color(255, 140, 0));
-        colorMap.put("darkorchid", new Color(153, 50, 204));
-        colorMap.put("darkred", new Color(139, 0, 0));
-        colorMap.put("darksalmon", new Color(233, 150, 122));
-        colorMap.put("darkseagreen", new Color(143, 188, 143));
-        colorMap.put("darkslateblue", new Color(72, 61, 139));
-        colorMap.put("darkslategray", new Color(47, 79, 79));
-        colorMap.put("darkslategrey", new Color(47, 79, 79));
-        colorMap.put("darkturquoise", new Color(0, 206, 209));
-        colorMap.put("darkviolet", new Color(148, 0, 211));
-        colorMap.put("deeppink", new Color(255, 20, 147));
-        colorMap.put("deepskyblue", new Color(0, 191, 255));
-        colorMap.put("dimgray", new Color(105, 105, 105));
-        colorMap.put("dimgrey", new Color(105, 105, 105));
-        colorMap.put("dodgerblue", new Color(30, 144, 255));
-        colorMap.put("firebrick", new Color(178, 34, 34));
-        colorMap.put("floralwhite", new Color(255, 250, 240));
-        colorMap.put("forestgreen", new Color(34, 139, 34));
-        colorMap.put("fuchsia", new Color(255, 0, 255));
-        colorMap.put("gainsboro", new Color(220, 220, 220));
-        colorMap.put("ghostwhite", new Color(248, 248, 255));
-        colorMap.put("gold", new Color(255, 215, 0));
-        colorMap.put("goldenrod", new Color(218, 165, 32));
-        colorMap.put("gray", new Color(128, 128, 128));
-        colorMap.put("green", new Color(0, 128, 0));
-        colorMap.put("greenyellow", new Color(173, 255, 47));
-        colorMap.put("grey", new Color(128, 128, 128));
-        colorMap.put("honeydew", new Color(240, 255, 240));
-        colorMap.put("hotpink", new Color(255, 105, 180));
-        colorMap.put("indianred", new Color(205, 92, 92));
-        colorMap.put("indigo", new Color(75, 0, 130));
-        colorMap.put("ivory", new Color(255, 255, 240));
-        colorMap.put("khaki", new Color(240, 230, 140));
-        colorMap.put("lavender", new Color(230, 230, 250));
-        colorMap.put("lavenderblush", new Color(255, 240, 245));
-        colorMap.put("lawngreen", new Color(124, 252, 0));
-        colorMap.put("lemonchiffon", new Color(255, 250, 205));
-        colorMap.put("lightblue", new Color(173, 216, 230));
-        colorMap.put("lightcoral", new Color(240, 128, 128));
-        colorMap.put("lightcyan", new Color(224, 255, 255));
-        colorMap.put("lightgoldenrodyellow", new Color(250, 250, 210));
-        colorMap.put("lightgray", new Color(211, 211, 211));
-        colorMap.put("lightgreen", new Color(144, 238, 144));
-        colorMap.put("lightgrey", new Color(211, 211, 211));
-        colorMap.put("lightpink", new Color(255, 182, 193));
-        colorMap.put("lightsalmon", new Color(255, 160, 122));
-        colorMap.put("lightseagreen", new Color(32, 178, 170));
-        colorMap.put("lightskyblue", new Color(135, 206, 250));
-        colorMap.put("lightslategray", new Color(119, 136, 153));
-        colorMap.put("lightslategrey", new Color(119, 136, 153));
-        colorMap.put("lightsteelblue", new Color(176, 196, 222));
-        colorMap.put("lightyellow", new Color(255, 255, 224));
-        colorMap.put("lime", new Color(0, 255, 0));
-        colorMap.put("limegreen", new Color(50, 205, 50));
-        colorMap.put("linen", new Color(250, 240, 230));
-        colorMap.put("magenta", new Color(255, 0, 255));
-        colorMap.put("maroon", new Color(128, 0, 0));
-        colorMap.put("mediumaquamarine", new Color(102, 205, 170));
-        colorMap.put("mediumblue", new Color(0, 0, 205));
-        colorMap.put("mediumorchid", new Color(186, 85, 211));
-        colorMap.put("mediumpurple", new Color(147, 112, 219));
-        colorMap.put("mediumseagreen", new Color(60, 179, 113));
-        colorMap.put("mediumslateblue", new Color(123, 104, 238));
-        colorMap.put("mediumspringgreen", new Color(0, 250, 154));
-        colorMap.put("mediumturquoise", new Color(72, 209, 204));
-        colorMap.put("mediumvioletred", new Color(199, 21, 133));
-        colorMap.put("midnightblue", new Color(25, 25, 112));
-        colorMap.put("mintcream", new Color(245, 255, 250));
-        colorMap.put("mistyrose", new Color(255, 228, 225));
-        colorMap.put("moccasin", new Color(255, 228, 181));
-        colorMap.put("navajowhite", new Color(255, 222, 173));
-        colorMap.put("navy", new Color(0, 0, 128));
-        colorMap.put("oldlace", new Color(253, 245, 230));
-        colorMap.put("olive", new Color(128, 128, 0));
-        colorMap.put("olivedrab", new Color(107, 142, 35));
-        colorMap.put("orange", new Color(255, 165, 0));
-        colorMap.put("orangered", new Color(255, 69, 0));
-        colorMap.put("orchid", new Color(218, 112, 214));
-        colorMap.put("palegoldenrod", new Color(238, 232, 170));
-        colorMap.put("palegreen", new Color(152, 251, 152));
-        colorMap.put("paleturquoise", new Color(175, 238, 238));
-        colorMap.put("palevioletred", new Color(219, 112, 147));
-        colorMap.put("papayawhip", new Color(255, 239, 213));
-        colorMap.put("peachpuff", new Color(255, 218, 185));
-        colorMap.put("peru", new Color(205, 133, 63));
-        colorMap.put("pink", new Color(255, 192, 203));
-        colorMap.put("plum ", new Color(221, 160, 221));
-        colorMap.put("plum", new Color(221, 160, 221));
-        colorMap.put("powderblue", new Color(176, 224, 230));
-        colorMap.put("purple", new Color(128, 0, 128));
-        colorMap.put("red", new Color(255, 0, 0));
-        colorMap.put("rosybrown", new Color(188, 143, 143));
-        colorMap.put("royalblue", new Color(65, 105, 225));
-        colorMap.put("saddlebrown", new Color(139, 69, 19));
-        colorMap.put("salmon", new Color(250, 128, 114));
-        colorMap.put("sandybrown", new Color(244, 164, 96));
-        colorMap.put("seagreen", new Color(46, 139, 87));
-        colorMap.put("seashell", new Color(255, 245, 238));
-        colorMap.put("sienna", new Color(160, 82, 45));
-        colorMap.put("silver", new Color(192, 192, 192));
-        colorMap.put("skyblue", new Color(135, 206, 235));
-        colorMap.put("slateblue", new Color(106, 90, 205));
-        colorMap.put("slategray", new Color(112, 128, 144));
-        colorMap.put("slategrey", new Color(112, 128, 144));
-        colorMap.put("snow", new Color(255, 250, 250));
-        colorMap.put("springgreen", new Color(0, 255, 127));
-        colorMap.put("steelblue", new Color(70, 130, 180));
-        colorMap.put("tan", new Color(210, 180, 140));
-        colorMap.put("teal", new Color(0, 128, 128));
-        colorMap.put("thistle", new Color(216, 191, 216));
-        colorMap.put("tomato", new Color(255, 99, 71));
-        colorMap.put("turquoise", new Color(64, 224, 208));
-        colorMap.put("violet", new Color(238, 130, 238));
-        colorMap.put("wheat", new Color(245, 222, 179));
-        colorMap.put("white", new Color(255, 255, 255));
-        colorMap.put("whitesmoke", new Color(245, 245, 245));
-        colorMap.put("yellow", new Color(255, 255, 0));
-        colorMap.put("yellowgreen", new Color(154, 205, 50));
-        colorMap.put("transparent", new Color(0, 0, 0, 0));
+        colorMap.put("aliceblue", createColor(240, 248, 255));
+        colorMap.put("antiquewhite", createColor(250, 235, 215));
+        colorMap.put("aqua", createColor(0, 255, 255));
+        colorMap.put("aquamarine", createColor(127, 255, 212));
+        colorMap.put("azure", createColor(240, 255, 255));
+        colorMap.put("beige", createColor(245, 245, 220));
+        colorMap.put("bisque", createColor(255, 228, 196));
+        colorMap.put("black", createColor(0, 0, 0));
+        colorMap.put("blanchedalmond", createColor(255, 235, 205));
+        colorMap.put("blue", createColor(0, 0, 255));
+        colorMap.put("blueviolet", createColor(138, 43, 226));
+        colorMap.put("brown", createColor(165, 42, 42));
+        colorMap.put("burlywood", createColor(222, 184, 135));
+        colorMap.put("cadetblue", createColor(95, 158, 160));
+        colorMap.put("chartreuse", createColor(127, 255, 0));
+        colorMap.put("chocolate", createColor(210, 105, 30));
+        colorMap.put("coral", createColor(255, 127, 80));
+        colorMap.put("cornflowerblue", createColor(100, 149, 237));
+        colorMap.put("cornsilk", createColor(255, 248, 220));
+        colorMap.put("crimson", createColor(220, 20, 60));
+        colorMap.put("cyan", createColor(0, 255, 255));
+        colorMap.put("darkblue", createColor(0, 0, 139));
+        colorMap.put("darkcyan", createColor(0, 139, 139));
+        colorMap.put("darkgoldenrod", createColor(184, 134, 11));
+        colorMap.put("darkgray", createColor(169, 169, 169));
+        colorMap.put("darkgreen", createColor(0, 100, 0));
+        colorMap.put("darkgrey", createColor(169, 169, 169));
+        colorMap.put("darkkhaki", createColor(189, 183, 107));
+        colorMap.put("darkmagenta", createColor(139, 0, 139));
+        colorMap.put("darkolivegreen", createColor(85, 107, 47));
+        colorMap.put("darkorange", createColor(255, 140, 0));
+        colorMap.put("darkorchid", createColor(153, 50, 204));
+        colorMap.put("darkred", createColor(139, 0, 0));
+        colorMap.put("darksalmon", createColor(233, 150, 122));
+        colorMap.put("darkseagreen", createColor(143, 188, 143));
+        colorMap.put("darkslateblue", createColor(72, 61, 139));
+        colorMap.put("darkslategray", createColor(47, 79, 79));
+        colorMap.put("darkslategrey", createColor(47, 79, 79));
+        colorMap.put("darkturquoise", createColor(0, 206, 209));
+        colorMap.put("darkviolet", createColor(148, 0, 211));
+        colorMap.put("deeppink", createColor(255, 20, 147));
+        colorMap.put("deepskyblue", createColor(0, 191, 255));
+        colorMap.put("dimgray", createColor(105, 105, 105));
+        colorMap.put("dimgrey", createColor(105, 105, 105));
+        colorMap.put("dodgerblue", createColor(30, 144, 255));
+        colorMap.put("firebrick", createColor(178, 34, 34));
+        colorMap.put("floralwhite", createColor(255, 250, 240));
+        colorMap.put("forestgreen", createColor(34, 139, 34));
+        colorMap.put("fuchsia", createColor(255, 0, 255));
+        colorMap.put("gainsboro", createColor(220, 220, 220));
+        colorMap.put("ghostwhite", createColor(248, 248, 255));
+        colorMap.put("gold", createColor(255, 215, 0));
+        colorMap.put("goldenrod", createColor(218, 165, 32));
+        colorMap.put("gray", createColor(128, 128, 128));
+        colorMap.put("green", createColor(0, 128, 0));
+        colorMap.put("greenyellow", createColor(173, 255, 47));
+        colorMap.put("grey", createColor(128, 128, 128));
+        colorMap.put("honeydew", createColor(240, 255, 240));
+        colorMap.put("hotpink", createColor(255, 105, 180));
+        colorMap.put("indianred", createColor(205, 92, 92));
+        colorMap.put("indigo", createColor(75, 0, 130));
+        colorMap.put("ivory", createColor(255, 255, 240));
+        colorMap.put("khaki", createColor(240, 230, 140));
+        colorMap.put("lavender", createColor(230, 230, 250));
+        colorMap.put("lavenderblush", createColor(255, 240, 245));
+        colorMap.put("lawngreen", createColor(124, 252, 0));
+        colorMap.put("lemonchiffon", createColor(255, 250, 205));
+        colorMap.put("lightblue", createColor(173, 216, 230));
+        colorMap.put("lightcoral", createColor(240, 128, 128));
+        colorMap.put("lightcyan", createColor(224, 255, 255));
+        colorMap.put("lightgoldenrodyellow", createColor(250, 250, 210));
+        colorMap.put("lightgray", createColor(211, 211, 211));
+        colorMap.put("lightgreen", createColor(144, 238, 144));
+        colorMap.put("lightgrey", createColor(211, 211, 211));
+        colorMap.put("lightpink", createColor(255, 182, 193));
+        colorMap.put("lightsalmon", createColor(255, 160, 122));
+        colorMap.put("lightseagreen", createColor(32, 178, 170));
+        colorMap.put("lightskyblue", createColor(135, 206, 250));
+        colorMap.put("lightslategray", createColor(119, 136, 153));
+        colorMap.put("lightslategrey", createColor(119, 136, 153));
+        colorMap.put("lightsteelblue", createColor(176, 196, 222));
+        colorMap.put("lightyellow", createColor(255, 255, 224));
+        colorMap.put("lime", createColor(0, 255, 0));
+        colorMap.put("limegreen", createColor(50, 205, 50));
+        colorMap.put("linen", createColor(250, 240, 230));
+        colorMap.put("magenta", createColor(255, 0, 255));
+        colorMap.put("maroon", createColor(128, 0, 0));
+        colorMap.put("mediumaquamarine", createColor(102, 205, 170));
+        colorMap.put("mediumblue", createColor(0, 0, 205));
+        colorMap.put("mediumorchid", createColor(186, 85, 211));
+        colorMap.put("mediumpurple", createColor(147, 112, 219));
+        colorMap.put("mediumseagreen", createColor(60, 179, 113));
+        colorMap.put("mediumslateblue", createColor(123, 104, 238));
+        colorMap.put("mediumspringgreen", createColor(0, 250, 154));
+        colorMap.put("mediumturquoise", createColor(72, 209, 204));
+        colorMap.put("mediumvioletred", createColor(199, 21, 133));
+        colorMap.put("midnightblue", createColor(25, 25, 112));
+        colorMap.put("mintcream", createColor(245, 255, 250));
+        colorMap.put("mistyrose", createColor(255, 228, 225));
+        colorMap.put("moccasin", createColor(255, 228, 181));
+        colorMap.put("navajowhite", createColor(255, 222, 173));
+        colorMap.put("navy", createColor(0, 0, 128));
+        colorMap.put("oldlace", createColor(253, 245, 230));
+        colorMap.put("olive", createColor(128, 128, 0));
+        colorMap.put("olivedrab", createColor(107, 142, 35));
+        colorMap.put("orange", createColor(255, 165, 0));
+        colorMap.put("orangered", createColor(255, 69, 0));
+        colorMap.put("orchid", createColor(218, 112, 214));
+        colorMap.put("palegoldenrod", createColor(238, 232, 170));
+        colorMap.put("palegreen", createColor(152, 251, 152));
+        colorMap.put("paleturquoise", createColor(175, 238, 238));
+        colorMap.put("palevioletred", createColor(219, 112, 147));
+        colorMap.put("papayawhip", createColor(255, 239, 213));
+        colorMap.put("peachpuff", createColor(255, 218, 185));
+        colorMap.put("peru", createColor(205, 133, 63));
+        colorMap.put("pink", createColor(255, 192, 203));
+        colorMap.put("plum ", createColor(221, 160, 221));
+        colorMap.put("plum", createColor(221, 160, 221));
+        colorMap.put("powderblue", createColor(176, 224, 230));
+        colorMap.put("purple", createColor(128, 0, 128));
+        colorMap.put("red", createColor(255, 0, 0));
+        colorMap.put("rosybrown", createColor(188, 143, 143));
+        colorMap.put("royalblue", createColor(65, 105, 225));
+        colorMap.put("saddlebrown", createColor(139, 69, 19));
+        colorMap.put("salmon", createColor(250, 128, 114));
+        colorMap.put("sandybrown", createColor(244, 164, 96));
+        colorMap.put("seagreen", createColor(46, 139, 87));
+        colorMap.put("seashell", createColor(255, 245, 238));
+        colorMap.put("sienna", createColor(160, 82, 45));
+        colorMap.put("silver", createColor(192, 192, 192));
+        colorMap.put("skyblue", createColor(135, 206, 235));
+        colorMap.put("slateblue", createColor(106, 90, 205));
+        colorMap.put("slategray", createColor(112, 128, 144));
+        colorMap.put("slategrey", createColor(112, 128, 144));
+        colorMap.put("snow", createColor(255, 250, 250));
+        colorMap.put("springgreen", createColor(0, 255, 127));
+        colorMap.put("steelblue", createColor(70, 130, 180));
+        colorMap.put("tan", createColor(210, 180, 140));
+        colorMap.put("teal", createColor(0, 128, 128));
+        colorMap.put("thistle", createColor(216, 191, 216));
+        colorMap.put("tomato", createColor(255, 99, 71));
+        colorMap.put("turquoise", createColor(64, 224, 208));
+        colorMap.put("violet", createColor(238, 130, 238));
+        colorMap.put("wheat", createColor(245, 222, 179));
+        colorMap.put("white", createColor(255, 255, 255));
+        colorMap.put("whitesmoke", createColor(245, 245, 245));
+        colorMap.put("yellow", createColor(255, 255, 0));
+        colorMap.put("yellowgreen", createColor(154, 205, 50));
+        colorMap.put("transparent", new ColorExt(0, 0, 0, 0, null));
     }
 
     /**
@@ -692,7 +754,8 @@ public final class ColorUtil {
      * @return true if the color profile name is of a built-in pseudo-profile
      */
     public static boolean isPseudoProfile(String colorProfileName) {
-        return CMYK_PSEUDO_PROFILE.equalsIgnoreCase(colorProfileName);
+        return CMYK_PSEUDO_PROFILE.equalsIgnoreCase(colorProfileName)
+                || SEPARATION_PSEUDO_PROFILE.equalsIgnoreCase(colorProfileName);
     }
 
     /**
@@ -710,7 +773,6 @@ public final class ColorUtil {
      * @return the CMYK color
      */
     public static Color toCMYKGrayColor(float black) {
-
         return org.apache.xmlgraphics.java2d.color.ColorUtil.toCMYKGrayColor(black);
     }
 }
index 353b8059b2e443d2e49b5cf58eb040455cc88eda..c2ac44d19965bc75a08d9c5e55547aba439a1efa 100644 (file)
@@ -58,6 +58,9 @@
       documents. Example: the fix of marks layering will be such a case when it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+      <action context="Renderers" dev="JM" type="add" fixes-bug="49403" due-to="Patrick Jaromin">
+        Initial work on spot colors (aka named colors) for PDF output.
+      </action>
       <action context="Renderers" dev="JM" type="fix">
         AFP Output: Fixed positioning of Java2D-based images (when GOCA is enabled).
       </action>
index 3332d11f2fcf972db2d1dcc7f31ca3b88dfd3a45..1ac1a117f5e09337e6d4868a34c059ecaad97d41 100644 (file)
@@ -23,8 +23,7 @@ import java.awt.Color;
 
 import junit.framework.TestCase;
 
-import org.apache.xmlgraphics.java2d.color.CMYKColorSpace;
-import org.apache.xmlgraphics.java2d.color.ColorExt;
+import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace;
 
 import org.apache.fop.fo.Constants;
 import org.apache.fop.util.ColorUtil;
@@ -50,10 +49,7 @@ public class BorderPropsTestCase extends TestCase {
         assertEquals(b1, b2);
 
         float[] cmyk = new float[] {1.0f, 1.0f, 0.5f, 1.0f};
-        CMYKColorSpace cmykCs = CMYKColorSpace.getInstance();
-        float[] rgb = cmykCs.toRGB(cmyk);
-        col = ColorExt.createFromFoRgbIcc(rgb[0], rgb[1], rgb[2],
-                "#CMYK", null, cmykCs, cmyk);
+        col = DeviceCMYKColorSpace.createColorExt(cmyk);
         b1 = new BorderProps(Constants.EN_INSET, 9999,
                 col, BorderProps.SEPARATE);
         ser = b1.toString();
index 83163c8881d6f6b8b7089ce6b8310840743b00a5..82fe841fc5026497b88d75a8502e090fff10e44e 100644 (file)
@@ -21,11 +21,12 @@ 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.CMYKColorSpace;
 import org.apache.xmlgraphics.java2d.color.ColorExt;
+import org.apache.xmlgraphics.java2d.color.ColorSpaces;
 
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.FopFactory;
@@ -110,8 +111,9 @@ 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");
+        URI sRGBLoc = new URI(
+                "file:src/java/org/apache/fop/pdf/sRGB%20Color%20Space%20Profile.icm");
+        ColorSpace cs = fopFactory.getColorSpace(null, sRGBLoc.toASCIIString());
         assertNotNull(cs);
 
 
@@ -120,7 +122,7 @@ public class ColorUtilTestCase extends TestCase {
 
         //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)";
+            + "\"" + sRGBLoc.toASCIIString() + "\",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
@@ -129,13 +131,21 @@ public class ColorUtilTestCase extends TestCase {
         //RGB fallback in any renderer.
         //TODO Anyone know what's going on here?
         assertEquals(0, colActual.getBlue());
-        assertEquals(cs, colActual.getColorSpace());
+        assertEquals(ColorSpace.getInstance(ColorSpace.CS_sRGB), colActual.getColorSpace());
         float[] comps = colActual.getColorComponents(null);
         assertEquals(3, comps.length);
         assertEquals(1f, comps[0], 0);
         assertEquals(0f, comps[1], 0);
         assertEquals(0f, comps[2], 0);
 
+        Color alt = colActual.getAlternateColors()[0];
+        assertEquals(cs, alt.getColorSpace());
+        comps = colActual.getColorComponents(null);
+        assertEquals(3, comps.length);
+        assertEquals(1f, comps[0], 0);
+        assertEquals(0f, comps[1], 0);
+        assertEquals(0f, comps[2], 0);
+
         assertEquals(colSpec, ColorUtil.colorToString(colActual));
 
         colSpec = "fop-rgb-icc(1.0,0.5,0.0,blah,"
@@ -157,8 +167,9 @@ public class ColorUtilTestCase extends TestCase {
         assertEquals(255, colActual.getRed());
         assertEquals(255, colActual.getGreen());
         assertEquals(0, colActual.getBlue());
-        assertEquals(CMYKColorSpace.getInstance(), colActual.getColorSpace());
-        float[] comps = colActual.getColorComponents(null);
+        Color alt = colActual.getAlternateColors()[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);
@@ -169,11 +180,12 @@ public class ColorUtilTestCase extends TestCase {
 
         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(CMYKColorSpace.getInstance(), colActual.getColorSpace());
-        comps = colActual.getColorComponents(null);
+        assertEquals(248, colActual.getRed(), 1);
+        assertEquals(199, colActual.getGreen(), 1);
+        assertEquals(172, colActual.getBlue(), 1);
+        alt = colActual.getAlternateColors()[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);
@@ -186,8 +198,9 @@ public class ColorUtilTestCase extends TestCase {
         assertEquals(255, colActual.getRed());
         assertEquals(255, colActual.getGreen());
         assertEquals(0, colActual.getBlue());
-        assertEquals(CMYKColorSpace.getInstance(), colActual.getColorSpace());
-        comps = colActual.getColorComponents(null);
+        alt = colActual.getAlternateColors()[0];
+        assertEquals(ColorSpaces.getDeviceCMYKColorSpace(), alt.getColorSpace());
+        comps = alt.getColorComponents(null);
         assertEquals(4, comps.length);
         assertEquals(0f, comps[0], 0);
         assertEquals(0f, comps[1], 0);
@@ -198,11 +211,12 @@ public class ColorUtilTestCase extends TestCase {
 
         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(127, colActual.getRed(), 1);
+        assertEquals(127, colActual.getGreen(), 1);
+        assertEquals(127, colActual.getBlue(), 1);
+        alt = colActual.getAlternateColors()[0];
+        assertEquals(ColorSpaces.getDeviceCMYKColorSpace(), alt.getColorSpace());
+        comps = alt.getColorComponents(null);
         assertEquals(4, comps.length);
         assertEquals(0f, comps[0], 0);
         assertEquals(0f, comps[1], 0);