Updated gui for user facility settings (#1327)
[openemr.git] / vendor / phpoffice / phpexcel / Classes / PHPExcel / Style / Font.php
blob296e348557a85888905caa642ee4ba7c4520b345
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_Font
32 * @category PHPExcel
33 * @package PHPExcel_Style
34 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
36 class PHPExcel_Style_Font extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable
38 /* Underline types */
39 const UNDERLINE_NONE = 'none';
40 const UNDERLINE_DOUBLE = 'double';
41 const UNDERLINE_DOUBLEACCOUNTING = 'doubleAccounting';
42 const UNDERLINE_SINGLE = 'single';
43 const UNDERLINE_SINGLEACCOUNTING = 'singleAccounting';
45 /**
46 * Font Name
48 * @var string
50 protected $_name = 'Calibri';
52 /**
53 * Font Size
55 * @var float
57 protected $_size = 11;
59 /**
60 * Bold
62 * @var boolean
64 protected $_bold = FALSE;
66 /**
67 * Italic
69 * @var boolean
71 protected $_italic = FALSE;
73 /**
74 * Superscript
76 * @var boolean
78 protected $_superScript = FALSE;
80 /**
81 * Subscript
83 * @var boolean
85 protected $_subScript = FALSE;
87 /**
88 * Underline
90 * @var string
92 protected $_underline = self::UNDERLINE_NONE;
94 /**
95 * Strikethrough
97 * @var boolean
99 protected $_strikethrough = FALSE;
102 * Foreground color
104 * @var PHPExcel_Style_Color
106 protected $_color;
109 * Create a new PHPExcel_Style_Font
111 * @param boolean $isSupervisor Flag indicating if this is a supervisor or not
112 * Leave this value at default unless you understand exactly what
113 * its ramifications are
114 * @param boolean $isConditional Flag indicating if this is a conditional style or not
115 * Leave this value at default unless you understand exactly what
116 * its ramifications are
118 public function __construct($isSupervisor = FALSE, $isConditional = FALSE)
120 // Supervisor?
121 parent::__construct($isSupervisor);
123 // Initialise values
124 if ($isConditional) {
125 $this->_name = NULL;
126 $this->_size = NULL;
127 $this->_bold = NULL;
128 $this->_italic = NULL;
129 $this->_superScript = NULL;
130 $this->_subScript = NULL;
131 $this->_underline = NULL;
132 $this->_strikethrough = NULL;
133 $this->_color = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor, $isConditional);
134 } else {
135 $this->_color = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor);
137 // bind parent if we are a supervisor
138 if ($isSupervisor) {
139 $this->_color->bindParent($this, '_color');
144 * Get the shared style component for the currently active cell in currently active sheet.
145 * Only used for style supervisor
147 * @return PHPExcel_Style_Font
149 public function getSharedComponent()
151 return $this->_parent->getSharedComponent()->getFont();
155 * Build style array from subcomponents
157 * @param array $array
158 * @return array
160 public function getStyleArray($array)
162 return array('font' => $array);
166 * Apply styles from array
168 * <code>
169 * $objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->applyFromArray(
170 * array(
171 * 'name' => 'Arial',
172 * 'bold' => TRUE,
173 * 'italic' => FALSE,
174 * 'underline' => PHPExcel_Style_Font::UNDERLINE_DOUBLE,
175 * 'strike' => FALSE,
176 * 'color' => array(
177 * 'rgb' => '808080'
180 * );
181 * </code>
183 * @param array $pStyles Array containing style information
184 * @throws PHPExcel_Exception
185 * @return PHPExcel_Style_Font
187 public function applyFromArray($pStyles = null) {
188 if (is_array($pStyles)) {
189 if ($this->_isSupervisor) {
190 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
191 } else {
192 if (array_key_exists('name', $pStyles)) {
193 $this->setName($pStyles['name']);
195 if (array_key_exists('bold', $pStyles)) {
196 $this->setBold($pStyles['bold']);
198 if (array_key_exists('italic', $pStyles)) {
199 $this->setItalic($pStyles['italic']);
201 if (array_key_exists('superScript', $pStyles)) {
202 $this->setSuperScript($pStyles['superScript']);
204 if (array_key_exists('subScript', $pStyles)) {
205 $this->setSubScript($pStyles['subScript']);
207 if (array_key_exists('underline', $pStyles)) {
208 $this->setUnderline($pStyles['underline']);
210 if (array_key_exists('strike', $pStyles)) {
211 $this->setStrikethrough($pStyles['strike']);
213 if (array_key_exists('color', $pStyles)) {
214 $this->getColor()->applyFromArray($pStyles['color']);
216 if (array_key_exists('size', $pStyles)) {
217 $this->setSize($pStyles['size']);
220 } else {
221 throw new PHPExcel_Exception("Invalid style array passed.");
223 return $this;
227 * Get Name
229 * @return string
231 public function getName() {
232 if ($this->_isSupervisor) {
233 return $this->getSharedComponent()->getName();
235 return $this->_name;
239 * Set Name
241 * @param string $pValue
242 * @return PHPExcel_Style_Font
244 public function setName($pValue = 'Calibri') {
245 if ($pValue == '') {
246 $pValue = 'Calibri';
248 if ($this->_isSupervisor) {
249 $styleArray = $this->getStyleArray(array('name' => $pValue));
250 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
251 } else {
252 $this->_name = $pValue;
254 return $this;
258 * Get Size
260 * @return double
262 public function getSize() {
263 if ($this->_isSupervisor) {
264 return $this->getSharedComponent()->getSize();
266 return $this->_size;
270 * Set Size
272 * @param double $pValue
273 * @return PHPExcel_Style_Font
275 public function setSize($pValue = 10) {
276 if ($pValue == '') {
277 $pValue = 10;
279 if ($this->_isSupervisor) {
280 $styleArray = $this->getStyleArray(array('size' => $pValue));
281 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
282 } else {
283 $this->_size = $pValue;
285 return $this;
289 * Get Bold
291 * @return boolean
293 public function getBold() {
294 if ($this->_isSupervisor) {
295 return $this->getSharedComponent()->getBold();
297 return $this->_bold;
301 * Set Bold
303 * @param boolean $pValue
304 * @return PHPExcel_Style_Font
306 public function setBold($pValue = false) {
307 if ($pValue == '') {
308 $pValue = false;
310 if ($this->_isSupervisor) {
311 $styleArray = $this->getStyleArray(array('bold' => $pValue));
312 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
313 } else {
314 $this->_bold = $pValue;
316 return $this;
320 * Get Italic
322 * @return boolean
324 public function getItalic() {
325 if ($this->_isSupervisor) {
326 return $this->getSharedComponent()->getItalic();
328 return $this->_italic;
332 * Set Italic
334 * @param boolean $pValue
335 * @return PHPExcel_Style_Font
337 public function setItalic($pValue = false) {
338 if ($pValue == '') {
339 $pValue = false;
341 if ($this->_isSupervisor) {
342 $styleArray = $this->getStyleArray(array('italic' => $pValue));
343 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
344 } else {
345 $this->_italic = $pValue;
347 return $this;
351 * Get SuperScript
353 * @return boolean
355 public function getSuperScript() {
356 if ($this->_isSupervisor) {
357 return $this->getSharedComponent()->getSuperScript();
359 return $this->_superScript;
363 * Set SuperScript
365 * @param boolean $pValue
366 * @return PHPExcel_Style_Font
368 public function setSuperScript($pValue = false) {
369 if ($pValue == '') {
370 $pValue = false;
372 if ($this->_isSupervisor) {
373 $styleArray = $this->getStyleArray(array('superScript' => $pValue));
374 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
375 } else {
376 $this->_superScript = $pValue;
377 $this->_subScript = !$pValue;
379 return $this;
383 * Get SubScript
385 * @return boolean
387 public function getSubScript() {
388 if ($this->_isSupervisor) {
389 return $this->getSharedComponent()->getSubScript();
391 return $this->_subScript;
395 * Set SubScript
397 * @param boolean $pValue
398 * @return PHPExcel_Style_Font
400 public function setSubScript($pValue = false) {
401 if ($pValue == '') {
402 $pValue = false;
404 if ($this->_isSupervisor) {
405 $styleArray = $this->getStyleArray(array('subScript' => $pValue));
406 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
407 } else {
408 $this->_subScript = $pValue;
409 $this->_superScript = !$pValue;
411 return $this;
415 * Get Underline
417 * @return string
419 public function getUnderline() {
420 if ($this->_isSupervisor) {
421 return $this->getSharedComponent()->getUnderline();
423 return $this->_underline;
427 * Set Underline
429 * @param string|boolean $pValue PHPExcel_Style_Font underline type
430 * If a boolean is passed, then TRUE equates to UNDERLINE_SINGLE,
431 * false equates to UNDERLINE_NONE
432 * @return PHPExcel_Style_Font
434 public function setUnderline($pValue = self::UNDERLINE_NONE) {
435 if (is_bool($pValue)) {
436 $pValue = ($pValue) ? self::UNDERLINE_SINGLE : self::UNDERLINE_NONE;
437 } elseif ($pValue == '') {
438 $pValue = self::UNDERLINE_NONE;
440 if ($this->_isSupervisor) {
441 $styleArray = $this->getStyleArray(array('underline' => $pValue));
442 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
443 } else {
444 $this->_underline = $pValue;
446 return $this;
450 * Get Strikethrough
452 * @return boolean
454 public function getStrikethrough() {
455 if ($this->_isSupervisor) {
456 return $this->getSharedComponent()->getStrikethrough();
458 return $this->_strikethrough;
462 * Set Strikethrough
464 * @param boolean $pValue
465 * @return PHPExcel_Style_Font
467 public function setStrikethrough($pValue = false) {
468 if ($pValue == '') {
469 $pValue = false;
471 if ($this->_isSupervisor) {
472 $styleArray = $this->getStyleArray(array('strike' => $pValue));
473 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
474 } else {
475 $this->_strikethrough = $pValue;
477 return $this;
481 * Get Color
483 * @return PHPExcel_Style_Color
485 public function getColor() {
486 return $this->_color;
490 * Set Color
492 * @param PHPExcel_Style_Color $pValue
493 * @throws PHPExcel_Exception
494 * @return PHPExcel_Style_Font
496 public function setColor(PHPExcel_Style_Color $pValue = null) {
497 // make sure parameter is a real color and not a supervisor
498 $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue;
500 if ($this->_isSupervisor) {
501 $styleArray = $this->getColor()->getStyleArray(array('argb' => $color->getARGB()));
502 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
503 } else {
504 $this->_color = $color;
506 return $this;
510 * Get hash code
512 * @return string Hash code
514 public function getHashCode() {
515 if ($this->_isSupervisor) {
516 return $this->getSharedComponent()->getHashCode();
518 return md5(
519 $this->_name
520 . $this->_size
521 . ($this->_bold ? 't' : 'f')
522 . ($this->_italic ? 't' : 'f')
523 . ($this->_superScript ? 't' : 'f')
524 . ($this->_subScript ? 't' : 'f')
525 . $this->_underline
526 . ($this->_strikethrough ? 't' : 'f')
527 . $this->_color->getHashCode()
528 . __CLASS__