package org.apache.fop.apps;
-import java.awt.color.ColorSpace;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
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;
/** Optional overriding LayoutManagerMaker */
private LayoutManagerMaker lmMakerOverride = null;
- private Set ignoredNamespaces;
+ private Set<String> ignoredNamespaces;
private FOURIResolver foURIResolver;
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>();
}
/**
* 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);
}
}
/** @return the set of namespaces that are ignored by FOP */
- public Set getIgnoredNamespace() {
+ public Set<String> getIgnoredNamespace() {
return Collections.unmodifiableSet(this.ignoredNamespaces);
}
}
/**
- * 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;
}
}
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);
}
//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});
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);
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;
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);
}
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;
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();
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();
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)";
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.");
+ }
}
/**
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();