3 namespace PhpOffice\PhpSpreadsheet\Writer\Xls
;
5 use PhpOffice\PhpSpreadsheet\Shared\StringHelper
;
19 * @var \PhpOffice\PhpSpreadsheet\Style\Font
26 * @param \PhpOffice\PhpSpreadsheet\Style\Font $font
28 public function __construct(\PhpOffice\PhpSpreadsheet\Style\Font
$font)
30 $this->colorIndex
= 0x7FFF;
35 * Set the color index.
37 * @param int $colorIndex
39 public function setColorIndex($colorIndex)
41 $this->colorIndex
= $colorIndex;
45 * Get font record data.
49 public function writeFont()
54 $icv = $this->colorIndex
; // Index to color palette
55 if ($this->font
->getSuperscript()) {
57 } elseif ($this->font
->getSubscript()) {
62 $bFamily = 0; // Font family
63 $bCharSet = \PhpOffice\PhpSpreadsheet\Shared\Font
::getCharsetFromFontName($this->font
->getName()); // Character set
65 $record = 0x31; // Record identifier
66 $reserved = 0x00; // Reserved
67 $grbit = 0x00; // Font attributes
68 if ($this->font
->getItalic()) {
71 if ($this->font
->getStrikethrough()) {
83 // Fontsize (in twips)
84 $this->font
->getSize() * 20,
89 self
::mapBold($this->font
->getBold()),
90 // Superscript/Subscript
92 self
::mapUnderline($this->font
->getUnderline()),
97 $data .= StringHelper
::UTF8toBIFF8UnicodeShort($this->font
->getName());
99 $length = strlen($data);
100 $header = pack('vv', $record, $length);
102 return $header . $data;
106 * Map to BIFF5-BIFF8 codes for bold.
112 private static function mapBold($bold)
115 return 0x2BC; // 700 = Bold font weight
118 return 0x190; // 400 = Normal font weight
122 * Map of BIFF2-BIFF8 codes for underline styles.
126 private static $mapUnderline = [
127 \PhpOffice\PhpSpreadsheet\Style\Font
::UNDERLINE_NONE
=> 0x00,
128 \PhpOffice\PhpSpreadsheet\Style\Font
::UNDERLINE_SINGLE
=> 0x01,
129 \PhpOffice\PhpSpreadsheet\Style\Font
::UNDERLINE_DOUBLE
=> 0x02,
130 \PhpOffice\PhpSpreadsheet\Style\Font
::UNDERLINE_SINGLEACCOUNTING
=> 0x21,
131 \PhpOffice\PhpSpreadsheet\Style\Font
::UNDERLINE_DOUBLEACCOUNTING
=> 0x22,
137 * @param string $underline
141 private static function mapUnderline($underline)
143 if (isset(self
::$mapUnderline[$underline])) {
144 return self
::$mapUnderline[$underline];