Passed
Pull Request — master (#4478)
by Owen
15:20
created

Font::setHyperlinkTheme()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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