Passed
Pull Request — master (#4426)
by
unknown
13:11
created

Font::setColor()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

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