updated a couple packages (#1567)
[openemr.git] / vendor / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Writer / Xls / Font.php
blobdf37dcb56c5c20572cc90b039d4b55a8ab6f80be
1 <?php
3 namespace PhpOffice\PhpSpreadsheet\Writer\Xls;
5 use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
7 class Font
9 /**
10 * Color index.
12 * @var int
14 private $colorIndex;
16 /**
17 * Font.
19 * @var \PhpOffice\PhpSpreadsheet\Style\Font
21 private $font;
23 /**
24 * Constructor.
26 * @param \PhpOffice\PhpSpreadsheet\Style\Font $font
28 public function __construct(\PhpOffice\PhpSpreadsheet\Style\Font $font)
30 $this->colorIndex = 0x7FFF;
31 $this->font = $font;
34 /**
35 * Set the color index.
37 * @param int $colorIndex
39 public function setColorIndex($colorIndex)
41 $this->colorIndex = $colorIndex;
44 /**
45 * Get font record data.
47 * @return string
49 public function writeFont()
51 $font_outline = 0;
52 $font_shadow = 0;
54 $icv = $this->colorIndex; // Index to color palette
55 if ($this->font->getSuperscript()) {
56 $sss = 1;
57 } elseif ($this->font->getSubscript()) {
58 $sss = 2;
59 } else {
60 $sss = 0;
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()) {
69 $grbit |= 0x02;
71 if ($this->font->getStrikethrough()) {
72 $grbit |= 0x08;
74 if ($font_outline) {
75 $grbit |= 0x10;
77 if ($font_shadow) {
78 $grbit |= 0x20;
81 $data = pack(
82 'vvvvvCCCC',
83 // Fontsize (in twips)
84 $this->font->getSize() * 20,
85 $grbit,
86 // Colour
87 $icv,
88 // Font weight
89 self::mapBold($this->font->getBold()),
90 // Superscript/Subscript
91 $sss,
92 self::mapUnderline($this->font->getUnderline()),
93 $bFamily,
94 $bCharSet,
95 $reserved
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.
108 * @param bool $bold
110 * @return int
112 private static function mapBold($bold)
114 if ($bold) {
115 return 0x2BC; // 700 = Bold font weight
118 return 0x190; // 400 = Normal font weight
122 * Map of BIFF2-BIFF8 codes for underline styles.
124 * @var array of int
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,
135 * Map underline.
137 * @param string $underline
139 * @return int
141 private static function mapUnderline($underline)
143 if (isset(self::$mapUnderline[$underline])) {
144 return self::$mapUnderline[$underline];
147 return 0x00;