PluginProbe
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin / 6.5.1.7
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin v6.5.1.7
6.5.1.7 6.5.1.6 6.5.1.5 6.5.1.4 6.5.1.3 6.5.1.2 6.5.1.1 6.5.0.9 6.5.0.8 6.5.0.7 6.5.0.6 trunk 3.4.2.40 3.4.2.41 3.4.2.42 3.4.2.43 3.4.2.44 3.4.2.45 3.4.2.46 3.4.2.47 3.4.2.48 3.4.2.49 3.4.2.50 6.3.2 6.3.3.1 All 47 releases
wpdatatables / lib / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Writer / Xls / Font.php

Font.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin 6.5.1.7, at lib/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xls/Font.php

147 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PhpOffice\PhpSpreadsheet\Writer\Xls;
4
5 use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
6
7 class Font
8 {
9 /**
10 * Color index.
11 *
12 * @var int
13 */
14 private $colorIndex;
15
16 /**
17 * Font.
18 *
19 * @var \PhpOffice\PhpSpreadsheet\Style\Font
20 */
21 private $font;
22
23 /**
24 * Constructor.
25 */
26 public function __construct(\PhpOffice\PhpSpreadsheet\Style\Font $font)
27 {
28 $this->colorIndex = 0x7FFF;
29 $this->font = $font;
30 }
31
32 /**
33 * Set the color index.
34 *
35 * @param int $colorIndex
36 */
37 public function setColorIndex($colorIndex): void
38 {
39 $this->colorIndex = $colorIndex;
40 }
41
42 /** @var int */
43 private static $notImplemented = 0;
44
45 /**
46 * Get font record data.
47 *
48 * @return string
49 */
50 public function writeFont()
51 {
52 $font_outline = self::$notImplemented;
53 $font_shadow = self::$notImplemented;
54
55 $icv = $this->colorIndex; // Index to color palette
56 if ($this->font->getSuperscript()) {
57 $sss = 1;
58 } elseif ($this->font->getSubscript()) {
59 $sss = 2;
60 } else {
61 $sss = 0;
62 }
63 $bFamily = 0; // Font family
64 $bCharSet = \PhpOffice\PhpSpreadsheet\Shared\Font::getCharsetFromFontName((string) $this->font->getName()); // Character set
65
66 $record = 0x31; // Record identifier
67 $reserved = 0x00; // Reserved
68 $grbit = 0x00; // Font attributes
69 if ($this->font->getItalic()) {
70 $grbit |= 0x02;
71 }
72 if ($this->font->getStrikethrough()) {
73 $grbit |= 0x08;
74 }
75 if ($font_outline) {
76 $grbit |= 0x10;
77 }
78 if ($font_shadow) {
79 $grbit |= 0x20;
80 }
81
82 $data = pack(
83 'vvvvvCCCC',
84 // Fontsize (in twips)
85 $this->font->getSize() * 20,
86 $grbit,
87 // Colour
88 $icv,
89 // Font weight
90 self::mapBold($this->font->getBold()),
91 // Superscript/Subscript
92 $sss,
93 self::mapUnderline((string) $this->font->getUnderline()),
94 $bFamily,
95 $bCharSet,
96 $reserved
97 );
98 $data .= StringHelper::UTF8toBIFF8UnicodeShort((string) $this->font->getName());
99
100 $length = strlen($data);
101 $header = pack('vv', $record, $length);
102
103 return $header . $data;
104 }
105
106 /**
107 * Map to BIFF5-BIFF8 codes for bold.
108 */
109 private static function mapBold(?bool $bold): int
110 {
111 if ($bold === true) {
112 return 0x2BC; // 700 = Bold font weight
113 }
114
115 return 0x190; // 400 = Normal font weight
116 }
117
118 /**
119 * Map of BIFF2-BIFF8 codes for underline styles.
120 *
121 * @var int[]
122 */
123 private static $mapUnderline = [
124 \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_NONE => 0x00,
125 \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLE => 0x01,
126 \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLE => 0x02,
127 \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLEACCOUNTING => 0x21,
128 \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLEACCOUNTING => 0x22,
129 ];
130
131 /**
132 * Map underline.
133 *
134 * @param string $underline
135 *
136 * @return int
137 */
138 private static function mapUnderline($underline)
139 {
140 if (isset(self::$mapUnderline[$underline])) {
141 return self::$mapUnderline[$underline];
142 }
143
144 return 0x00;
145 }
146 }
147