1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Style; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Chart\ChartColor; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Theme; |
7
|
|
|
|
8
|
|
|
class Font extends Supervisor |
9
|
|
|
{ |
10
|
|
|
// Underline types |
11
|
|
|
const UNDERLINE_NONE = 'none'; |
12
|
|
|
const UNDERLINE_DOUBLE = 'double'; |
13
|
|
|
const UNDERLINE_DOUBLEACCOUNTING = 'doubleAccounting'; |
14
|
|
|
const UNDERLINE_SINGLE = 'single'; |
15
|
|
|
const UNDERLINE_SINGLEACCOUNTING = 'singleAccounting'; |
16
|
|
|
|
17
|
|
|
const CAP_ALL = 'all'; |
18
|
|
|
const CAP_SMALL = 'small'; |
19
|
|
|
const CAP_NONE = 'none'; |
20
|
|
|
private const VALID_CAPS = [self::CAP_ALL, self::CAP_SMALL, self::CAP_NONE]; |
21
|
|
|
|
22
|
|
|
protected ?string $cap = null; |
23
|
|
|
|
24
|
|
|
public const DEFAULT_FONT_NAME = 'Calibri'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Font Name. |
28
|
|
|
*/ |
29
|
|
|
protected ?string $name = self::DEFAULT_FONT_NAME; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The following 7 are used only for chart titles, I think. |
33
|
|
|
*/ |
34
|
|
|
private string $latin = ''; |
35
|
|
|
|
36
|
|
|
private string $eastAsian = ''; |
37
|
|
|
|
38
|
|
|
private string $complexScript = ''; |
39
|
|
|
|
40
|
|
|
private int $baseLine = 0; |
41
|
|
|
|
42
|
|
|
private string $strikeType = ''; |
43
|
|
|
|
44
|
|
|
private ?ChartColor $underlineColor = null; |
45
|
|
|
|
46
|
|
|
private ?ChartColor $chartColor = null; |
47
|
|
|
// end of chart title items |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Font Size. |
51
|
|
|
*/ |
52
|
|
|
protected ?float $size = 11; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Bold. |
56
|
|
|
*/ |
57
|
|
|
protected ?bool $bold = false; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Italic. |
61
|
|
|
*/ |
62
|
|
|
protected ?bool $italic = false; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Superscript. |
66
|
|
|
*/ |
67
|
|
|
protected ?bool $superscript = false; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Subscript. |
71
|
|
|
*/ |
72
|
|
|
protected ?bool $subscript = false; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Underline. |
76
|
|
|
*/ |
77
|
|
|
protected ?string $underline = self::UNDERLINE_NONE; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Strikethrough. |
81
|
|
|
*/ |
82
|
|
|
protected ?bool $strikethrough = false; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Foreground color. |
86
|
|
|
*/ |
87
|
|
|
protected Color $color; |
88
|
|
|
|
89
|
|
|
public ?int $colorIndex = null; |
90
|
|
|
|
91
|
|
|
protected string $scheme = ''; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Create a new Font. |
95
|
|
|
* |
96
|
|
|
* @param bool $isSupervisor Flag indicating if this is a supervisor or not |
97
|
|
|
* Leave this value at default unless you understand exactly what |
98
|
|
|
* its ramifications are |
99
|
|
|
* @param bool $isConditional Flag indicating if this is a conditional style or not |
100
|
|
|
* Leave this value at default unless you understand exactly what |
101
|
|
|
* its ramifications are |
102
|
10760 |
|
*/ |
103
|
|
|
public function __construct(bool $isSupervisor = false, bool $isConditional = false) |
104
|
|
|
{ |
105
|
10760 |
|
// Supervisor? |
106
|
|
|
parent::__construct($isSupervisor); |
107
|
|
|
|
108
|
10760 |
|
// Initialise values |
109
|
402 |
|
if ($isConditional) { |
110
|
402 |
|
$this->name = null; |
111
|
402 |
|
$this->size = null; |
112
|
402 |
|
$this->bold = null; |
113
|
402 |
|
$this->italic = null; |
114
|
402 |
|
$this->superscript = null; |
115
|
402 |
|
$this->subscript = null; |
116
|
402 |
|
$this->underline = null; |
117
|
402 |
|
$this->strikethrough = null; |
118
|
|
|
$this->color = new Color(Color::COLOR_BLACK, $isSupervisor, $isConditional); |
119
|
10757 |
|
} else { |
120
|
|
|
$this->color = new Color(Color::COLOR_BLACK, $isSupervisor); |
121
|
|
|
} |
122
|
10760 |
|
// bind parent if we are a supervisor |
123
|
10575 |
|
if ($isSupervisor) { |
124
|
|
|
$this->color->bindParent($this, 'color'); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function applyThemeFonts(Theme $theme): void |
129
|
|
|
{ |
130
|
|
|
$this->setName($theme->getMinorFontLatin()); |
131
|
94 |
|
$this->setLatin($theme->getMinorFontLatin()); |
132
|
|
|
$this->setEastAsian($theme->getMinorFontEastAsian()); |
133
|
|
|
$this->setComplexScript($theme->getMinorFontComplexScript()); |
134
|
94 |
|
} |
135
|
|
|
|
136
|
94 |
|
/** |
137
|
|
|
* Get the shared style component for the currently active cell in currently active sheet. |
138
|
|
|
* Only used for style supervisor. |
139
|
|
|
*/ |
140
|
|
|
public function getSharedComponent(): self |
141
|
|
|
{ |
142
|
|
|
/** @var Style $parent */ |
143
|
|
|
$parent = $this->parent; |
144
|
|
|
|
145
|
|
|
return $parent->getSharedComponent()->getFont(); |
146
|
109 |
|
} |
147
|
|
|
|
148
|
109 |
|
/** |
149
|
|
|
* Build style array from subcomponents. |
150
|
|
|
* |
151
|
|
|
* @param mixed[] $array |
152
|
|
|
* |
153
|
|
|
* @return array{font: mixed[]} |
154
|
|
|
*/ |
155
|
|
|
public function getStyleArray(array $array): array |
156
|
|
|
{ |
157
|
|
|
return ['font' => $array]; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Apply styles from array. |
162
|
|
|
* |
163
|
|
|
* <code> |
164
|
|
|
* $spreadsheet->getActiveSheet()->getStyle('B2')->getFont()->applyFromArray( |
165
|
|
|
* [ |
166
|
|
|
* 'name' => 'Arial', |
167
|
|
|
* 'bold' => TRUE, |
168
|
|
|
* 'italic' => FALSE, |
169
|
|
|
* 'underline' => \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLE, |
170
|
|
|
* 'strikethrough' => FALSE, |
171
|
|
|
* 'color' => [ |
172
|
|
|
* 'rgb' => '808080' |
173
|
274 |
|
* ] |
174
|
|
|
* ] |
175
|
274 |
|
* ); |
176
|
1 |
|
* </code> |
177
|
|
|
* |
178
|
274 |
|
* @param array{name?: string, latin?: string, eastAsian?: string, complexScript?: string, bold?: bool, italic?: bool, superscript?: bool, subscript?: bool, underline?: bool|string, strikethrough?: bool, color?: string[], size?: ?int, chartColor?: ChartColor, scheme?: string, cap?: string} $styleArray Array containing style information |
179
|
178 |
|
* |
180
|
|
|
* @return $this |
181
|
274 |
|
*/ |
182
|
25 |
|
public function applyFromArray(array $styleArray): static |
183
|
|
|
{ |
184
|
274 |
|
if ($this->isSupervisor) { |
185
|
17 |
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray)); |
186
|
|
|
} else { |
187
|
274 |
|
if (isset($styleArray['name'])) { |
188
|
17 |
|
$this->setName($styleArray['name']); |
189
|
|
|
} |
190
|
274 |
|
if (isset($styleArray['latin'])) { |
191
|
181 |
|
$this->setLatin($styleArray['latin']); |
192
|
|
|
} |
193
|
274 |
|
if (isset($styleArray['eastAsian'])) { |
194
|
121 |
|
$this->setEastAsian($styleArray['eastAsian']); |
195
|
|
|
} |
196
|
274 |
|
if (isset($styleArray['complexScript'])) { |
197
|
30 |
|
$this->setComplexScript($styleArray['complexScript']); |
198
|
|
|
} |
199
|
274 |
|
if (isset($styleArray['bold'])) { |
200
|
28 |
|
$this->setBold($styleArray['bold']); |
201
|
|
|
} |
202
|
274 |
|
if (isset($styleArray['italic'])) { |
203
|
66 |
|
$this->setItalic($styleArray['italic']); |
204
|
|
|
} |
205
|
274 |
|
if (isset($styleArray['superscript'])) { |
206
|
59 |
|
$this->setSuperscript($styleArray['superscript']); |
207
|
|
|
} |
208
|
274 |
|
if (isset($styleArray['subscript'])) { |
209
|
|
|
$this->setSubscript($styleArray['subscript']); |
210
|
118 |
|
} |
211
|
118 |
|
if (isset($styleArray['underline'])) { |
212
|
118 |
|
$this->setUnderline($styleArray['underline']); |
213
|
|
|
} |
214
|
274 |
|
if (isset($styleArray['strikethrough'])) { |
215
|
118 |
|
$this->setStrikethrough($styleArray['strikethrough']); |
216
|
|
|
} |
217
|
274 |
|
if (isset($styleArray['color'])) { |
218
|
13 |
|
/** @var array{rgb?: string, argb?: string, theme?: int} */ |
219
|
|
|
$temp = $styleArray['color']; |
220
|
274 |
|
$this->getColor() |
221
|
51 |
|
->applyFromArray($temp); |
222
|
|
|
} |
223
|
274 |
|
if (isset($styleArray['size'])) { |
224
|
21 |
|
$this->setSize($styleArray['size']); |
225
|
|
|
} |
226
|
|
|
if (isset($styleArray['chartColor'])) { |
227
|
|
|
$this->chartColor = $styleArray['chartColor']; |
228
|
274 |
|
} |
229
|
|
|
if (isset($styleArray['scheme'])) { |
230
|
|
|
$this->setScheme($styleArray['scheme']); |
231
|
|
|
} |
232
|
|
|
if (isset($styleArray['cap'])) { |
233
|
|
|
$this->setCap($styleArray['cap']); |
234
|
1219 |
|
} |
235
|
|
|
} |
236
|
1219 |
|
|
237
|
42 |
|
return $this; |
238
|
|
|
} |
239
|
|
|
|
240
|
1219 |
|
/** |
241
|
|
|
* Get Name. |
242
|
|
|
*/ |
243
|
53 |
|
public function getName(): ?string |
244
|
|
|
{ |
245
|
53 |
|
if ($this->isSupervisor) { |
246
|
8 |
|
return $this->getSharedComponent()->getName(); |
247
|
|
|
} |
248
|
|
|
|
249
|
53 |
|
return $this->name; |
250
|
|
|
} |
251
|
|
|
|
252
|
53 |
|
public function getLatin(): string |
253
|
|
|
{ |
254
|
53 |
|
if ($this->isSupervisor) { |
255
|
8 |
|
return $this->getSharedComponent()->getLatin(); |
256
|
|
|
} |
257
|
|
|
|
258
|
53 |
|
return $this->latin; |
259
|
|
|
} |
260
|
|
|
|
261
|
53 |
|
public function getEastAsian(): string |
262
|
|
|
{ |
263
|
53 |
|
if ($this->isSupervisor) { |
264
|
8 |
|
return $this->getSharedComponent()->getEastAsian(); |
265
|
|
|
} |
266
|
|
|
|
267
|
53 |
|
return $this->eastAsian; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
public function getComplexScript(): string |
271
|
|
|
{ |
272
|
|
|
if ($this->isSupervisor) { |
273
|
998 |
|
return $this->getSharedComponent()->getComplexScript(); |
274
|
|
|
} |
275
|
998 |
|
|
276
|
1 |
|
return $this->complexScript; |
277
|
|
|
} |
278
|
998 |
|
|
279
|
41 |
|
/** |
280
|
41 |
|
* Set Name and turn off Scheme. |
281
|
|
|
*/ |
282
|
998 |
|
public function setName(string $fontname): self |
283
|
|
|
{ |
284
|
|
|
if ($fontname == '') { |
285
|
998 |
|
$fontname = 'Calibri'; |
286
|
|
|
} |
287
|
|
|
if ($this->isSupervisor) { |
288
|
48 |
|
$styleArray = $this->getStyleArray(['name' => $fontname]); |
289
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
290
|
48 |
|
} else { |
291
|
12 |
|
$this->name = $fontname; |
292
|
|
|
} |
293
|
48 |
|
|
294
|
48 |
|
return $this->setScheme(''); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
public function setLatin(string $fontname): self |
298
|
|
|
{ |
299
|
|
|
if ($fontname == '') { |
300
|
|
|
$fontname = 'Calibri'; |
301
|
|
|
} |
302
|
|
|
if (!$this->isSupervisor) { |
303
|
48 |
|
$this->latin = $fontname; |
304
|
|
|
} else { |
305
|
|
|
// should never be true |
306
|
41 |
|
// @codeCoverageIgnoreStart |
307
|
|
|
$styleArray = $this->getStyleArray(['latin' => $fontname]); |
308
|
41 |
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
309
|
12 |
|
// @codeCoverageIgnoreEnd |
310
|
|
|
} |
311
|
41 |
|
|
312
|
41 |
|
return $this; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
public function setEastAsian(string $fontname): self |
316
|
|
|
{ |
317
|
|
|
if ($fontname == '') { |
318
|
|
|
$fontname = 'Calibri'; |
319
|
|
|
} |
320
|
|
|
if (!$this->isSupervisor) { |
321
|
41 |
|
$this->eastAsian = $fontname; |
322
|
|
|
} else { |
323
|
|
|
// should never be true |
324
|
41 |
|
// @codeCoverageIgnoreStart |
325
|
|
|
$styleArray = $this->getStyleArray(['eastAsian' => $fontname]); |
326
|
41 |
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
327
|
12 |
|
// @codeCoverageIgnoreEnd |
328
|
|
|
} |
329
|
41 |
|
|
330
|
41 |
|
return $this; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
public function setComplexScript(string $fontname): self |
334
|
|
|
{ |
335
|
|
|
if ($fontname == '') { |
336
|
|
|
$fontname = 'Calibri'; |
337
|
|
|
} |
338
|
|
|
if (!$this->isSupervisor) { |
339
|
41 |
|
$this->complexScript = $fontname; |
340
|
|
|
} else { |
341
|
|
|
// should never be true |
342
|
|
|
// @codeCoverageIgnoreStart |
343
|
|
|
$styleArray = $this->getStyleArray(['complexScript' => $fontname]); |
344
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
345
|
1165 |
|
// @codeCoverageIgnoreEnd |
346
|
|
|
} |
347
|
1165 |
|
|
348
|
36 |
|
return $this; |
349
|
|
|
} |
350
|
|
|
|
351
|
1165 |
|
/** |
352
|
|
|
* Get Size. |
353
|
|
|
*/ |
354
|
|
|
public function getSize(): ?float |
355
|
|
|
{ |
356
|
|
|
if ($this->isSupervisor) { |
357
|
|
|
return $this->getSharedComponent()->getSize(); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
return $this->size; |
361
|
928 |
|
} |
362
|
|
|
|
363
|
928 |
|
/** |
364
|
254 |
|
* Set Size. |
365
|
|
|
* |
366
|
|
|
* @param mixed $sizeInPoints A float representing the value of a positive measurement in points (1/72 of an inch) |
367
|
|
|
* |
368
|
|
|
* @return $this |
369
|
928 |
|
*/ |
370
|
57 |
|
public function setSize(mixed $sizeInPoints, bool $nullOk = false): static |
371
|
1 |
|
{ |
372
|
|
|
if (is_string($sizeInPoints) || is_int($sizeInPoints)) { |
373
|
|
|
$sizeInPoints = (float) $sizeInPoints; // $pValue = 0 if given string is not numeric |
374
|
|
|
} |
375
|
928 |
|
|
376
|
20 |
|
// Size must be a positive floating point number |
377
|
20 |
|
// ECMA-376-1:2016, part 1, chapter 18.4.11 sz (Font Size), p. 1536 |
378
|
|
|
if (!is_float($sizeInPoints) || !($sizeInPoints > 0)) { |
379
|
928 |
|
if (!$nullOk || $sizeInPoints !== null) { |
380
|
|
|
$sizeInPoints = 10.0; |
381
|
|
|
} |
382
|
928 |
|
} |
383
|
|
|
|
384
|
|
|
if ($this->isSupervisor) { |
385
|
|
|
$styleArray = $this->getStyleArray(['size' => $sizeInPoints]); |
386
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
387
|
|
|
} else { |
388
|
1141 |
|
$this->size = $sizeInPoints; |
389
|
|
|
} |
390
|
1141 |
|
|
391
|
62 |
|
return $this; |
392
|
|
|
} |
393
|
|
|
|
394
|
1141 |
|
/** |
395
|
|
|
* Get Bold. |
396
|
|
|
*/ |
397
|
|
|
public function getBold(): ?bool |
398
|
|
|
{ |
399
|
|
|
if ($this->isSupervisor) { |
400
|
|
|
return $this->getSharedComponent()->getBold(); |
401
|
|
|
} |
402
|
763 |
|
|
403
|
|
|
return $this->bold; |
404
|
763 |
|
} |
405
|
72 |
|
|
406
|
72 |
|
/** |
407
|
|
|
* Set Bold. |
408
|
763 |
|
* |
409
|
|
|
* @return $this |
410
|
|
|
*/ |
411
|
763 |
|
public function setBold(bool $bold): static |
412
|
|
|
{ |
413
|
|
|
if ($this->isSupervisor) { |
414
|
|
|
$styleArray = $this->getStyleArray(['bold' => $bold]); |
415
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
416
|
|
|
} else { |
417
|
1129 |
|
$this->bold = $bold; |
418
|
|
|
} |
419
|
1129 |
|
|
420
|
49 |
|
return $this; |
421
|
|
|
} |
422
|
|
|
|
423
|
1129 |
|
/** |
424
|
|
|
* Get Italic. |
425
|
|
|
*/ |
426
|
|
|
public function getItalic(): ?bool |
427
|
|
|
{ |
428
|
|
|
if ($this->isSupervisor) { |
429
|
|
|
return $this->getSharedComponent()->getItalic(); |
430
|
|
|
} |
431
|
667 |
|
|
432
|
|
|
return $this->italic; |
433
|
667 |
|
} |
434
|
19 |
|
|
435
|
19 |
|
/** |
436
|
|
|
* Set Italic. |
437
|
667 |
|
* |
438
|
|
|
* @return $this |
439
|
|
|
*/ |
440
|
667 |
|
public function setItalic(bool $italic): static |
441
|
|
|
{ |
442
|
|
|
if ($this->isSupervisor) { |
443
|
|
|
$styleArray = $this->getStyleArray(['italic' => $italic]); |
444
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
445
|
|
|
} else { |
446
|
998 |
|
$this->italic = $italic; |
447
|
|
|
} |
448
|
998 |
|
|
449
|
25 |
|
return $this; |
450
|
|
|
} |
451
|
|
|
|
452
|
998 |
|
/** |
453
|
|
|
* Get Superscript. |
454
|
|
|
*/ |
455
|
|
|
public function getSuperscript(): ?bool |
456
|
|
|
{ |
457
|
|
|
if ($this->isSupervisor) { |
458
|
|
|
return $this->getSharedComponent()->getSuperscript(); |
459
|
|
|
} |
460
|
41 |
|
|
461
|
|
|
return $this->superscript; |
462
|
41 |
|
} |
463
|
5 |
|
|
464
|
5 |
|
/** |
465
|
|
|
* Set Superscript. |
466
|
41 |
|
* |
467
|
41 |
|
* @return $this |
468
|
29 |
|
*/ |
469
|
|
|
public function setSuperscript(bool $superscript): static |
470
|
|
|
{ |
471
|
|
|
if ($this->isSupervisor) { |
472
|
41 |
|
$styleArray = $this->getStyleArray(['superscript' => $superscript]); |
473
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
474
|
|
|
} else { |
475
|
|
|
$this->superscript = $superscript; |
476
|
|
|
if ($this->superscript) { |
477
|
|
|
$this->subscript = false; |
478
|
998 |
|
} |
479
|
|
|
} |
480
|
998 |
|
|
481
|
25 |
|
return $this; |
482
|
|
|
} |
483
|
|
|
|
484
|
998 |
|
/** |
485
|
|
|
* Get Subscript. |
486
|
|
|
*/ |
487
|
|
|
public function getSubscript(): ?bool |
488
|
|
|
{ |
489
|
|
|
if ($this->isSupervisor) { |
490
|
|
|
return $this->getSharedComponent()->getSubscript(); |
491
|
|
|
} |
492
|
39 |
|
|
493
|
|
|
return $this->subscript; |
494
|
39 |
|
} |
495
|
3 |
|
|
496
|
3 |
|
/** |
497
|
|
|
* Set Subscript. |
498
|
39 |
|
* |
499
|
39 |
|
* @return $this |
500
|
27 |
|
*/ |
501
|
|
|
public function setSubscript(bool $subscript): static |
502
|
|
|
{ |
503
|
|
|
if ($this->isSupervisor) { |
504
|
39 |
|
$styleArray = $this->getStyleArray(['subscript' => $subscript]); |
505
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
506
|
|
|
} else { |
507
|
42 |
|
$this->subscript = $subscript; |
508
|
|
|
if ($this->subscript) { |
509
|
42 |
|
$this->superscript = false; |
510
|
8 |
|
} |
511
|
|
|
} |
512
|
|
|
|
513
|
42 |
|
return $this; |
514
|
|
|
} |
515
|
|
|
|
516
|
32 |
|
public function getBaseLine(): int |
517
|
|
|
{ |
518
|
32 |
|
if ($this->isSupervisor) { |
519
|
32 |
|
return $this->getSharedComponent()->getBaseLine(); |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
return $this->baseLine; |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
public function setBaseLine(int $baseLine): self |
526
|
|
|
{ |
527
|
|
|
if (!$this->isSupervisor) { |
528
|
32 |
|
$this->baseLine = $baseLine; |
529
|
|
|
} else { |
530
|
|
|
// should never be true |
531
|
42 |
|
// @codeCoverageIgnoreStart |
532
|
|
|
$styleArray = $this->getStyleArray(['baseLine' => $baseLine]); |
533
|
42 |
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
534
|
8 |
|
// @codeCoverageIgnoreEnd |
535
|
|
|
} |
536
|
|
|
|
537
|
42 |
|
return $this; |
538
|
|
|
} |
539
|
|
|
|
540
|
35 |
|
public function getStrikeType(): string |
541
|
|
|
{ |
542
|
35 |
|
if ($this->isSupervisor) { |
543
|
35 |
|
return $this->getSharedComponent()->getStrikeType(); |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
return $this->strikeType; |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
public function setStrikeType(string $strikeType): self |
550
|
|
|
{ |
551
|
|
|
if (!$this->isSupervisor) { |
552
|
35 |
|
$this->strikeType = $strikeType; |
553
|
|
|
} else { |
554
|
|
|
// should never be true |
555
|
42 |
|
// @codeCoverageIgnoreStart |
556
|
|
|
$styleArray = $this->getStyleArray(['strikeType' => $strikeType]); |
557
|
42 |
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
558
|
8 |
|
// @codeCoverageIgnoreEnd |
559
|
|
|
} |
560
|
|
|
|
561
|
42 |
|
return $this; |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
public function getUnderlineColor(): ?ChartColor |
565
|
8 |
|
{ |
566
|
|
|
if ($this->isSupervisor) { |
567
|
8 |
|
return $this->getSharedComponent()->getUnderlineColor(); |
568
|
8 |
|
} |
569
|
|
|
|
570
|
|
|
return $this->underlineColor; |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
/** @param array{value: null|string, alpha: null|int|string, brightness?: null|int|string, type: null|string} $colorArray */ |
574
|
|
|
public function setUnderlineColor(array $colorArray): self |
575
|
|
|
{ |
576
|
|
|
if (!$this->isSupervisor) { |
577
|
8 |
|
$this->underlineColor = new ChartColor($colorArray); |
578
|
|
|
} else { |
579
|
|
|
// should never be true |
580
|
61 |
|
// @codeCoverageIgnoreStart |
581
|
|
|
$styleArray = $this->getStyleArray(['underlineColor' => $colorArray]); |
582
|
61 |
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
583
|
8 |
|
// @codeCoverageIgnoreEnd |
584
|
|
|
} |
585
|
|
|
|
586
|
61 |
|
return $this; |
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
public function getChartColor(): ?ChartColor |
590
|
30 |
|
{ |
591
|
|
|
if ($this->isSupervisor) { |
592
|
30 |
|
return $this->getSharedComponent()->getChartColor(); |
593
|
30 |
|
} |
594
|
|
|
|
595
|
|
|
return $this->chartColor; |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
/** @param array{value: null|string, alpha: null|int|string, brightness?: null|int|string, type: null|string} $colorArray */ |
599
|
|
|
public function setChartColor(array $colorArray): self |
600
|
|
|
{ |
601
|
|
|
if (!$this->isSupervisor) { |
602
|
30 |
|
$this->chartColor = new ChartColor($colorArray); |
603
|
|
|
} else { |
604
|
|
|
// should never be true |
605
|
12 |
|
// @codeCoverageIgnoreStart |
606
|
|
|
$styleArray = $this->getStyleArray(['chartColor' => $colorArray]); |
607
|
12 |
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
608
|
|
|
// @codeCoverageIgnoreEnd |
609
|
12 |
|
} |
610
|
|
|
|
611
|
|
|
return $this; |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
public function setChartColorFromObject(?ChartColor $chartColor): self |
615
|
1055 |
|
{ |
616
|
|
|
$this->chartColor = $chartColor; |
617
|
1055 |
|
|
618
|
37 |
|
return $this; |
619
|
|
|
} |
620
|
|
|
|
621
|
1055 |
|
/** |
622
|
|
|
* Get Underline. |
623
|
|
|
*/ |
624
|
|
|
public function getUnderline(): ?string |
625
|
|
|
{ |
626
|
|
|
if ($this->isSupervisor) { |
627
|
|
|
return $this->getSharedComponent()->getUnderline(); |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
return $this->underline; |
631
|
|
|
} |
632
|
|
|
|
633
|
560 |
|
/** |
634
|
|
|
* Set Underline. |
635
|
560 |
|
* |
636
|
10 |
|
* @param bool|string $underlineStyle \PhpOffice\PhpSpreadsheet\Style\Font underline type |
637
|
553 |
|
* If a boolean is passed, then TRUE equates to UNDERLINE_SINGLE, |
638
|
2 |
|
* false equates to UNDERLINE_NONE |
639
|
|
|
* |
640
|
560 |
|
* @return $this |
641
|
34 |
|
*/ |
642
|
34 |
|
public function setUnderline($underlineStyle): static |
643
|
|
|
{ |
644
|
560 |
|
if (is_bool($underlineStyle)) { |
645
|
|
|
$underlineStyle = ($underlineStyle) ? self::UNDERLINE_SINGLE : self::UNDERLINE_NONE; |
646
|
|
|
} elseif ($underlineStyle == '') { |
647
|
560 |
|
$underlineStyle = self::UNDERLINE_NONE; |
648
|
|
|
} |
649
|
|
|
if ($this->isSupervisor) { |
650
|
|
|
$styleArray = $this->getStyleArray(['underline' => $underlineStyle]); |
651
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
652
|
|
|
} else { |
653
|
1003 |
|
$this->underline = $underlineStyle; |
654
|
|
|
} |
655
|
1003 |
|
|
656
|
31 |
|
return $this; |
657
|
|
|
} |
658
|
|
|
|
659
|
1003 |
|
/** |
660
|
|
|
* Get Strikethrough. |
661
|
|
|
*/ |
662
|
|
|
public function getStrikethrough(): ?bool |
663
|
|
|
{ |
664
|
|
|
if ($this->isSupervisor) { |
665
|
|
|
return $this->getSharedComponent()->getStrikethrough(); |
666
|
|
|
} |
667
|
525 |
|
|
668
|
|
|
return $this->strikethrough; |
669
|
525 |
|
} |
670
|
10 |
|
|
671
|
10 |
|
/** |
672
|
|
|
* Set Strikethrough. |
673
|
525 |
|
* |
674
|
|
|
* @return $this |
675
|
|
|
*/ |
676
|
525 |
|
public function setStrikethrough(bool $strikethru): static |
677
|
|
|
{ |
678
|
|
|
if ($this->isSupervisor) { |
679
|
|
|
$styleArray = $this->getStyleArray(['strikethrough' => $strikethru]); |
680
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
681
|
|
|
} else { |
682
|
1561 |
|
$this->strikethrough = $strikethru; |
683
|
|
|
} |
684
|
1561 |
|
|
685
|
|
|
return $this; |
686
|
|
|
} |
687
|
|
|
|
688
|
|
|
/** |
689
|
|
|
* Get Color. |
690
|
|
|
*/ |
691
|
|
|
public function getColor(): Color |
692
|
85 |
|
{ |
693
|
|
|
return $this->color; |
694
|
|
|
} |
695
|
85 |
|
|
696
|
|
|
/** |
697
|
85 |
|
* Set Color. |
698
|
11 |
|
* |
699
|
11 |
|
* @return $this |
700
|
|
|
*/ |
701
|
74 |
|
public function setColor(Color $color): static |
702
|
|
|
{ |
703
|
|
|
// make sure parameter is a real color and not a supervisor |
704
|
85 |
|
$color = $color->getIsSupervisor() ? $color->getSharedComponent() : $color; |
705
|
|
|
|
706
|
|
|
if ($this->isSupervisor) { |
707
|
1316 |
|
$styleArray = $this->getColor()->getStyleArray(['argb' => $color->getARGB()]); |
708
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
709
|
1316 |
|
} else { |
710
|
1316 |
|
$this->color = $color; |
711
|
|
|
} |
712
|
|
|
|
713
|
1 |
|
return $this; |
714
|
1 |
|
} |
715
|
1 |
|
|
716
|
1 |
|
private function hashChartColor(?ChartColor $underlineColor): string |
717
|
|
|
{ |
718
|
|
|
if ($underlineColor === null) { |
719
|
|
|
return ''; |
720
|
|
|
} |
721
|
|
|
|
722
|
|
|
return |
723
|
|
|
$underlineColor->getValue() |
724
|
1316 |
|
. $underlineColor->getType() |
725
|
|
|
. (string) $underlineColor->getAlpha(); |
726
|
1316 |
|
} |
727
|
14 |
|
|
728
|
|
|
/** |
729
|
|
|
* Get hash code. |
730
|
1316 |
|
* |
731
|
1316 |
|
* @return string Hash code |
732
|
1316 |
|
*/ |
733
|
1316 |
|
public function getHashCode(): string |
734
|
1316 |
|
{ |
735
|
1316 |
|
if ($this->isSupervisor) { |
736
|
1316 |
|
return $this->getSharedComponent()->getHashCode(); |
737
|
1316 |
|
} |
738
|
1316 |
|
|
739
|
1316 |
|
return md5( |
740
|
1316 |
|
$this->name |
741
|
1316 |
|
. $this->size |
742
|
1316 |
|
. ($this->bold ? 't' : 'f') |
743
|
1316 |
|
. ($this->italic ? 't' : 'f') |
744
|
1316 |
|
. ($this->superscript ? 't' : 'f') |
745
|
1316 |
|
. ($this->subscript ? 't' : 'f') |
746
|
1316 |
|
. $this->underline |
747
|
1316 |
|
. ($this->strikethrough ? 't' : 'f') |
748
|
1316 |
|
. $this->color->getHashCode() |
749
|
1316 |
|
. $this->scheme |
750
|
1316 |
|
. implode( |
751
|
1316 |
|
'*', |
752
|
1316 |
|
[ |
753
|
1316 |
|
$this->latin, |
754
|
1316 |
|
$this->eastAsian, |
755
|
1316 |
|
$this->complexScript, |
756
|
|
|
$this->strikeType, |
757
|
|
|
$this->hashChartColor($this->chartColor), |
758
|
|
|
$this->hashChartColor($this->underlineColor), |
759
|
14 |
|
(string) $this->baseLine, |
760
|
|
|
(string) $this->cap, |
761
|
14 |
|
] |
762
|
14 |
|
) |
763
|
14 |
|
. __CLASS__ |
764
|
14 |
|
); |
765
|
14 |
|
} |
766
|
14 |
|
|
767
|
14 |
|
/** @return mixed[] */ |
768
|
14 |
|
protected function exportArray1(): array |
769
|
14 |
|
{ |
770
|
14 |
|
$exportedArray = []; |
771
|
14 |
|
$this->exportArray2($exportedArray, 'baseLine', $this->getBaseLine()); |
772
|
14 |
|
$this->exportArray2($exportedArray, 'bold', $this->getBold()); |
773
|
14 |
|
$this->exportArray2($exportedArray, 'cap', $this->getCap()); |
774
|
14 |
|
$this->exportArray2($exportedArray, 'chartColor', $this->getChartColor()); |
775
|
14 |
|
$this->exportArray2($exportedArray, 'color', $this->getColor()); |
776
|
14 |
|
$this->exportArray2($exportedArray, 'complexScript', $this->getComplexScript()); |
777
|
14 |
|
$this->exportArray2($exportedArray, 'eastAsian', $this->getEastAsian()); |
778
|
14 |
|
$this->exportArray2($exportedArray, 'italic', $this->getItalic()); |
779
|
14 |
|
$this->exportArray2($exportedArray, 'latin', $this->getLatin()); |
780
|
|
|
$this->exportArray2($exportedArray, 'name', $this->getName()); |
781
|
14 |
|
$this->exportArray2($exportedArray, 'scheme', $this->getScheme()); |
782
|
|
|
$this->exportArray2($exportedArray, 'size', $this->getSize()); |
783
|
|
|
$this->exportArray2($exportedArray, 'strikethrough', $this->getStrikethrough()); |
784
|
397 |
|
$this->exportArray2($exportedArray, 'strikeType', $this->getStrikeType()); |
785
|
|
|
$this->exportArray2($exportedArray, 'subscript', $this->getSubscript()); |
786
|
397 |
|
$this->exportArray2($exportedArray, 'superscript', $this->getSuperscript()); |
787
|
9 |
|
$this->exportArray2($exportedArray, 'underline', $this->getUnderline()); |
788
|
|
|
$this->exportArray2($exportedArray, 'underlineColor', $this->getUnderlineColor()); |
789
|
|
|
|
790
|
397 |
|
return $exportedArray; |
791
|
|
|
} |
792
|
|
|
|
793
|
998 |
|
public function getScheme(): string |
794
|
|
|
{ |
795
|
998 |
|
if ($this->isSupervisor) { |
796
|
998 |
|
return $this->getSharedComponent()->getScheme(); |
797
|
41 |
|
} |
798
|
41 |
|
|
799
|
|
|
return $this->scheme; |
800
|
998 |
|
} |
801
|
|
|
|
802
|
|
|
public function setScheme(string $scheme): self |
803
|
|
|
{ |
804
|
998 |
|
if ($scheme === '' || $scheme === 'major' || $scheme === 'minor') { |
805
|
|
|
if ($this->isSupervisor) { |
806
|
|
|
$styleArray = $this->getStyleArray(['scheme' => $scheme]); |
807
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
808
|
|
|
} else { |
809
|
|
|
$this->scheme = $scheme; |
810
|
|
|
} |
811
|
|
|
} |
812
|
|
|
|
813
|
|
|
return $this; |
814
|
21 |
|
} |
815
|
|
|
|
816
|
21 |
|
/** |
817
|
|
|
* Set capitalization attribute. If not one of the permitted |
818
|
21 |
|
* values (all, small, or none), set it to null. |
819
|
|
|
* This will be honored only for the font for chart titles. |
820
|
|
|
* None is distinguished from null because null will inherit |
821
|
28 |
|
* the current value, whereas 'none' will override it. |
822
|
|
|
*/ |
823
|
28 |
|
public function setCap(string $cap): self |
824
|
|
|
{ |
825
|
|
|
$this->cap = in_array($cap, self::VALID_CAPS, true) ? $cap : null; |
826
|
19 |
|
|
827
|
|
|
return $this; |
828
|
19 |
|
} |
829
|
19 |
|
|
830
|
|
|
public function getCap(): ?string |
831
|
19 |
|
{ |
832
|
|
|
return $this->cap; |
833
|
|
|
} |
834
|
|
|
|
835
|
|
|
public function setHyperlinkTheme(): self |
836
|
|
|
{ |
837
|
1122 |
|
$this->color->setHyperlinkTheme(); |
838
|
|
|
$this->setUnderline(self::UNDERLINE_SINGLE); |
839
|
1122 |
|
|
840
|
1122 |
|
return $this; |
841
|
1122 |
|
} |
842
|
|
|
|
843
|
|
|
/** |
844
|
|
|
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
845
|
|
|
*/ |
846
|
|
|
public function __clone() |
847
|
|
|
{ |
848
|
|
|
$this->color = clone $this->color; |
849
|
|
|
$this->chartColor = ($this->chartColor === null) ? null : clone $this->chartColor; |
850
|
|
|
$this->underlineColor = ($this->underlineColor === null) ? null : clone $this->underlineColor; |
851
|
|
|
} |
852
|
|
|
} |
853
|
|
|
|