ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
TCPDF_COLORS Class Reference

PHP color class for TCPDF. More...

+ Collaboration diagram for TCPDF_COLORS:

Static Public Member Functions

static getSpotColor ($name, &$spotc)
 Return the Spot color array. More...
 
static convertHTMLColorToDec ($hcolor, &$spotc, $defcol=array('R'=>128, 'G'=>128, 'B'=>128))
 Returns an array (RGB or CMYK) from an html color name, or a six-digit (i.e. More...
 
static getColorStringFromArray ($c)
 Convert a color array into a string representation. More...
 
static _JScolor ($color)
 Convert color to javascript color. More...
 

Static Public Attributes

static $webcolor
 Array of WEB safe colors static. More...
 
static $jscolor = array ('transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray')
 Array of valid JavaScript color names static. More...
 
static $spotcolor
 Array of Spot colors (C,M,Y,K,name) Color keys must be in lowercase and without spaces. More...
 

Detailed Description

PHP color class for TCPDF.

Definition at line 48 of file tcpdf_colors.php.

Member Function Documentation

◆ _JScolor()

static TCPDF_COLORS::_JScolor (   $color)
static

Convert color to javascript color.

Parameters
$color(string) color name or "#RRGGBB"
Since
2.1.002 (2008-02-12) static

Definition at line 446 of file tcpdf_colors.php.

446 {
447 if (substr($color, 0, 1) == '#') {
448 return sprintf("['RGB',%F,%F,%F]", (hexdec(substr($color, 1, 2)) / 255), (hexdec(substr($color, 3, 2)) / 255), (hexdec(substr($color, 5, 2)) / 255));
449 }
450 if (!in_array($color, self::$jscolor)) {
451 // default transparent color
452 $color = $jscolor[0];
453 }
454 return 'color.'.$color;
455 }
static $jscolor
Array of valid JavaScript color names static.

References $jscolor.

Referenced by TCPDF\_addfield().

+ Here is the caller graph for this function:

◆ convertHTMLColorToDec()

static TCPDF_COLORS::convertHTMLColorToDec (   $hcolor,
$spotc,
  $defcol = array('R'=>128,'G'=>128,'B'=>128) 
)
static

Returns an array (RGB or CMYK) from an html color name, or a six-digit (i.e.

#3FE5AA), or three-digit (i.e. #7FF) hexadecimal color, or a javascript color array, or javascript color name.

Parameters
$hcolor(string) HTML color.
$spotc(array) Reference to an array of spot colors.
$defcol(array) Color to return in case of error.
Returns
array RGB or CMYK color, or false in case of error. static

Definition at line 273 of file tcpdf_colors.php.

273 {
274 $color = preg_replace('/[\s]*/', '', $hcolor); // remove extra spaces
275 $color = strtolower($color);
276 // check for javascript color array syntax
277 if (strpos($color, '[') !== false) {
278 if (preg_match('/[\[][\"\'](t|g|rgb|cmyk)[\"\'][\,]?([0-9\.]*)[\,]?([0-9\.]*)[\,]?([0-9\.]*)[\,]?([0-9\.]*)[\]]/', $color, $m) > 0) {
279 $returncolor = array();
280 switch ($m[1]) {
281 case 'cmyk': {
282 // RGB
283 $returncolor['C'] = max(0, min(100, (floatval($m[2]) * 100)));
284 $returncolor['M'] = max(0, min(100, (floatval($m[3]) * 100)));
285 $returncolor['Y'] = max(0, min(100, (floatval($m[4]) * 100)));
286 $returncolor['K'] = max(0, min(100, (floatval($m[5]) * 100)));
287 break;
288 }
289 case 'rgb': {
290 // RGB
291 $returncolor['R'] = max(0, min(255, (floatval($m[2]) * 255)));
292 $returncolor['G'] = max(0, min(255, (floatval($m[3]) * 255)));
293 $returncolor['B'] = max(0, min(255, (floatval($m[4]) * 255)));
294 break;
295 }
296 case 'g': {
297 // grayscale
298 $returncolor['G'] = max(0, min(255, (floatval($m[2]) * 255)));
299 break;
300 }
301 case 't':
302 default: {
303 // transparent (empty array)
304 break;
305 }
306 }
307 return $returncolor;
308 }
309 } elseif ((substr($color, 0, 4) != 'cmyk') AND (substr($color, 0, 3) != 'rgb') AND (($dotpos = strpos($color, '.')) !== false)) {
310 // remove class parent (i.e.: color.red)
311 $color = substr($color, ($dotpos + 1));
312 if ($color == 'transparent') {
313 // transparent (empty array)
314 return array();
315 }
316 }
317 if (strlen($color) == 0) {
318 return $defcol;
319 }
320 // RGB ARRAY
321 if (substr($color, 0, 3) == 'rgb') {
322 $codes = substr($color, 4);
323 $codes = str_replace(')', '', $codes);
324 $returncolor = explode(',', $codes);
325 foreach ($returncolor as $key => $val) {
326 if (strpos($val, '%') > 0) {
327 // percentage
328 $returncolor[$key] = (255 * intval($val) / 100);
329 } else {
330 $returncolor[$key] = intval($val);
331 }
332 // normalize value
333 $returncolor[$key] = max(0, min(255, $returncolor[$key]));
334 }
335 return $returncolor;
336 }
337 // CMYK ARRAY
338 if (substr($color, 0, 4) == 'cmyk') {
339 $codes = substr($color, 5);
340 $codes = str_replace(')', '', $codes);
341 $returncolor = explode(',', $codes);
342 foreach ($returncolor as $key => $val) {
343 if (strpos($val, '%') !== false) {
344 // percentage
345 $returncolor[$key] = (100 * intval($val) / 100);
346 } else {
347 $returncolor[$key] = intval($val);
348 }
349 // normalize value
350 $returncolor[$key] = max(0, min(100, $returncolor[$key]));
351 }
352 return $returncolor;
353 }
354 if ($color[0] != '#') {
355 // COLOR NAME
356 if (isset(self::$webcolor[$color])) {
357 // web color
358 $color_code = self::$webcolor[$color];
359 } else {
360 // spot color
361 $returncolor = self::getSpotColor($color, $spotc);
362 if ($returncolor === false) {
363 $returncolor = $defcol;
364 }
365 return $returncolor;
366 }
367 } else {
368 $color_code = substr($color, 1);
369 }
370 // HEXADECIMAL REPRESENTATION
371 switch (strlen($color_code)) {
372 case 3: {
373 // 3-digit RGB hexadecimal representation
374 $r = substr($color_code, 0, 1);
375 $g = substr($color_code, 1, 1);
376 $b = substr($color_code, 2, 1);
377 $returncolor = array();
378 $returncolor['R'] = max(0, min(255, hexdec($r.$r)));
379 $returncolor['G'] = max(0, min(255, hexdec($g.$g)));
380 $returncolor['B'] = max(0, min(255, hexdec($b.$b)));
381 break;
382 }
383 case 6: {
384 // 6-digit RGB hexadecimal representation
385 $returncolor = array();
386 $returncolor['R'] = max(0, min(255, hexdec(substr($color_code, 0, 2))));
387 $returncolor['G'] = max(0, min(255, hexdec(substr($color_code, 2, 2))));
388 $returncolor['B'] = max(0, min(255, hexdec(substr($color_code, 4, 2))));
389 break;
390 }
391 case 8: {
392 // 8-digit CMYK hexadecimal representation
393 $returncolor = array();
394 $returncolor['C'] = max(0, min(100, round(hexdec(substr($color_code, 0, 2)) / 2.55)));
395 $returncolor['M'] = max(0, min(100, round(hexdec(substr($color_code, 2, 2)) / 2.55)));
396 $returncolor['Y'] = max(0, min(100, round(hexdec(substr($color_code, 4, 2)) / 2.55)));
397 $returncolor['K'] = max(0, min(100, round(hexdec(substr($color_code, 6, 2)) / 2.55)));
398 break;
399 }
400 default: {
401 $returncolor = $defcol;
402 break;
403 }
404 }
405 return $returncolor;
406 }
static getSpotColor($name, &$spotc)
Return the Spot color array.
$r
Definition: example_031.php:79

References $r, and getSpotColor().

Referenced by TCPDF_STATIC\getAnnotOptFromJSProp(), TCPDF\getCSSBorderStyle(), TCPDF\getHtmlDomArray(), TCPDF\setSVGStyles(), and TCPDF\startSVGElementHandler().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getColorStringFromArray()

static TCPDF_COLORS::getColorStringFromArray (   $c)
static

Convert a color array into a string representation.

Parameters
$c(array) Array of colors.
Returns
(string) The color array representation.
Since
5.9.137 (2011-12-01) static

Definition at line 415 of file tcpdf_colors.php.

415 {
416 $c = array_values($c);
417 $color = '[';
418 switch (count($c)) {
419 case 4: {
420 // CMYK
421 $color .= sprintf('%F %F %F %F', (max(0, min(100, floatval($c[0]))) / 100), (max(0, min(100, floatval($c[1]))) / 100), (max(0, min(100, floatval($c[2]))) / 100), (max(0, min(100, floatval($c[3]))) / 100));
422 break;
423 }
424 case 3: {
425 // RGB
426 $color .= sprintf('%F %F %F', (max(0, min(255, floatval($c[0]))) / 255), (max(0, min(255, floatval($c[1]))) / 255), (max(0, min(255, floatval($c[2]))) / 255));
427 break;
428 }
429 case 1: {
430 // grayscale
431 $color .= sprintf('%F', (max(0, min(255, floatval($c[0]))) / 255));
432 break;
433 }
434 }
435 $color .= ']';
436 return $color;
437 }

◆ getSpotColor()

static TCPDF_COLORS::getSpotColor (   $name,
$spotc 
)
static

Return the Spot color array.

Parameters
$name(string) Name of the spot color.
$spotc(array) Reference to an array of spot colors.
Returns
(array) Spot color array or false if not defined.
Since
5.9.125 (2011-10-03) static

Definition at line 249 of file tcpdf_colors.php.

249 {
250 if (isset($spotc[$name])) {
251 return $spotc[$name];
252 }
253 $color = preg_replace('/[\s]*/', '', $name); // remove extra spaces
254 $color = strtolower($color);
255 if (isset(self::$spotcolor[$color])) {
256 if (!isset($spotc[$name])) {
257 $i = (1 + count($spotc));
258 $spotc[$name] = array('C' => self::$spotcolor[$color][0], 'M' => self::$spotcolor[$color][1], 'Y' => self::$spotcolor[$color][2], 'K' => self::$spotcolor[$color][3], 'name' => self::$spotcolor[$color][4], 'i' => $i);
259 }
260 return $spotc[self::$spotcolor[$color][4]];
261 }
262 return false;
263 }

Referenced by TCPDF\colorRegistrationBar(), convertHTMLColorToDec(), and TCPDF\setSpotColor().

+ Here is the caller graph for this function:

Field Documentation

◆ $jscolor

TCPDF_COLORS::$jscolor = array ('transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray')
static

Array of valid JavaScript color names static.

Definition at line 210 of file tcpdf_colors.php.

Referenced by _JScolor().

◆ $spotcolor

TCPDF_COLORS::$spotcolor
static
Initial value:
= array (
'none' => array( 0, 0, 0, 0, 'None'),
'all' => array(100, 100, 100, 100, 'All'),
'cyan' => array(100, 0, 0, 0, 'Cyan'),
'magenta' => array( 0, 100, 0, 0, 'Magenta'),
'yellow' => array( 0, 0, 100, 0, 'Yellow'),
'key' => array( 0, 0, 0, 100, 'Key'),
'white' => array( 0, 0, 0, 0, 'White'),
'black' => array( 0, 0, 0, 100, 'Black'),
'red' => array( 0, 100, 100, 0, 'Red'),
'green' => array(100, 0, 100, 0, 'Green'),
'blue' => array(100, 100, 0, 0, 'Blue'),
)

Array of Spot colors (C,M,Y,K,name) Color keys must be in lowercase and without spaces.

As long as no open standard for spot colours exists, you have to buy a colour book by one of the colour manufacturers and insert the values and names of spot colours directly. Common industry standard spot colors are: ANPA-COLOR, DIC, FOCOLTONE, GCMI, HKS, PANTONE, TOYO, TRUMATCH. static

Definition at line 219 of file tcpdf_colors.php.

◆ $webcolor

TCPDF_COLORS::$webcolor
static

Array of WEB safe colors static.

Definition at line 54 of file tcpdf_colors.php.


The documentation for this class was generated from the following file: