|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of PHPPresentation - A pure PHP library for reading and writing |
|
4
|
|
|
* presentations documents. |
|
5
|
|
|
* |
|
6
|
|
|
* PHPPresentation is free software distributed under the terms of the GNU Lesser |
|
7
|
|
|
* General Public License version 3 as published by the Free Software Foundation. |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please read the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. For the full list of |
|
11
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors. |
|
12
|
|
|
* |
|
13
|
|
|
* @link https://github.com/PHPOffice/PHPPresentation |
|
14
|
|
|
* @copyright 2009-2015 PHPPresentation contributors |
|
15
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace PhpOffice\PhpPresentation\Style; |
|
19
|
|
|
|
|
20
|
|
|
use PhpOffice\PhpPresentation\ComparableInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* \PhpOffice\PhpPresentation\Style\Font |
|
24
|
|
|
*/ |
|
25
|
|
|
class Font implements ComparableInterface |
|
26
|
|
|
{ |
|
27
|
|
|
/* Underline types */ |
|
28
|
|
|
const UNDERLINE_NONE = 'none'; |
|
29
|
|
|
const UNDERLINE_DASH = 'dash'; |
|
30
|
|
|
const UNDERLINE_DASHHEAVY = 'dashHeavy'; |
|
31
|
|
|
const UNDERLINE_DASHLONG = 'dashLong'; |
|
32
|
|
|
const UNDERLINE_DASHLONGHEAVY = 'dashLongHeavy'; |
|
33
|
|
|
const UNDERLINE_DOUBLE = 'dbl'; |
|
34
|
|
|
const UNDERLINE_DOTHASH = 'dotDash'; |
|
35
|
|
|
const UNDERLINE_DOTHASHHEAVY = 'dotDashHeavy'; |
|
36
|
|
|
const UNDERLINE_DOTDOTDASH = 'dotDotDash'; |
|
37
|
|
|
const UNDERLINE_DOTDOTDASHHEAVY = 'dotDotDashHeavy'; |
|
38
|
|
|
const UNDERLINE_DOTTED = 'dotted'; |
|
39
|
|
|
const UNDERLINE_DOTTEDHEAVY = 'dottedHeavy'; |
|
40
|
|
|
const UNDERLINE_HEAVY = 'heavy'; |
|
41
|
|
|
const UNDERLINE_SINGLE = 'sng'; |
|
42
|
|
|
const UNDERLINE_WAVY = 'wavy'; |
|
43
|
|
|
const UNDERLINE_WAVYDOUBLE = 'wavyDbl'; |
|
44
|
|
|
const UNDERLINE_WAVYHEAVY = 'wavyHeavy'; |
|
45
|
|
|
const UNDERLINE_WORDS = 'words'; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Name |
|
49
|
|
|
* |
|
50
|
|
|
* @var string |
|
51
|
|
|
*/ |
|
52
|
|
|
private $name; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Font Size |
|
56
|
|
|
* |
|
57
|
|
|
* @var float|int |
|
58
|
|
|
*/ |
|
59
|
|
|
private $size; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Bold |
|
63
|
|
|
* |
|
64
|
|
|
* @var boolean |
|
65
|
|
|
*/ |
|
66
|
|
|
private $bold; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Italic |
|
70
|
|
|
* |
|
71
|
|
|
* @var boolean |
|
72
|
|
|
*/ |
|
73
|
|
|
private $italic; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Superscript |
|
77
|
|
|
* |
|
78
|
|
|
* @var boolean |
|
79
|
|
|
*/ |
|
80
|
|
|
private $superScript; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Subscript |
|
84
|
|
|
* |
|
85
|
|
|
* @var boolean |
|
86
|
|
|
*/ |
|
87
|
|
|
private $subScript; |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Underline |
|
91
|
|
|
* |
|
92
|
|
|
* @var string |
|
93
|
|
|
*/ |
|
94
|
|
|
private $underline; |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Strikethrough |
|
98
|
|
|
* |
|
99
|
|
|
* @var boolean |
|
100
|
|
|
*/ |
|
101
|
|
|
private $strikethrough; |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Foreground color |
|
105
|
|
|
* |
|
106
|
|
|
* @var \PhpOffice\PhpPresentation\Style\Color |
|
107
|
|
|
*/ |
|
108
|
|
|
private $color; |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Character Spacing |
|
112
|
|
|
* |
|
113
|
|
|
* @var int |
|
114
|
|
|
*/ |
|
115
|
|
|
private $characterSpacing; |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Hash index |
|
119
|
|
|
* |
|
120
|
|
|
* @var string |
|
121
|
|
|
*/ |
|
122
|
|
|
private $hashIndex; |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Create a new \PhpOffice\PhpPresentation\Style\Font |
|
126
|
|
|
*/ |
|
127
|
408 |
|
public function __construct() |
|
128
|
|
|
{ |
|
129
|
|
|
// Initialise values |
|
130
|
408 |
|
$this->name = 'Calibri'; |
|
131
|
408 |
|
$this->size = 10; |
|
132
|
408 |
|
$this->characterSpacing = 0; |
|
133
|
408 |
|
$this->bold = false; |
|
134
|
408 |
|
$this->italic = false; |
|
135
|
408 |
|
$this->superScript = false; |
|
136
|
408 |
|
$this->subScript = false; |
|
137
|
408 |
|
$this->underline = self::UNDERLINE_NONE; |
|
138
|
408 |
|
$this->strikethrough = false; |
|
139
|
408 |
|
$this->color = new Color(Color::COLOR_BLACK); |
|
140
|
408 |
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Get Name |
|
144
|
|
|
* |
|
145
|
|
|
* @return string |
|
146
|
|
|
*/ |
|
147
|
102 |
|
public function getName() |
|
148
|
|
|
{ |
|
149
|
102 |
|
return $this->name; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Set Name |
|
154
|
|
|
* |
|
155
|
|
|
* @param string $pValue |
|
156
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Font |
|
157
|
|
|
*/ |
|
158
|
125 |
|
public function setName($pValue = 'Calibri') |
|
159
|
|
|
{ |
|
160
|
125 |
|
if ($pValue == '') { |
|
161
|
1 |
|
$pValue = 'Calibri'; |
|
162
|
|
|
} |
|
163
|
125 |
|
$this->name = $pValue; |
|
164
|
|
|
|
|
165
|
125 |
|
return $this; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Get Character Spacing |
|
170
|
|
|
* |
|
171
|
|
|
* @return double |
|
172
|
|
|
*/ |
|
173
|
31 |
|
public function getCharacterSpacing() |
|
174
|
|
|
{ |
|
175
|
31 |
|
return $this->characterSpacing; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Set Character Spacing |
|
180
|
|
|
* Value in pt |
|
181
|
|
|
* @param float|int $pValue |
|
182
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Font |
|
183
|
|
|
*/ |
|
184
|
2 |
|
public function setCharacterSpacing($pValue = 0) |
|
185
|
|
|
{ |
|
186
|
2 |
|
if ($pValue == '') { |
|
187
|
1 |
|
$pValue = 0; |
|
188
|
|
|
} |
|
189
|
2 |
|
$this->characterSpacing = $pValue * 100; |
|
190
|
|
|
|
|
191
|
2 |
|
return $this; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* Get Size |
|
196
|
|
|
* |
|
197
|
|
|
* @return double |
|
198
|
|
|
*/ |
|
199
|
154 |
|
public function getSize() |
|
200
|
|
|
{ |
|
201
|
154 |
|
return $this->size; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Set Size |
|
206
|
|
|
* |
|
207
|
|
|
* @param float|int $pValue |
|
208
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Font |
|
209
|
|
|
*/ |
|
210
|
292 |
|
public function setSize($pValue = 10) |
|
211
|
|
|
{ |
|
212
|
292 |
|
if ($pValue == '') { |
|
213
|
1 |
|
$pValue = 10; |
|
214
|
|
|
} |
|
215
|
292 |
|
$this->size = $pValue; |
|
216
|
|
|
|
|
217
|
292 |
|
return $this; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* Get Bold |
|
222
|
|
|
* |
|
223
|
|
|
* @return boolean |
|
224
|
|
|
*/ |
|
225
|
127 |
|
public function isBold() |
|
226
|
|
|
{ |
|
227
|
127 |
|
return $this->bold; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* Set Bold |
|
232
|
|
|
* |
|
233
|
|
|
* @param boolean $pValue |
|
234
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Font |
|
235
|
|
|
*/ |
|
236
|
10 |
|
public function setBold($pValue = false) |
|
237
|
|
|
{ |
|
238
|
10 |
|
if ($pValue == '') { |
|
239
|
4 |
|
$pValue = false; |
|
240
|
|
|
} |
|
241
|
10 |
|
$this->bold = $pValue; |
|
242
|
|
|
|
|
243
|
10 |
|
return $this; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* Get Italic |
|
248
|
|
|
* |
|
249
|
|
|
* @return boolean |
|
250
|
|
|
*/ |
|
251
|
139 |
|
public function isItalic() |
|
252
|
|
|
{ |
|
253
|
139 |
|
return $this->italic; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* Set Italic |
|
258
|
|
|
* |
|
259
|
|
|
* @param boolean $pValue |
|
260
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Font |
|
261
|
|
|
*/ |
|
262
|
9 |
|
public function setItalic($pValue = false) |
|
263
|
|
|
{ |
|
264
|
9 |
|
if ($pValue == '') { |
|
265
|
7 |
|
$pValue = false; |
|
266
|
|
|
} |
|
267
|
9 |
|
$this->italic = $pValue; |
|
268
|
|
|
|
|
269
|
9 |
|
return $this; |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* Get SuperScript |
|
274
|
|
|
* |
|
275
|
|
|
* @return boolean |
|
276
|
|
|
*/ |
|
277
|
66 |
|
public function isSuperScript() |
|
278
|
|
|
{ |
|
279
|
66 |
|
return $this->superScript; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* Set SuperScript |
|
284
|
|
|
* |
|
285
|
|
|
* @param boolean $pValue |
|
286
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Font |
|
287
|
|
|
*/ |
|
288
|
7 |
|
public function setSuperScript($pValue = false) |
|
289
|
|
|
{ |
|
290
|
7 |
|
if ($pValue == '') { |
|
291
|
2 |
|
$pValue = false; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
7 |
|
$this->superScript = $pValue; |
|
295
|
|
|
|
|
296
|
|
|
// Set SubScript at false only if SuperScript is true |
|
297
|
7 |
|
if ($pValue === true) { |
|
298
|
7 |
|
$this->subScript = false; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
7 |
|
return $this; |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
/** |
|
305
|
|
|
* Get SubScript |
|
306
|
|
|
* |
|
307
|
|
|
* @return boolean |
|
308
|
|
|
*/ |
|
309
|
66 |
|
public function isSubScript() |
|
310
|
|
|
{ |
|
311
|
66 |
|
return $this->subScript; |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
/** |
|
315
|
|
|
* Set SubScript |
|
316
|
|
|
* |
|
317
|
|
|
* @param boolean $pValue |
|
318
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Font |
|
319
|
|
|
*/ |
|
320
|
7 |
|
public function setSubScript($pValue = false) |
|
321
|
|
|
{ |
|
322
|
7 |
|
if ($pValue == '') { |
|
323
|
2 |
|
$pValue = false; |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
7 |
|
$this->subScript = $pValue; |
|
327
|
|
|
|
|
328
|
|
|
// Set SuperScript at false only if SubScript is true |
|
329
|
7 |
|
if ($pValue === true) { |
|
330
|
7 |
|
$this->superScript = false; |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
7 |
|
return $this; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* Get Underline |
|
338
|
|
|
* |
|
339
|
|
|
* @return string |
|
340
|
|
|
*/ |
|
341
|
66 |
|
public function getUnderline() |
|
342
|
|
|
{ |
|
343
|
66 |
|
return $this->underline; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* Set Underline |
|
348
|
|
|
* |
|
349
|
|
|
* @param string $pValue \PhpOffice\PhpPresentation\Style\Font underline type |
|
350
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Font |
|
351
|
|
|
*/ |
|
352
|
8 |
|
public function setUnderline($pValue = self::UNDERLINE_NONE) |
|
353
|
|
|
{ |
|
354
|
8 |
|
if ($pValue == '') { |
|
355
|
4 |
|
$pValue = self::UNDERLINE_NONE; |
|
356
|
|
|
} |
|
357
|
8 |
|
$this->underline = $pValue; |
|
358
|
|
|
|
|
359
|
8 |
|
return $this; |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
/** |
|
363
|
|
|
* Get Strikethrough |
|
364
|
|
|
* |
|
365
|
|
|
* @return boolean |
|
366
|
|
|
*/ |
|
367
|
66 |
|
public function isStrikethrough() |
|
368
|
|
|
{ |
|
369
|
66 |
|
return $this->strikethrough; |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
/** |
|
373
|
|
|
* Set Strikethrough |
|
374
|
|
|
* |
|
375
|
|
|
* @param boolean $pValue |
|
376
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Font |
|
377
|
|
|
*/ |
|
378
|
5 |
|
public function setStrikethrough($pValue = false) |
|
379
|
|
|
{ |
|
380
|
5 |
|
if ($pValue == '') { |
|
381
|
4 |
|
$pValue = false; |
|
382
|
|
|
} |
|
383
|
5 |
|
$this->strikethrough = $pValue; |
|
384
|
|
|
|
|
385
|
5 |
|
return $this; |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
/** |
|
389
|
|
|
* Get Color |
|
390
|
|
|
* |
|
391
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Color|\PhpOffice\PhpPresentation\Style\SchemeColor |
|
392
|
|
|
*/ |
|
393
|
152 |
|
public function getColor() |
|
394
|
|
|
{ |
|
395
|
152 |
|
return $this->color; |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
/** |
|
399
|
|
|
* Set Color |
|
400
|
|
|
* |
|
401
|
|
|
* @param \PhpOffice\PhpPresentation\Style\Color|\PhpOffice\PhpPresentation\Style\SchemeColor $pValue |
|
402
|
|
|
* @throws \Exception |
|
403
|
|
|
* @return \PhpOffice\PhpPresentation\Style\Font |
|
404
|
|
|
*/ |
|
405
|
233 |
|
public function setColor($pValue = null) |
|
406
|
|
|
{ |
|
407
|
233 |
|
if (!$pValue instanceof Color) { |
|
408
|
1 |
|
throw new \Exception('$pValue must be an instance of \PhpOffice\PhpPresentation\Style\Color'); |
|
409
|
|
|
} |
|
410
|
232 |
|
$this->color = $pValue; |
|
411
|
|
|
|
|
412
|
232 |
|
return $this; |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
|
|
/** |
|
416
|
|
|
* Get hash code |
|
417
|
|
|
* |
|
418
|
|
|
* @return string Hash code |
|
419
|
|
|
*/ |
|
420
|
90 |
|
public function getHashCode() |
|
421
|
|
|
{ |
|
422
|
90 |
|
return md5($this->name . $this->size . ($this->bold ? 't' : 'f') . ($this->italic ? 't' : 'f') . ($this->superScript ? 't' : 'f') . ($this->subScript ? 't' : 'f') . $this->underline . ($this->strikethrough ? 't' : 'f') . $this->color->getHashCode() . __CLASS__); |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
/** |
|
426
|
|
|
* Get hash index |
|
427
|
|
|
* |
|
428
|
|
|
* Note that this index may vary during script execution! Only reliable moment is |
|
429
|
|
|
* while doing a write of a workbook and when changes are not allowed. |
|
430
|
|
|
* |
|
431
|
|
|
* @return string Hash index |
|
432
|
|
|
*/ |
|
433
|
1 |
|
public function getHashIndex() |
|
434
|
|
|
{ |
|
435
|
1 |
|
return $this->hashIndex; |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
/** |
|
439
|
|
|
* Set hash index |
|
440
|
|
|
* |
|
441
|
|
|
* Note that this index may vary during script execution! Only reliable moment is |
|
442
|
|
|
* while doing a write of a workbook and when changes are not allowed. |
|
443
|
|
|
* |
|
444
|
|
|
* @param string $value Hash index |
|
445
|
|
|
*/ |
|
446
|
1 |
|
public function setHashIndex($value) |
|
447
|
|
|
{ |
|
448
|
1 |
|
$this->hashIndex = $value; |
|
449
|
1 |
|
} |
|
450
|
|
|
} |
|
451
|
|
|
|