3 * @package php-font-lib
4 * @link https://github.com/PhenX/php-font-lib
5 * @author Fabien Ménager <fabien.menager@gmail.com>
6 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
15 * TrueType font file header.
17 * @package php-font-lib
19 * @property File $font
21 class Header
extends \FontLib\Header
{
22 protected $def = array(
23 "format" => self
::uint32
,
24 "numTables" => self
::uint16
,
25 "searchRange" => self
::uint16
,
26 "entrySelector" => self
::uint16
,
27 "rangeShift" => self
::uint16
,
30 public function parse() {
33 $this->data
= $font->unpack(array(
34 "EOTSize" => self
::uint32
,
35 "FontDataSize" => self
::uint32
,
36 "Version" => self
::uint32
,
37 "Flags" => self
::uint32
,
38 "FontPANOSE" => array(self
::uint8
, 10),
39 "Charset" => self
::uint8
,
40 "Italic" => self
::uint8
,
41 "Weight" => self
::uint32
,
42 "fsType" => self
::uint16
,
43 "MagicNumber" => self
::uint16
,
44 "UnicodeRange1" => self
::uint32
,
45 "UnicodeRange2" => self
::uint32
,
46 "UnicodeRange3" => self
::uint32
,
47 "UnicodeRange4" => self
::uint32
,
48 "CodePageRange1" => self
::uint32
,
49 "CodePageRange2" => self
::uint32
,
50 "CheckSumAdjustment" => self
::uint32
,
51 "Reserved1" => self
::uint32
,
52 "Reserved2" => self
::uint32
,
53 "Reserved3" => self
::uint32
,
54 "Reserved4" => self
::uint32
,
57 $this->data
["Padding1"] = $font->readUInt16();
58 $this->readString("FamilyName");
60 $this->data
["Padding2"] = $font->readUInt16();
61 $this->readString("StyleName");
63 $this->data
["Padding3"] = $font->readUInt16();
64 $this->readString("VersionName");
66 $this->data
["Padding4"] = $font->readUInt16();
67 $this->readString("FullName");
69 switch ($this->data
["Version"]) {
71 throw new Exception("Unknown EOT version " . $this->data
["Version"]);
78 $this->data
["Padding5"] = $font->readUInt16();
79 $this->readString("RootString");
83 $this->data
["Padding5"] = $font->readUInt16();
84 $this->readString("RootString");
86 $this->data
["RootStringCheckSum"] = $font->readUInt32();
87 $this->data
["EUDCCodePage"] = $font->readUInt32();
89 $this->data
["Padding6"] = $font->readUInt16();
90 $this->readString("Signature");
92 $this->data
["EUDCFlags"] = $font->readUInt32();
93 $this->data
["EUDCFontSize"] = $font->readUInt32();
97 if (!empty($this->data
["RootString"])) {
98 $this->data
["RootString"] = explode("\0", $this->data
["RootString"]);
102 private function readString($name) {
104 $size = $font->readUInt16();
106 $this->data
["{$name}Size"] = $size;
107 $this->data
[$name] = Font
::UTF16ToUTF8($font->read($size));
110 public function encode() {
111 //return $this->font->pack($this->def, $this->data);