Pdf extends Spot
in package
Com\Tecnick\Color\Pdf
PDF Color class
Tags
Table of Contents
Constants
- 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, 'magenta' => 1, 'yellow' => 0, 'key' => 0, 'alpha' => 1]], 'yellow' => ['name' => 'Yellow', 'color' => ['cyan' => 0, 'magenta' => 0, 'yellow' => 1, 'key' => 0, 'alpha' => 1]], 'key' => ['name' => 'Key', 'color' => ['cyan' => 0, 'magenta' => 0, 'yellow' => 0, 'key' => 1, 'alpha' => 1]], 'white' => ['name' => 'White', 'color' => ['cyan' => 0, 'magenta' => 0, 'yellow' => 0, 'key' => 0, 'alpha' => 1]], 'black' => ['name' => 'Black', 'color' => ['cyan' => 0, 'magenta' => 0, 'yellow' => 0, 'key' => 1, 'alpha' => 1]], 'red' => ['name' => 'Red', 'color' => ['cyan' => 0, 'magenta' => 1, 'yellow' => 1, 'key' => 0, 'alpha' => 1]], 'green' => ['name' => 'Green', 'color' => ['cyan' => 1, 'magenta' => 0, 'yellow' => 1, 'key' => 0, 'alpha' => 1]], 'blue' => ['name' => 'Blue', 'color' => ['cyan' => 1, 'magenta' => 1, 'yellow' => 0, 'key' => 0, 'alpha' => 1]]]
- Array of default Spot colors Color keys must be in lowercase and without spaces.
- JSCOLOR = ['transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray']
- Array of valid JavaScript color names to be used in PDF documents
- WEBHEX = ['aliceblue' => 'f0f8ffff', 'antiquewhite' => 'faebd7ff', 'aqua' => '00ffffff', 'aquamarine' => '7fffd4ff', 'azure' => 'f0ffffff', 'beige' => 'f5f5dcff', 'bisque' => 'ffe4c4ff', 'black' => '000000ff', 'blanchedalmond' => 'ffebcdff', 'blue' => '0000ffff', 'blueviolet' => '8a2be2ff', 'brown' => 'a52a2aff', 'burlywood' => 'deb887ff', 'cadetblue' => '5f9ea0ff', 'chartreuse' => '7fff00ff', 'chocolate' => 'd2691eff', 'coral' => 'ff7f50ff', 'cornflowerblue' => '6495edff', 'cornsilk' => 'fff8dcff', 'crimson' => 'dc143cff', 'cyan' => '00ffffff', 'darkblue' => '00008bff', 'darkcyan' => '008b8bff', 'darkgoldenrod' => 'b8860bff', 'dkgray' => 'a9a9a9ff', 'darkgray' => 'a9a9a9ff', 'darkgrey' => 'a9a9a9ff', 'darkgreen' => '006400ff', 'darkkhaki' => 'bdb76bff', 'darkmagenta' => '8b008bff', 'darkolivegreen' => '556b2fff', 'darkorange' => 'ff8c00ff', 'darkorchid' => '9932ccff', 'darkred' => '8b0000ff', 'darksalmon' => 'e9967aff', 'darkseagreen' => '8fbc8fff', 'darkslateblue' => '483d8bff', 'darkslategray' => '2f4f4fff', 'darkslategrey' => '2f4f4fff', 'darkturquoise' => '00ced1ff', 'darkviolet' => '9400d3ff', 'deeppink' => 'ff1493ff', 'deepskyblue' => '00bfffff', 'dimgray' => '696969ff', 'dimgrey' => '696969ff', 'dodgerblue' => '1e90ffff', 'firebrick' => 'b22222ff', 'floralwhite' => 'fffaf0ff', 'forestgreen' => '228b22ff', 'fuchsia' => 'ff00ffff', 'gainsboro' => 'dcdcdcff', 'ghostwhite' => 'f8f8ffff', 'gold' => 'ffd700ff', 'goldenrod' => 'daa520ff', 'gray' => '808080ff', 'grey' => '808080ff', 'green' => '008000ff', 'greenyellow' => 'adff2fff', 'honeydew' => 'f0fff0ff', 'hotpink' => 'ff69b4ff', 'indianred' => 'cd5c5cff', 'indigo' => '4b0082ff', 'ivory' => 'fffff0ff', 'khaki' => 'f0e68cff', 'lavender' => 'e6e6faff', 'lavenderblush' => 'fff0f5ff', 'lawngreen' => '7cfc00ff', 'lemonchiffon' => 'fffacdff', 'lightblue' => 'add8e6ff', 'lightcoral' => 'f08080ff', 'lightcyan' => 'e0ffffff', 'lightgoldenrodyellow' => 'fafad2ff', 'ltgray' => 'd3d3d3ff', 'lightgray' => 'd3d3d3ff', 'lightgrey' => 'd3d3d3ff', 'lightgreen' => '90ee90ff', 'lightpink' => 'ffb6c1ff', 'lightsalmon' => 'ffa07aff', 'lightseagreen' => '20b2aaff', 'lightskyblue' => '87cefaff', 'lightslategray' => '778899ff', 'lightslategrey' => '778899ff', 'lightsteelblue' => 'b0c4deff', 'lightyellow' => 'ffffe0ff', 'lime' => '00ff00ff', 'limegreen' => '32cd32ff', 'linen' => 'faf0e6ff', 'magenta' => 'ff00ffff', 'maroon' => '800000ff', 'mediumaquamarine' => '66cdaaff', 'mediumblue' => '0000cdff', 'mediumorchid' => 'ba55d3ff', 'mediumpurple' => '9370d8ff', 'mediumseagreen' => '3cb371ff', 'mediumslateblue' => '7b68eeff', 'mediumspringgreen' => '00fa9aff', 'mediumturquoise' => '48d1ccff', 'mediumvioletred' => 'c71585ff', 'midnightblue' => '191970ff', 'mintcream' => 'f5fffaff', 'mistyrose' => 'ffe4e1ff', 'moccasin' => 'ffe4b5ff', 'navajowhite' => 'ffdeadff', 'navy' => '000080ff', 'oldlace' => 'fdf5e6ff', 'olive' => '808000ff', 'olivedrab' => '6b8e23ff', 'orange' => 'ffa500ff', 'orangered' => 'ff4500ff', 'orchid' => 'da70d6ff', 'palegoldenrod' => 'eee8aaff', 'palegreen' => '98fb98ff', 'paleturquoise' => 'afeeeeff', 'palevioletred' => 'd87093ff', 'papayawhip' => 'ffefd5ff', 'peachpuff' => 'ffdab9ff', 'peru' => 'cd853fff', 'pink' => 'ffc0cbff', 'plum' => 'dda0ddff', 'powderblue' => 'b0e0e6ff', 'purple' => '800080ff', 'red' => 'ff0000ff', 'rosybrown' => 'bc8f8fff', 'royalblue' => '4169e1ff', 'saddlebrown' => '8b4513ff', 'salmon' => 'fa8072ff', 'sandybrown' => 'f4a460ff', 'seagreen' => '2e8b57ff', 'seashell' => 'fff5eeff', 'sienna' => 'a0522dff', 'silver' => 'c0c0c0ff', 'skyblue' => '87ceebff', 'slateblue' => '6a5acdff', 'slategray' => '708090ff', 'slategrey' => '708090ff', 'snow' => 'fffafaff', 'springgreen' => '00ff7fff', 'steelblue' => '4682b4ff', 'tan' => 'd2b48cff', 'teal' => '008080ff', 'thistle' => 'd8bfd8ff', 'tomato' => 'ff6347ff', 'turquoise' => '40e0d0ff', 'violet' => 'ee82eeff', 'wheat' => 'f5deb3ff', 'white' => 'ffffffff', 'whitesmoke' => 'f5f5f5ff', 'yellow' => 'ffff00ff', 'yellowgreen' => '9acd32ff']
- Maps WEB safe color names with theur hexadecimal representation (#RRGGBBAA).
Methods
- addSpotColor() : string
- Add a new spot color or overwrite an existing one with the same name.
- extractHexCode() : string
- Extract the hexadecimal code from the input string and add the alpha channel if missing
- getClosestWebColor() : string
- Get the name of the closest web color
- getColorObj() : Model|null
- Parse the input color string and return the correspondent color Object
- getColorObject() : Model|null
- Returns a color object from an HTML, CSS or Spot color representation.
- getHexFromName() : string
- Get the color hexadecimal hash code from name
- getJsColorString() : string
- Convert color to javascript string
- getNameFromHex() : string
- Get the color name code from hexadecimal hash
- getPdfColor() : string
- Get the color components format used in PDF documents NOTE: the alpha channel is omitted
- getPdfRgbComponents() : string
- Get the RGB color components format used in PDF documents
- getPdfSpotObjects() : string
- Returns the PDF command to output Spot color objects.
- getPdfSpotResources() : string
- Returns the PDF command to output Spot color resources.
- getPdfSpotResourcesByKeys() : string
- Returns the PDF command to output Spot color resources.
- getRgbObjFromHex() : Rgb
- Get the RGB color object from hexadecimal hash
- getRgbObjFromName() : Rgb
- Get the RGB color object from color name
- getRgbSquareDistance() : float
- Get the square of the distance between 2 RGB points
- getSpotColor() : TSpotColor
- Return the requested spot color data array
- getSpotColorObj() : Cmyk
- Return the requested spot color CMYK object
- getSpotColors() : array<string, TSpotColor>
- Returns the array of spot colors.
- normalizeSpotColorName() : string
- Return the normalized version of the spot color name
- normalizeValue() : float
Constants
DEFAULT_SPOT_COLORS
Array of default Spot colors Color keys must be in lowercase and without spaces.
public array<string, array{name:
string, color: array{cyan: int|float, magenta: int|float, yellow:
int|float, key: int|float, alpha: int|float}}>
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, 'magenta' => 1, 'yellow' => 0, 'key' => 0,
'alpha' => 1]], 'yellow' => ['name' => 'Yellow', 'color'
=> ['cyan' => 0, 'magenta' => 0, 'yellow' => 1, 'key'
=> 0, 'alpha' => 1]], 'key' => ['name' => 'Key',
'color' => ['cyan' => 0, 'magenta' => 0, 'yellow' => 0,
'key' => 1, 'alpha' => 1]], 'white' => ['name' =>
'White', 'color' => ['cyan' => 0, 'magenta' => 0, 'yellow'
=> 0, 'key' => 0, 'alpha' => 1]], 'black' => ['name'
=> 'Black', 'color' => ['cyan' => 0, 'magenta' => 0,
'yellow' => 0, 'key' => 1, 'alpha' => 1]], 'red' =>
['name' => 'Red', 'color' => ['cyan' => 0, 'magenta' =>
1, 'yellow' => 1, 'key' => 0, 'alpha' => 1]], 'green'
=> ['name' => 'Green', 'color' => ['cyan' => 1,
'magenta' => 0, 'yellow' => 1, 'key' => 0, 'alpha' =>
1]], 'blue' => ['name' => 'Blue', 'color' => ['cyan' =>
1, 'magenta' => 1, 'yellow' => 0, 'key' => 0, 'alpha'
=> 1]]]
JSCOLOR
Array of valid JavaScript color names to be used in PDF documents
public mixed JSCOLOR = ['transparent', 'black',
'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow',
'dkGray', 'gray', 'ltGray']
WEBHEX
Maps WEB safe color names with theur hexadecimal representation (#RRGGBBAA).
public mixed WEBHEX = ['aliceblue' =>
'f0f8ffff', 'antiquewhite' => 'faebd7ff', 'aqua' =>
'00ffffff', 'aquamarine' => '7fffd4ff', 'azure' =>
'f0ffffff', 'beige' => 'f5f5dcff', 'bisque' => 'ffe4c4ff',
'black' => '000000ff', 'blanchedalmond' => 'ffebcdff', 'blue'
=> '0000ffff', 'blueviolet' => '8a2be2ff', 'brown' =>
'a52a2aff', 'burlywood' => 'deb887ff', 'cadetblue' =>
'5f9ea0ff', 'chartreuse' => '7fff00ff', 'chocolate' =>
'd2691eff', 'coral' => 'ff7f50ff', 'cornflowerblue' =>
'6495edff', 'cornsilk' => 'fff8dcff', 'crimson' =>
'dc143cff', 'cyan' => '00ffffff', 'darkblue' => '00008bff',
'darkcyan' => '008b8bff', 'darkgoldenrod' => 'b8860bff',
'dkgray' => 'a9a9a9ff', 'darkgray' => 'a9a9a9ff', 'darkgrey'
=> 'a9a9a9ff', 'darkgreen' => '006400ff', 'darkkhaki' =>
'bdb76bff', 'darkmagenta' => '8b008bff', 'darkolivegreen' =>
'556b2fff', 'darkorange' => 'ff8c00ff', 'darkorchid' =>
'9932ccff', 'darkred' => '8b0000ff', 'darksalmon' =>
'e9967aff', 'darkseagreen' => '8fbc8fff', 'darkslateblue' =>
'483d8bff', 'darkslategray' => '2f4f4fff', 'darkslategrey' =>
'2f4f4fff', 'darkturquoise' => '00ced1ff', 'darkviolet' =>
'9400d3ff', 'deeppink' => 'ff1493ff', 'deepskyblue' =>
'00bfffff', 'dimgray' => '696969ff', 'dimgrey' => '696969ff',
'dodgerblue' => '1e90ffff', 'firebrick' => 'b22222ff',
'floralwhite' => 'fffaf0ff', 'forestgreen' => '228b22ff',
'fuchsia' => 'ff00ffff', 'gainsboro' => 'dcdcdcff',
'ghostwhite' => 'f8f8ffff', 'gold' => 'ffd700ff', 'goldenrod'
=> 'daa520ff', 'gray' => '808080ff', 'grey' => '808080ff',
'green' => '008000ff', 'greenyellow' => 'adff2fff',
'honeydew' => 'f0fff0ff', 'hotpink' => 'ff69b4ff',
'indianred' => 'cd5c5cff', 'indigo' => '4b0082ff', 'ivory'
=> 'fffff0ff', 'khaki' => 'f0e68cff', 'lavender' =>
'e6e6faff', 'lavenderblush' => 'fff0f5ff', 'lawngreen' =>
'7cfc00ff', 'lemonchiffon' => 'fffacdff', 'lightblue' =>
'add8e6ff', 'lightcoral' => 'f08080ff', 'lightcyan' =>
'e0ffffff', 'lightgoldenrodyellow' => 'fafad2ff', 'ltgray' =>
'd3d3d3ff', 'lightgray' => 'd3d3d3ff', 'lightgrey' =>
'd3d3d3ff', 'lightgreen' => '90ee90ff', 'lightpink' =>
'ffb6c1ff', 'lightsalmon' => 'ffa07aff', 'lightseagreen' =>
'20b2aaff', 'lightskyblue' => '87cefaff', 'lightslategray' =>
'778899ff', 'lightslategrey' => '778899ff', 'lightsteelblue'
=> 'b0c4deff', 'lightyellow' => 'ffffe0ff', 'lime' =>
'00ff00ff', 'limegreen' => '32cd32ff', 'linen' => 'faf0e6ff',
'magenta' => 'ff00ffff', 'maroon' => '800000ff',
'mediumaquamarine' => '66cdaaff', 'mediumblue' => '0000cdff',
'mediumorchid' => 'ba55d3ff', 'mediumpurple' => '9370d8ff',
'mediumseagreen' => '3cb371ff', 'mediumslateblue' =>
'7b68eeff', 'mediumspringgreen' => '00fa9aff', 'mediumturquoise'
=> '48d1ccff', 'mediumvioletred' => 'c71585ff',
'midnightblue' => '191970ff', 'mintcream' => 'f5fffaff',
'mistyrose' => 'ffe4e1ff', 'moccasin' => 'ffe4b5ff',
'navajowhite' => 'ffdeadff', 'navy' => '000080ff', 'oldlace'
=> 'fdf5e6ff', 'olive' => '808000ff', 'olivedrab' =>
'6b8e23ff', 'orange' => 'ffa500ff', 'orangered' =>
'ff4500ff', 'orchid' => 'da70d6ff', 'palegoldenrod' =>
'eee8aaff', 'palegreen' => '98fb98ff', 'paleturquoise' =>
'afeeeeff', 'palevioletred' => 'd87093ff', 'papayawhip' =>
'ffefd5ff', 'peachpuff' => 'ffdab9ff', 'peru' => 'cd853fff',
'pink' => 'ffc0cbff', 'plum' => 'dda0ddff', 'powderblue'
=> 'b0e0e6ff', 'purple' => '800080ff', 'red' =>
'ff0000ff', 'rosybrown' => 'bc8f8fff', 'royalblue' =>
'4169e1ff', 'saddlebrown' => '8b4513ff', 'salmon' =>
'fa8072ff', 'sandybrown' => 'f4a460ff', 'seagreen' =>
'2e8b57ff', 'seashell' => 'fff5eeff', 'sienna' => 'a0522dff',
'silver' => 'c0c0c0ff', 'skyblue' => '87ceebff', 'slateblue'
=> '6a5acdff', 'slategray' => '708090ff', 'slategrey' =>
'708090ff', 'snow' => 'fffafaff', 'springgreen' =>
'00ff7fff', 'steelblue' => '4682b4ff', 'tan' => 'd2b48cff',
'teal' => '008080ff', 'thistle' => 'd8bfd8ff', 'tomato' =>
'ff6347ff', 'turquoise' => '40e0d0ff', 'violet' =>
'ee82eeff', 'wheat' => 'f5deb3ff', 'white' => 'ffffffff',
'whitesmoke' => 'f5f5f5ff', 'yellow' => 'ffff00ff',
'yellowgreen' => '9acd32ff']
Methods
addSpotColor()
Add a new spot color or overwrite an existing one with the same name.
public addSpotColor(string $name,
Cmyk $cmyk)
: string
Parameters
- $name : string
-
Full name of the spot color.
- $cmyk : Cmyk
-
CMYK color object
Return values
string —Spot color key.
extractHexCode()
Extract the hexadecimal code from the input string and add the alpha channel if missing
public extractHexCode(string $hex)
: string
Parameters
- $hex : string
-
string containing the hexadecimal color hash (i.e. #RGB, #RGBA, #RRGGBB, #RRGGBBAA)
Tags
Return values
string —the hash code (e.g.: '40e0d0')
getClosestWebColor()
Get the name of the closest web color
public getClosestWebColor(array<string,
float> $col)
: string
Parameters
- $col : array<string, float>
-
Color as RGB array (keys: 'red', 'green', 'blue')
Return values
stringgetColorObj()
Parse the input color string and return the correspondent color Object
public getColorObj(string $color)
:
Model|null
Parameters
- $color : string
-
String containing web color definition
Tags
Return values
Model|nullgetColorObject()
Returns a color object from an HTML, CSS or Spot color representation.
public getColorObject(string $color)
:
Model|null
Parameters
- $color : string
-
HTML, CSS or Spot color to parse
Return values
Model|nullgetHexFromName()
Get the color hexadecimal hash code from name
public getHexFromName(string $name)
: string
Parameters
- $name : string
-
Name of the color to search (e.g.: 'turquoise')
Tags
Return values
string —color hexadecimal code (e.g.: '40e0d0ff')
getJsColorString()
Convert color to javascript string
public getJsColorString(string $color)
: string
Parameters
- $color : string
-
color name or color object
Return values
stringgetNameFromHex()
Get the color name code from hexadecimal hash
public getNameFromHex(string $hex)
: string
Parameters
- $hex : string
-
hexadecimal color hash (i.e. #RRGGBBAA)
Tags
Return values
string —color name
getPdfColor()
Get the color components format used in PDF documents NOTE: the alpha channel is omitted
public getPdfColor(string $color[,
bool $stroke
= false
][,
float $tint
= 1
]) : string
Parameters
- $color : string
-
HTML, CSS or Spot color to parse
- $stroke : bool = false
-
True for stroking (lines, drawing) and false for non-stroking (text and area filling).
- $tint : float = 1
-
Intensity of the color (from 0 to 1; 1 = full intensity).
Return values
stringgetPdfRgbComponents()
Get the RGB color components format used in PDF documents
public getPdfRgbComponents(string $color)
: string
Parameters
- $color : string
-
HTML, CSS or Spot color to parse
Return values
stringgetPdfSpotObjects()
Returns the PDF command to output Spot color objects.
public getPdfSpotObjects(int &$pon)
: string
Parameters
- $pon : int
-
Current PDF object number
Return values
string —PDF command
getPdfSpotResources()
Returns the PDF command to output Spot color resources.
public getPdfSpotResources()
: string
Return values
string —PDF command
getPdfSpotResourcesByKeys()
Returns the PDF command to output Spot color resources.
public getPdfSpotResourcesByKeys(array<string|int,
string> $keys)
: string
Parameters
- $keys : array<string|int, string>
-
Array of font keys.
Return values
string —PDF command
getRgbObjFromHex()
Get the RGB color object from hexadecimal hash
public getRgbObjFromHex(string $hex)
:
Rgb
Parameters
- $hex : string
-
hexadecimal color hash (i.e. #RGB, #RGBA, #RRGGBB, #RRGGBBAA)
Tags
Return values
RgbgetRgbObjFromName()
Get the RGB color object from color name
public getRgbObjFromName(string $name)
:
Rgb
Parameters
- $name : string
-
Color name
Tags
Return values
Rgb —object
getRgbSquareDistance()
Get the square of the distance between 2 RGB points
public getRgbSquareDistance(array<string,
float> $cola,
array<string,
float> $colb)
: float
Parameters
- $cola : array<string, float>
-
First color as RGB array
- $colb : array<string, float>
-
Second color as RGB array
Return values
floatgetSpotColor()
Return the requested spot color data array
public getSpotColor(string $name)
: TSpotColor
Parameters
- $name : string
-
Full name of the spot color.
Tags
Return values
TSpotColorgetSpotColorObj()
Return the requested spot color CMYK object
public getSpotColorObj(string $name)
:
Cmyk
Parameters
- $name : string
-
Full name of the spot color.
Tags
Return values
CmykgetSpotColors()
Returns the array of spot colors.
public getSpotColors()
: array<string,
TSpotColor>
Return values
array<string, TSpotColor>normalizeSpotColorName()
Return the normalized version of the spot color name
public normalizeSpotColorName(string $name)
: string
Parameters
- $name : string
-
Full name of the spot color.
Return values
stringnormalizeValue()
public abstract normalizeValue(mixed $value,
int $max)
: float
Parameters
- $value : mixed
- $max : int