ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Font.php
Go to the documentation of this file.
1<?php
37{
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';
44
50 protected $_name = 'Calibri';
51
57 protected $_size = 11;
58
64 protected $_bold = FALSE;
65
71 protected $_italic = FALSE;
72
78 protected $_superScript = FALSE;
79
85 protected $_subScript = FALSE;
86
93
99 protected $_strikethrough = FALSE;
100
106 protected $_color;
107
118 public function __construct($isSupervisor = FALSE, $isConditional = FALSE)
119 {
120 // Supervisor?
121 parent::__construct($isSupervisor);
122
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);
136 }
137 // bind parent if we are a supervisor
138 if ($isSupervisor) {
139 $this->_color->bindParent($this, '_color');
140 }
141 }
142
149 public function getSharedComponent()
150 {
151 return $this->_parent->getSharedComponent()->getFont();
152 }
153
160 public function getStyleArray($array)
161 {
162 return array('font' => $array);
163 }
164
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']);
194 }
195 if (array_key_exists('bold', $pStyles)) {
196 $this->setBold($pStyles['bold']);
197 }
198 if (array_key_exists('italic', $pStyles)) {
199 $this->setItalic($pStyles['italic']);
200 }
201 if (array_key_exists('superScript', $pStyles)) {
202 $this->setSuperScript($pStyles['superScript']);
203 }
204 if (array_key_exists('subScript', $pStyles)) {
205 $this->setSubScript($pStyles['subScript']);
206 }
207 if (array_key_exists('underline', $pStyles)) {
208 $this->setUnderline($pStyles['underline']);
209 }
210 if (array_key_exists('strike', $pStyles)) {
211 $this->setStrikethrough($pStyles['strike']);
212 }
213 if (array_key_exists('color', $pStyles)) {
214 $this->getColor()->applyFromArray($pStyles['color']);
215 }
216 if (array_key_exists('size', $pStyles)) {
217 $this->setSize($pStyles['size']);
218 }
219 }
220 } else {
221 throw new PHPExcel_Exception("Invalid style array passed.");
222 }
223 return $this;
224 }
225
231 public function getName() {
232 if ($this->_isSupervisor) {
233 return $this->getSharedComponent()->getName();
234 }
235 return $this->_name;
236 }
237
244 public function setName($pValue = 'Calibri') {
245 if ($pValue == '') {
246 $pValue = 'Calibri';
247 }
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;
253 }
254 return $this;
255 }
256
262 public function getSize() {
263 if ($this->_isSupervisor) {
264 return $this->getSharedComponent()->getSize();
265 }
266 return $this->_size;
267 }
268
275 public function setSize($pValue = 10) {
276 if ($pValue == '') {
277 $pValue = 10;
278 }
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;
284 }
285 return $this;
286 }
287
293 public function getBold() {
294 if ($this->_isSupervisor) {
295 return $this->getSharedComponent()->getBold();
296 }
297 return $this->_bold;
298 }
299
306 public function setBold($pValue = false) {
307 if ($pValue == '') {
308 $pValue = false;
309 }
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;
315 }
316 return $this;
317 }
318
324 public function getItalic() {
325 if ($this->_isSupervisor) {
326 return $this->getSharedComponent()->getItalic();
327 }
328 return $this->_italic;
329 }
330
337 public function setItalic($pValue = false) {
338 if ($pValue == '') {
339 $pValue = false;
340 }
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;
346 }
347 return $this;
348 }
349
355 public function getSuperScript() {
356 if ($this->_isSupervisor) {
357 return $this->getSharedComponent()->getSuperScript();
358 }
359 return $this->_superScript;
360 }
361
368 public function setSuperScript($pValue = false) {
369 if ($pValue == '') {
370 $pValue = false;
371 }
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;
378 }
379 return $this;
380 }
381
387 public function getSubScript() {
388 if ($this->_isSupervisor) {
389 return $this->getSharedComponent()->getSubScript();
390 }
391 return $this->_subScript;
392 }
393
400 public function setSubScript($pValue = false) {
401 if ($pValue == '') {
402 $pValue = false;
403 }
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;
410 }
411 return $this;
412 }
413
419 public function getUnderline() {
420 if ($this->_isSupervisor) {
421 return $this->getSharedComponent()->getUnderline();
422 }
423 return $this->_underline;
424 }
425
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;
439 }
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;
445 }
446 return $this;
447 }
448
454 public function getStrikethrough() {
455 if ($this->_isSupervisor) {
456 return $this->getSharedComponent()->getStrikethrough();
457 }
459 }
460
467 public function setStrikethrough($pValue = false) {
468 if ($pValue == '') {
469 $pValue = false;
470 }
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;
476 }
477 return $this;
478 }
479
485 public function getColor() {
486 return $this->_color;
487 }
488
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;
499
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;
505 }
506 return $this;
507 }
508
514 public function getHashCode() {
515 if ($this->_isSupervisor) {
516 return $this->getSharedComponent()->getHashCode();
517 }
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__
529 );
530 }
531
532}
An exception for terminatinating execution or to throw for unit testing.
setUnderline($pValue=self::UNDERLINE_NONE)
Set Underline.
Definition: Font.php:434
getStyleArray($array)
Build style array from subcomponents.
Definition: Font.php:160
applyFromArray($pStyles=null)
Apply styles from array.
Definition: Font.php:187
getBold()
Get Bold.
Definition: Font.php:293
setItalic($pValue=false)
Set Italic.
Definition: Font.php:337
getSize()
Get Size.
Definition: Font.php:262
setSuperScript($pValue=false)
Set SuperScript.
Definition: Font.php:368
setSize($pValue=10)
Set Size.
Definition: Font.php:275
getHashCode()
Get hash code.
Definition: Font.php:514
setName($pValue='Calibri')
Set Name.
Definition: Font.php:244
const UNDERLINE_DOUBLE
Definition: Font.php:40
getUnderline()
Get Underline.
Definition: Font.php:419
__construct($isSupervisor=FALSE, $isConditional=FALSE)
Create a new PHPExcel_Style_Font.
Definition: Font.php:118
setBold($pValue=false)
Set Bold.
Definition: Font.php:306
const UNDERLINE_SINGLEACCOUNTING
Definition: Font.php:43
getSharedComponent()
Get the shared style component for the currently active cell in currently active sheet.
Definition: Font.php:149
getColor()
Get Color.
Definition: Font.php:485
getItalic()
Get Italic.
Definition: Font.php:324
const UNDERLINE_DOUBLEACCOUNTING
Definition: Font.php:41
setStrikethrough($pValue=false)
Set Strikethrough.
Definition: Font.php:467
getStrikethrough()
Get Strikethrough.
Definition: Font.php:454
const UNDERLINE_SINGLE
Definition: Font.php:42
setColor(PHPExcel_Style_Color $pValue=null)
Set Color.
Definition: Font.php:496
getSuperScript()
Get SuperScript.
Definition: Font.php:355
getName()
Get Name.
Definition: Font.php:231
const UNDERLINE_NONE
Definition: Font.php:39
setSubScript($pValue=false)
Set SubScript.
Definition: Font.php:400
getSubScript()
Get SubScript.
Definition: Font.php:387
getActiveSheet()
Get the currently active sheet.
Definition: Supervisor.php:92
getSelectedCells()
Get the currently active cell coordinate in currently active sheet.
Definition: Supervisor.php:103