| 1 |
<?php |
| 2 |
|
| 3 |
namespace TablePress\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 |
private const COLOR_SCHEME_2013_PLUS_NAME = 'Office 2013+'; |
| 28 |
|
| 29 |
public const COLOR_SCHEME_2007_2010_NAME = 'Office 2007-2010'; |
| 30 |
public const COLOR_SCHEME_2007_2010 = [ |
| 31 |
'dk1' => '000000', |
| 32 |
'lt1' => 'FFFFFF', |
| 33 |
'dk2' => '1F497D', |
| 34 |
'lt2' => 'EEECE1', |
| 35 |
'accent1' => '4F81BD', |
| 36 |
'accent2' => 'C0504D', |
| 37 |
'accent3' => '9BBB59', |
| 38 |
'accent4' => '8064A2', |
| 39 |
'accent5' => '4BACC6', |
| 40 |
'accent6' => 'F79646', |
| 41 |
'hlink' => '0000FF', |
| 42 |
'folHlink' => '800080', |
| 43 |
]; |
| 44 |
|
| 45 |
public const COLOR_SCHEME_2023_PLUS_NAME = 'Office 2023+'; |
| 46 |
public const COLOR_SCHEME_2023_PLUS = [ |
| 47 |
'dk1' => '000000', |
| 48 |
'lt1' => 'FFFFFF', |
| 49 |
'dk2' => '0E2841', |
| 50 |
'lt2' => 'E8E8E8', |
| 51 |
'accent1' => '156082', |
| 52 |
'accent2' => 'E97132', |
| 53 |
'accent3' => '196B24', |
| 54 |
'accent4' => '0F9ED5', |
| 55 |
'accent5' => 'A02B93', |
| 56 |
'accent6' => '4EA72E', |
| 57 |
'hlink' => '467886', |
| 58 |
'folHlink' => '96607D', |
| 59 |
]; |
| 60 |
|
| 61 |
/** @var string[] */ |
| 62 |
private array $themeColors = self::COLOR_SCHEME_2007_2010; |
| 63 |
|
| 64 |
private string $majorFontLatin = 'Cambria'; |
| 65 |
|
| 66 |
private string $majorFontEastAsian = ''; |
| 67 |
|
| 68 |
private string $majorFontComplexScript = ''; |
| 69 |
|
| 70 |
private string $minorFontLatin = 'Calibri'; |
| 71 |
|
| 72 |
private string $minorFontEastAsian = ''; |
| 73 |
|
| 74 |
private string $minorFontComplexScript = ''; |
| 75 |
|
| 76 |
/** |
| 77 |
* Map of Major (header) fonts to write. |
| 78 |
* |
| 79 |
* @var string[] |
| 80 |
*/ |
| 81 |
private array $majorFontSubstitutions = self::FONTS_TIMES_SUBSTITUTIONS; |
| 82 |
|
| 83 |
/** |
| 84 |
* Map of Minor (body) fonts to write. |
| 85 |
* |
| 86 |
* @var string[] |
| 87 |
*/ |
| 88 |
private array $minorFontSubstitutions = self::FONTS_ARIAL_SUBSTITUTIONS; |
| 89 |
|
| 90 |
public const FONTS_TIMES_SUBSTITUTIONS = [ |
| 91 |
'Jpan' => 'MS Pゴシック', |
| 92 |
'Hang' => '맑은 고딕', |
| 93 |
'Hans' => '宋体', |
| 94 |
'Hant' => '新細明體', |
| 95 |
'Arab' => 'Times New Roman', |
| 96 |
'Hebr' => 'Times New Roman', |
| 97 |
'Thai' => 'Tahoma', |
| 98 |
'Ethi' => 'Nyala', |
| 99 |
'Beng' => 'Vrinda', |
| 100 |
'Gujr' => 'Shruti', |
| 101 |
'Khmr' => 'MoolBoran', |
| 102 |
'Knda' => 'Tunga', |
| 103 |
'Guru' => 'Raavi', |
| 104 |
'Cans' => 'Euphemia', |
| 105 |
'Cher' => 'Plantagenet Cherokee', |
| 106 |
'Yiii' => 'Microsoft Yi Baiti', |
| 107 |
'Tibt' => 'Microsoft Himalaya', |
| 108 |
'Thaa' => 'MV Boli', |
| 109 |
'Deva' => 'Mangal', |
| 110 |
'Telu' => 'Gautami', |
| 111 |
'Taml' => 'Latha', |
| 112 |
'Syrc' => 'Estrangelo Edessa', |
| 113 |
'Orya' => 'Kalinga', |
| 114 |
'Mlym' => 'Kartika', |
| 115 |
'Laoo' => 'DokChampa', |
| 116 |
'Sinh' => 'Iskoola Pota', |
| 117 |
'Mong' => 'Mongolian Baiti', |
| 118 |
'Viet' => 'Times New Roman', |
| 119 |
'Uigh' => 'Microsoft Uighur', |
| 120 |
'Geor' => 'Sylfaen', |
| 121 |
]; |
| 122 |
|
| 123 |
public const FONTS_ARIAL_SUBSTITUTIONS = [ |
| 124 |
'Jpan' => 'MS Pゴシック', |
| 125 |
'Hang' => '맑은 고딕', |
| 126 |
'Hans' => '宋体', |
| 127 |
'Hant' => '新細明體', |
| 128 |
'Arab' => 'Arial', |
| 129 |
'Hebr' => 'Arial', |
| 130 |
'Thai' => 'Tahoma', |
| 131 |
'Ethi' => 'Nyala', |
| 132 |
'Beng' => 'Vrinda', |
| 133 |
'Gujr' => 'Shruti', |
| 134 |
'Khmr' => 'DaunPenh', |
| 135 |
'Knda' => 'Tunga', |
| 136 |
'Guru' => 'Raavi', |
| 137 |
'Cans' => 'Euphemia', |
| 138 |
'Cher' => 'Plantagenet Cherokee', |
| 139 |
'Yiii' => 'Microsoft Yi Baiti', |
| 140 |
'Tibt' => 'Microsoft Himalaya', |
| 141 |
'Thaa' => 'MV Boli', |
| 142 |
'Deva' => 'Mangal', |
| 143 |
'Telu' => 'Gautami', |
| 144 |
'Taml' => 'Latha', |
| 145 |
'Syrc' => 'Estrangelo Edessa', |
| 146 |
'Orya' => 'Kalinga', |
| 147 |
'Mlym' => 'Kartika', |
| 148 |
'Laoo' => 'DokChampa', |
| 149 |
'Sinh' => 'Iskoola Pota', |
| 150 |
'Mong' => 'Mongolian Baiti', |
| 151 |
'Viet' => 'Arial', |
| 152 |
'Uigh' => 'Microsoft Uighur', |
| 153 |
'Geor' => 'Sylfaen', |
| 154 |
]; |
| 155 |
|
| 156 |
/** @return string[] */ |
| 157 |
public function getThemeColors(): array |
| 158 |
{ |
| 159 |
return $this->themeColors; |
| 160 |
} |
| 161 |
|
| 162 |
public function setThemeColor(string $key, string $value): self |
| 163 |
{ |
| 164 |
$this->themeColors[$key] = $value; |
| 165 |
|
| 166 |
return $this; |
| 167 |
} |
| 168 |
|
| 169 |
public function getThemeColorName(): string |
| 170 |
{ |
| 171 |
return $this->themeColorName; |
| 172 |
} |
| 173 |
|
| 174 |
/** @param null|string[] $themeColors */ |
| 175 |
public function setThemeColorName(string $name, ?array $themeColors = null, ?Spreadsheet $spreadsheet = null): self |
| 176 |
{ |
| 177 |
if ($name === self::COLOR_SCHEME_2013_PLUS_NAME) { |
| 178 |
// Ensure against this value being found in |
| 179 |
// spreadsheets created while constant was public. |
| 180 |
$name = self::COLOR_SCHEME_2013_2022_NAME; |
| 181 |
} |
| 182 |
$this->themeColorName = $name; |
| 183 |
if ($name === self::COLOR_SCHEME_2007_2010_NAME) { |
| 184 |
$themeColors = $themeColors ?? self::COLOR_SCHEME_2007_2010; |
| 185 |
$this->majorFontLatin = 'Cambria'; |
| 186 |
$this->minorFontLatin = 'Calibri'; |
| 187 |
} elseif ($name === self::COLOR_SCHEME_2013_2022_NAME) { |
| 188 |
$themeColors = $themeColors ?? self::COLOR_SCHEME_2013_2022; |
| 189 |
$this->majorFontLatin = 'Calibri Light'; |
| 190 |
$this->minorFontLatin = 'Calibri'; |
| 191 |
} elseif ($name === self::COLOR_SCHEME_2023_PLUS_NAME) { |
| 192 |
$themeColors = $themeColors ?? self::COLOR_SCHEME_2023_PLUS; |
| 193 |
$this->majorFontLatin = 'Aptos Display'; |
| 194 |
$this->minorFontLatin = 'Aptos Narrow'; |
| 195 |
} |
| 196 |
if ($themeColors !== null) { |
| 197 |
$this->themeColors = $themeColors; |
| 198 |
} |
| 199 |
if ($spreadsheet !== null) { |
| 200 |
$spreadsheet->getDefaultStyle()->getFont() |
| 201 |
->applyThemeFonts($this); |
| 202 |
} |
| 203 |
|
| 204 |
return $this; |
| 205 |
} |
| 206 |
|
| 207 |
public function getMajorFontLatin(): string |
| 208 |
{ |
| 209 |
return $this->majorFontLatin; |
| 210 |
} |
| 211 |
|
| 212 |
public function getMajorFontEastAsian(): string |
| 213 |
{ |
| 214 |
return $this->majorFontEastAsian; |
| 215 |
} |
| 216 |
|
| 217 |
public function getMajorFontComplexScript(): string |
| 218 |
{ |
| 219 |
return $this->majorFontComplexScript; |
| 220 |
} |
| 221 |
|
| 222 |
/** @return string[] */ |
| 223 |
public function getMajorFontSubstitutions(): array |
| 224 |
{ |
| 225 |
return $this->majorFontSubstitutions; |
| 226 |
} |
| 227 |
|
| 228 |
/** @param null|string[] $substitutions */ |
| 229 |
public function setMajorFontValues(?string $latin, ?string $eastAsian, ?string $complexScript, ?array $substitutions): self |
| 230 |
{ |
| 231 |
if (!empty($latin)) { |
| 232 |
$this->majorFontLatin = $latin; |
| 233 |
} |
| 234 |
if ($eastAsian !== null) { |
| 235 |
$this->majorFontEastAsian = $eastAsian; |
| 236 |
} |
| 237 |
if ($complexScript !== null) { |
| 238 |
$this->majorFontComplexScript = $complexScript; |
| 239 |
} |
| 240 |
if ($substitutions !== null) { |
| 241 |
$this->majorFontSubstitutions = $substitutions; |
| 242 |
} |
| 243 |
|
| 244 |
return $this; |
| 245 |
} |
| 246 |
|
| 247 |
public function getMinorFontLatin(): string |
| 248 |
{ |
| 249 |
return $this->minorFontLatin; |
| 250 |
} |
| 251 |
|
| 252 |
public function getMinorFontEastAsian(): string |
| 253 |
{ |
| 254 |
return $this->minorFontEastAsian; |
| 255 |
} |
| 256 |
|
| 257 |
public function getMinorFontComplexScript(): string |
| 258 |
{ |
| 259 |
return $this->minorFontComplexScript; |
| 260 |
} |
| 261 |
|
| 262 |
/** @return string[] */ |
| 263 |
public function getMinorFontSubstitutions(): array |
| 264 |
{ |
| 265 |
return $this->minorFontSubstitutions; |
| 266 |
} |
| 267 |
|
| 268 |
/** @param null|string[] $substitutions */ |
| 269 |
public function setMinorFontValues(?string $latin, ?string $eastAsian, ?string $complexScript, ?array $substitutions): self |
| 270 |
{ |
| 271 |
if (!empty($latin)) { |
| 272 |
$this->minorFontLatin = $latin; |
| 273 |
} |
| 274 |
if ($eastAsian !== null) { |
| 275 |
$this->minorFontEastAsian = $eastAsian; |
| 276 |
} |
| 277 |
if ($complexScript !== null) { |
| 278 |
$this->minorFontComplexScript = $complexScript; |
| 279 |
} |
| 280 |
if ($substitutions !== null) { |
| 281 |
$this->minorFontSubstitutions = $substitutions; |
| 282 |
} |
| 283 |
|
| 284 |
return $this; |
| 285 |
} |
| 286 |
|
| 287 |
public function getThemeFontName(): string |
| 288 |
{ |
| 289 |
return $this->themeFontName; |
| 290 |
} |
| 291 |
|
| 292 |
public function setThemeFontName(?string $name): self |
| 293 |
{ |
| 294 |
if (!empty($name)) { |
| 295 |
$this->themeFontName = $name; |
| 296 |
} |
| 297 |
|
| 298 |
return $this; |
| 299 |
} |
| 300 |
} |
| 301 |
|