}
/* Verify rgb replacement arguments */
if ((red < 0.0 || red > 1.0)
|| (green < 0.0 || green > 1.0)
|| (blue < 0.0 || blue > 1.0)) {
throw new PropertyException("Color values out of range");
}
/* Get and verify ICC profile name */
String iccProfileName = null;
if (st.hasMoreTokens()) {
iccProfileName = st.nextToken().trim();
}
if (iccProfileName == null || iccProfileName.length() == 0) {
throw new PropertyException("ICC profile name missing");
}
/* Get and verify ICC profile source */
String iccProfileSrc = null;
if (st.hasMoreTokens()) {
iccProfileSrc = st.nextToken().trim();
// Strip quotes
iccProfileSrc = iccProfileSrc.substring(1, iccProfileSrc.length() - 1);
}
if (iccProfileSrc == null || iccProfileSrc.length() == 0) {
throw new PropertyException("ICC profile source missing");
}
/* ICC profile arguments */
List iccArgList = new LinkedList();
while (st.hasMoreTokens()) {
String str = st.nextToken().trim();
iccArgList.add(new Float(str));
}
/* Copy ICC profile arguments from list to array */
float[] iccComponents = new float[iccArgList.size()];
for (int ix = 0; ix < iccArgList.size(); ix++) {
iccComponents[ix] = ((Float)iccArgList.get(ix)).floatValue();
}
/* Ask FOP factory to get ColorSpace for the specified ICC profile source */
ColorSpace colorSpace = (foUserAgent != null
? foUserAgent.getFactory().getColorSpace(
foUserAgent.getBaseURL(), iccProfileSrc) : null);
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(red, green, blue);
}
} catch (Exception e) {
throw new PropertyException(
"Arguments to rgb-icc() must be [0..255] or [0%..100%]");
}
} else {
throw new PropertyException("Unknown color format: " + value
+ ". Must be fop-rgb-icc(r,g,b,NCNAME,\"src\",....)");
}
return parsedColor;
}