ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 436 of file tcpdf_colors.php.

436 {
437 if (substr($color, 0, 1) == '#') {
438 return sprintf("['RGB',%F,%F,%F]", (hexdec(substr($color, 1, 2)) / 255), (hexdec(substr($color, 3, 2)) / 255), (hexdec(substr($color, 5, 2)) / 255));
439 }
440 if (!in_array($color, self::$jscolor)) {
441 // default transparent color
442 $color = $jscolor[0];
443 }
444 return 'color.'.$color;
445 }
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 263 of file tcpdf_colors.php.

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

References 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 405 of file tcpdf_colors.php.

405 {
406 $c = array_values($c);
407 $color = '[';
408 switch (count($c)) {
409 case 4: {
410 // CMYK
411 $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));
412 break;
413 }
414 case 3: {
415 // RGB
416 $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));
417 break;
418 }
419 case 1: {
420 // grayscale
421 $color .= sprintf('%F', (max(0, min(255, floatval($c[0]))) / 255));
422 break;
423 }
424 }
425 $color .= ']';
426 return $color;
427 }

◆ 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 239 of file tcpdf_colors.php.

239 {
240 if (isset($spotc[$name])) {
241 return $spotc[$name];
242 }
243 $color = preg_replace('/[\s]*/', '', $name); // remove extra spaces
244 $color = strtolower($color);
245 if (isset(self::$spotcolor[$color])) {
246 if (!isset($spotc[$name])) {
247 $i = (1 + count($spotc));
248 $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);
249 }
250 return $spotc[self::$spotcolor[$color][4]];
251 }
252 return false;
253 }

Referenced by 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 (
'mytcpdfblack' => array(0, 0, 0, 100, 'My TCPDF Black'),
'mytcpdfred' => array(30, 100, 90, 10, 'My TCPDF Red'),
'mytcpdfgreen' => array(100, 30, 100, 0, 'My TCPDF Green'),
'mytcpdfblue' => array(100, 60, 10, 5, 'My TCPDF Blue'),
'mytcpdfyellow' => array(0, 20, 100, 0, 'My TCPDF Yellow'),
)

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: