1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27:
28:
29: 30: 31: 32: 33: 34: 35:
36: class PHPExcel_Style_Font extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable
37: {
38:
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:
45: 46: 47: 48: 49:
50: protected $_name = 'Calibri';
51:
52: 53: 54: 55: 56:
57: protected $_size = 11;
58:
59: 60: 61: 62: 63:
64: protected $_bold = FALSE;
65:
66: 67: 68: 69: 70:
71: protected $_italic = FALSE;
72:
73: 74: 75: 76: 77:
78: protected $_superScript = FALSE;
79:
80: 81: 82: 83: 84:
85: protected $_subScript = FALSE;
86:
87: 88: 89: 90: 91:
92: protected $_underline = self::UNDERLINE_NONE;
93:
94: 95: 96: 97: 98:
99: protected $_strikethrough = FALSE;
100:
101: 102: 103: 104: 105:
106: protected $_color;
107:
108: 109: 110: 111: 112: 113: 114: 115: 116: 117:
118: public function __construct($isSupervisor = FALSE, $isConditional = FALSE)
119: {
120:
121: parent::__construct($isSupervisor);
122:
123:
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:
138: if ($isSupervisor) {
139: $this->_color->bindParent($this, '_color');
140: }
141: }
142:
143: 144: 145: 146: 147: 148:
149: public function getSharedComponent()
150: {
151: return $this->_parent->getSharedComponent()->getFont();
152: }
153:
154: 155: 156: 157: 158: 159:
160: public function getStyleArray($array)
161: {
162: return array('font' => $array);
163: }
164:
165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186:
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:
226: 227: 228: 229: 230:
231: public function getName() {
232: if ($this->_isSupervisor) {
233: return $this->getSharedComponent()->getName();
234: }
235: return $this->_name;
236: }
237:
238: 239: 240: 241: 242: 243:
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:
257: 258: 259: 260: 261:
262: public function getSize() {
263: if ($this->_isSupervisor) {
264: return $this->getSharedComponent()->getSize();
265: }
266: return $this->_size;
267: }
268:
269: 270: 271: 272: 273: 274:
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:
288: 289: 290: 291: 292:
293: public function getBold() {
294: if ($this->_isSupervisor) {
295: return $this->getSharedComponent()->getBold();
296: }
297: return $this->_bold;
298: }
299:
300: 301: 302: 303: 304: 305:
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:
319: 320: 321: 322: 323:
324: public function getItalic() {
325: if ($this->_isSupervisor) {
326: return $this->getSharedComponent()->getItalic();
327: }
328: return $this->_italic;
329: }
330:
331: 332: 333: 334: 335: 336:
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:
350: 351: 352: 353: 354:
355: public function getSuperScript() {
356: if ($this->_isSupervisor) {
357: return $this->getSharedComponent()->getSuperScript();
358: }
359: return $this->_superScript;
360: }
361:
362: 363: 364: 365: 366: 367:
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:
382: 383: 384: 385: 386:
387: public function getSubScript() {
388: if ($this->_isSupervisor) {
389: return $this->getSharedComponent()->getSubScript();
390: }
391: return $this->_subScript;
392: }
393:
394: 395: 396: 397: 398: 399:
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:
414: 415: 416: 417: 418:
419: public function getUnderline() {
420: if ($this->_isSupervisor) {
421: return $this->getSharedComponent()->getUnderline();
422: }
423: return $this->_underline;
424: }
425:
426: 427: 428: 429: 430: 431: 432: 433:
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:
449: 450: 451: 452: 453:
454: public function getStrikethrough() {
455: if ($this->_isSupervisor) {
456: return $this->getSharedComponent()->getStrikethrough();
457: }
458: return $this->_strikethrough;
459: }
460:
461: 462: 463: 464: 465: 466:
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:
480: 481: 482: 483: 484:
485: public function getColor() {
486: return $this->_color;
487: }
488:
489: 490: 491: 492: 493: 494: 495:
496: public function setColor(PHPExcel_Style_Color $pValue = null) {
497:
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:
509: 510: 511: 512: 513:
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: }
533: