Passed
Pull Request — master (#4503)
by Owen
12:07
created

Font::getAutoColor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
rs 10
ccs 0
cts 0
cp 0
cc 2
nc 2
nop 0
crap 6
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
    protected bool $autoColor = false;
89
90
    public ?int $colorIndex = null;
91
92
    protected string $scheme = '';
93
94
    /**
95
     * Create a new Font.
96
     *
97
     * @param bool $isSupervisor Flag indicating if this is a supervisor or not
98
     *                                    Leave this value at default unless you understand exactly what
99
     *                                        its ramifications are
100
     * @param bool $isConditional Flag indicating if this is a conditional style or not
101
     *                                    Leave this value at default unless you understand exactly what
102 10760
     *                                        its ramifications are
103
     */
104
    public function __construct(bool $isSupervisor = false, bool $isConditional = false)
105 10760
    {
106
        // Supervisor?
107
        parent::__construct($isSupervisor);
108 10760
109 402
        // Initialise values
110 402
        if ($isConditional) {
111 402
            $this->name = null;
112 402
            $this->size = null;
113 402
            $this->bold = null;
114 402
            $this->italic = null;
115 402
            $this->superscript = null;
116 402
            $this->subscript = null;
117 402
            $this->underline = null;
118
            $this->strikethrough = null;
119 10757
            $this->color = new Color(Color::COLOR_BLACK, $isSupervisor, $isConditional);
120
        } else {
121
            $this->color = new Color(Color::COLOR_BLACK, $isSupervisor);
122 10760
        }
123 10575
        // bind parent if we are a supervisor
124
        if ($isSupervisor) {
125
            $this->color->bindParent($this, 'color');
126
        }
127
    }
128
129
    /**
130
     * Get the shared style component for the currently active cell in currently active sheet.
131 94
     * Only used for style supervisor.
132
     */
133
    public function getSharedComponent(): self
134 94
    {
135
        /** @var Style $parent */
136 94
        $parent = $this->parent;
137
138
        return $parent->getSharedComponent()->getFont();
139
    }
140
141
    /**
142
     * Build style array from subcomponents.
143
     *
144
     * @param mixed[] $array
145
     *
146 109
     * @return array{font: mixed[]}
147
     */
148 109
    public function getStyleArray(array $array): array
149
    {
150
        return ['font' => $array];
151
    }
152
153
    /**
154
     * Apply styles from array.
155
     *
156
     * <code>
157
     * $spreadsheet->getActiveSheet()->getStyle('B2')->getFont()->applyFromArray(
158
     *     [
159
     *         'name' => 'Arial',
160
     *         'bold' => TRUE,
161
     *         'italic' => FALSE,
162
     *         'underline' => \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLE,
163
     *         'strikethrough' => FALSE,
164
     *         'color' => [
165
     *             'rgb' => '808080'
166
     *         ]
167
     *     ]
168
     * );
169
     * </code>
170
     *
171
     * @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
172
     *
173 274
     * @return $this
174
     */
175 274
    public function applyFromArray(array $styleArray): static
176 1
    {
177
        if ($this->isSupervisor) {
178 274
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray));
179 178
        } else {
180
            if (isset($styleArray['name'])) {
181 274
                $this->setName($styleArray['name']);
182 25
            }
183
            if (isset($styleArray['latin'])) {
184 274
                $this->setLatin($styleArray['latin']);
185 17
            }
186
            if (isset($styleArray['eastAsian'])) {
187 274
                $this->setEastAsian($styleArray['eastAsian']);
188 17
            }
189
            if (isset($styleArray['complexScript'])) {
190 274
                $this->setComplexScript(
191 181
                    $styleArray['complexScript']
192
                );
193 274
            }
194 121
            if (isset($styleArray['bold'])) {
195
                $this->setBold($styleArray['bold']);
196 274
            }
197 30
            if (isset($styleArray['italic'])) {
198
                $this->setItalic($styleArray['italic']);
199 274
            }
200 28
            if (isset($styleArray['superscript'])) {
201
                $this->setSuperscript($styleArray['superscript']);
202 274
            }
203 66
            if (isset($styleArray['subscript'])) {
204
                $this->setSubscript($styleArray['subscript']);
205 274
            }
206 59
            if (isset($styleArray['underline'])) {
207
                $this->setUnderline($styleArray['underline']);
208 274
            }
209
            if (isset($styleArray['strikethrough'])) {
210 118
                $this->setStrikethrough(
211 118
                    $styleArray['strikethrough']
212 118
                );
213
            }
214 274
            if (isset($styleArray['color'])) {
215 118
                /** @var array{rgb?: string, argb?: string, theme?: int} */
216
                $temp = $styleArray['color'];
217 274
                $this->getColor()
218 13
                    ->applyFromArray($temp);
219
            }
220 274
            if (isset($styleArray['size'])) {
221 51
                $this->setSize($styleArray['size']);
222
            }
223 274
            if (isset($styleArray['chartColor'])) {
224 21
                $this->chartColor = $styleArray['chartColor'];
225
            }
226
            if (isset($styleArray['scheme'])) {
227
                $this->setScheme($styleArray['scheme']);
228 274
            }
229
            if (isset($styleArray['cap'])) {
230
                $this->setCap($styleArray['cap']);
231
            }
232
            if (isset($styleArray['autoColor'])) {
233
                $this->setAutoColor($styleArray['autoColor']);
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->autoColor ? 't' : 'f')
749 1316
            . $this->color->getHashCode()
750 1316
            . $this->scheme
751 1316
            . implode(
752 1316
                '*',
753 1316
                [
754 1316
                    $this->latin,
755 1316
                    $this->eastAsian,
756
                    $this->complexScript,
757
                    $this->strikeType,
758
                    $this->hashChartColor($this->chartColor),
759 14
                    $this->hashChartColor($this->underlineColor),
760
                    (string) $this->baseLine,
761 14
                    (string) $this->cap,
762 14
                ]
763 14
            )
764 14
            . __CLASS__
765 14
        );
766 14
    }
767 14
768 14
    /** @return mixed[] */
769 14
    protected function exportArray1(): array
770 14
    {
771 14
        $exportedArray = [];
772 14
        $this->exportArray2($exportedArray, 'baseLine', $this->getBaseLine());
773 14
        $this->exportArray2($exportedArray, 'bold', $this->getBold());
774 14
        $this->exportArray2($exportedArray, 'cap', $this->getCap());
775 14
        $this->exportArray2($exportedArray, 'chartColor', $this->getChartColor());
776 14
        $this->exportArray2($exportedArray, 'color', $this->getColor());
777 14
        $this->exportArray2($exportedArray, 'complexScript', $this->getComplexScript());
778 14
        $this->exportArray2($exportedArray, 'eastAsian', $this->getEastAsian());
779 14
        $this->exportArray2($exportedArray, 'italic', $this->getItalic());
780
        $this->exportArray2($exportedArray, 'latin', $this->getLatin());
781 14
        $this->exportArray2($exportedArray, 'name', $this->getName());
782
        $this->exportArray2($exportedArray, 'scheme', $this->getScheme());
783
        $this->exportArray2($exportedArray, 'size', $this->getSize());
784 397
        $this->exportArray2($exportedArray, 'strikethrough', $this->getStrikethrough());
785
        $this->exportArray2($exportedArray, 'strikeType', $this->getStrikeType());
786 397
        $this->exportArray2($exportedArray, 'subscript', $this->getSubscript());
787 9
        $this->exportArray2($exportedArray, 'superscript', $this->getSuperscript());
788
        $this->exportArray2($exportedArray, 'underline', $this->getUnderline());
789
        $this->exportArray2($exportedArray, 'underlineColor', $this->getUnderlineColor());
790 397
        $this->exportArray2($exportedArray, 'autoColor', $this->getAutoColor());
791
792
        return $exportedArray;
793 998
    }
794
795 998
    public function getScheme(): string
796 998
    {
797 41
        if ($this->isSupervisor) {
798 41
            return $this->getSharedComponent()->getScheme();
799
        }
800 998
801
        return $this->scheme;
802
    }
803
804 998
    public function setScheme(string $scheme): self
805
    {
806
        if ($scheme === '' || $scheme === 'major' || $scheme === 'minor') {
807
            if ($this->isSupervisor) {
808
                $styleArray = $this->getStyleArray(['scheme' => $scheme]);
809
                $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
810
            } else {
811
                $this->scheme = $scheme;
812
            }
813
        }
814 21
815
        return $this;
816 21
    }
817
818 21
    /**
819
     * Set capitalization attribute. If not one of the permitted
820
     * values (all, small, or none), set it to null.
821 28
     * This will be honored only for the font for chart titles.
822
     * None is distinguished from null because null will inherit
823 28
     * the current value, whereas 'none' will override it.
824
     */
825
    public function setCap(string $cap): self
826 19
    {
827
        $this->cap = in_array($cap, self::VALID_CAPS, true) ? $cap : null;
828 19
829 19
        return $this;
830
    }
831 19
832
    public function getCap(): ?string
833
    {
834
        return $this->cap;
835
    }
836
837 1122
    public function setHyperlinkTheme(): self
838
    {
839 1122
        $this->color->setHyperlinkTheme();
840 1122
        $this->setUnderline(self::UNDERLINE_SINGLE);
841 1122
842
        return $this;
843
    }
844
845
    public function setAutoColor(bool $autoColor): self
846
    {
847
        if ($this->isSupervisor) {
848
            $styleArray = $this->getStyleArray(['autoColor' => $autoColor]);
849
            $this->getActiveSheet()
850
                ->getStyle($this->getSelectedCells())
851
                ->applyFromArray($styleArray);
852
        } else {
853
            $this->autoColor = $autoColor;
854
        }
855
856
        return $this;
857
    }
858
859
    public function getAutoColor(): bool
860
    {
861
        if ($this->isSupervisor) {
862
            return $this->getSharedComponent()->getAutoColor();
863
        }
864
865
        return $this->autoColor;
866
    }
867
868
    /**
869
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
870
     */
871
    public function __clone()
872
    {
873
        $this->color = clone $this->color;
874
        $this->chartColor = ($this->chartColor === null) ? null : clone $this->chartColor;
875
        $this->underlineColor = ($this->underlineColor === null) ? null : clone $this->underlineColor;
876
    }
877
}
878