Debian Codegraph @

vendor/dompdf/php-font-lib/src/FontLib/EOT/Header.php

raw
1 <?php
2 /**
3 * @package php-font-lib
4 * @link https://github.com/dompdf/php-font-lib
5 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
6 */
7
8 namespace FontLib\EOT;
9
10 use Exception;
11 use FontLib\Font;
12
13 /**
14 * TrueType font file header.
15 *
16 * @package php-font-lib
17 *
18 * @property File $font
19 */
20 class Header extends \FontLib\Header {
21 protected $def = array(
22 "format" => self::uint32,
23 "numTables" => self::uint16,
24 "searchRange" => self::uint16,
25 "entrySelector" => self::uint16,
26 "rangeShift" => self::uint16,
27 );
28
29 public function parse() {
30 $font = $this->font;
31
32 $this->data = $font->unpack(array(
33 "EOTSize" => self::uint32,
34 "FontDataSize" => self::uint32,
35 "Version" => self::uint32,
36 "Flags" => self::uint32,
37 "FontPANOSE" => array(self::uint8, 10),
38 "Charset" => self::uint8,
39 "Italic" => self::uint8,
40 "Weight" => self::uint32,
41 "fsType" => self::uint16,
42 "MagicNumber" => self::uint16,
43 "UnicodeRange1" => self::uint32,
44 "UnicodeRange2" => self::uint32,
45 "UnicodeRange3" => self::uint32,
46 "UnicodeRange4" => self::uint32,
47 "CodePageRange1" => self::uint32,
48 "CodePageRange2" => self::uint32,
49 "CheckSumAdjustment" => self::uint32,
50 "Reserved1" => self::uint32,
51 "Reserved2" => self::uint32,
52 "Reserved3" => self::uint32,
53 "Reserved4" => self::uint32,
54 ));
55
56 $this->data["Padding1"] = $font->readUInt16();
57 $this->readString("FamilyName");
58
59 $this->data["Padding2"] = $font->readUInt16();
60 $this->readString("StyleName");
61
62 $this->data["Padding3"] = $font->readUInt16();
63 $this->readString("VersionName");
64
65 $this->data["Padding4"] = $font->readUInt16();
66 $this->readString("FullName");
67
68 switch ($this->data["Version"]) {
69 default:
70 throw new Exception("Unknown EOT version " . $this->data["Version"]);
71
72 case 0x00010000:
73 // Nothing to do more
74 break;
75
76 case 0x00020001:
77 $this->data["Padding5"] = $font->readUInt16();
78 $this->readString("RootString");
79 break;
80
81 case 0x00020002:
82 $this->data["Padding5"] = $font->readUInt16();
83 $this->readString("RootString");
84
85 $this->data["RootStringCheckSum"] = $font->readUInt32();
86 $this->data["EUDCCodePage"] = $font->readUInt32();
87
88 $this->data["Padding6"] = $font->readUInt16();
89 $this->readString("Signature");
90
91 $this->data["EUDCFlags"] = $font->readUInt32();
92 $this->data["EUDCFontSize"] = $font->readUInt32();
93 break;
94 }
95
96 if (!empty($this->data["RootString"])) {
97 $this->data["RootString"] = explode("\0", $this->data["RootString"]);
98 }
99 }
100
101 private function readString($name) {
102 $font = $this->font;
103 $size = $font->readUInt16();
104
105 $this->data["{$name}Size"] = $size;
106 $this->data[$name] = Font::UTF16ToUTF8($font->read($size));
107 }
108
109 public function encode() {
110 //return $this->font->pack($this->def, $this->data);
111 }
112 }