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
|
391 |
|
'Cans' => 'Euphemia', |
141
|
|
|
'Cher' => 'Plantagenet Cherokee', |
142
|
391 |
|
'Yiii' => 'Microsoft Yi Baiti', |
143
|
|
|
'Tibt' => 'Microsoft Himalaya', |
144
|
|
|
'Thaa' => 'MV Boli', |
145
|
662 |
|
'Deva' => 'Mangal', |
146
|
|
|
'Telu' => 'Gautami', |
147
|
662 |
|
'Taml' => 'Latha', |
148
|
|
|
'Syrc' => 'Estrangelo Edessa', |
149
|
662 |
|
'Orya' => 'Kalinga', |
150
|
|
|
'Mlym' => 'Kartika', |
151
|
|
|
'Laoo' => 'DokChampa', |
152
|
382 |
|
'Sinh' => 'Iskoola Pota', |
153
|
|
|
'Mong' => 'Mongolian Baiti', |
154
|
382 |
|
'Viet' => 'Arial', |
155
|
|
|
'Uigh' => 'Microsoft Uighur', |
156
|
|
|
'Geor' => 'Sylfaen', |
157
|
|
|
]; |
158
|
663 |
|
|
159
|
|
|
/** @return string[] */ |
160
|
663 |
|
public function getThemeColors(): array |
161
|
663 |
|
{ |
162
|
1 |
|
return $this->themeColors; |
163
|
662 |
|
} |
164
|
2 |
|
|
165
|
|
|
public function setThemeColor(string $key, string $value): self |
166
|
663 |
|
{ |
167
|
3 |
|
$this->themeColors[$key] = $value; |
168
|
|
|
|
169
|
|
|
return $this; |
170
|
663 |
|
} |
171
|
|
|
|
172
|
|
|
public function getThemeColorName(): string |
173
|
382 |
|
{ |
174
|
|
|
return $this->themeColorName; |
175
|
382 |
|
} |
176
|
|
|
|
177
|
|
|
/** @param null|string[] $themeColors */ |
178
|
382 |
|
public function setThemeColorName(string $name, ?array $themeColors = null, ?Spreadsheet $spreadsheet = null): self |
179
|
|
|
{ |
180
|
382 |
|
$this->themeColorName = $name; |
181
|
|
|
if ($name === self::COLOR_SCHEME_2007_2010_NAME) { |
182
|
|
|
$themeColors = $themeColors ?? self::COLOR_SCHEME_2007_2010; |
183
|
382 |
|
$this->majorFontLatin = 'Cambria'; |
184
|
|
|
$this->minorFontLatin = 'Calibri'; |
185
|
382 |
|
} elseif ($name === self::COLOR_SCHEME_2013_PLUS_NAME) { //* @phpstan-ignore-line |
|
|
|
|
186
|
|
|
// delete this block when deprecated constants removed |
187
|
|
|
$themeColors = $themeColors ?? self::COLOR_SCHEME_2013_PLUS; //* @phpstan-ignore-line |
|
|
|
|
188
|
|
|
$this->majorFontLatin = 'Calibri Light'; |
189
|
382 |
|
$this->minorFontLatin = 'Calibri'; |
190
|
|
|
} elseif ($name === self::COLOR_SCHEME_2013_2022_NAME) { |
191
|
382 |
|
$themeColors = $themeColors ?? self::COLOR_SCHEME_2013_2022; |
192
|
|
|
$this->majorFontLatin = 'Calibri Light'; |
193
|
|
|
$this->minorFontLatin = 'Calibri'; |
194
|
|
|
} elseif ($name === self::COLOR_SCHEME_2023_PLUS_NAME) { |
195
|
662 |
|
$themeColors = $themeColors ?? self::COLOR_SCHEME_2023_PLUS; |
196
|
|
|
$this->majorFontLatin = 'Aptos Display'; |
197
|
662 |
|
$this->minorFontLatin = 'Aptos Narrow'; |
198
|
662 |
|
} |
199
|
|
|
if ($themeColors !== null) { |
200
|
662 |
|
$this->themeColors = $themeColors; |
201
|
662 |
|
} |
202
|
|
|
if ($spreadsheet !== null) { |
203
|
662 |
|
$spreadsheet->getDefaultStyle()->getFont() |
204
|
662 |
|
->applyThemeFonts($this); |
205
|
|
|
} |
206
|
662 |
|
|
207
|
662 |
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
662 |
|
public function getMajorFontLatin(): string |
211
|
|
|
{ |
212
|
|
|
return $this->majorFontLatin; |
213
|
382 |
|
} |
214
|
|
|
|
215
|
382 |
|
public function getMajorFontEastAsian(): string |
216
|
|
|
{ |
217
|
|
|
return $this->majorFontEastAsian; |
218
|
382 |
|
} |
219
|
|
|
|
220
|
382 |
|
public function getMajorFontComplexScript(): string |
221
|
|
|
{ |
222
|
|
|
return $this->majorFontComplexScript; |
223
|
382 |
|
} |
224
|
|
|
|
225
|
382 |
|
/** @return string[] */ |
226
|
|
|
public function getMajorFontSubstitutions(): array |
227
|
|
|
{ |
228
|
|
|
return $this->majorFontSubstitutions; |
229
|
382 |
|
} |
230
|
|
|
|
231
|
382 |
|
/** @param null|string[] $substitutions */ |
232
|
|
|
public function setMajorFontValues(?string $latin, ?string $eastAsian, ?string $complexScript, ?array $substitutions): self |
233
|
|
|
{ |
234
|
|
|
if (!empty($latin)) { |
235
|
662 |
|
$this->majorFontLatin = $latin; |
236
|
|
|
} |
237
|
662 |
|
if ($eastAsian !== null) { |
238
|
662 |
|
$this->majorFontEastAsian = $eastAsian; |
239
|
|
|
} |
240
|
662 |
|
if ($complexScript !== null) { |
241
|
662 |
|
$this->majorFontComplexScript = $complexScript; |
242
|
|
|
} |
243
|
662 |
|
if ($substitutions !== null) { |
244
|
662 |
|
$this->majorFontSubstitutions = $substitutions; |
245
|
|
|
} |
246
|
662 |
|
|
247
|
662 |
|
return $this; |
248
|
|
|
} |
249
|
|
|
|
250
|
662 |
|
public function getMinorFontLatin(): string |
251
|
|
|
{ |
252
|
|
|
return $this->minorFontLatin; |
253
|
382 |
|
} |
254
|
|
|
|
255
|
382 |
|
public function getMinorFontEastAsian(): string |
256
|
|
|
{ |
257
|
|
|
return $this->minorFontEastAsian; |
258
|
662 |
|
} |
259
|
|
|
|
260
|
662 |
|
public function getMinorFontComplexScript(): string |
261
|
662 |
|
{ |
262
|
|
|
return $this->minorFontComplexScript; |
263
|
|
|
} |
264
|
662 |
|
|
265
|
|
|
/** @return string[] */ |
266
|
|
|
public function getMinorFontSubstitutions(): array |
267
|
|
|
{ |
268
|
|
|
return $this->minorFontSubstitutions; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** @param null|string[] $substitutions */ |
272
|
|
|
public function setMinorFontValues(?string $latin, ?string $eastAsian, ?string $complexScript, ?array $substitutions): self |
273
|
|
|
{ |
274
|
|
|
if (!empty($latin)) { |
275
|
|
|
$this->minorFontLatin = $latin; |
276
|
|
|
} |
277
|
|
|
if ($eastAsian !== null) { |
278
|
|
|
$this->minorFontEastAsian = $eastAsian; |
279
|
|
|
} |
280
|
|
|
if ($complexScript !== null) { |
281
|
|
|
$this->minorFontComplexScript = $complexScript; |
282
|
|
|
} |
283
|
|
|
if ($substitutions !== null) { |
284
|
|
|
$this->minorFontSubstitutions = $substitutions; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
return $this; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
public function getThemeFontName(): string |
291
|
|
|
{ |
292
|
|
|
return $this->themeFontName; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
public function setThemeFontName(?string $name): self |
296
|
|
|
{ |
297
|
|
|
if (!empty($name)) { |
298
|
|
|
$this->themeFontName = $name; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
return $this; |
302
|
|
|
} |
303
|
|
|
} |
304
|
|
|
|
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.