Passed
Push — master ( 84b7ab...30369c )
by
unknown
18:09 queued 14s
created

Theme::setMinorFontValues()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.6111
c 0
b 0
f 0
cc 5
nc 16
nop 4
crap 5
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet;
4
5
class Theme
6
{
7
    private string $themeColorName = 'Office';
8
9
    private string $themeFontName = 'Office';
10
11
    public const HYPERLINK_THEME = 10;
12
    public const COLOR_SCHEME_2013_2022_NAME = 'Office 2013-2022';
13
    public const COLOR_SCHEME_2013_2022 = [
14
        'dk1' => '000000',
15
        'lt1' => 'FFFFFF',
16
        'dk2' => '44546A',
17
        'lt2' => 'E7E6E6',
18
        'accent1' => '4472C4',
19
        'accent2' => 'ED7D31',
20
        'accent3' => 'A5A5A5',
21
        'accent4' => 'FFC000',
22
        'accent5' => '5B9BD5',
23
        'accent6' => '70AD47',
24
        'hlink' => '0563C1',
25
        'folHlink' => '954F72',
26
    ];
27
    /** @deprecated 4.4.0 Use COLOR_SCHEME_2013_2022_NAME */
28
    public const COLOR_SCHEME_2013_PLUS_NAME = 'Office 2013+';
29
    /** @deprecated 4.4.0 Use COLOR_SCHEME_2013_2022 */
30
    public const COLOR_SCHEME_2013_PLUS = self::COLOR_SCHEME_2013_2022;
31
32
    public const COLOR_SCHEME_2007_2010_NAME = 'Office 2007-2010';
33
    public const COLOR_SCHEME_2007_2010 = [
34
        'dk1' => '000000',
35
        'lt1' => 'FFFFFF',
36
        'dk2' => '1F497D',
37
        'lt2' => 'EEECE1',
38
        'accent1' => '4F81BD',
39
        'accent2' => 'C0504D',
40
        'accent3' => '9BBB59',
41
        'accent4' => '8064A2',
42
        'accent5' => '4BACC6',
43
        'accent6' => 'F79646',
44
        'hlink' => '0000FF',
45
        'folHlink' => '800080',
46
    ];
47
48
    public const COLOR_SCHEME_2023_PLUS_NAME = 'Office 2023+';
49
    public const COLOR_SCHEME_2023_PLUS = [
50
        'dk1' => '000000',
51
        'lt1' => 'FFFFFF',
52
        'dk2' => '0E2841',
53
        'lt2' => 'E8E8E8',
54
        'accent1' => '156082',
55
        'accent2' => 'E97132',
56
        'accent3' => '196B24',
57
        'accent4' => '0F9ED5',
58
        'accent5' => 'A02B93',
59
        'accent6' => '4EA72E',
60
        'hlink' => '467886',
61
        'folHlink' => '96607D',
62
    ];
63
64
    /** @var string[] */
65
    private array $themeColors = self::COLOR_SCHEME_2007_2010;
66
67
    private string $majorFontLatin = 'Cambria';
68
69
    private string $majorFontEastAsian = '';
70
71
    private string $majorFontComplexScript = '';
72
73
    private string $minorFontLatin = 'Calibri';
74
75
    private string $minorFontEastAsian = '';
76
77
    private string $minorFontComplexScript = '';
78
79
    /**
80
     * Map of Major (header) fonts to write.
81
     *
82
     * @var string[]
83
     */
84
    private array $majorFontSubstitutions = self::FONTS_TIMES_SUBSTITUTIONS;
85
86
    /**
87
     * Map of Minor (body) fonts to write.
88
     *
89
     * @var string[]
90
     */
91
    private array $minorFontSubstitutions = self::FONTS_ARIAL_SUBSTITUTIONS;
92
93
    public const FONTS_TIMES_SUBSTITUTIONS = [
94
        'Jpan' => 'MS Pゴシック',
95
        'Hang' => '맑은 고딕',
96
        'Hans' => '宋体',
97
        'Hant' => '新細明體',
98
        'Arab' => 'Times New Roman',
99
        'Hebr' => 'Times New Roman',
100
        'Thai' => 'Tahoma',
101
        'Ethi' => 'Nyala',
102
        'Beng' => 'Vrinda',
103
        'Gujr' => 'Shruti',
104
        'Khmr' => 'MoolBoran',
105
        'Knda' => 'Tunga',
106
        'Guru' => 'Raavi',
107
        'Cans' => 'Euphemia',
108
        'Cher' => 'Plantagenet Cherokee',
109
        'Yiii' => 'Microsoft Yi Baiti',
110
        'Tibt' => 'Microsoft Himalaya',
111
        'Thaa' => 'MV Boli',
112
        'Deva' => 'Mangal',
113
        'Telu' => 'Gautami',
114
        'Taml' => 'Latha',
115
        'Syrc' => 'Estrangelo Edessa',
116
        'Orya' => 'Kalinga',
117
        'Mlym' => 'Kartika',
118
        'Laoo' => 'DokChampa',
119
        'Sinh' => 'Iskoola Pota',
120
        'Mong' => 'Mongolian Baiti',
121
        'Viet' => 'Times New Roman',
122
        'Uigh' => 'Microsoft Uighur',
123
        'Geor' => 'Sylfaen',
124
    ];
125
126
    public const FONTS_ARIAL_SUBSTITUTIONS = [
127
        'Jpan' => 'MS Pゴシック',
128
        'Hang' => '맑은 고딕',
129
        'Hans' => '宋体',
130
        'Hant' => '新細明體',
131
        'Arab' => 'Arial',
132
        'Hebr' => 'Arial',
133
        'Thai' => 'Tahoma',
134
        'Ethi' => 'Nyala',
135
        'Beng' => 'Vrinda',
136
        'Gujr' => 'Shruti',
137
        'Khmr' => 'DaunPenh',
138
        'Knda' => 'Tunga',
139
        'Guru' => 'Raavi',
140
        'Cans' => 'Euphemia',
141
        'Cher' => 'Plantagenet Cherokee',
142
        'Yiii' => 'Microsoft Yi Baiti',
143
        'Tibt' => 'Microsoft Himalaya',
144
        'Thaa' => 'MV Boli',
145
        'Deva' => 'Mangal',
146
        'Telu' => 'Gautami',
147
        'Taml' => 'Latha',
148
        'Syrc' => 'Estrangelo Edessa',
149
        'Orya' => 'Kalinga',
150
        'Mlym' => 'Kartika',
151
        'Laoo' => 'DokChampa',
152
        'Sinh' => 'Iskoola Pota',
153
        'Mong' => 'Mongolian Baiti',
154
        'Viet' => 'Arial',
155
        'Uigh' => 'Microsoft Uighur',
156
        'Geor' => 'Sylfaen',
157
    ];
158
159
    /** @return string[] */
160 394
    public function getThemeColors(): array
161
    {
162 394
        return $this->themeColors;
163
    }
164
165 665
    public function setThemeColor(string $key, string $value): self
166
    {
167 665
        $this->themeColors[$key] = $value;
168
169 665
        return $this;
170
    }
171
172 385
    public function getThemeColorName(): string
173
    {
174 385
        return $this->themeColorName;
175
    }
176
177
    /** @param null|string[] $themeColors */
178 666
    public function setThemeColorName(string $name, ?array $themeColors = null, ?Spreadsheet $spreadsheet = null): self
179
    {
180 666
        $this->themeColorName = $name;
181 666
        if ($name === self::COLOR_SCHEME_2007_2010_NAME) {
182 1
            $themeColors = $themeColors ?? self::COLOR_SCHEME_2007_2010;
183 1
            $this->majorFontLatin = 'Cambria';
184 1
            $this->minorFontLatin = 'Calibri';
185 665
        } elseif ($name === self::COLOR_SCHEME_2013_PLUS_NAME) { //* @phpstan-ignore-line
0 ignored issues
show
Deprecated Code introduced by
The constant PhpOffice\PhpSpreadsheet...R_SCHEME_2013_PLUS_NAME has been deprecated: 4.4.0 Use COLOR_SCHEME_2013_2022_NAME ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

185
        } elseif ($name === /** @scrutinizer ignore-deprecated */ self::COLOR_SCHEME_2013_PLUS_NAME) { //* @phpstan-ignore-line

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
186
            // delete this block when deprecated constants removed
187 1
            $themeColors = $themeColors ?? self::COLOR_SCHEME_2013_PLUS; //* @phpstan-ignore-line
0 ignored issues
show
Deprecated Code introduced by
The constant PhpOffice\PhpSpreadsheet...:COLOR_SCHEME_2013_PLUS has been deprecated: 4.4.0 Use COLOR_SCHEME_2013_2022 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

187
            $themeColors = $themeColors ?? /** @scrutinizer ignore-deprecated */ self::COLOR_SCHEME_2013_PLUS; //* @phpstan-ignore-line

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
188 1
            $this->majorFontLatin = 'Calibri Light';
189 1
            $this->minorFontLatin = 'Calibri';
190 664
        } elseif ($name === self::COLOR_SCHEME_2013_2022_NAME) {
191 2
            $themeColors = $themeColors ?? self::COLOR_SCHEME_2013_2022;
192 2
            $this->majorFontLatin = 'Calibri Light';
193 2
            $this->minorFontLatin = 'Calibri';
194 662
        } elseif ($name === self::COLOR_SCHEME_2023_PLUS_NAME) {
195 1
            $themeColors = $themeColors ?? self::COLOR_SCHEME_2023_PLUS;
196 1
            $this->majorFontLatin = 'Aptos Display';
197 1
            $this->minorFontLatin = 'Aptos Narrow';
198
        }
199 666
        if ($themeColors !== null) {
200 5
            $this->themeColors = $themeColors;
201
        }
202 666
        if ($spreadsheet !== null) {
203 1
            $spreadsheet->getDefaultStyle()->getFont()
204 1
                ->applyThemeFonts($this);
205
        }
206
207 666
        return $this;
208
    }
209
210 385
    public function getMajorFontLatin(): string
211
    {
212 385
        return $this->majorFontLatin;
213
    }
214
215 385
    public function getMajorFontEastAsian(): string
216
    {
217 385
        return $this->majorFontEastAsian;
218
    }
219
220 385
    public function getMajorFontComplexScript(): string
221
    {
222 385
        return $this->majorFontComplexScript;
223
    }
224
225
    /** @return string[] */
226 385
    public function getMajorFontSubstitutions(): array
227
    {
228 385
        return $this->majorFontSubstitutions;
229
    }
230
231
    /** @param null|string[] $substitutions */
232 665
    public function setMajorFontValues(?string $latin, ?string $eastAsian, ?string $complexScript, ?array $substitutions): self
233
    {
234 665
        if (!empty($latin)) {
235 665
            $this->majorFontLatin = $latin;
236
        }
237 665
        if ($eastAsian !== null) {
238 665
            $this->majorFontEastAsian = $eastAsian;
239
        }
240 665
        if ($complexScript !== null) {
241 665
            $this->majorFontComplexScript = $complexScript;
242
        }
243 665
        if ($substitutions !== null) {
244 665
            $this->majorFontSubstitutions = $substitutions;
245
        }
246
247 665
        return $this;
248
    }
249
250 385
    public function getMinorFontLatin(): string
251
    {
252 385
        return $this->minorFontLatin;
253
    }
254
255 385
    public function getMinorFontEastAsian(): string
256
    {
257 385
        return $this->minorFontEastAsian;
258
    }
259
260 385
    public function getMinorFontComplexScript(): string
261
    {
262 385
        return $this->minorFontComplexScript;
263
    }
264
265
    /** @return string[] */
266 385
    public function getMinorFontSubstitutions(): array
267
    {
268 385
        return $this->minorFontSubstitutions;
269
    }
270
271
    /** @param null|string[] $substitutions */
272 665
    public function setMinorFontValues(?string $latin, ?string $eastAsian, ?string $complexScript, ?array $substitutions): self
273
    {
274 665
        if (!empty($latin)) {
275 665
            $this->minorFontLatin = $latin;
276
        }
277 665
        if ($eastAsian !== null) {
278 665
            $this->minorFontEastAsian = $eastAsian;
279
        }
280 665
        if ($complexScript !== null) {
281 665
            $this->minorFontComplexScript = $complexScript;
282
        }
283 665
        if ($substitutions !== null) {
284 665
            $this->minorFontSubstitutions = $substitutions;
285
        }
286
287 665
        return $this;
288
    }
289
290 385
    public function getThemeFontName(): string
291
    {
292 385
        return $this->themeFontName;
293
    }
294
295 665
    public function setThemeFontName(?string $name): self
296
    {
297 665
        if (!empty($name)) {
298 665
            $this->themeFontName = $name;
299
        }
300
301 665
        return $this;
302
    }
303
}
304