Class ColorUtil
java.lang.Object
org.apache.fop.util.ColorUtil
Generic Color helper class.
This class supports parsing string values into color values and creating color values for strings. It provides a list of standard color names.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final StringThe name for the uncalibrated CMYK pseudo-profileKeeps all the predefined and parsed colors.private static final org.apache.commons.logging.LogLogger instancestatic final StringThe name for the Separation pseudo-profile used for spot colors -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor since this is an utility class. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcolorToString(Color color) Creates a re-parsable string representation of the given color.private static ColorcreateColor(int r, int g, int b) private static float[]getICCComponents(ListIterator<String> args) private static ColorgetsRGBFallback(org.apache.xmlgraphics.java2d.color.ColorWithAlternatives color) private static voidInitializes the colorMap with some predefined values.static booleanIndicates whether the color is a gray value.static booleanisPseudoProfile(String colorProfileName) Indicates whether the given color profile name is one of the pseudo-profiles supported by FOP (ex.static ColorlightenColor(Color col, float factor) Lightens up a color for groove, ridge, inset and outset border effects.private static ColorparseAsCIELabColor(FOUserAgent foUserAgent, String value) Parse a color specified using the cie-lab-color() function.private static ColorparseAsCMYK(String value) Parse a color given with the cmyk() function.private static ColorparseAsFopRgbIcc(FOUserAgent foUserAgent, String value) Parse a color specified using the fop-rgb-icc() function.private static ColorparseAsFopRgbNamedColor(FOUserAgent foUserAgent, String value) Parse a color specified using the fop-rgb-named-color() function.private static ColorparseAsJavaAWTColor(String value) Tries to parse the standard java.awt.Color toString output.private static ColorparseAsOCA(String value) private static ColorparseAsRGB(String value) Parse a color given with the rgb() function.private static ColorparseAsSystemColor(String value) Tries to parse a color given with the system-color() function.static ColorparseColorString(FOUserAgent foUserAgent, String value) Creates a color from a given string.private static floatparseComponent(String argument, float min, float max, String function) private static floatparseComponent1(String argument, String function) private static floatparseComponent255(String str, String function) private static ColorparseFallback(ListIterator<String> args, String value) private static ColorparseWithHash(String value) Parse a color given in the #....private static StringtoCIELabFunctionCall(org.apache.xmlgraphics.java2d.color.ColorWithAlternatives color) static ColortoCMYKGrayColor(float black) Creates an uncalibrated CMYK color with the given gray value.private static StringtoFunctionCall(org.apache.xmlgraphics.java2d.color.ColorWithAlternatives color) Create string representation of a fop-rgb-icc (or fop-rgb-named-color) function call from the given color.private static StringtoRGBFunctionCall(Color color) private static ColortoSRGBColor(Color color) private static StringunescapeString(String iccProfileSrc)
-
Field Details
-
CMYK_PSEUDO_PROFILE
The name for the uncalibrated CMYK pseudo-profile- See Also:
-
SEPARATION_PSEUDO_PROFILE
The name for the Separation pseudo-profile used for spot colors- See Also:
-
ALPHA_PSEUDO_PROFILE
- See Also:
-
colorMap
-
log
private static final org.apache.commons.logging.Log logLogger instance
-
-
Constructor Details
-
ColorUtil
private ColorUtil()Private constructor since this is an utility class.
-
-
Method Details
-
parseColorString
public static Color parseColorString(FOUserAgent foUserAgent, String value) throws PropertyException Creates a color from a given string.This function supports a wide variety of inputs.
- #RGB (hex 0..f)
- #RGBA (hex 0..f)
- #RRGGBB (hex 00..ff)
- #RRGGBBAA (hex 00..ff)
- rgb(r,g,b) (0..255 or 0%..100%)
- java.awt.Color[r=r,g=g,b=b] (0..255)
- system-color(colorname)
- transparent
- colorname
- fop-rgb-icc(r,g,b,cs,cs-src,[num]+) (r/g/b: 0..1, num: 0..1)
- cmyk(c,m,y,k) (0..1)
- Parameters:
foUserAgent- FOUserAgent objectvalue- the string to parse.- Returns:
- a Color representing the string if possible
- Throws:
PropertyException- if the string is not parsable or does not follow any of the given formats.
-
parseAsSystemColor
Tries to parse a color given with the system-color() function.- Parameters:
value- the complete line- Returns:
- a color if possible
- Throws:
PropertyException- if the format is wrong.
-
parseAsJavaAWTColor
Tries to parse the standard java.awt.Color toString output.- Parameters:
value- the complete line- Returns:
- a color if possible
- Throws:
PropertyException- if the format is wrong.- See Also:
-
parseAsRGB
Parse a color given with the rgb() function.- Parameters:
value- the complete line- Returns:
- a color if possible
- Throws:
PropertyException- if the format is wrong.
-
parseComponent255
- Throws:
PropertyException
-
parseComponent1
- Throws:
PropertyException
-
parseComponent
private static float parseComponent(String argument, float min, float max, String function) throws PropertyException - Throws:
PropertyException
-
parseFallback
private static Color parseFallback(ListIterator<String> args, String value) throws PropertyException - Throws:
PropertyException
-
parseWithHash
Parse a color given in the #.... format.- Parameters:
value- the complete line- Returns:
- a color if possible
- Throws:
PropertyException- if the format is wrong.
-
parseAsFopRgbIcc
private static Color parseAsFopRgbIcc(FOUserAgent foUserAgent, String value) throws PropertyException Parse a color specified using the fop-rgb-icc() function.- Parameters:
value- the function call- Returns:
- a color if possible
- Throws:
PropertyException- if the format is wrong.
-
getICCComponents
-
parseAsFopRgbNamedColor
private static Color parseAsFopRgbNamedColor(FOUserAgent foUserAgent, String value) throws PropertyException Parse a color specified using the fop-rgb-named-color() function.- Parameters:
value- the function call- Returns:
- a color if possible
- Throws:
PropertyException- if the format is wrong.
-
parseAsCIELabColor
private static Color parseAsCIELabColor(FOUserAgent foUserAgent, String value) throws PropertyException Parse a color specified using the cie-lab-color() function.- Parameters:
value- the function call- Returns:
- a color if possible
- Throws:
PropertyException- if the format is wrong.
-
unescapeString
-
parseAsCMYK
Parse a color given with the cmyk() function.- Parameters:
value- the complete line- Returns:
- a color if possible
- Throws:
PropertyException- if the format is wrong.
-
parseAsOCA
- Throws:
PropertyException
-
colorToString
Creates a re-parsable string representation of the given color.First, the color will be converted into the sRGB colorspace. It will then be printed as #rrggbb, or as #rrrggbbaa if an alpha value is present.
- Parameters:
color- the color to represent.- Returns:
- a re-parsable string representadion.
-
toRGBFunctionCall
-
getsRGBFallback
private static Color getsRGBFallback(org.apache.xmlgraphics.java2d.color.ColorWithAlternatives color) -
toSRGBColor
-
toFunctionCall
private static String toFunctionCall(org.apache.xmlgraphics.java2d.color.ColorWithAlternatives color) Create string representation of a fop-rgb-icc (or fop-rgb-named-color) function call from the given color.- Parameters:
color- the color to turn into a function call- Returns:
- the string representing the internal fop-rgb-icc() or fop-rgb-named-color() function call
-
toCIELabFunctionCall
private static String toCIELabFunctionCall(org.apache.xmlgraphics.java2d.color.ColorWithAlternatives color) -
createColor
-
initializeColorMap
private static void initializeColorMap()Initializes the colorMap with some predefined values. -
lightenColor
-
isPseudoProfile
Indicates whether the given color profile name is one of the pseudo-profiles supported by FOP (ex. #CMYK).- Parameters:
colorProfileName- the color profile name to check- Returns:
- true if the color profile name is of a built-in pseudo-profile
-
isGray
Indicates whether the color is a gray value.- Parameters:
col- the color- Returns:
- true if it is a gray value
-
toCMYKGrayColor
Creates an uncalibrated CMYK color with the given gray value.- Parameters:
black- the gray component (0 - 1)- Returns:
- the CMYK color
-