diff options
author | Jeremias Maerki <jeremias@apache.org> | 2010-06-29 16:52:06 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2010-06-29 16:52:06 +0000 |
commit | fdb20deabe93eade9c6903b98904e19de2ae49c2 (patch) | |
tree | 1d216d15b1aace31f94887813fc536e938ecf849 /src/java/org/apache/fop/util | |
parent | ce1985d668d74d0b8a8d4c485ccd744a5d1ea5f0 (diff) | |
download | xmlgraphics-fop-fdb20deabe93eade9c6903b98904e19de2ae49c2.tar.gz xmlgraphics-fop-fdb20deabe93eade9c6903b98904e19de2ae49c2.zip |
Round-trip for fop-rgb-named-color() function.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_Color@959028 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/util')
-rw-r--r-- | src/java/org/apache/fop/util/ColorUtil.java | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/src/java/org/apache/fop/util/ColorUtil.java b/src/java/org/apache/fop/util/ColorUtil.java index 983b3c421..71c97f84e 100644 --- a/src/java/org/apache/fop/util/ColorUtil.java +++ b/src/java/org/apache/fop/util/ColorUtil.java @@ -660,31 +660,50 @@ public final class ColorUtil { */ public static String toFunctionCall(ColorExt color) { Color[] alt = color.getAlternateColors(); - if (alt.length == 0) { + ICCColor icc = null; + for (int i = 0, c = alt.length; i < c; i++) { + if (alt[i] instanceof ICCColor) { + //Find first ICCColor in alternatives + icc = (ICCColor)alt[i]; + break; + } + } + if (icc == null) { 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("); + + String functionName; float[] rgb = color.getColorComponents(null); assert rgb.length == 3; + sb.append("("); 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(","); + String profileName = icc.getColorProfileName(); + sb.append(profileName).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]); + + if (icc.getColorSpace() instanceof NamedColorSpace) { + NamedColorSpace ncs = (NamedColorSpace)icc.getColorSpace(); + if (SEPARATION_PSEUDO_PROFILE.equalsIgnoreCase(profileName)) { + functionName = "fop-rgb-icc"; + } else { + functionName = "fop-rgb-named-color"; + } + sb.append(",").append(ncs.getColorName()); + } else { + functionName = "fop-rgb-icc"; + float[] colorComponents = icc.getColorComponents(null); + for (int ix = 0; ix < colorComponents.length; ix++) { + sb.append(","); + sb.append(colorComponents[ix]); + } } sb.append(")"); - return sb.toString(); + return functionName + sb.toString(); } private static Color createColor(int r, int g, int b) { |