import java.util.List;
import org.apache.xmlgraphics.java2d.color.ColorConverter;
+import org.apache.xmlgraphics.java2d.color.ColorUtil;
import org.apache.fop.afp.AFPDataObjectInfo;
import org.apache.fop.afp.AFPObjectAreaInfo;
}
/** {@inheritDoc} */
+ @Override
public void setViewport(AFPDataObjectInfo dataObjectInfo) {
super.setViewport(dataObjectInfo);
* @param color the active color to use
*/
public void setColor(Color color) {
- if (!color.equals(graphicsState.color)) {
+ if (!ColorUtil.isSameColor(color, graphicsState.color)) {
addObject(new GraphicsSetProcessColor(colorConverter.convert(color)));
graphicsState.color = color;
}
}
/** {@inheritDoc} */
+ @Override
public String toString() {
return "GraphicsObject: " + getName();
}
}
/** {@inheritDoc} */
+ @Override
public void setComplete(boolean complete) {
Iterator it = objects.iterator();
while (it.hasNext()) {
}
/** {@inheritDoc} */
+ @Override
protected void writeStart(OutputStream os) throws IOException {
super.writeStart(os);
byte[] data = new byte[17];
}
/** {@inheritDoc} */
+ @Override
protected void writeContent(OutputStream os) throws IOException {
super.writeContent(os);
writeObjects(objects, os);
}
/** {@inheritDoc} */
+ @Override
protected void writeEnd(OutputStream os) throws IOException {
byte[] data = new byte[17];
copySF(data, Type.END, Category.GRAPHICS);
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.xmlgraphics.java2d.color.CIELabColorSpace;
+import org.apache.xmlgraphics.java2d.color.ColorUtil;
import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives;
/**
* @throws IOException if an I/O error occurs
*/
public void setExtendedTextColor(Color col) throws IOException {
- //Check in both directions
- if (col.equals(currentColor) && currentColor.equals(col)) {
+ if (ColorUtil.isSameColor(col, currentColor)) {
return;
}
if (col instanceof ColorWithAlternatives) {
import org.apache.xmlgraphics.image.loader.ImageContext;
import org.apache.xmlgraphics.image.loader.ImageManager;
-import org.apache.xmlgraphics.java2d.color.ICCColorSpaceExt;
+import org.apache.xmlgraphics.java2d.color.RenderingIntent;
import org.apache.fop.fo.ElementMapping;
import org.apache.fop.fo.ElementMappingRegistry;
this.fontManager = new FontManager() {
/** {@inheritDoc} */
+ @Override
public void setFontBaseURL(String fontBase) throws MalformedURLException {
super.setFontBaseURL(getFOURIResolver().checkBaseURL(fontBase));
}
* @throws MalformedURLException if there's a problem with a file URL
* @deprecated use getFontManager().setFontBaseURL(fontBase) instead
*/
+ @Deprecated
public void setFontBaseURL(String fontBase) throws MalformedURLException {
getFontManager().setFontBaseURL(fontBase);
}
* @return the font base URL
* @deprecated use getFontManager().setFontBaseURL(fontBase) instead
*/
+ @Deprecated
public String getFontBaseURL() {
return getFontManager().getFontBaseURL();
}
* @return true if kerning on base 14 fonts is enabled
* @deprecated use getFontManager().isBase14KerningEnabled() instead
*/
+ @Deprecated
public boolean isBase14KerningEnabled() {
return getFontManager().isBase14KerningEnabled();
}
* @param value true if kerning should be activated
* @deprecated use getFontManager().setBase14KerningEnabled(boolean) instead
*/
+ @Deprecated
public void setBase14KerningEnabled(boolean value) {
getFontManager().setBase14KerningEnabled(value);
}
* @param useCache use cache or not
* @deprecated use getFontManager().setUseCache(boolean) instead
*/
+ @Deprecated
public void setUseCache(boolean useCache) {
getFontManager().setUseCache(useCache);
}
* @return whether this factory is uses the cache
* @deprecated use getFontManager().useCache() instead
*/
+ @Deprecated
public boolean useCache() {
return getFontManager().useCache();
}
* @return the font cache
* @deprecated use getFontManager().getFontCache() instead
*/
+ @Deprecated
public FontCache getFontCache() {
return getFontManager().getFontCache();
}
* @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 (see {@link ICCColorSpaceExt}.*)
+ * @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,
- int renderingIntent) {
+ RenderingIntent renderingIntent) {
return colorSpaceCache.get(profileName, baseUri, iccProfileSrc, renderingIntent);
}
* @throws PropertyException
* for invalid or inconsistent FO input
*/
+ @Override
public Property convertProperty(Property p,
PropertyList propertyList, FObj fo)
throws PropertyException {
* @param foUserAgent FOP user agent
* @return float the AWT color represented by this ColorType instance
*/
+ @Override
public Color getColor(FOUserAgent foUserAgent) {
return color;
}
/** {@inheritDoc} */
+ @Override
public String toString() {
return ColorUtil.colorToString(color);
}
/**
* @return this.colorType cast as an Object
*/
+ @Override
public Object getObject() {
return this;
}
/** {@inheritDoc} */
+ @Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o instanceof ColorProperty) {
- return ((ColorProperty) o).color.equals(this.color);
+ return org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor(
+ ((ColorProperty) o).color, this.color);
}
return false;
}
/** {@inheritDoc} */
+ @Override
public int hashCode() {
return this.color.hashCode();
}
package org.apache.fop.pdf;
+import java.awt.Color;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.GeneralPath;
import java.util.Iterator;
+import org.apache.xmlgraphics.java2d.color.ColorUtil;
+
import org.apache.fop.util.AbstractPaintingState;
/**
*/
public boolean setPaint(Paint p) {
PDFData data = getPDFData();
- Paint paint = data.paint;
- if (paint == null) {
+ Paint currentPaint = data.paint;
+ if (currentPaint == null) {
if (p != null) {
data.paint = p;
return true;
}
- } else if (!paint.equals(p)) {
+ } else if (p instanceof Color && currentPaint instanceof Color) {
+ if (!ColorUtil.isSameColor((Color)p, (Color)currentPaint)) {
+ data.paint = p;
+ return true;
+ }
+ } else if (!currentPaint.equals(p)) {
data.paint = p;
return true;
}
}
/** {@inheritDoc} */
+ @Override
protected AbstractData instantiateData() {
return new PDFData();
}
/** {@inheritDoc} */
+ @Override
protected AbstractPaintingState instantiate() {
return new PDFPaintingState();
}
* This call should be used when the q operator is used
* so that the state is known when popped.
*/
+ @Override
public void save() {
AbstractData data = getData();
AbstractData copy = (AbstractData)data.clone();
private float characterSpacing = 0f;
/** {@inheritDoc} */
+ @Override
public Object clone() {
PDFData obj = (PDFData)super.clone();
obj.paint = this.paint;
}
/** {@inheritDoc} */
+ @Override
public String toString() {
return super.toString()
+ ", paint=" + paint
}
/** {@inheritDoc} */
+ @Override
protected AbstractData instantiate() {
return new PDFData();
}
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
}
/** {@inheritDoc} */
+ @Override
protected String getMainNamespace() {
return NAMESPACE;
}
}
/** {@inheritDoc} */
+ @Override
public IFDocumentNavigationHandler getDocumentNavigationHandler() {
return this;
}
}
/** {@inheritDoc} */
+ @Override
public void startDocument() throws IFException {
super.startDocument();
try {
}
/** {@inheritDoc} */
+ @Override
public void startDocumentHeader() throws IFException {
try {
handler.startElement(EL_HEADER);
}
/** {@inheritDoc} */
+ @Override
public void endDocumentHeader() throws IFException {
try {
handler.endElement(EL_HEADER);
}
/** {@inheritDoc} */
+ @Override
public void startDocumentTrailer() throws IFException {
try {
handler.startElement(EL_TRAILER);
}
/** {@inheritDoc} */
+ @Override
public void endDocumentTrailer() throws IFException {
try {
handler.endElement(EL_TRAILER);
}
/** {@inheritDoc} */
+ @Override
public void startPageHeader() throws IFException {
try {
handler.startElement(EL_PAGE_HEADER);
}
/** {@inheritDoc} */
+ @Override
public void endPageHeader() throws IFException {
try {
handler.endElement(EL_PAGE_HEADER);
}
/** {@inheritDoc} */
+ @Override
public void startPageTrailer() throws IFException {
try {
handler.startElement(EL_PAGE_TRAILER);
}
/** {@inheritDoc} */
+ @Override
public void endPageTrailer() throws IFException {
try {
commitNavigation();
}
}
if (color != null) {
- changed = !color.equals(state.getTextColor());
+ changed = !org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor(
+ color, state.getTextColor());
if (changed) {
state.setTextColor(color);
addAttribute(atts, "color", toString(color));
import java.awt.Color;
+import org.apache.xmlgraphics.java2d.color.ColorUtil;
+
public class IFState {
private IFState parent;
* @param color the new text color
*/
public void setTextColor(Color color) {
- //Check in both directions due to limitations of java.awt.Color
- if (!color.equals(this.textColor) || !this.textColor.equals(color)) {
+ if (!ColorUtil.isSameColor(color, this.textColor)) {
this.fontChanged = true;
}
this.textColor = color;
import java.awt.geom.Area;
import java.awt.geom.GeneralPath;
+import org.apache.xmlgraphics.java2d.color.ColorUtil;
+
import org.apache.fop.fo.Constants;
import org.apache.fop.fonts.FontInfo;
* @return true if the background color has changed
*/
public boolean updateColor(Color col) {
- if (!col.equals(getGraph().getColor())) {
+ if (!ColorUtil.isSameColor(col, getGraph().getColor())) {
getGraph().setColor(col);
return true;
} else {
* @return true if the new paint changes the current paint
*/
public boolean updatePaint(Paint p) {
- if (getGraph().getPaint() == null) {
+ Paint currentPaint = getGraph().getPaint();
+ if (currentPaint == null) {
if (p != null) {
getGraph().setPaint(p);
return true;
}
- } else if (!p.equals(getGraph().getPaint())) {
+ } else if (p instanceof Color && currentPaint instanceof Color) {
+ if (!ColorUtil.isSameColor((Color)p, (Color)currentPaint)) {
+ getGraph().setPaint(p);
+ return true;
+ }
+ } else if (!p.equals(currentPaint)) {
getGraph().setPaint(p);
return true;
}
}
/** {@inheritDoc} */
+ @Override
public String toString() {
String s = "Java2DGraphicsState " + currentGraphics.toString()
+ ", Stroke (width: " + currentStrokeWidth + " style: "
}
/** {@inheritDoc} */
+ @Override
public int hashCode() {
return toString().hashCode();
}
/** {@inheritDoc} */
+ @Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
if (obj instanceof BorderProps) {
BorderProps other = (BorderProps)obj;
return (style == other.style)
- && color.equals(other.color)
+ && org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor(
+ color, other.color)
&& width == other.width
&& mode == other.mode;
}
}
/** {@inheritDoc} */
+ @Override
public String toString() {
StringBuffer sbuf = new StringBuffer();
sbuf.append('(');
*/
public boolean setColor(Color col) {
Color other = getData().color;
- //Check in both directions due to limitations of java.awt.Color
- if (!col.equals(other) || !other.equals(col)) {
+ if (!org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor(col, other)) {
getData().color = col;
return true;
}
*/
public boolean setBackColor(Color col) {
Color other = getData().backColor;
- //Check in both directions due to limitations of java.awt.Color
- if (!col.equals(other) || !other.equals(col)) {
+ if (!org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor(col, other)) {
getData().backColor = col;
return true;
}
}
/** {@inheritDoc} */
+ @Override
public Object clone() {
AbstractPaintingState state = instantiate();
state.stateStack = new StateStack(this.stateStack);
}
/** {@inheritDoc} */
+ @Override
public String toString() {
return ", stateStack=" + stateStack
+ ", currentData=" + data;
}
/** {@inheritDoc} */
+ @Override
public Object clone() {
AbstractData data = instantiate();
data.color = this.color;
}
/** {@inheritDoc} */
+ @Override
public String toString() {
return "color=" + color
+ ", backColor=" + backColor
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.xmlgraphics.java2d.color.ICCColorSpaceExt;
+import org.apache.xmlgraphics.java2d.color.ICCColorSpaceWithIntent;
+import org.apache.xmlgraphics.java2d.color.RenderingIntent;
/**
* Map with cached ICC based ColorSpace objects.
private static Log log = LogFactory.getLog(ColorSpaceCache.class);
private URIResolver resolver;
- private Map colorSpaceMap = Collections.synchronizedMap(new java.util.HashMap());
+ private Map<String, ColorSpace> colorSpaceMap
+ = Collections.synchronizedMap(new java.util.HashMap<String, ColorSpace>());
/**
* Default constructor
* @param profileName the profile name
* @param base a base URI to resolve relative URIs
* @param iccProfileSrc ICC Profile source to return a ColorSpace for
- * @param renderingIntent overriding rendering intent (see {@link ICCColorSpaceExt}.*)
+ * @param renderingIntent overriding rendering intent
* @return ICC ColorSpace object or null if ColorSpace could not be created
*/
public ColorSpace get(String profileName, String base, String iccProfileSrc,
- int renderingIntent) {
+ RenderingIntent renderingIntent) {
String key = profileName + ":" + base + iccProfileSrc;
ColorSpace colorSpace = null;
if (!colorSpaceMap.containsKey(key)) {
// iccProfile = ICC_Profile.getInstance(iccProfileSrc);
}
if (iccProfile != null) {
- colorSpace = new ICCColorSpaceExt(iccProfile, renderingIntent,
+ colorSpace = new ICCColorSpaceWithIntent(iccProfile, renderingIntent,
profileName, iccProfileSrc);
}
} catch (Exception e) {
log.warn("Color profile '" + iccProfileSrc + "' not found.");
}
} else {
- colorSpace = (ColorSpace)colorSpaceMap.get(key);
+ colorSpace = colorSpaceMap.get(key);
}
return colorSpace;
}
import org.apache.xmlgraphics.java2d.color.ColorSpaces;
import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives;
import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace;
-import org.apache.xmlgraphics.java2d.color.ICCColorSpaceExt;
import org.apache.xmlgraphics.java2d.color.NamedColorSpace;
+import org.apache.xmlgraphics.java2d.color.RenderingIntent;
import org.apache.xmlgraphics.java2d.color.profile.NamedColorProfile;
import org.apache.xmlgraphics.java2d.color.profile.NamedColorProfileParser;
* This map is used to predefine given colors, as well as speeding up
* parsing of already parsed colors.
*/
- private static Map colorMap = null;
+ private static Map<String, Color> colorMap = null;
/** Logger instance */
protected static Log log = LogFactory.getLog(ColorUtil.class);
return null;
}
- Color parsedColor = (Color) colorMap.get(value.toLowerCase());
+ Color parsedColor = colorMap.get(value.toLowerCase());
if (parsedColor == null) {
if (value.startsWith("#")) {
throw new PropertyException("Unknown color format: " + value
+ ". Must be system-color(x)");
}
- return (Color) colorMap.get(value);
+ return colorMap.get(value);
}
/**
/* Ask FOP factory to get ColorSpace for the specified ICC profile source */
if (foUserAgent != null && iccProfileSrc != null) {
assert colorSpace == null;
- int renderingIntent = ICCColorSpaceExt.AUTO; //TODO connect to fo:color-profile
+ RenderingIntent renderingIntent = RenderingIntent.AUTO;
+ //TODO connect to fo:color-profile/@rendering-intent
colorSpace = foUserAgent.getFactory().getColorSpace(iccProfileName,
foUserAgent.getBaseURL(), iccProfileSrc,
renderingIntent);
/* Ask FOP factory to get ColorSpace for the specified ICC profile source */
if (foUserAgent != null && iccProfileSrc != null) {
- int renderingIntent = ICCColorSpaceExt.AUTO; //TODO connect to fo:color-profile
+ RenderingIntent renderingIntent = RenderingIntent.AUTO;
+ //TODO connect to fo:color-profile/@rendering-intent
colorSpace = (ICC_ColorSpace)foUserAgent.getFactory().getColorSpace(
iccProfileName,
foUserAgent.getBaseURL(), iccProfileSrc,
* Initializes the colorMap with some predefined values.
*/
private static void initializeColorMap() {
- colorMap = Collections.synchronizedMap(new java.util.HashMap());
+ colorMap = Collections.synchronizedMap(new java.util.HashMap<String, Color>());
colorMap.put("aliceblue", createColor(240, 248, 255));
colorMap.put("antiquewhite", createColor(250, 235, 215));
import org.apache.xmlgraphics.java2d.color.ColorSpaces;
import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives;
-import org.apache.xmlgraphics.java2d.color.ICCColorSpaceExt;
import org.apache.xmlgraphics.java2d.color.NamedColorSpace;
+import org.apache.xmlgraphics.java2d.color.RenderingIntent;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.FopFactory;
*/
col2 = ColorUtil.parseColorString(null, "fop-rgb-icc(0.5,0.5,0.5,#CMYK,,0.5,0.5,0.5,0.0)");
- assertFalse(col1.equals(col2));
+ assertTrue(col1.equals(col2));
+ assertFalse(org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor(col1, col2));
}
/**
URI sRGBLoc = new URI(
"file:src/java/org/apache/fop/pdf/sRGB%20Color%20Space%20Profile.icm");
ColorSpace cs = fopFactory.getColorSpace("sRGBAlt", null, sRGBLoc.toASCIIString(),
- ICCColorSpaceExt.AUTO);
+ RenderingIntent.AUTO);
assertNotNull("Color profile not found", cs);
FOUserAgent ua = fopFactory.newFOUserAgent();
FopFactory fopFactory = FopFactory.newInstance();
URI ncpLoc = new URI("file:test/resources/color/ncp-example.icc");
ColorSpace cs = fopFactory.getColorSpace("NCP", null, ncpLoc.toASCIIString(),
- ICCColorSpaceExt.AUTO);
+ RenderingIntent.AUTO);
assertNotNull("Color profile not found", cs);
FOUserAgent ua = fopFactory.newFOUserAgent();