1665 |
raphael |
1 |
<?php
|
|
|
2 |
//============================================================+
|
|
|
3 |
// File name : tcpdf_colors.php
|
|
|
4 |
// Version : 1.0.000
|
|
|
5 |
// Begin : 2002-04-09
|
|
|
6 |
// Last Update : 2013-03-25
|
|
|
7 |
// Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
|
|
|
8 |
// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
|
|
|
9 |
// -------------------------------------------------------------------
|
|
|
10 |
// Copyright (C) 2002-2013 Nicola Asuni - Tecnick.com LTD
|
|
|
11 |
//
|
|
|
12 |
// This file is part of TCPDF software library.
|
|
|
13 |
//
|
|
|
14 |
// TCPDF is free software: you can redistribute it and/or modify it
|
|
|
15 |
// under the terms of the GNU Lesser General Public License as
|
|
|
16 |
// published by the Free Software Foundation, either version 3 of the
|
|
|
17 |
// License, or (at your option) any later version.
|
|
|
18 |
//
|
|
|
19 |
// TCPDF is distributed in the hope that it will be useful, but
|
|
|
20 |
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
21 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
22 |
// See the GNU Lesser General Public License for more details.
|
|
|
23 |
//
|
|
|
24 |
// You should have received a copy of the GNU Lesser General Public License
|
|
|
25 |
// along with TCPDF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
26 |
//
|
|
|
27 |
// See LICENSE.TXT file for more information.
|
|
|
28 |
// -------------------------------------------------------------------
|
|
|
29 |
//
|
|
|
30 |
// Description : Array of WEB safe colors
|
|
|
31 |
//
|
|
|
32 |
//============================================================+
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* @file
|
|
|
36 |
* PHP color class for TCPDF
|
|
|
37 |
* @author Nicola Asuni
|
|
|
38 |
* @package com.tecnick.tcpdf
|
|
|
39 |
*/
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* @class TCPDF_COLORS
|
|
|
43 |
* PHP color class for TCPDF
|
|
|
44 |
* @package com.tecnick.tcpdf
|
|
|
45 |
* @version 1.0.000
|
|
|
46 |
* @author Nicola Asuni - info@tecnick.com
|
|
|
47 |
*/
|
|
|
48 |
class TCPDF_COLORS {
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Array of WEB safe colors
|
|
|
52 |
* @public static
|
|
|
53 |
*/
|
|
|
54 |
public static $webcolor = array (
|
|
|
55 |
'aliceblue' => 'f0f8ff',
|
|
|
56 |
'antiquewhite' => 'faebd7',
|
|
|
57 |
'aqua' => '00ffff',
|
|
|
58 |
'aquamarine' => '7fffd4',
|
|
|
59 |
'azure' => 'f0ffff',
|
|
|
60 |
'beige' => 'f5f5dc',
|
|
|
61 |
'bisque' => 'ffe4c4',
|
|
|
62 |
'black' => '000000',
|
|
|
63 |
'blanchedalmond' => 'ffebcd',
|
|
|
64 |
'blue' => '0000ff',
|
|
|
65 |
'blueviolet' => '8a2be2',
|
|
|
66 |
'brown' => 'a52a2a',
|
|
|
67 |
'burlywood' => 'deb887',
|
|
|
68 |
'cadetblue' => '5f9ea0',
|
|
|
69 |
'chartreuse' => '7fff00',
|
|
|
70 |
'chocolate' => 'd2691e',
|
|
|
71 |
'coral' => 'ff7f50',
|
|
|
72 |
'cornflowerblue' => '6495ed',
|
|
|
73 |
'cornsilk' => 'fff8dc',
|
|
|
74 |
'crimson' => 'dc143c',
|
|
|
75 |
'cyan' => '00ffff',
|
|
|
76 |
'darkblue' => '00008b',
|
|
|
77 |
'darkcyan' => '008b8b',
|
|
|
78 |
'darkgoldenrod' => 'b8860b',
|
|
|
79 |
'dkgray' => 'a9a9a9',
|
|
|
80 |
'darkgray' => 'a9a9a9',
|
|
|
81 |
'darkgrey' => 'a9a9a9',
|
|
|
82 |
'darkgreen' => '006400',
|
|
|
83 |
'darkkhaki' => 'bdb76b',
|
|
|
84 |
'darkmagenta' => '8b008b',
|
|
|
85 |
'darkolivegreen' => '556b2f',
|
|
|
86 |
'darkorange' => 'ff8c00',
|
|
|
87 |
'darkorchid' => '9932cc',
|
|
|
88 |
'darkred' => '8b0000',
|
|
|
89 |
'darksalmon' => 'e9967a',
|
|
|
90 |
'darkseagreen' => '8fbc8f',
|
|
|
91 |
'darkslateblue' => '483d8b',
|
|
|
92 |
'darkslategray' => '2f4f4f',
|
|
|
93 |
'darkslategrey' => '2f4f4f',
|
|
|
94 |
'darkturquoise' => '00ced1',
|
|
|
95 |
'darkviolet' => '9400d3',
|
|
|
96 |
'deeppink' => 'ff1493',
|
|
|
97 |
'deepskyblue' => '00bfff',
|
|
|
98 |
'dimgray' => '696969',
|
|
|
99 |
'dimgrey' => '696969',
|
|
|
100 |
'dodgerblue' => '1e90ff',
|
|
|
101 |
'firebrick' => 'b22222',
|
|
|
102 |
'floralwhite' => 'fffaf0',
|
|
|
103 |
'forestgreen' => '228b22',
|
|
|
104 |
'fuchsia' => 'ff00ff',
|
|
|
105 |
'gainsboro' => 'dcdcdc',
|
|
|
106 |
'ghostwhite' => 'f8f8ff',
|
|
|
107 |
'gold' => 'ffd700',
|
|
|
108 |
'goldenrod' => 'daa520',
|
|
|
109 |
'gray' => '808080',
|
|
|
110 |
'grey' => '808080',
|
|
|
111 |
'green' => '008000',
|
|
|
112 |
'greenyellow' => 'adff2f',
|
|
|
113 |
'honeydew' => 'f0fff0',
|
|
|
114 |
'hotpink' => 'ff69b4',
|
|
|
115 |
'indianred' => 'cd5c5c',
|
|
|
116 |
'indigo' => '4b0082',
|
|
|
117 |
'ivory' => 'fffff0',
|
|
|
118 |
'khaki' => 'f0e68c',
|
|
|
119 |
'lavender' => 'e6e6fa',
|
|
|
120 |
'lavenderblush' => 'fff0f5',
|
|
|
121 |
'lawngreen' => '7cfc00',
|
|
|
122 |
'lemonchiffon' => 'fffacd',
|
|
|
123 |
'lightblue' => 'add8e6',
|
|
|
124 |
'lightcoral' => 'f08080',
|
|
|
125 |
'lightcyan' => 'e0ffff',
|
|
|
126 |
'lightgoldenrodyellow' => 'fafad2',
|
|
|
127 |
'ltgray' => 'd3d3d3',
|
|
|
128 |
'lightgray' => 'd3d3d3',
|
|
|
129 |
'lightgrey' => 'd3d3d3',
|
|
|
130 |
'lightgreen' => '90ee90',
|
|
|
131 |
'lightpink' => 'ffb6c1',
|
|
|
132 |
'lightsalmon' => 'ffa07a',
|
|
|
133 |
'lightseagreen' => '20b2aa',
|
|
|
134 |
'lightskyblue' => '87cefa',
|
|
|
135 |
'lightslategray' => '778899',
|
|
|
136 |
'lightslategrey' => '778899',
|
|
|
137 |
'lightsteelblue' => 'b0c4de',
|
|
|
138 |
'lightyellow' => 'ffffe0',
|
|
|
139 |
'lime' => '00ff00',
|
|
|
140 |
'limegreen' => '32cd32',
|
|
|
141 |
'linen' => 'faf0e6',
|
|
|
142 |
'magenta' => 'ff00ff',
|
|
|
143 |
'maroon' => '800000',
|
|
|
144 |
'mediumaquamarine' => '66cdaa',
|
|
|
145 |
'mediumblue' => '0000cd',
|
|
|
146 |
'mediumorchid' => 'ba55d3',
|
|
|
147 |
'mediumpurple' => '9370d8',
|
|
|
148 |
'mediumseagreen' => '3cb371',
|
|
|
149 |
'mediumslateblue' => '7b68ee',
|
|
|
150 |
'mediumspringgreen' => '00fa9a',
|
|
|
151 |
'mediumturquoise' => '48d1cc',
|
|
|
152 |
'mediumvioletred' => 'c71585',
|
|
|
153 |
'midnightblue' => '191970',
|
|
|
154 |
'mintcream' => 'f5fffa',
|
|
|
155 |
'mistyrose' => 'ffe4e1',
|
|
|
156 |
'moccasin' => 'ffe4b5',
|
|
|
157 |
'navajowhite' => 'ffdead',
|
|
|
158 |
'navy' => '000080',
|
|
|
159 |
'oldlace' => 'fdf5e6',
|
|
|
160 |
'olive' => '808000',
|
|
|
161 |
'olivedrab' => '6b8e23',
|
|
|
162 |
'orange' => 'ffa500',
|
|
|
163 |
'orangered' => 'ff4500',
|
|
|
164 |
'orchid' => 'da70d6',
|
|
|
165 |
'palegoldenrod' => 'eee8aa',
|
|
|
166 |
'palegreen' => '98fb98',
|
|
|
167 |
'paleturquoise' => 'afeeee',
|
|
|
168 |
'palevioletred' => 'd87093',
|
|
|
169 |
'papayawhip' => 'ffefd5',
|
|
|
170 |
'peachpuff' => 'ffdab9',
|
|
|
171 |
'peru' => 'cd853f',
|
|
|
172 |
'pink' => 'ffc0cb',
|
|
|
173 |
'plum' => 'dda0dd',
|
|
|
174 |
'powderblue' => 'b0e0e6',
|
|
|
175 |
'purple' => '800080',
|
|
|
176 |
'red' => 'ff0000',
|
|
|
177 |
'rosybrown' => 'bc8f8f',
|
|
|
178 |
'royalblue' => '4169e1',
|
|
|
179 |
'saddlebrown' => '8b4513',
|
|
|
180 |
'salmon' => 'fa8072',
|
|
|
181 |
'sandybrown' => 'f4a460',
|
|
|
182 |
'seagreen' => '2e8b57',
|
|
|
183 |
'seashell' => 'fff5ee',
|
|
|
184 |
'sienna' => 'a0522d',
|
|
|
185 |
'silver' => 'c0c0c0',
|
|
|
186 |
'skyblue' => '87ceeb',
|
|
|
187 |
'slateblue' => '6a5acd',
|
|
|
188 |
'slategray' => '708090',
|
|
|
189 |
'slategrey' => '708090',
|
|
|
190 |
'snow' => 'fffafa',
|
|
|
191 |
'springgreen' => '00ff7f',
|
|
|
192 |
'steelblue' => '4682b4',
|
|
|
193 |
'tan' => 'd2b48c',
|
|
|
194 |
'teal' => '008080',
|
|
|
195 |
'thistle' => 'd8bfd8',
|
|
|
196 |
'tomato' => 'ff6347',
|
|
|
197 |
'turquoise' => '40e0d0',
|
|
|
198 |
'violet' => 'ee82ee',
|
|
|
199 |
'wheat' => 'f5deb3',
|
|
|
200 |
'white' => 'ffffff',
|
|
|
201 |
'whitesmoke' => 'f5f5f5',
|
|
|
202 |
'yellow' => 'ffff00',
|
|
|
203 |
'yellowgreen' => '9acd32'
|
|
|
204 |
); // end of web colors
|
|
|
205 |
|
|
|
206 |
/**
|
|
|
207 |
* Array of valid JavaScript color names
|
|
|
208 |
* @public static
|
|
|
209 |
*/
|
|
|
210 |
public static $jscolor = array ('transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray');
|
|
|
211 |
|
|
|
212 |
/**
|
|
|
213 |
* Array of Spot colors (C,M,Y,K,name)
|
|
|
214 |
* Color keys must be in lowercase and without spaces.
|
|
|
215 |
* 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.
|
|
|
216 |
* Common industry standard spot colors are: ANPA-COLOR, DIC, FOCOLTONE, GCMI, HKS, PANTONE, TOYO, TRUMATCH.
|
|
|
217 |
* @public static
|
|
|
218 |
*/
|
|
|
219 |
public static $spotcolor = array (
|
|
|
220 |
// the following are just examples, fill the array with your own values
|
|
|
221 |
'mytcpdfblack' => array(0, 0, 0, 100, 'My TCPDF Black'),
|
|
|
222 |
'mytcpdfred' => array(30, 100, 90, 10, 'My TCPDF Red'),
|
|
|
223 |
'mytcpdfgreen' => array(100, 30, 100, 0, 'My TCPDF Green'),
|
|
|
224 |
'mytcpdfblue' => array(100, 60, 10, 5, 'My TCPDF Blue'),
|
|
|
225 |
'mytcpdfyellow' => array(0, 20, 100, 0, 'My TCPDF Yellow'),
|
|
|
226 |
// ...
|
|
|
227 |
); // end of spot colors
|
|
|
228 |
|
|
|
229 |
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
230 |
|
|
|
231 |
/**
|
|
|
232 |
* Return the Spot color array.
|
|
|
233 |
* @param $name (string) Name of the spot color.
|
|
|
234 |
* @param $spotc (array) Reference to an array of spot colors.
|
|
|
235 |
* @return (array) Spot color array or false if not defined.
|
|
|
236 |
* @since 5.9.125 (2011-10-03)
|
|
|
237 |
* @public static
|
|
|
238 |
*/
|
|
|
239 |
public static function getSpotColor($name, &$spotc) {
|
|
|
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 |
}
|
|
|
254 |
|
|
|
255 |
/**
|
|
|
256 |
* 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.
|
|
|
257 |
* @param $hcolor (string) HTML color.
|
|
|
258 |
* @param $spotc (array) Reference to an array of spot colors.
|
|
|
259 |
* @param $defcol (array) Color to return in case of error.
|
|
|
260 |
* @return array RGB or CMYK color, or false in case of error.
|
|
|
261 |
* @public static
|
|
|
262 |
*/
|
|
|
263 |
public static function convertHTMLColorToDec($hcolor, &$spotc, $defcol=array('R'=>128,'G'=>128,'B'=>128)) {
|
|
|
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 |
}
|
|
|
397 |
|
|
|
398 |
/**
|
|
|
399 |
* Convert a color array into a string representation.
|
|
|
400 |
* @param $c (array) Array of colors.
|
|
|
401 |
* @return (string) The color array representation.
|
|
|
402 |
* @since 5.9.137 (2011-12-01)
|
|
|
403 |
* @public static
|
|
|
404 |
*/
|
|
|
405 |
public static function getColorStringFromArray($c) {
|
|
|
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 |
}
|
|
|
428 |
|
|
|
429 |
/**
|
|
|
430 |
* Convert color to javascript color.
|
|
|
431 |
* @param $color (string) color name or "#RRGGBB"
|
|
|
432 |
* @protected
|
|
|
433 |
* @since 2.1.002 (2008-02-12)
|
|
|
434 |
* @public static
|
|
|
435 |
*/
|
|
|
436 |
public static function _JScolor($color) {
|
|
|
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 |
}
|
|
|
446 |
|
|
|
447 |
|
|
|
448 |
} // --- END OF CLASS ---
|
|
|
449 |
|
|
|
450 |
//============================================================+
|
|
|
451 |
// END OF FILE
|
|
|
452 |
//============================================================+
|