Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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