1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
<?php /** * @package php-font-lib * @link https://github.com/PhenX/php-font-lib * @author Fabien Ménager <fabien.menager@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */
/** * `post` font table. * * @package php-font-lib */ class Font_Table_post extends Font_Table { protected $def = array( "format" => self::Fixed, "italicAngle" => self::Fixed, "underlinePosition" => self::FWord, "underlineThickness" => self::FWord, "isFixedPitch" => self::uint32, "minMemType42" => self::uint32, "maxMemType42" => self::uint32, "minMemType1" => self::uint32, "maxMemType1" => self::uint32, ); protected function _parse(){ $font = $this->getFont(); $data = $font->unpack($this->def); $names = array(); switch($data["format"]) { case 1: $names = Font_TrueType::$macCharNames; break; case 2: $data["numberOfGlyphs"] = $font->readUInt16(); $glyphNameIndex = array(); for($i = 0; $i < $data["numberOfGlyphs"]; $i++) { $glyphNameIndex[] = $font->readUInt16(); } $data["glyphNameIndex"] = $glyphNameIndex; $namesPascal = array(); for($i = 0; $i < $data["numberOfGlyphs"]; $i++) { $len = $font->readUInt8(); $namesPascal[] = $font->read($len); } foreach($glyphNameIndex as $g => $index) { if ($index < 258) { $names[$g] = Font_TrueType::$macCharNames[$index]; } else { $names[$g] = $namesPascal[$index - 258]; } } break; case 2.5: // TODO break; case 3: // nothing break; case 4: // TODO break; } $data["names"] = $names; $this->data = $data; } function _encode(){ $font = $this->getFont(); $data = $this->data; $data["format"] = 3; $length = $font->pack($this->def, $data); return $length;
/* $subset = $font->getSubset(); switch($data["format"]) { case 1: // nothing to do break; case 2: $old_names = $data["names"]; $glyphNameIndex = range(0, count($subset)); $names = array(); foreach($subset as $gid) { $names[] = $data["names"][$data["glyphNameIndex"][$gid]]; } $numberOfGlyphs = count($names); $length += $font->writeUInt16($numberOfGlyphs); foreach($glyphNameIndex as $gni) { $length += $font->writeUInt16($gni); } //$names = array_slice($names, 257); foreach($names as $name) { $len = strlen($name); $length += $font->writeUInt8($len); $length += $font->write($name, $len); } break; case 2.5: // TODO break; case 3: // nothing break; case 4: // TODO break; } return $length;*/ } }
|