PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Reader / Xml / Style / Font.php

Font.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Reader/Xml/Style/Font.php

92 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Reader\Xml\Style;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Style\Font as FontUnderline;
6 use SimpleXMLElement;
7
8 class Font extends StyleBase
9 {
10 protected const UNDERLINE_STYLES = [
11 FontUnderline::UNDERLINE_NONE,
12 FontUnderline::UNDERLINE_DOUBLE,
13 FontUnderline::UNDERLINE_DOUBLEACCOUNTING,
14 FontUnderline::UNDERLINE_SINGLE,
15 FontUnderline::UNDERLINE_SINGLEACCOUNTING,
16 ];
17
18 /**
19 * @param mixed[][] $style
20 *
21 * @return mixed[][]
22 */
23 protected function parseUnderline(array $style, string $styleAttributeValue): array
24 {
25 if (self::identifyFixedStyleValue(self::UNDERLINE_STYLES, $styleAttributeValue)) {
26 $style['font']['underline'] = $styleAttributeValue;
27 }
28
29 return $style;
30 }
31
32 /**
33 * @param mixed[][] $style
34 *
35 * @return mixed[][]
36 */
37 protected function parseVerticalAlign(array $style, string $styleAttributeValue): array
38 {
39 if ($styleAttributeValue == 'Superscript') {
40 $style['font']['superscript'] = true;
41 }
42 if ($styleAttributeValue == 'Subscript') {
43 $style['font']['subscript'] = true;
44 }
45
46 return $style;
47 }
48
49 /** @return mixed[] */
50 public function parseStyle(SimpleXMLElement $styleAttributes): array
51 {
52 $style = [];
53
54 foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
55 $styleAttributeValue = (string) $styleAttributeValue;
56 switch ($styleAttributeKey) {
57 case 'FontName':
58 $style['font']['name'] = $styleAttributeValue;
59
60 break;
61 case 'Size':
62 $style['font']['size'] = $styleAttributeValue;
63
64 break;
65 case 'Color':
66 /** @var string[][][] $style */
67 $style['font']['color']['rgb'] = (string) substr($styleAttributeValue, 1);
68
69 break;
70 case 'Bold':
71 $style['font']['bold'] = $styleAttributeValue === '1';
72
73 break;
74 case 'Italic':
75 $style['font']['italic'] = $styleAttributeValue === '1';
76
77 break;
78 case 'Underline':
79 $style = $this->parseUnderline($style, $styleAttributeValue);
80
81 break;
82 case 'VerticalAlign':
83 $style = $this->parseVerticalAlign($style, $styleAttributeValue);
84
85 break;
86 }
87 }
88
89 return $style;
90 }
91 }
92