Font::setBold()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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