Class PDColor
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.graphics.color.PDColor
-
public final class PDColor extends java.lang.Object
A color value, consisting of one or more color components, or for pattern color spaces, a name and optional color components. Color values are not associated with any given color space. Instances of PDColor are immutable.
-
-
Field Summary
Fields Modifier and Type Field Description private PDColorSpace
colorSpace
private float[]
components
private COSName
patternName
-
Constructor Summary
Constructors Constructor Description PDColor(float[] components, COSName patternName, PDColorSpace colorSpace)
Creates a PDColor containing the given color component values and pattern name.PDColor(float[] components, PDColorSpace colorSpace)
Creates a PDColor containing the given color component values.PDColor(COSArray array, PDColorSpace colorSpace)
Creates a PDColor containing the given color value.PDColor(COSName patternName, PDColorSpace colorSpace)
Creates a PDColor containing the given pattern name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PDColorSpace
getColorSpace()
Returns the color space in which this color value is defined.float[]
getComponents()
Returns the components of this color value.COSName
getPatternName()
Returns the pattern name from this color value.boolean
isPattern()
Returns true if this color value is a pattern.COSArray
toCOSArray()
Returns the color component values as a COS arrayint
toRGB()
Returns the packed RGB value for this color, if any.java.lang.String
toString()
-
-
-
Field Detail
-
components
private final float[] components
-
patternName
private final COSName patternName
-
colorSpace
private final PDColorSpace colorSpace
-
-
Constructor Detail
-
PDColor
public PDColor(COSArray array, PDColorSpace colorSpace)
Creates a PDColor containing the given color value.- Parameters:
array
- a COS array containing the color valuecolorSpace
- color space in which the color value is defined
-
PDColor
public PDColor(float[] components, PDColorSpace colorSpace)
Creates a PDColor containing the given color component values.- Parameters:
components
- array of color component valuescolorSpace
- color space in which the components are defined
-
PDColor
public PDColor(COSName patternName, PDColorSpace colorSpace)
Creates a PDColor containing the given pattern name.- Parameters:
patternName
- the name of a pattern in a pattern dictionarycolorSpace
- color space in which the pattern is defined
-
PDColor
public PDColor(float[] components, COSName patternName, PDColorSpace colorSpace)
Creates a PDColor containing the given color component values and pattern name.- Parameters:
components
- array of color component valuespatternName
- the name of a pattern in a pattern dictionarycolorSpace
- color space in which the pattern/components are defined
-
-
Method Detail
-
getComponents
public float[] getComponents()
Returns the components of this color value.- Returns:
- the components of this color value, never null.
-
getPatternName
public COSName getPatternName()
Returns the pattern name from this color value.- Returns:
- the pattern name from this color value
-
isPattern
public boolean isPattern()
Returns true if this color value is a pattern.- Returns:
- true if this color value is a pattern
-
toRGB
public int toRGB() throws java.io.IOException
Returns the packed RGB value for this color, if any.- Returns:
- RGB
- Throws:
java.io.IOException
- if the color conversion failsjava.lang.IllegalStateException
- if this color value is a pattern.
-
toCOSArray
public COSArray toCOSArray()
Returns the color component values as a COS array- Returns:
- the color component values as a COS array
-
getColorSpace
public PDColorSpace getColorSpace()
Returns the color space in which this color value is defined.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-