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