if (poss != -1 && pose != -1) {
String[] args = value.substring(poss + 1, pose).split(",");
try {
if (args.length < 5) {
throw new PropertyException("Too few arguments for rgb-icc() function");
}
/* Get and verify ICC profile name */
String iccProfileName = args[3].trim();
if (iccProfileName == null || "".equals(iccProfileName)) {
throw new PropertyException("ICC profile name missing");
}
ColorSpace colorSpace = null;
String iccProfileSrc = null;
if (isPseudoProfile(iccProfileName)) {
if (CMYK_PSEUDO_PROFILE.equalsIgnoreCase(iccProfileName)) {
colorSpace = DeviceCMYKColorSpace.getInstance();
} else {
assert false : "Incomplete implementation";
}
} else {
/* Get and verify ICC profile source */
iccProfileSrc = args[4].trim();
if (iccProfileSrc == null || "".equals(iccProfileSrc)) {
throw new PropertyException("ICC profile source missing");
}
if (iccProfileSrc.startsWith("\"") || iccProfileSrc.startsWith("'")) {
iccProfileSrc = iccProfileSrc.substring(1);
}
if (iccProfileSrc.endsWith("\"") || iccProfileSrc.endsWith("'")) {
iccProfileSrc = iccProfileSrc.substring(0, iccProfileSrc.length() - 1);
}
}
/* 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());
}
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]");
}
/* Ask FOP factory to get ColorSpace for the specified ICC profile source */
if (foUserAgent != null && iccProfileSrc != null) {
colorSpace = foUserAgent.getFactory().getColorSpace(
foUserAgent.getBaseURL(), iccProfileSrc);
}
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);
} 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));
}
} catch (PropertyException pe) {
//simply re-throw
throw pe;
} catch (Exception e) {
//wrap in a PropertyException
throw new PropertyException(e);
}
} else {
throw new PropertyException("Unknown color format: " + value
+ ". Must be fop-rgb-icc(r,g,b,NCNAME,src,....)");
}
return parsedColor;
}