Table of contents
Namespace: Com\Tecnick\Color
class Spot extends Web implements SpotRegistryInterface
Extends: Web
Implements: SpotRegistryInterface
Source: src/Spot.php:58
Spot Color class
Extension points: getSpotColor() and the protected resolveSpotColorData(). The registry mutators and the PDF emitters are final.
Types
TLabTriplet
array{0: float, 1: float, 2: float}
TLabRange
array{0: float, 1: float, 2: float, 3: float}
TSpotColor
array{
'i': int,
'n': int,
'name': string,
'color': Cmyk,
'space': 'DeviceCMYK'|'Lab',
'lab': array{
'whitepoint': TLabTriplet,
'blackpoint': TLabTriplet,
'range': TLabRange,
'c0': TLabTriplet,
'model': Lab,
}|null,
}
Constants
DEFAULT_SPOT_COLORS
Array of default Spot colors Color keys must be in lowercase and without spaces.
public const DEFAULT_SPOT_COLORS = ['none' => ['name' => 'None', 'color' => ['cyan' => 0, 'magenta' => 0, 'yellow' => 0, 'key' => 0, 'alpha' => 1]], 'all' => ['name' => 'All', 'color' => ['cyan' => 1, 'magenta' => 1, 'yellow' => 1, 'key' => 1, 'alpha' => 1]], 'cyan' => ['name' => 'Cyan', 'color' => ['cyan' => 1, 'magenta' => 0, 'yellow' => 0, 'key' => 0, 'alpha' => 1]], 'magenta' => ['name' => 'Magenta', 'color' => ['cyan' => 0, 'm
// … truncated, see source
Source: src/Spot.php:75
Methods
addSpotColor()
Add a new spot color or overwrite an existing one with the same name.
final public addSpotColor(string $name, Cmyk $cmyk): string
Parameters:
$name(string): Full name of the spot color.$cmyk(Cmyk): CMYK color object
Returns: string: Spot color key.
Throws:
- Exception: if the name is unusable or the color has already been emitted by getPdfSpotObjects()
Source: src/Spot.php:413
addSpotColorFromArray()
Add a new spot color from an array of CMYK components.
final public addSpotColorFromArray(
string $name,
array<string,int|float|string> $components
): string
Parameters:
$name(string): Full name of the spot color.$components(array<string,int|float|string>): CMYK components.
Returns: string: Spot color key.
Throws:
- Exception: if the name is unusable or the color has already been emitted
- UnknownComponentException: if $components carries a name the CMYK model does not define
Source: src/Spot.php:441
addSpotLabColor()
Add a new Lab-based spot color or overwrite an existing one with the same name.
The optional Lab settings are passed as separate trailing array arguments, in this order: whitepoint, blackpoint, range, col0. For example: addSpotLabColor(‘My Color’, 50.0, 10.0, -20.0, $whitepoint, $blackpoint, $range, $col0); Each option array is read element by element, so a shorter array is allowed and any missing element falls back to its default: D65 whitepoint [0.9505, 1.0, 1.089], zero blackpoint, [-128, 127, -128, 127] range and [100, 0, 0] col0.
NOTE: the stored CMYK equivalent is an approximation computed from the Lab values using the D65 whitepoint; the whitepoint option only affects the PDF Lab color space metadata emitted by getPdfSpotObjects(), not the CMYK fallback.
The range option is clamped to [-128..127], the interval the Lab color model represents.
final public addSpotLabColor(
string $name,
float $lstar,
float $astar,
float $bstar,
array<int,float> $labOptions
): string
Parameters:
$name(string): Full name of the spot color.$lstar(float): Lab L* component in [0..100].$astar(float): Lab a* component.$bstar(float): Lab b* component.$labOptions(array<int,float>): Optional Lab settings: whitepoint, blackpoint, range, col0.
Returns: string: Spot color key.
Throws:
- Exception: if the name is unusable or the color has already been emitted by getPdfSpotObjects()
Source: src/Spot.php:475
encodeSpotColorName()
Encode a spot color name as a PDF name object.
The original name is preserved as-is, including spaces and uppercase letters. Any byte that is not a regular PDF name character is escaped as “#” followed by a 2-digit uppercase hexadecimal code, as required by the PDF name object syntax (ISO 32000-1:2008, 7.3.5). For example “SPOTTYPE 279 C” becomes “SPOTTYPE#20279#20C”.
The result is not truncated to the 127-byte name object limit set by ISO 32000-1:2008, Annex C.2.
final public encodeSpotColorName(string $name): string
Parameters:
$name(string): Full name of the spot color.
Returns: string
Source: src/Spot.php:258
getPdfSpotObjects()
Returns the PDF command to output Spot color objects.
Only the entries emitted here can be listed as a resource by getPdfSpotResources().
final public getPdfSpotObjects(int &$pon): string
Parameters:
$pon(int): Current PDF object number
Returns: string: PDF command
Source: src/Spot.php:626
getPdfSpotResources()
Returns the PDF command to output Spot color resources.
Call getPdfSpotObjects() first: every registered spot color must have been emitted as a PDF object.
final public getPdfSpotResources(): string
Returns: string: PDF command
Throws:
- Exception: if a registered spot color has not been emitted
Source: src/Spot.php:777
getPdfSpotResourcesByKeys()
Returns the PDF command to output the Spot color resources for the given keys.
final public getPdfSpotResourcesByKeys(string[] $keys): string
Parameters:
$keys(string[]): Array of spot color keys.
Returns: string: PDF command
Throws:
- Exception: if a key is not registered or has not been emitted
Source: src/Spot.php:791
getSpotColor()
Return the requested spot color data array, registering it on first use.
A default spot color that is not yet registered is added to the internal registry, so that it is emitted by getPdfSpotObjects() and getPdfSpotResources(). Use resolveSpotColorData() for a lookup with no side effect.
public getSpotColor(string $name): TSpotColor
Parameters:
$name(string): Full name of the spot color.
Returns: TSpotColor
Throws:
- Exception: if the color is not found
Source: src/Spot.php:293
getSpotColorObj()
Return a copy of the requested spot color CMYK object.
final public getSpotColorObj(string $name): Cmyk
Parameters:
$name(string): Full name of the spot color.
Returns: Cmyk
Throws:
- Exception: if the color is not found
Source: src/Spot.php:352
getSpotColors()
Returns the array of spot colors.
The color models are copies of the registered ones.
final public getSpotColors(): array<string,TSpotColor>
Returns: array<string,TSpotColor>
Source: src/Spot.php:202
getSpotLabColorObj()
Return a copy of the requested spot color Lab object.
A CMYK-defined spot color has no Lab metadata, so its Lab equivalent is derived on the fly.
final public getSpotLabColorObj(string $name): Lab
Parameters:
$name(string): Full name of the spot color.
Returns: Lab
Throws:
- Exception: if the color is not found
Source: src/Spot.php:367
normalizeSpotColorName()
Return the normalized case-insensitive version of the spot color name to be used as key.
Every character outside [a-z0-9] is dropped, so names that differ only in punctuation, spacing or accents share a key: ‘Bleu Ciel é’ and ‘Bleu-Ciel’ both normalize to ‘bleuciel’.
final public normalizeSpotColorName(string $name): string
Parameters:
$name(string): Full name of the spot color.
Returns: string
Source: src/Spot.php:238
Inherited members
From Css
From Web
- WEBHEX: Maps WEB safe color names with their hexadecimal representation (#RRGGBBAA).
- extractHexCode(): Extract the hexadecimal code from the input string and add the alpha channel if missing
- getClosestWebColor(): Get the name of the closest web color
- getClosestWebColorByDeltaE(): Get the name of the perceptually closest web color.
- getClosestWebColorByDeltaEFromString(): Get the name of the perceptually closest web color from a color definition string.
- getClosestWebColorFromString(): Get the name of the closest web color from a color definition string.
- getColorObj(): Parse the input color string and return the corresponding color object
- getHexFromName(): Get the color hexadecimal hash code from name
- getLabSquareDistance(): Get the square of the CIE76 color difference between 2 Lab points.
- getNameFromHex(): Get the color name code from hexadecimal hash
- getRgbObjFromHex(): Get the RGB color object from hexadecimal hash
- getRgbObjFromName(): Get the RGB color object from color name
- getRgbSquareDistance(): Get the square of the distance between 2 RGB points
- normalizeValue(): Get the normalized value from [0..$max] to [0..1]
- tryGetColorObj(): Parse the input color string, returning null instead of raising.