Passed
Push — master ( 30369c...0dbe15 )
by
unknown
23:07 queued 15:34
created

Font::setBold()   A

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 10765
    public function __construct(bool $isSupervisor = false, bool $isConditional = false)
106
    {
107
        // Supervisor?
108 10765
        parent::__construct($isSupervisor);
109
110
        // Initialise values
111 10765
        if ($isConditional) {
112 402
            $this->name = null;
113 402
            $this->size = null;
114 402
            $this->bold = null;
115 402
            $this->italic = null;
116 402
            $this->superscript = null;
117 402
            $this->subscript = null;
118 402
            $this->underline = null;
119 402
            $this->strikethrough = null;
120 402
            $this->color = new Color(Color::COLOR_BLACK, $isSupervisor, $isConditional);
121
        } else {
122 10762
            $this->color = new Color(Color::COLOR_BLACK, $isSupervisor);
123
        }
124
        // bind parent if we are a supervisor
125 10765
        if ($isSupervisor) {
126 10580
            $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 100
    public function getSharedComponent(): self
143
    {
144
        /** @var Style $parent */
145 100
        $parent = $this->parent;
146
147 100
        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 112
    public function getStyleArray(array $array): array
158
    {
159 112
        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 277
    public function applyFromArray(array $styleArray): static
185
    {
186 277
        if ($this->isSupervisor) {
187 1
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray));
188
        } else {
189 277
            if (isset($styleArray['name'])) {
190 179
                $this->setName($styleArray['name']);
191
            }
192 277
            if (isset($styleArray['latin'])) {
193 25
                $this->setLatin($styleArray['latin']);
194
            }
195 277
            if (isset($styleArray['eastAsian'])) {
196 17
                $this->setEastAsian($styleArray['eastAsian']);
197
            }
198 277
            if (isset($styleArray['complexScript'])) {
199 17
                $this->setComplexScript(
200 17
                    $styleArray['complexScript']
201 17
                );
202
            }
203 277
            if (isset($styleArray['bold'])) {
204 183
                $this->setBold($styleArray['bold']);
205
            }
206 277
            if (isset($styleArray['italic'])) {
207 123
                $this->setItalic($styleArray['italic']);
208
            }
209 277
            if (isset($styleArray['superscript'])) {
210 30
                $this->setSuperscript($styleArray['superscript']);
211
            }
212 277
            if (isset($styleArray['subscript'])) {
213 28
                $this->setSubscript($styleArray['subscript']);
214
            }
215 277
            if (isset($styleArray['underline'])) {
216 66
                $this->setUnderline($styleArray['underline']);
217
            }
218 277
            if (isset($styleArray['strikethrough'])) {
219 59
                $this->setStrikethrough(
220 59
                    $styleArray['strikethrough']
221 59
                );
222
            }
223 277
            if (isset($styleArray['color'])) {
224
                /** @var array{rgb?: string, argb?: string, theme?: int} */
225 118
                $temp = $styleArray['color'];
226 118
                $this->getColor()
227 118
                    ->applyFromArray($temp);
228
            }
229 277
            if (isset($styleArray['size'])) {
230 118
                $this->setSize($styleArray['size']);
231
            }
232 277
            if (isset($styleArray['chartColor'])) {
233 13
                $this->chartColor = $styleArray['chartColor'];
234
            }
235 277
            if (isset($styleArray['scheme'])) {
236 52
                $this->setScheme($styleArray['scheme']);
237
            }
238 277
            if (isset($styleArray['cap'])) {
239 21
                $this->setCap($styleArray['cap']);
240
            }
241 277
            if (isset($styleArray['autoColor'])) {
242 12
                $this->setAutoColor($styleArray['autoColor']);
243
            }
244
        }
245
246 277
        return $this;
247
    }
248
249
    /**
250
     * Get Name.
251
     */
252 1234
    public function getName(): ?string
253
    {
254 1234
        if ($this->isSupervisor) {
255 47
            return $this->getSharedComponent()->getName();
256
        }
257
258 1234
        return $this->name;
259
    }
260
261 53
    public function getLatin(): string
262
    {
263 53
        if ($this->isSupervisor) {
264 8
            return $this->getSharedComponent()->getLatin();
265
        }
266
267 53
        return $this->latin;
268
    }
269
270 53
    public function getEastAsian(): string
271
    {
272 53
        if ($this->isSupervisor) {
273 8
            return $this->getSharedComponent()->getEastAsian();
274
        }
275
276 53
        return $this->eastAsian;
277
    }
278
279 53
    public function getComplexScript(): string
280
    {
281 53
        if ($this->isSupervisor) {
282 8
            return $this->getSharedComponent()->getComplexScript();
283
        }
284
285 53
        return $this->complexScript;
286
    }
287
288
    /**
289
     * Set Name and turn off Scheme.
290
     */
291 1002
    public function setName(string $fontname): self
292
    {
293 1002
        if ($fontname == '') {
294 1
            $fontname = 'Calibri';
295
        }
296 1002
        if ($this->isSupervisor) {
297 42
            $styleArray = $this->getStyleArray(['name' => $fontname]);
298 42
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
299
        } else {
300 1002
            $this->name = $fontname;
301
        }
302
303 1002
        return $this->setScheme('');
304
    }
305
306 49
    public function setLatin(string $fontname): self
307
    {
308 49
        if ($fontname == '') {
309 12
            $fontname = 'Calibri';
310
        }
311 49
        if (!$this->isSupervisor) {
312 49
            $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 49
        return $this;
322
    }
323
324 42
    public function setEastAsian(string $fontname): self
325
    {
326 42
        if ($fontname == '') {
327 13
            $fontname = 'Calibri';
328
        }
329 42
        if (!$this->isSupervisor) {
330 42
            $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 42
        return $this;
340
    }
341
342 42
    public function setComplexScript(string $fontname): self
343
    {
344 42
        if ($fontname == '') {
345 13
            $fontname = 'Calibri';
346
        }
347 42
        if (!$this->isSupervisor) {
348 42
            $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 42
        return $this;
358
    }
359
360
    /**
361
     * Get Size.
362
     */
363 1170
    public function getSize(): ?float
364
    {
365 1170
        if ($this->isSupervisor) {
366 36
            return $this->getSharedComponent()->getSize();
367
        }
368
369 1170
        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 932
    public function setSize(mixed $sizeInPoints, bool $nullOk = false): static
380
    {
381 932
        if (is_string($sizeInPoints) || is_int($sizeInPoints)) {
382 254
            $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 932
        if (!is_float($sizeInPoints) || !($sizeInPoints > 0)) {
388 57
            if (!$nullOk || $sizeInPoints !== null) {
389 1
                $sizeInPoints = 10.0;
390
            }
391
        }
392
393 932
        if ($this->isSupervisor) {
394 20
            $styleArray = $this->getStyleArray(['size' => $sizeInPoints]);
395 20
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
396
        } else {
397 932
            $this->size = $sizeInPoints;
398
        }
399
400 932
        return $this;
401
    }
402
403
    /**
404
     * Get Bold.
405
     */
406 1146
    public function getBold(): ?bool
407
    {
408 1146
        if ($this->isSupervisor) {
409 62
            return $this->getSharedComponent()->getBold();
410
        }
411
412 1146
        return $this->bold;
413
    }
414
415
    /**
416
     * Set Bold.
417
     *
418
     * @return $this
419
     */
420 768
    public function setBold(bool $bold): static
421
    {
422 768
        if ($this->isSupervisor) {
423 74
            $styleArray = $this->getStyleArray(['bold' => $bold]);
424 74
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
425
        } else {
426 768
            $this->bold = $bold;
427
        }
428
429 768
        return $this;
430
    }
431
432
    /**
433
     * Get Italic.
434
     */
435 1134
    public function getItalic(): ?bool
436
    {
437 1134
        if ($this->isSupervisor) {
438 49
            return $this->getSharedComponent()->getItalic();
439
        }
440
441 1134
        return $this->italic;
442
    }
443
444
    /**
445
     * Set Italic.
446
     *
447
     * @return $this
448
     */
449 672
    public function setItalic(bool $italic): static
450
    {
451 672
        if ($this->isSupervisor) {
452 21
            $styleArray = $this->getStyleArray(['italic' => $italic]);
453 21
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
454
        } else {
455 672
            $this->italic = $italic;
456
        }
457
458 672
        return $this;
459
    }
460
461
    /**
462
     * Get Superscript.
463
     */
464 1002
    public function getSuperscript(): ?bool
465
    {
466 1002
        if ($this->isSupervisor) {
467 25
            return $this->getSharedComponent()->getSuperscript();
468
        }
469
470 1002
        return $this->superscript;
471
    }
472
473
    /**
474
     * Set Superscript.
475
     *
476
     * @return $this
477
     */
478 41
    public function setSuperscript(bool $superscript): static
479
    {
480 41
        if ($this->isSupervisor) {
481 5
            $styleArray = $this->getStyleArray(['superscript' => $superscript]);
482 5
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
483
        } else {
484 41
            $this->superscript = $superscript;
485 41
            if ($this->superscript) {
486 29
                $this->subscript = false;
487
            }
488
        }
489
490 41
        return $this;
491
    }
492
493
    /**
494
     * Get Subscript.
495
     */
496 1002
    public function getSubscript(): ?bool
497
    {
498 1002
        if ($this->isSupervisor) {
499 25
            return $this->getSharedComponent()->getSubscript();
500
        }
501
502 1002
        return $this->subscript;
503
    }
504
505
    /**
506
     * Set Subscript.
507
     *
508
     * @return $this
509
     */
510 39
    public function setSubscript(bool $subscript): static
511
    {
512 39
        if ($this->isSupervisor) {
513 3
            $styleArray = $this->getStyleArray(['subscript' => $subscript]);
514 3
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
515
        } else {
516 39
            $this->subscript = $subscript;
517 39
            if ($this->subscript) {
518 27
                $this->superscript = false;
519
            }
520
        }
521
522 39
        return $this;
523
    }
524
525 42
    public function getBaseLine(): int
526
    {
527 42
        if ($this->isSupervisor) {
528 8
            return $this->getSharedComponent()->getBaseLine();
529
        }
530
531 42
        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 42
    public function getStrikeType(): string
550
    {
551 42
        if ($this->isSupervisor) {
552 8
            return $this->getSharedComponent()->getStrikeType();
553
        }
554
555 42
        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 42
    public function getUnderlineColor(): ?ChartColor
574
    {
575 42
        if ($this->isSupervisor) {
576 8
            return $this->getSharedComponent()->getUnderlineColor();
577
        }
578
579 42
        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 61
    public function getChartColor(): ?ChartColor
599
    {
600 61
        if ($this->isSupervisor) {
601 8
            return $this->getSharedComponent()->getChartColor();
602
        }
603
604 61
        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 1060
    public function getUnderline(): ?string
634
    {
635 1060
        if ($this->isSupervisor) {
636 37
            return $this->getSharedComponent()->getUnderline();
637
        }
638
639 1060
        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 564
    public function setUnderline($underlineStyle): static
652
    {
653 564
        if (is_bool($underlineStyle)) {
654 10
            $underlineStyle = ($underlineStyle) ? self::UNDERLINE_SINGLE : self::UNDERLINE_NONE;
655 557
        } elseif ($underlineStyle == '') {
656 2
            $underlineStyle = self::UNDERLINE_NONE;
657
        }
658 564
        if ($this->isSupervisor) {
659 34
            $styleArray = $this->getStyleArray(['underline' => $underlineStyle]);
660 34
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
661
        } else {
662 564
            $this->underline = $underlineStyle;
663
        }
664
665 564
        return $this;
666
    }
667
668
    /**
669
     * Get Strikethrough.
670
     */
671 1007
    public function getStrikethrough(): ?bool
672
    {
673 1007
        if ($this->isSupervisor) {
674 31
            return $this->getSharedComponent()->getStrikethrough();
675
        }
676
677 1007
        return $this->strikethrough;
678
    }
679
680
    /**
681
     * Set Strikethrough.
682
     *
683
     * @return $this
684
     */
685 529
    public function setStrikethrough(bool $strikethru): static
686
    {
687 529
        if ($this->isSupervisor) {
688 10
            $styleArray = $this->getStyleArray(['strikethrough' => $strikethru]);
689 10
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
690
        } else {
691 529
            $this->strikethrough = $strikethru;
692
        }
693
694 529
        return $this;
695
    }
696
697
    /**
698
     * Get Color.
699
     */
700 1565
    public function getColor(): Color
701
    {
702 1565
        return $this->color;
703
    }
704
705
    /**
706
     * Set Color.
707
     *
708
     * @return $this
709
     */
710 85
    public function setColor(Color $color): static
711
    {
712
        // make sure parameter is a real color and not a supervisor
713 85
        $color = $color->getIsSupervisor() ? $color->getSharedComponent() : $color;
714
715 85
        if ($this->isSupervisor) {
716 11
            $styleArray = $this->getColor()->getStyleArray(['argb' => $color->getARGB()]);
717 11
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
718
        } else {
719 74
            $this->color = $color;
720
        }
721
722 85
        return $this;
723
    }
724
725 1321
    private function hashChartColor(?ChartColor $underlineColor): string
726
    {
727 1321
        if ($underlineColor === null) {
728 1321
            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 1321
    public function getHashCode(): string
743
    {
744 1321
        if ($this->isSupervisor) {
745 14
            return $this->getSharedComponent()->getHashCode();
746
        }
747
748 1321
        return md5(
749 1321
            $this->name
750 1321
            . $this->size
751 1321
            . ($this->bold ? 't' : 'f')
752 1321
            . ($this->italic ? 't' : 'f')
753 1321
            . ($this->superscript ? 't' : 'f')
754 1321
            . ($this->subscript ? 't' : 'f')
755 1321
            . $this->underline
756 1321
            . ($this->strikethrough ? 't' : 'f')
757 1321
            . ($this->autoColor ? 't' : 'f')
758 1321
            . $this->color->getHashCode()
759 1321
            . $this->scheme
760 1321
            . implode(
761 1321
                '*',
762 1321
                [
763 1321
                    $this->latin,
764 1321
                    $this->eastAsian,
765 1321
                    $this->complexScript,
766 1321
                    $this->strikeType,
767 1321
                    $this->hashChartColor($this->chartColor),
768 1321
                    $this->hashChartColor($this->underlineColor),
769 1321
                    (string) $this->baseLine,
770 1321
                    (string) $this->cap,
771 1321
                ]
772 1321
            )
773 1321
            . __CLASS__
774 1321
        );
775
    }
776
777
    /** @return mixed[] */
778 14
    protected function exportArray1(): array
779
    {
780 14
        $exportedArray = [];
781 14
        $this->exportArray2($exportedArray, 'baseLine', $this->getBaseLine());
782 14
        $this->exportArray2($exportedArray, 'bold', $this->getBold());
783 14
        $this->exportArray2($exportedArray, 'cap', $this->getCap());
784 14
        $this->exportArray2($exportedArray, 'chartColor', $this->getChartColor());
785 14
        $this->exportArray2($exportedArray, 'color', $this->getColor());
786 14
        $this->exportArray2($exportedArray, 'complexScript', $this->getComplexScript());
787 14
        $this->exportArray2($exportedArray, 'eastAsian', $this->getEastAsian());
788 14
        $this->exportArray2($exportedArray, 'italic', $this->getItalic());
789 14
        $this->exportArray2($exportedArray, 'latin', $this->getLatin());
790 14
        $this->exportArray2($exportedArray, 'name', $this->getName());
791 14
        $this->exportArray2($exportedArray, 'scheme', $this->getScheme());
792 14
        $this->exportArray2($exportedArray, 'size', $this->getSize());
793 14
        $this->exportArray2($exportedArray, 'strikethrough', $this->getStrikethrough());
794 14
        $this->exportArray2($exportedArray, 'strikeType', $this->getStrikeType());
795 14
        $this->exportArray2($exportedArray, 'subscript', $this->getSubscript());
796 14
        $this->exportArray2($exportedArray, 'superscript', $this->getSuperscript());
797 14
        $this->exportArray2($exportedArray, 'underline', $this->getUnderline());
798 14
        $this->exportArray2($exportedArray, 'underlineColor', $this->getUnderlineColor());
799 14
        $this->exportArray2($exportedArray, 'autoColor', $this->getAutoColor());
800
801 14
        return $exportedArray;
802
    }
803
804 401
    public function getScheme(): string
805
    {
806 401
        if ($this->isSupervisor) {
807 9
            return $this->getSharedComponent()->getScheme();
808
        }
809
810 401
        return $this->scheme;
811
    }
812
813 1002
    public function setScheme(string $scheme): self
814
    {
815 1002
        if ($scheme === '' || $scheme === 'major' || $scheme === 'minor') {
816 1002
            if ($this->isSupervisor) {
817 42
                $styleArray = $this->getStyleArray(['scheme' => $scheme]);
818 42
                $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
819
            } else {
820 1002
                $this->scheme = $scheme;
821
            }
822
        }
823
824 1002
        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 28
    public function getCap(): ?string
842
    {
843 28
        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 14
    public function setAutoColor(bool $autoColor): self
855
    {
856 14
        if ($this->isSupervisor) {
857
            $styleArray = $this->getStyleArray(['autoColor' => $autoColor]);
858
            $this->getActiveSheet()
859
                ->getStyle($this->getSelectedCells())
860
                ->applyFromArray($styleArray);
861
        } else {
862 14
            $this->autoColor = $autoColor;
863
        }
864
865 14
        return $this;
866
    }
867
868 442
    public function getAutoColor(): bool
869
    {
870 442
        if ($this->isSupervisor) {
871 9
            return $this->getSharedComponent()->getAutoColor();
872
        }
873
874 442
        return $this->autoColor;
875
    }
876
877
    /**
878
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
879
     */
880 1125
    public function __clone()
881
    {
882 1125
        $this->color = clone $this->color;
883 1125
        $this->chartColor = ($this->chartColor === null) ? null : clone $this->chartColor;
884 1125
        $this->underlineColor = ($this->underlineColor === null) ? null : clone $this->underlineColor;
885
    }
886
}
887