Updated gui for user facility settings (#1327)
[openemr.git] / vendor / phpoffice / phpexcel / Classes / PHPExcel / Style / Color.php
bloba56c9a6338b9c6d85b2d8a07d458846705c7f667
1 <?php
2 /**
3 * PHPExcel
5 * Copyright (c) 2006 - 2014 PHPExcel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * @category PHPExcel
22 * @package PHPExcel_Style
23 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version ##VERSION##, ##DATE##
29 /**
30 * PHPExcel_Style_Color
32 * @category PHPExcel
33 * @package PHPExcel_Style
34 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
36 class PHPExcel_Style_Color extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable
38 /* Colors */
39 const COLOR_BLACK = 'FF000000';
40 const COLOR_WHITE = 'FFFFFFFF';
41 const COLOR_RED = 'FFFF0000';
42 const COLOR_DARKRED = 'FF800000';
43 const COLOR_BLUE = 'FF0000FF';
44 const COLOR_DARKBLUE = 'FF000080';
45 const COLOR_GREEN = 'FF00FF00';
46 const COLOR_DARKGREEN = 'FF008000';
47 const COLOR_YELLOW = 'FFFFFF00';
48 const COLOR_DARKYELLOW = 'FF808000';
50 /**
51 * Indexed colors array
53 * @var array
55 protected static $_indexedColors;
57 /**
58 * ARGB - Alpha RGB
60 * @var string
62 protected $_argb = NULL;
64 /**
65 * Parent property name
67 * @var string
69 protected $_parentPropertyName;
72 /**
73 * Create a new PHPExcel_Style_Color
75 * @param string $pARGB ARGB value for the colour
76 * @param boolean $isSupervisor Flag indicating if this is a supervisor or not
77 * Leave this value at default unless you understand exactly what
78 * its ramifications are
79 * @param boolean $isConditional Flag indicating if this is a conditional style or not
80 * Leave this value at default unless you understand exactly what
81 * its ramifications are
83 public function __construct($pARGB = PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor = FALSE, $isConditional = FALSE)
85 // Supervisor?
86 parent::__construct($isSupervisor);
88 // Initialise values
89 if (!$isConditional) {
90 $this->_argb = $pARGB;
94 /**
95 * Bind parent. Only used for supervisor
97 * @param mixed $parent
98 * @param string $parentPropertyName
99 * @return PHPExcel_Style_Color
101 public function bindParent($parent, $parentPropertyName=NULL)
103 $this->_parent = $parent;
104 $this->_parentPropertyName = $parentPropertyName;
105 return $this;
109 * Get the shared style component for the currently active cell in currently active sheet.
110 * Only used for style supervisor
112 * @return PHPExcel_Style_Color
114 public function getSharedComponent()
116 switch ($this->_parentPropertyName) {
117 case '_endColor':
118 return $this->_parent->getSharedComponent()->getEndColor(); break;
119 case '_color':
120 return $this->_parent->getSharedComponent()->getColor(); break;
121 case '_startColor':
122 return $this->_parent->getSharedComponent()->getStartColor(); break;
127 * Build style array from subcomponents
129 * @param array $array
130 * @return array
132 public function getStyleArray($array)
134 switch ($this->_parentPropertyName) {
135 case '_endColor':
136 $key = 'endcolor';
137 break;
138 case '_color':
139 $key = 'color';
140 break;
141 case '_startColor':
142 $key = 'startcolor';
143 break;
146 return $this->_parent->getStyleArray(array($key => $array));
150 * Apply styles from array
152 * <code>
153 * $objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray( array('rgb' => '808080') );
154 * </code>
156 * @param array $pStyles Array containing style information
157 * @throws PHPExcel_Exception
158 * @return PHPExcel_Style_Color
160 public function applyFromArray($pStyles = NULL) {
161 if (is_array($pStyles)) {
162 if ($this->_isSupervisor) {
163 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
164 } else {
165 if (array_key_exists('rgb', $pStyles)) {
166 $this->setRGB($pStyles['rgb']);
168 if (array_key_exists('argb', $pStyles)) {
169 $this->setARGB($pStyles['argb']);
172 } else {
173 throw new PHPExcel_Exception("Invalid style array passed.");
175 return $this;
179 * Get ARGB
181 * @return string
183 public function getARGB() {
184 if ($this->_isSupervisor) {
185 return $this->getSharedComponent()->getARGB();
187 return $this->_argb;
191 * Set ARGB
193 * @param string $pValue
194 * @return PHPExcel_Style_Color
196 public function setARGB($pValue = PHPExcel_Style_Color::COLOR_BLACK) {
197 if ($pValue == '') {
198 $pValue = PHPExcel_Style_Color::COLOR_BLACK;
200 if ($this->_isSupervisor) {
201 $styleArray = $this->getStyleArray(array('argb' => $pValue));
202 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
203 } else {
204 $this->_argb = $pValue;
206 return $this;
210 * Get RGB
212 * @return string
214 public function getRGB() {
215 if ($this->_isSupervisor) {
216 return $this->getSharedComponent()->getRGB();
218 return substr($this->_argb, 2);
222 * Set RGB
224 * @param string $pValue RGB value
225 * @return PHPExcel_Style_Color
227 public function setRGB($pValue = '000000') {
228 if ($pValue == '') {
229 $pValue = '000000';
231 if ($this->_isSupervisor) {
232 $styleArray = $this->getStyleArray(array('argb' => 'FF' . $pValue));
233 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
234 } else {
235 $this->_argb = 'FF' . $pValue;
237 return $this;
241 * Get a specified colour component of an RGB value
243 * @private
244 * @param string $RGB The colour as an RGB value (e.g. FF00CCCC or CCDDEE
245 * @param int $offset Position within the RGB value to extract
246 * @param boolean $hex Flag indicating whether the component should be returned as a hex or a
247 * decimal value
248 * @return string The extracted colour component
250 private static function _getColourComponent($RGB,$offset,$hex=TRUE) {
251 $colour = substr($RGB, $offset, 2);
252 if (!$hex)
253 $colour = hexdec($colour);
254 return $colour;
258 * Get the red colour component of an RGB value
260 * @param string $RGB The colour as an RGB value (e.g. FF00CCCC or CCDDEE
261 * @param boolean $hex Flag indicating whether the component should be returned as a hex or a
262 * decimal value
263 * @return string The red colour component
265 public static function getRed($RGB,$hex=TRUE) {
266 return self::_getColourComponent($RGB, strlen($RGB) - 6, $hex);
270 * Get the green colour component of an RGB value
272 * @param string $RGB The colour as an RGB value (e.g. FF00CCCC or CCDDEE
273 * @param boolean $hex Flag indicating whether the component should be returned as a hex or a
274 * decimal value
275 * @return string The green colour component
277 public static function getGreen($RGB,$hex=TRUE) {
278 return self::_getColourComponent($RGB, strlen($RGB) - 4, $hex);
282 * Get the blue colour component of an RGB value
284 * @param string $RGB The colour as an RGB value (e.g. FF00CCCC or CCDDEE
285 * @param boolean $hex Flag indicating whether the component should be returned as a hex or a
286 * decimal value
287 * @return string The blue colour component
289 public static function getBlue($RGB,$hex=TRUE) {
290 return self::_getColourComponent($RGB, strlen($RGB) - 2, $hex);
294 * Adjust the brightness of a color
296 * @param string $hex The colour as an RGBA or RGB value (e.g. FF00CCCC or CCDDEE)
297 * @param float $adjustPercentage The percentage by which to adjust the colour as a float from -1 to 1
298 * @return string The adjusted colour as an RGBA or RGB value (e.g. FF00CCCC or CCDDEE)
300 public static function changeBrightness($hex, $adjustPercentage) {
301 $rgba = (strlen($hex) == 8);
303 $red = self::getRed($hex, FALSE);
304 $green = self::getGreen($hex, FALSE);
305 $blue = self::getBlue($hex, FALSE);
306 if ($adjustPercentage > 0) {
307 $red += (255 - $red) * $adjustPercentage;
308 $green += (255 - $green) * $adjustPercentage;
309 $blue += (255 - $blue) * $adjustPercentage;
310 } else {
311 $red += $red * $adjustPercentage;
312 $green += $green * $adjustPercentage;
313 $blue += $blue * $adjustPercentage;
316 if ($red < 0) $red = 0;
317 elseif ($red > 255) $red = 255;
318 if ($green < 0) $green = 0;
319 elseif ($green > 255) $green = 255;
320 if ($blue < 0) $blue = 0;
321 elseif ($blue > 255) $blue = 255;
323 $rgb = strtoupper( str_pad(dechex($red), 2, '0', 0) .
324 str_pad(dechex($green), 2, '0', 0) .
325 str_pad(dechex($blue), 2, '0', 0)
327 return (($rgba) ? 'FF' : '') . $rgb;
331 * Get indexed color
333 * @param int $pIndex Index entry point into the colour array
334 * @param boolean $background Flag to indicate whether default background or foreground colour
335 * should be returned if the indexed colour doesn't exist
336 * @return PHPExcel_Style_Color
338 public static function indexedColor($pIndex, $background=FALSE) {
339 // Clean parameter
340 $pIndex = intval($pIndex);
342 // Indexed colors
343 if (is_null(self::$_indexedColors)) {
344 self::$_indexedColors = array(
345 1 => 'FF000000', // System Colour #1 - Black
346 2 => 'FFFFFFFF', // System Colour #2 - White
347 3 => 'FFFF0000', // System Colour #3 - Red
348 4 => 'FF00FF00', // System Colour #4 - Green
349 5 => 'FF0000FF', // System Colour #5 - Blue
350 6 => 'FFFFFF00', // System Colour #6 - Yellow
351 7 => 'FFFF00FF', // System Colour #7- Magenta
352 8 => 'FF00FFFF', // System Colour #8- Cyan
353 9 => 'FF800000', // Standard Colour #9
354 10 => 'FF008000', // Standard Colour #10
355 11 => 'FF000080', // Standard Colour #11
356 12 => 'FF808000', // Standard Colour #12
357 13 => 'FF800080', // Standard Colour #13
358 14 => 'FF008080', // Standard Colour #14
359 15 => 'FFC0C0C0', // Standard Colour #15
360 16 => 'FF808080', // Standard Colour #16
361 17 => 'FF9999FF', // Chart Fill Colour #17
362 18 => 'FF993366', // Chart Fill Colour #18
363 19 => 'FFFFFFCC', // Chart Fill Colour #19
364 20 => 'FFCCFFFF', // Chart Fill Colour #20
365 21 => 'FF660066', // Chart Fill Colour #21
366 22 => 'FFFF8080', // Chart Fill Colour #22
367 23 => 'FF0066CC', // Chart Fill Colour #23
368 24 => 'FFCCCCFF', // Chart Fill Colour #24
369 25 => 'FF000080', // Chart Line Colour #25
370 26 => 'FFFF00FF', // Chart Line Colour #26
371 27 => 'FFFFFF00', // Chart Line Colour #27
372 28 => 'FF00FFFF', // Chart Line Colour #28
373 29 => 'FF800080', // Chart Line Colour #29
374 30 => 'FF800000', // Chart Line Colour #30
375 31 => 'FF008080', // Chart Line Colour #31
376 32 => 'FF0000FF', // Chart Line Colour #32
377 33 => 'FF00CCFF', // Standard Colour #33
378 34 => 'FFCCFFFF', // Standard Colour #34
379 35 => 'FFCCFFCC', // Standard Colour #35
380 36 => 'FFFFFF99', // Standard Colour #36
381 37 => 'FF99CCFF', // Standard Colour #37
382 38 => 'FFFF99CC', // Standard Colour #38
383 39 => 'FFCC99FF', // Standard Colour #39
384 40 => 'FFFFCC99', // Standard Colour #40
385 41 => 'FF3366FF', // Standard Colour #41
386 42 => 'FF33CCCC', // Standard Colour #42
387 43 => 'FF99CC00', // Standard Colour #43
388 44 => 'FFFFCC00', // Standard Colour #44
389 45 => 'FFFF9900', // Standard Colour #45
390 46 => 'FFFF6600', // Standard Colour #46
391 47 => 'FF666699', // Standard Colour #47
392 48 => 'FF969696', // Standard Colour #48
393 49 => 'FF003366', // Standard Colour #49
394 50 => 'FF339966', // Standard Colour #50
395 51 => 'FF003300', // Standard Colour #51
396 52 => 'FF333300', // Standard Colour #52
397 53 => 'FF993300', // Standard Colour #53
398 54 => 'FF993366', // Standard Colour #54
399 55 => 'FF333399', // Standard Colour #55
400 56 => 'FF333333' // Standard Colour #56
404 if (array_key_exists($pIndex, self::$_indexedColors)) {
405 return new PHPExcel_Style_Color(self::$_indexedColors[$pIndex]);
408 if ($background) {
409 return new PHPExcel_Style_Color('FFFFFFFF');
411 return new PHPExcel_Style_Color('FF000000');
415 * Get hash code
417 * @return string Hash code
419 public function getHashCode() {
420 if ($this->_isSupervisor) {
421 return $this->getSharedComponent()->getHashCode();
423 return md5(
424 $this->_argb
425 . __CLASS__