@@ -17,21 +17,21 @@ |
||
17 | 17 | private $f; |
18 | 18 | |
19 | 19 | function __construct($file) { |
20 | - $this->f = fopen($file, "r"); |
|
20 | + $this->f = fopen($file, "r"); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | function parse() { |
24 | - $map = array(); |
|
24 | + $map = array(); |
|
25 | 25 | |
26 | - while ($line = fgets($this->f)) { |
|
27 | - if (preg_match('/^[\!\=]([0-9A-F]{2,})\s+U\+([0-9A-F]{2})([0-9A-F]{2})\s+([^\s]+)/', $line, $matches)) { |
|
28 | - $unicode = (hexdec($matches[2]) << 8) + hexdec($matches[3]); |
|
29 | - $map[hexdec($matches[1])] = array($unicode, $matches[4]); |
|
30 | - } |
|
31 | - } |
|
26 | + while ($line = fgets($this->f)) { |
|
27 | + if (preg_match('/^[\!\=]([0-9A-F]{2,})\s+U\+([0-9A-F]{2})([0-9A-F]{2})\s+([^\s]+)/', $line, $matches)) { |
|
28 | + $unicode = (hexdec($matches[2]) << 8) + hexdec($matches[3]); |
|
29 | + $map[hexdec($matches[1])] = array($unicode, $matches[4]); |
|
30 | + } |
|
31 | + } |
|
32 | 32 | |
33 | - ksort($map); |
|
33 | + ksort($map); |
|
34 | 34 | |
35 | - return $map; |
|
35 | + return $map; |
|
36 | 36 | } |
37 | 37 | } |
@@ -22,10 +22,10 @@ |
||
22 | 22 | public $instructions; |
23 | 23 | |
24 | 24 | function getMatrix() { |
25 | - return array( |
|
26 | - $this->a, $this->b, |
|
27 | - $this->c, $this->d, |
|
28 | - $this->e, $this->f, |
|
29 | - ); |
|
25 | + return array( |
|
26 | + $this->a, $this->b, |
|
27 | + $this->c, $this->d, |
|
28 | + $this->e, $this->f, |
|
29 | + ); |
|
30 | 30 | } |
31 | 31 | } |
32 | 32 | \ No newline at end of file |
@@ -26,310 +26,310 @@ |
||
26 | 26 | public $points; |
27 | 27 | |
28 | 28 | function parseData() { |
29 | - parent::parseData(); |
|
30 | - |
|
31 | - if (!$this->size) { |
|
32 | - return; |
|
33 | - } |
|
34 | - |
|
35 | - $font = $this->getFont(); |
|
36 | - |
|
37 | - $noc = $this->numberOfContours; |
|
38 | - |
|
39 | - if ($noc == 0) { |
|
40 | - return; |
|
41 | - } |
|
42 | - |
|
43 | - $endPtsOfContours = $font->r(array(self::uint16, $noc)); |
|
44 | - |
|
45 | - $instructionLength = $font->readUInt16(); |
|
46 | - $this->instructions = $font->r(array(self::uint8, $instructionLength)); |
|
47 | - |
|
48 | - $count = $endPtsOfContours[$noc - 1] + 1; |
|
49 | - |
|
50 | - // Flags |
|
51 | - $flags = array(); |
|
52 | - for ($index = 0; $index < $count; $index++) { |
|
53 | - $flags[$index] = $font->readUInt8(); |
|
54 | - |
|
55 | - if ($flags[$index] & self::REPEAT) { |
|
56 | - $repeats = $font->readUInt8(); |
|
57 | - |
|
58 | - for ($i = 1; $i <= $repeats; $i++) { |
|
59 | - $flags[$index + $i] = $flags[$index]; |
|
60 | - } |
|
61 | - |
|
62 | - $index += $repeats; |
|
63 | - } |
|
64 | - } |
|
65 | - |
|
66 | - $points = array(); |
|
67 | - foreach ($flags as $i => $flag) { |
|
68 | - $points[$i]["onCurve"] = $flag & self::ON_CURVE; |
|
69 | - $points[$i]["endOfContour"] = in_array($i, $endPtsOfContours); |
|
70 | - } |
|
71 | - |
|
72 | - // X Coords |
|
73 | - $x = 0; |
|
74 | - for ($i = 0; $i < $count; $i++) { |
|
75 | - $flag = $flags[$i]; |
|
76 | - |
|
77 | - if ($flag & self::THIS_X_IS_SAME) { |
|
78 | - if ($flag & self::X_SHORT_VECTOR) { |
|
79 | - $x += $font->readUInt8(); |
|
80 | - } |
|
81 | - } |
|
82 | - else { |
|
83 | - if ($flag & self::X_SHORT_VECTOR) { |
|
84 | - $x -= $font->readUInt8(); |
|
85 | - } |
|
86 | - else { |
|
87 | - $x += $font->readInt16(); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - $points[$i]["x"] = $x; |
|
92 | - } |
|
93 | - |
|
94 | - // Y Coords |
|
95 | - $y = 0; |
|
96 | - for ($i = 0; $i < $count; $i++) { |
|
97 | - $flag = $flags[$i]; |
|
98 | - |
|
99 | - if ($flag & self::THIS_Y_IS_SAME) { |
|
100 | - if ($flag & self::Y_SHORT_VECTOR) { |
|
101 | - $y += $font->readUInt8(); |
|
102 | - } |
|
103 | - } |
|
104 | - else { |
|
105 | - if ($flag & self::Y_SHORT_VECTOR) { |
|
106 | - $y -= $font->readUInt8(); |
|
107 | - } |
|
108 | - else { |
|
109 | - $y += $font->readInt16(); |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - $points[$i]["y"] = $y; |
|
114 | - } |
|
115 | - |
|
116 | - $this->points = $points; |
|
29 | + parent::parseData(); |
|
30 | + |
|
31 | + if (!$this->size) { |
|
32 | + return; |
|
33 | + } |
|
34 | + |
|
35 | + $font = $this->getFont(); |
|
36 | + |
|
37 | + $noc = $this->numberOfContours; |
|
38 | + |
|
39 | + if ($noc == 0) { |
|
40 | + return; |
|
41 | + } |
|
42 | + |
|
43 | + $endPtsOfContours = $font->r(array(self::uint16, $noc)); |
|
44 | + |
|
45 | + $instructionLength = $font->readUInt16(); |
|
46 | + $this->instructions = $font->r(array(self::uint8, $instructionLength)); |
|
47 | + |
|
48 | + $count = $endPtsOfContours[$noc - 1] + 1; |
|
49 | + |
|
50 | + // Flags |
|
51 | + $flags = array(); |
|
52 | + for ($index = 0; $index < $count; $index++) { |
|
53 | + $flags[$index] = $font->readUInt8(); |
|
54 | + |
|
55 | + if ($flags[$index] & self::REPEAT) { |
|
56 | + $repeats = $font->readUInt8(); |
|
57 | + |
|
58 | + for ($i = 1; $i <= $repeats; $i++) { |
|
59 | + $flags[$index + $i] = $flags[$index]; |
|
60 | + } |
|
61 | + |
|
62 | + $index += $repeats; |
|
63 | + } |
|
64 | + } |
|
65 | + |
|
66 | + $points = array(); |
|
67 | + foreach ($flags as $i => $flag) { |
|
68 | + $points[$i]["onCurve"] = $flag & self::ON_CURVE; |
|
69 | + $points[$i]["endOfContour"] = in_array($i, $endPtsOfContours); |
|
70 | + } |
|
71 | + |
|
72 | + // X Coords |
|
73 | + $x = 0; |
|
74 | + for ($i = 0; $i < $count; $i++) { |
|
75 | + $flag = $flags[$i]; |
|
76 | + |
|
77 | + if ($flag & self::THIS_X_IS_SAME) { |
|
78 | + if ($flag & self::X_SHORT_VECTOR) { |
|
79 | + $x += $font->readUInt8(); |
|
80 | + } |
|
81 | + } |
|
82 | + else { |
|
83 | + if ($flag & self::X_SHORT_VECTOR) { |
|
84 | + $x -= $font->readUInt8(); |
|
85 | + } |
|
86 | + else { |
|
87 | + $x += $font->readInt16(); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + $points[$i]["x"] = $x; |
|
92 | + } |
|
93 | + |
|
94 | + // Y Coords |
|
95 | + $y = 0; |
|
96 | + for ($i = 0; $i < $count; $i++) { |
|
97 | + $flag = $flags[$i]; |
|
98 | + |
|
99 | + if ($flag & self::THIS_Y_IS_SAME) { |
|
100 | + if ($flag & self::Y_SHORT_VECTOR) { |
|
101 | + $y += $font->readUInt8(); |
|
102 | + } |
|
103 | + } |
|
104 | + else { |
|
105 | + if ($flag & self::Y_SHORT_VECTOR) { |
|
106 | + $y -= $font->readUInt8(); |
|
107 | + } |
|
108 | + else { |
|
109 | + $y += $font->readInt16(); |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + $points[$i]["y"] = $y; |
|
114 | + } |
|
115 | + |
|
116 | + $this->points = $points; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | public function splitSVGPath($path) { |
120 | - preg_match_all('/([a-z])|(-?\d+(?:\.\d+)?)/i', $path, $matches, PREG_PATTERN_ORDER); |
|
120 | + preg_match_all('/([a-z])|(-?\d+(?:\.\d+)?)/i', $path, $matches, PREG_PATTERN_ORDER); |
|
121 | 121 | |
122 | - return $matches[0]; |
|
122 | + return $matches[0]; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | public function makePoints($path) { |
126 | - $path = $this->splitSVGPath($path); |
|
127 | - $l = count($path); |
|
128 | - $i = 0; |
|
129 | - |
|
130 | - $points = array(); |
|
131 | - |
|
132 | - while ($i < $l) { |
|
133 | - switch ($path[$i]) { |
|
134 | - // moveTo |
|
135 | - case "M": |
|
136 | - $points[] = array( |
|
137 | - "onCurve" => true, |
|
138 | - "x" => $path[++$i], |
|
139 | - "y" => $path[++$i], |
|
140 | - "endOfContour" => false, |
|
141 | - ); |
|
142 | - break; |
|
143 | - |
|
144 | - // lineTo |
|
145 | - case "L": |
|
146 | - $points[] = array( |
|
147 | - "onCurve" => true, |
|
148 | - "x" => $path[++$i], |
|
149 | - "y" => $path[++$i], |
|
150 | - "endOfContour" => false, |
|
151 | - ); |
|
152 | - break; |
|
153 | - |
|
154 | - // quadraticCurveTo |
|
155 | - case "Q": |
|
156 | - $points[] = array( |
|
157 | - "onCurve" => false, |
|
158 | - "x" => $path[++$i], |
|
159 | - "y" => $path[++$i], |
|
160 | - "endOfContour" => false, |
|
161 | - ); |
|
162 | - $points[] = array( |
|
163 | - "onCurve" => true, |
|
164 | - "x" => $path[++$i], |
|
165 | - "y" => $path[++$i], |
|
166 | - "endOfContour" => false, |
|
167 | - ); |
|
168 | - break; |
|
169 | - |
|
170 | - // closePath |
|
171 | - /** @noinspection PhpMissingBreakStatementInspection */ |
|
172 | - case "z": |
|
173 | - $points[count($points) - 1]["endOfContour"] = true; |
|
174 | - |
|
175 | - default: |
|
176 | - $i++; |
|
177 | - break; |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - return $points; |
|
126 | + $path = $this->splitSVGPath($path); |
|
127 | + $l = count($path); |
|
128 | + $i = 0; |
|
129 | + |
|
130 | + $points = array(); |
|
131 | + |
|
132 | + while ($i < $l) { |
|
133 | + switch ($path[$i]) { |
|
134 | + // moveTo |
|
135 | + case "M": |
|
136 | + $points[] = array( |
|
137 | + "onCurve" => true, |
|
138 | + "x" => $path[++$i], |
|
139 | + "y" => $path[++$i], |
|
140 | + "endOfContour" => false, |
|
141 | + ); |
|
142 | + break; |
|
143 | + |
|
144 | + // lineTo |
|
145 | + case "L": |
|
146 | + $points[] = array( |
|
147 | + "onCurve" => true, |
|
148 | + "x" => $path[++$i], |
|
149 | + "y" => $path[++$i], |
|
150 | + "endOfContour" => false, |
|
151 | + ); |
|
152 | + break; |
|
153 | + |
|
154 | + // quadraticCurveTo |
|
155 | + case "Q": |
|
156 | + $points[] = array( |
|
157 | + "onCurve" => false, |
|
158 | + "x" => $path[++$i], |
|
159 | + "y" => $path[++$i], |
|
160 | + "endOfContour" => false, |
|
161 | + ); |
|
162 | + $points[] = array( |
|
163 | + "onCurve" => true, |
|
164 | + "x" => $path[++$i], |
|
165 | + "y" => $path[++$i], |
|
166 | + "endOfContour" => false, |
|
167 | + ); |
|
168 | + break; |
|
169 | + |
|
170 | + // closePath |
|
171 | + /** @noinspection PhpMissingBreakStatementInspection */ |
|
172 | + case "z": |
|
173 | + $points[count($points) - 1]["endOfContour"] = true; |
|
174 | + |
|
175 | + default: |
|
176 | + $i++; |
|
177 | + break; |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + return $points; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | function encode() { |
185 | - if (empty($this->points)) { |
|
186 | - return parent::encode(); |
|
187 | - } |
|
185 | + if (empty($this->points)) { |
|
186 | + return parent::encode(); |
|
187 | + } |
|
188 | 188 | |
189 | - return $this->size = $this->encodePoints($this->points); |
|
189 | + return $this->size = $this->encodePoints($this->points); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | public function encodePoints($points) { |
193 | - $endPtsOfContours = array(); |
|
194 | - $flags = array(); |
|
195 | - $coords_x = array(); |
|
196 | - $coords_y = array(); |
|
197 | - |
|
198 | - $last_x = 0; |
|
199 | - $last_y = 0; |
|
200 | - $xMin = $yMin = 0xFFFF; |
|
201 | - $xMax = $yMax = -0xFFFF; |
|
202 | - foreach ($points as $i => $point) { |
|
203 | - $flag = 0; |
|
204 | - if ($point["onCurve"]) { |
|
205 | - $flag |= self::ON_CURVE; |
|
206 | - } |
|
207 | - |
|
208 | - if ($point["endOfContour"]) { |
|
209 | - $endPtsOfContours[] = $i; |
|
210 | - } |
|
211 | - |
|
212 | - // Simplified, we could do some optimizations |
|
213 | - if ($point["x"] == $last_x) { |
|
214 | - $flag |= self::THIS_X_IS_SAME; |
|
215 | - } |
|
216 | - else { |
|
217 | - $x = intval($point["x"]); |
|
218 | - $xMin = min($x, $xMin); |
|
219 | - $xMax = max($x, $xMax); |
|
220 | - $coords_x[] = $x - $last_x; // int16 |
|
221 | - } |
|
222 | - |
|
223 | - // Simplified, we could do some optimizations |
|
224 | - if ($point["y"] == $last_y) { |
|
225 | - $flag |= self::THIS_Y_IS_SAME; |
|
226 | - } |
|
227 | - else { |
|
228 | - $y = intval($point["y"]); |
|
229 | - $yMin = min($y, $yMin); |
|
230 | - $yMax = max($y, $yMax); |
|
231 | - $coords_y[] = $y - $last_y; // int16 |
|
232 | - } |
|
233 | - |
|
234 | - $flags[] = $flag; |
|
235 | - $last_x = $point["x"]; |
|
236 | - $last_y = $point["y"]; |
|
237 | - } |
|
238 | - |
|
239 | - $font = $this->getFont(); |
|
240 | - |
|
241 | - $l = 0; |
|
242 | - $l += $font->writeInt16(count($endPtsOfContours)); // endPtsOfContours |
|
243 | - $l += $font->writeFWord(isset($this->xMin) ? $this->xMin : $xMin); // xMin |
|
244 | - $l += $font->writeFWord(isset($this->yMin) ? $this->yMin : $yMin); // yMin |
|
245 | - $l += $font->writeFWord(isset($this->xMax) ? $this->xMax : $xMax); // xMax |
|
246 | - $l += $font->writeFWord(isset($this->yMax) ? $this->yMax : $yMax); // yMax |
|
247 | - |
|
248 | - // Simple glyf |
|
249 | - $l += $font->w(array(self::uint16, count($endPtsOfContours)), $endPtsOfContours); // endPtsOfContours |
|
250 | - $l += $font->writeUInt16(0); // instructionLength |
|
251 | - $l += $font->w(array(self::uint8, count($flags)), $flags); // flags |
|
252 | - $l += $font->w(array(self::int16, count($coords_x)), $coords_x); // xCoordinates |
|
253 | - $l += $font->w(array(self::int16, count($coords_y)), $coords_y); // yCoordinates |
|
254 | - return $l; |
|
193 | + $endPtsOfContours = array(); |
|
194 | + $flags = array(); |
|
195 | + $coords_x = array(); |
|
196 | + $coords_y = array(); |
|
197 | + |
|
198 | + $last_x = 0; |
|
199 | + $last_y = 0; |
|
200 | + $xMin = $yMin = 0xFFFF; |
|
201 | + $xMax = $yMax = -0xFFFF; |
|
202 | + foreach ($points as $i => $point) { |
|
203 | + $flag = 0; |
|
204 | + if ($point["onCurve"]) { |
|
205 | + $flag |= self::ON_CURVE; |
|
206 | + } |
|
207 | + |
|
208 | + if ($point["endOfContour"]) { |
|
209 | + $endPtsOfContours[] = $i; |
|
210 | + } |
|
211 | + |
|
212 | + // Simplified, we could do some optimizations |
|
213 | + if ($point["x"] == $last_x) { |
|
214 | + $flag |= self::THIS_X_IS_SAME; |
|
215 | + } |
|
216 | + else { |
|
217 | + $x = intval($point["x"]); |
|
218 | + $xMin = min($x, $xMin); |
|
219 | + $xMax = max($x, $xMax); |
|
220 | + $coords_x[] = $x - $last_x; // int16 |
|
221 | + } |
|
222 | + |
|
223 | + // Simplified, we could do some optimizations |
|
224 | + if ($point["y"] == $last_y) { |
|
225 | + $flag |= self::THIS_Y_IS_SAME; |
|
226 | + } |
|
227 | + else { |
|
228 | + $y = intval($point["y"]); |
|
229 | + $yMin = min($y, $yMin); |
|
230 | + $yMax = max($y, $yMax); |
|
231 | + $coords_y[] = $y - $last_y; // int16 |
|
232 | + } |
|
233 | + |
|
234 | + $flags[] = $flag; |
|
235 | + $last_x = $point["x"]; |
|
236 | + $last_y = $point["y"]; |
|
237 | + } |
|
238 | + |
|
239 | + $font = $this->getFont(); |
|
240 | + |
|
241 | + $l = 0; |
|
242 | + $l += $font->writeInt16(count($endPtsOfContours)); // endPtsOfContours |
|
243 | + $l += $font->writeFWord(isset($this->xMin) ? $this->xMin : $xMin); // xMin |
|
244 | + $l += $font->writeFWord(isset($this->yMin) ? $this->yMin : $yMin); // yMin |
|
245 | + $l += $font->writeFWord(isset($this->xMax) ? $this->xMax : $xMax); // xMax |
|
246 | + $l += $font->writeFWord(isset($this->yMax) ? $this->yMax : $yMax); // yMax |
|
247 | + |
|
248 | + // Simple glyf |
|
249 | + $l += $font->w(array(self::uint16, count($endPtsOfContours)), $endPtsOfContours); // endPtsOfContours |
|
250 | + $l += $font->writeUInt16(0); // instructionLength |
|
251 | + $l += $font->w(array(self::uint8, count($flags)), $flags); // flags |
|
252 | + $l += $font->w(array(self::int16, count($coords_x)), $coords_x); // xCoordinates |
|
253 | + $l += $font->w(array(self::int16, count($coords_y)), $coords_y); // yCoordinates |
|
254 | + return $l; |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | public function getSVGContours($points = null) { |
258 | - $path = ""; |
|
258 | + $path = ""; |
|
259 | 259 | |
260 | - if (!$points) { |
|
261 | - if (empty($this->points)) { |
|
262 | - $this->parseData(); |
|
263 | - } |
|
260 | + if (!$points) { |
|
261 | + if (empty($this->points)) { |
|
262 | + $this->parseData(); |
|
263 | + } |
|
264 | 264 | |
265 | - $points = $this->points; |
|
266 | - } |
|
265 | + $points = $this->points; |
|
266 | + } |
|
267 | 267 | |
268 | - $length = (empty($points) ? 0 : count($points)); |
|
269 | - $firstIndex = 0; |
|
270 | - $count = 0; |
|
268 | + $length = (empty($points) ? 0 : count($points)); |
|
269 | + $firstIndex = 0; |
|
270 | + $count = 0; |
|
271 | 271 | |
272 | - for ($i = 0; $i < $length; $i++) { |
|
273 | - $count++; |
|
272 | + for ($i = 0; $i < $length; $i++) { |
|
273 | + $count++; |
|
274 | 274 | |
275 | - if ($points[$i]["endOfContour"]) { |
|
276 | - $path .= $this->getSVGPath($points, $firstIndex, $count); |
|
277 | - $firstIndex = $i + 1; |
|
278 | - $count = 0; |
|
279 | - } |
|
280 | - } |
|
275 | + if ($points[$i]["endOfContour"]) { |
|
276 | + $path .= $this->getSVGPath($points, $firstIndex, $count); |
|
277 | + $firstIndex = $i + 1; |
|
278 | + $count = 0; |
|
279 | + } |
|
280 | + } |
|
281 | 281 | |
282 | - return $path; |
|
282 | + return $path; |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | protected function getSVGPath($points, $startIndex, $count) { |
286 | - $offset = 0; |
|
287 | - $path = ""; |
|
288 | - |
|
289 | - while ($offset < $count) { |
|
290 | - $point = $points[$startIndex + $offset % $count]; |
|
291 | - $point_p1 = $points[$startIndex + ($offset + 1) % $count]; |
|
292 | - |
|
293 | - if ($offset == 0) { |
|
294 | - $path .= "M{$point['x']},{$point['y']} "; |
|
295 | - } |
|
296 | - |
|
297 | - if ($point["onCurve"]) { |
|
298 | - if ($point_p1["onCurve"]) { |
|
299 | - $path .= "L{$point_p1['x']},{$point_p1['y']} "; |
|
300 | - $offset++; |
|
301 | - } |
|
302 | - else { |
|
303 | - $point_p2 = $points[$startIndex + ($offset + 2) % $count]; |
|
304 | - |
|
305 | - if ($point_p2["onCurve"]) { |
|
306 | - $path .= "Q{$point_p1['x']},{$point_p1['y']},{$point_p2['x']},{$point_p2['y']} "; |
|
307 | - } |
|
308 | - else { |
|
309 | - $path .= "Q{$point_p1['x']},{$point_p1['y']}," . $this->midValue($point_p1['x'], $point_p2['x']) . "," . $this->midValue($point_p1['y'], $point_p2['y']) . " "; |
|
310 | - } |
|
311 | - |
|
312 | - $offset += 2; |
|
313 | - } |
|
314 | - } |
|
315 | - else { |
|
316 | - if ($point_p1["onCurve"]) { |
|
317 | - $path .= "Q{$point['x']},{$point['y']},{$point_p1['x']},{$point_p1['y']} "; |
|
318 | - } |
|
319 | - else { |
|
320 | - $path .= "Q{$point['x']},{$point['y']}," . $this->midValue($point['x'], $point_p1['x']) . "," . $this->midValue($point['y'], $point_p1['y']) . " "; |
|
321 | - } |
|
322 | - |
|
323 | - $offset++; |
|
324 | - } |
|
325 | - } |
|
326 | - |
|
327 | - $path .= "z "; |
|
328 | - |
|
329 | - return $path; |
|
286 | + $offset = 0; |
|
287 | + $path = ""; |
|
288 | + |
|
289 | + while ($offset < $count) { |
|
290 | + $point = $points[$startIndex + $offset % $count]; |
|
291 | + $point_p1 = $points[$startIndex + ($offset + 1) % $count]; |
|
292 | + |
|
293 | + if ($offset == 0) { |
|
294 | + $path .= "M{$point['x']},{$point['y']} "; |
|
295 | + } |
|
296 | + |
|
297 | + if ($point["onCurve"]) { |
|
298 | + if ($point_p1["onCurve"]) { |
|
299 | + $path .= "L{$point_p1['x']},{$point_p1['y']} "; |
|
300 | + $offset++; |
|
301 | + } |
|
302 | + else { |
|
303 | + $point_p2 = $points[$startIndex + ($offset + 2) % $count]; |
|
304 | + |
|
305 | + if ($point_p2["onCurve"]) { |
|
306 | + $path .= "Q{$point_p1['x']},{$point_p1['y']},{$point_p2['x']},{$point_p2['y']} "; |
|
307 | + } |
|
308 | + else { |
|
309 | + $path .= "Q{$point_p1['x']},{$point_p1['y']}," . $this->midValue($point_p1['x'], $point_p2['x']) . "," . $this->midValue($point_p1['y'], $point_p2['y']) . " "; |
|
310 | + } |
|
311 | + |
|
312 | + $offset += 2; |
|
313 | + } |
|
314 | + } |
|
315 | + else { |
|
316 | + if ($point_p1["onCurve"]) { |
|
317 | + $path .= "Q{$point['x']},{$point['y']},{$point_p1['x']},{$point_p1['y']} "; |
|
318 | + } |
|
319 | + else { |
|
320 | + $path .= "Q{$point['x']},{$point['y']}," . $this->midValue($point['x'], $point_p1['x']) . "," . $this->midValue($point['y'], $point_p1['y']) . " "; |
|
321 | + } |
|
322 | + |
|
323 | + $offset++; |
|
324 | + } |
|
325 | + } |
|
326 | + |
|
327 | + $path .= "z "; |
|
328 | + |
|
329 | + return $path; |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | function midValue($a, $b) { |
333 | - return $a + ($b - $a) / 2; |
|
333 | + return $a + ($b - $a) / 2; |
|
334 | 334 | } |
335 | 335 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | function parseData() { |
29 | 29 | parent::parseData(); |
30 | 30 | |
31 | - if (!$this->size) { |
|
31 | + if ( ! $this->size) { |
|
32 | 32 | return; |
33 | 33 | } |
34 | 34 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | public function getSVGContours($points = null) { |
258 | 258 | $path = ""; |
259 | 259 | |
260 | - if (!$points) { |
|
260 | + if ( ! $points) { |
|
261 | 261 | if (empty($this->points)) { |
262 | 262 | $this->parseData(); |
263 | 263 | } |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | $path .= "Q{$point_p1['x']},{$point_p1['y']},{$point_p2['x']},{$point_p2['y']} "; |
307 | 307 | } |
308 | 308 | else { |
309 | - $path .= "Q{$point_p1['x']},{$point_p1['y']}," . $this->midValue($point_p1['x'], $point_p2['x']) . "," . $this->midValue($point_p1['y'], $point_p2['y']) . " "; |
|
309 | + $path .= "Q{$point_p1['x']},{$point_p1['y']},".$this->midValue($point_p1['x'], $point_p2['x']).",".$this->midValue($point_p1['y'], $point_p2['y'])." "; |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | $offset += 2; |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | $path .= "Q{$point['x']},{$point['y']},{$point_p1['x']},{$point_p1['y']} "; |
318 | 318 | } |
319 | 319 | else { |
320 | - $path .= "Q{$point['x']},{$point['y']}," . $this->midValue($point['x'], $point_p1['x']) . "," . $this->midValue($point['y'], $point_p1['y']) . " "; |
|
320 | + $path .= "Q{$point['x']},{$point['y']},".$this->midValue($point['x'], $point_p1['x']).",".$this->midValue($point['y'], $point_p1['y'])." "; |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | $offset++; |
@@ -78,12 +78,10 @@ discard block |
||
78 | 78 | if ($flag & self::X_SHORT_VECTOR) { |
79 | 79 | $x += $font->readUInt8(); |
80 | 80 | } |
81 | - } |
|
82 | - else { |
|
81 | + } else { |
|
83 | 82 | if ($flag & self::X_SHORT_VECTOR) { |
84 | 83 | $x -= $font->readUInt8(); |
85 | - } |
|
86 | - else { |
|
84 | + } else { |
|
87 | 85 | $x += $font->readInt16(); |
88 | 86 | } |
89 | 87 | } |
@@ -100,12 +98,10 @@ discard block |
||
100 | 98 | if ($flag & self::Y_SHORT_VECTOR) { |
101 | 99 | $y += $font->readUInt8(); |
102 | 100 | } |
103 | - } |
|
104 | - else { |
|
101 | + } else { |
|
105 | 102 | if ($flag & self::Y_SHORT_VECTOR) { |
106 | 103 | $y -= $font->readUInt8(); |
107 | - } |
|
108 | - else { |
|
104 | + } else { |
|
109 | 105 | $y += $font->readInt16(); |
110 | 106 | } |
111 | 107 | } |
@@ -212,8 +208,7 @@ discard block |
||
212 | 208 | // Simplified, we could do some optimizations |
213 | 209 | if ($point["x"] == $last_x) { |
214 | 210 | $flag |= self::THIS_X_IS_SAME; |
215 | - } |
|
216 | - else { |
|
211 | + } else { |
|
217 | 212 | $x = intval($point["x"]); |
218 | 213 | $xMin = min($x, $xMin); |
219 | 214 | $xMax = max($x, $xMax); |
@@ -223,8 +218,7 @@ discard block |
||
223 | 218 | // Simplified, we could do some optimizations |
224 | 219 | if ($point["y"] == $last_y) { |
225 | 220 | $flag |= self::THIS_Y_IS_SAME; |
226 | - } |
|
227 | - else { |
|
221 | + } else { |
|
228 | 222 | $y = intval($point["y"]); |
229 | 223 | $yMin = min($y, $yMin); |
230 | 224 | $yMax = max($y, $yMax); |
@@ -298,25 +292,21 @@ discard block |
||
298 | 292 | if ($point_p1["onCurve"]) { |
299 | 293 | $path .= "L{$point_p1['x']},{$point_p1['y']} "; |
300 | 294 | $offset++; |
301 | - } |
|
302 | - else { |
|
295 | + } else { |
|
303 | 296 | $point_p2 = $points[$startIndex + ($offset + 2) % $count]; |
304 | 297 | |
305 | 298 | if ($point_p2["onCurve"]) { |
306 | 299 | $path .= "Q{$point_p1['x']},{$point_p1['y']},{$point_p2['x']},{$point_p2['y']} "; |
307 | - } |
|
308 | - else { |
|
300 | + } else { |
|
309 | 301 | $path .= "Q{$point_p1['x']},{$point_p1['y']}," . $this->midValue($point_p1['x'], $point_p2['x']) . "," . $this->midValue($point_p1['y'], $point_p2['y']) . " "; |
310 | 302 | } |
311 | 303 | |
312 | 304 | $offset += 2; |
313 | 305 | } |
314 | - } |
|
315 | - else { |
|
306 | + } else { |
|
316 | 307 | if ($point_p1["onCurve"]) { |
317 | 308 | $path .= "Q{$point['x']},{$point['y']},{$point_p1['x']},{$point_p1['y']} "; |
318 | - } |
|
319 | - else { |
|
309 | + } else { |
|
320 | 310 | $path .= "Q{$point['x']},{$point['y']}," . $this->midValue($point['x'], $point_p1['x']) . "," . $this->midValue($point['y'], $point_p1['y']) . " "; |
321 | 311 | } |
322 | 312 |
@@ -79,18 +79,15 @@ discard block |
||
79 | 79 | if ($flags & self::ARGS_ARE_XY_VALUES) { |
80 | 80 | $e = $font->readInt16(); |
81 | 81 | $f = $font->readInt16(); |
82 | - } |
|
83 | - else { |
|
82 | + } else { |
|
84 | 83 | $point_compound = $font->readUInt16(); |
85 | 84 | $point_component = $font->readUInt16(); |
86 | 85 | } |
87 | - } |
|
88 | - else { |
|
86 | + } else { |
|
89 | 87 | if ($flags & self::ARGS_ARE_XY_VALUES) { |
90 | 88 | $e = $font->readInt8(); |
91 | 89 | $f = $font->readInt8(); |
92 | - } |
|
93 | - else { |
|
90 | + } else { |
|
94 | 91 | $point_compound = $font->readUInt8(); |
95 | 92 | $point_component = $font->readUInt8(); |
96 | 93 | } |
@@ -98,12 +95,10 @@ discard block |
||
98 | 95 | |
99 | 96 | if ($flags & self::WE_HAVE_A_SCALE) { |
100 | 97 | $a = $d = $font->readInt16(); |
101 | - } |
|
102 | - elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) { |
|
98 | + } elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) { |
|
103 | 99 | $a = $font->readInt16(); |
104 | 100 | $d = $font->readInt16(); |
105 | - } |
|
106 | - elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) { |
|
101 | + } elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) { |
|
107 | 102 | $a = $font->readInt16(); |
108 | 103 | $b = $font->readInt16(); |
109 | 104 | $c = $font->readInt16(); |
@@ -150,8 +145,7 @@ discard block |
||
150 | 145 | if (abs($_component->e) > 0x7F || abs($_component->f) > 0x7F) { |
151 | 146 | $flags |= self::ARG_1_AND_2_ARE_WORDS; |
152 | 147 | } |
153 | - } |
|
154 | - elseif ($_component->point_component > 0xFF || $_component->point_compound > 0xFF) { |
|
148 | + } elseif ($_component->point_component > 0xFF || $_component->point_compound > 0xFF) { |
|
155 | 149 | $flags |= self::ARG_1_AND_2_ARE_WORDS; |
156 | 150 | } |
157 | 151 | |
@@ -160,12 +154,10 @@ discard block |
||
160 | 154 | if ($_component->a != 1.0) { |
161 | 155 | $flags |= self::WE_HAVE_A_SCALE; |
162 | 156 | } |
163 | - } |
|
164 | - else { |
|
157 | + } else { |
|
165 | 158 | $flags |= self::WE_HAVE_AN_X_AND_Y_SCALE; |
166 | 159 | } |
167 | - } |
|
168 | - else { |
|
160 | + } else { |
|
169 | 161 | $flags |= self::WE_HAVE_A_TWO_BY_TWO; |
170 | 162 | } |
171 | 163 | |
@@ -182,18 +174,15 @@ discard block |
||
182 | 174 | if ($flags & self::ARGS_ARE_XY_VALUES) { |
183 | 175 | $size += $font->writeInt16($_component->e); |
184 | 176 | $size += $font->writeInt16($_component->f); |
185 | - } |
|
186 | - else { |
|
177 | + } else { |
|
187 | 178 | $size += $font->writeUInt16($_component->point_compound); |
188 | 179 | $size += $font->writeUInt16($_component->point_component); |
189 | 180 | } |
190 | - } |
|
191 | - else { |
|
181 | + } else { |
|
192 | 182 | if ($flags & self::ARGS_ARE_XY_VALUES) { |
193 | 183 | $size += $font->writeInt8($_component->e); |
194 | 184 | $size += $font->writeInt8($_component->f); |
195 | - } |
|
196 | - else { |
|
185 | + } else { |
|
197 | 186 | $size += $font->writeUInt8($_component->point_compound); |
198 | 187 | $size += $font->writeUInt8($_component->point_component); |
199 | 188 | } |
@@ -201,12 +190,10 @@ discard block |
||
201 | 190 | |
202 | 191 | if ($flags & self::WE_HAVE_A_SCALE) { |
203 | 192 | $size += $font->writeInt16($_component->a); |
204 | - } |
|
205 | - elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) { |
|
193 | + } elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) { |
|
206 | 194 | $size += $font->writeInt16($_component->a); |
207 | 195 | $size += $font->writeInt16($_component->d); |
208 | - } |
|
209 | - elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) { |
|
196 | + } elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) { |
|
210 | 197 | $size += $font->writeInt16($_component->a); |
211 | 198 | $size += $font->writeInt16($_component->b); |
212 | 199 | $size += $font->writeInt16($_component->c); |
@@ -32,22 +32,22 @@ discard block |
||
32 | 32 | public $components = array(); |
33 | 33 | |
34 | 34 | function getGlyphIDs() { |
35 | - if (empty($this->components)) { |
|
36 | - $this->parseData(); |
|
37 | - } |
|
35 | + if (empty($this->components)) { |
|
36 | + $this->parseData(); |
|
37 | + } |
|
38 | 38 | |
39 | - $glyphIDs = array(); |
|
40 | - foreach ($this->components as $_component) { |
|
41 | - $glyphIDs[] = $_component->glyphIndex; |
|
39 | + $glyphIDs = array(); |
|
40 | + foreach ($this->components as $_component) { |
|
41 | + $glyphIDs[] = $_component->glyphIndex; |
|
42 | 42 | |
43 | - $_glyph = $this->table->data[$_component->glyphIndex]; |
|
43 | + $_glyph = $this->table->data[$_component->glyphIndex]; |
|
44 | 44 | |
45 | - if ($_glyph !== $this) { |
|
46 | - $glyphIDs = array_merge($glyphIDs, $_glyph->getGlyphIDs()); |
|
47 | - } |
|
48 | - } |
|
45 | + if ($_glyph !== $this) { |
|
46 | + $glyphIDs = array_merge($glyphIDs, $_glyph->getGlyphIDs()); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - return $glyphIDs; |
|
50 | + return $glyphIDs; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /*function parse() { |
@@ -55,199 +55,199 @@ discard block |
||
55 | 55 | }*/ |
56 | 56 | |
57 | 57 | function parseData() { |
58 | - parent::parseData(); |
|
59 | - |
|
60 | - $font = $this->getFont(); |
|
61 | - |
|
62 | - do { |
|
63 | - $flags = $font->readUInt16(); |
|
64 | - $glyphIndex = $font->readUInt16(); |
|
65 | - |
|
66 | - $a = 1.0; |
|
67 | - $b = 0.0; |
|
68 | - $c = 0.0; |
|
69 | - $d = 1.0; |
|
70 | - $e = 0.0; |
|
71 | - $f = 0.0; |
|
72 | - |
|
73 | - $point_compound = null; |
|
74 | - $point_component = null; |
|
75 | - |
|
76 | - $instructions = null; |
|
77 | - |
|
78 | - if ($flags & self::ARG_1_AND_2_ARE_WORDS) { |
|
79 | - if ($flags & self::ARGS_ARE_XY_VALUES) { |
|
80 | - $e = $font->readInt16(); |
|
81 | - $f = $font->readInt16(); |
|
82 | - } |
|
83 | - else { |
|
84 | - $point_compound = $font->readUInt16(); |
|
85 | - $point_component = $font->readUInt16(); |
|
86 | - } |
|
87 | - } |
|
88 | - else { |
|
89 | - if ($flags & self::ARGS_ARE_XY_VALUES) { |
|
90 | - $e = $font->readInt8(); |
|
91 | - $f = $font->readInt8(); |
|
92 | - } |
|
93 | - else { |
|
94 | - $point_compound = $font->readUInt8(); |
|
95 | - $point_component = $font->readUInt8(); |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - if ($flags & self::WE_HAVE_A_SCALE) { |
|
100 | - $a = $d = $font->readInt16(); |
|
101 | - } |
|
102 | - elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) { |
|
103 | - $a = $font->readInt16(); |
|
104 | - $d = $font->readInt16(); |
|
105 | - } |
|
106 | - elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) { |
|
107 | - $a = $font->readInt16(); |
|
108 | - $b = $font->readInt16(); |
|
109 | - $c = $font->readInt16(); |
|
110 | - $d = $font->readInt16(); |
|
111 | - } |
|
112 | - |
|
113 | - //if ($flags & self::WE_HAVE_INSTRUCTIONS) { |
|
114 | - // |
|
115 | - //} |
|
116 | - |
|
117 | - $component = new OutlineComponent(); |
|
118 | - $component->flags = $flags; |
|
119 | - $component->glyphIndex = $glyphIndex; |
|
120 | - $component->a = $a; |
|
121 | - $component->b = $b; |
|
122 | - $component->c = $c; |
|
123 | - $component->d = $d; |
|
124 | - $component->e = $e; |
|
125 | - $component->f = $f; |
|
126 | - $component->point_compound = $point_compound; |
|
127 | - $component->point_component = $point_component; |
|
128 | - $component->instructions = $instructions; |
|
129 | - |
|
130 | - $this->components[] = $component; |
|
131 | - } while ($flags & self::MORE_COMPONENTS); |
|
132 | - if ($flags & self::WE_HAVE_INSTRUCTIONS) { |
|
133 | - $numInstr = $font->readUInt16(); |
|
134 | - $instr = $font->read($numInstr); |
|
135 | - $this->components[count($this->components) - 1]->instructions = pack('n', $numInstr) . $instr; |
|
136 | - } |
|
58 | + parent::parseData(); |
|
59 | + |
|
60 | + $font = $this->getFont(); |
|
61 | + |
|
62 | + do { |
|
63 | + $flags = $font->readUInt16(); |
|
64 | + $glyphIndex = $font->readUInt16(); |
|
65 | + |
|
66 | + $a = 1.0; |
|
67 | + $b = 0.0; |
|
68 | + $c = 0.0; |
|
69 | + $d = 1.0; |
|
70 | + $e = 0.0; |
|
71 | + $f = 0.0; |
|
72 | + |
|
73 | + $point_compound = null; |
|
74 | + $point_component = null; |
|
75 | + |
|
76 | + $instructions = null; |
|
77 | + |
|
78 | + if ($flags & self::ARG_1_AND_2_ARE_WORDS) { |
|
79 | + if ($flags & self::ARGS_ARE_XY_VALUES) { |
|
80 | + $e = $font->readInt16(); |
|
81 | + $f = $font->readInt16(); |
|
82 | + } |
|
83 | + else { |
|
84 | + $point_compound = $font->readUInt16(); |
|
85 | + $point_component = $font->readUInt16(); |
|
86 | + } |
|
87 | + } |
|
88 | + else { |
|
89 | + if ($flags & self::ARGS_ARE_XY_VALUES) { |
|
90 | + $e = $font->readInt8(); |
|
91 | + $f = $font->readInt8(); |
|
92 | + } |
|
93 | + else { |
|
94 | + $point_compound = $font->readUInt8(); |
|
95 | + $point_component = $font->readUInt8(); |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + if ($flags & self::WE_HAVE_A_SCALE) { |
|
100 | + $a = $d = $font->readInt16(); |
|
101 | + } |
|
102 | + elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) { |
|
103 | + $a = $font->readInt16(); |
|
104 | + $d = $font->readInt16(); |
|
105 | + } |
|
106 | + elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) { |
|
107 | + $a = $font->readInt16(); |
|
108 | + $b = $font->readInt16(); |
|
109 | + $c = $font->readInt16(); |
|
110 | + $d = $font->readInt16(); |
|
111 | + } |
|
112 | + |
|
113 | + //if ($flags & self::WE_HAVE_INSTRUCTIONS) { |
|
114 | + // |
|
115 | + //} |
|
116 | + |
|
117 | + $component = new OutlineComponent(); |
|
118 | + $component->flags = $flags; |
|
119 | + $component->glyphIndex = $glyphIndex; |
|
120 | + $component->a = $a; |
|
121 | + $component->b = $b; |
|
122 | + $component->c = $c; |
|
123 | + $component->d = $d; |
|
124 | + $component->e = $e; |
|
125 | + $component->f = $f; |
|
126 | + $component->point_compound = $point_compound; |
|
127 | + $component->point_component = $point_component; |
|
128 | + $component->instructions = $instructions; |
|
129 | + |
|
130 | + $this->components[] = $component; |
|
131 | + } while ($flags & self::MORE_COMPONENTS); |
|
132 | + if ($flags & self::WE_HAVE_INSTRUCTIONS) { |
|
133 | + $numInstr = $font->readUInt16(); |
|
134 | + $instr = $font->read($numInstr); |
|
135 | + $this->components[count($this->components) - 1]->instructions = pack('n', $numInstr) . $instr; |
|
136 | + } |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | function encode() { |
140 | - $font = $this->getFont(); |
|
141 | - |
|
142 | - $gids = $font->getSubset(); |
|
143 | - |
|
144 | - $size = $font->writeInt16(-1); |
|
145 | - $size += $font->writeFWord($this->xMin); |
|
146 | - $size += $font->writeFWord($this->yMin); |
|
147 | - $size += $font->writeFWord($this->xMax); |
|
148 | - $size += $font->writeFWord($this->yMax); |
|
149 | - |
|
150 | - foreach ($this->components as $_i => $_component) { |
|
151 | - $flags = 0; |
|
152 | - if ($_component->point_component === null && $_component->point_compound === null) { |
|
153 | - $flags |= self::ARGS_ARE_XY_VALUES; |
|
154 | - |
|
155 | - if (abs($_component->e) > 0x7F || abs($_component->f) > 0x7F) { |
|
156 | - $flags |= self::ARG_1_AND_2_ARE_WORDS; |
|
157 | - } |
|
158 | - } |
|
159 | - elseif ($_component->point_component > 0xFF || $_component->point_compound > 0xFF) { |
|
160 | - $flags |= self::ARG_1_AND_2_ARE_WORDS; |
|
161 | - } |
|
162 | - |
|
163 | - if ($_component->b == 0 && $_component->c == 0) { |
|
164 | - if ($_component->a == $_component->d) { |
|
165 | - if ($_component->a != 1.0) { |
|
166 | - $flags |= self::WE_HAVE_A_SCALE; |
|
167 | - } |
|
168 | - } |
|
169 | - else { |
|
170 | - $flags |= self::WE_HAVE_AN_X_AND_Y_SCALE; |
|
171 | - } |
|
172 | - } |
|
173 | - else { |
|
174 | - $flags |= self::WE_HAVE_A_TWO_BY_TWO; |
|
175 | - } |
|
176 | - |
|
177 | - if ($_i < count($this->components) - 1) { |
|
178 | - $flags |= self::MORE_COMPONENTS; |
|
179 | - } elseif($_component->instructions !== null) { |
|
180 | - $flags |= self::WE_HAVE_INSTRUCTIONS; |
|
181 | - } |
|
182 | - |
|
183 | - $size += $font->writeUInt16($flags); |
|
184 | - |
|
185 | - $new_gid = array_search($_component->glyphIndex, $gids); |
|
186 | - $size += $font->writeUInt16($new_gid); |
|
187 | - |
|
188 | - if ($flags & self::ARG_1_AND_2_ARE_WORDS) { |
|
189 | - if ($flags & self::ARGS_ARE_XY_VALUES) { |
|
190 | - $size += $font->writeInt16($_component->e); |
|
191 | - $size += $font->writeInt16($_component->f); |
|
192 | - } |
|
193 | - else { |
|
194 | - $size += $font->writeUInt16($_component->point_compound); |
|
195 | - $size += $font->writeUInt16($_component->point_component); |
|
196 | - } |
|
197 | - } |
|
198 | - else { |
|
199 | - if ($flags & self::ARGS_ARE_XY_VALUES) { |
|
200 | - $size += $font->writeInt8($_component->e); |
|
201 | - $size += $font->writeInt8($_component->f); |
|
202 | - } |
|
203 | - else { |
|
204 | - $size += $font->writeUInt8($_component->point_compound); |
|
205 | - $size += $font->writeUInt8($_component->point_component); |
|
206 | - } |
|
207 | - } |
|
208 | - |
|
209 | - if ($flags & self::WE_HAVE_A_SCALE) { |
|
210 | - $size += $font->writeInt16($_component->a); |
|
211 | - } |
|
212 | - elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) { |
|
213 | - $size += $font->writeInt16($_component->a); |
|
214 | - $size += $font->writeInt16($_component->d); |
|
215 | - } |
|
216 | - elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) { |
|
217 | - $size += $font->writeInt16($_component->a); |
|
218 | - $size += $font->writeInt16($_component->b); |
|
219 | - $size += $font->writeInt16($_component->c); |
|
220 | - $size += $font->writeInt16($_component->d); |
|
221 | - } |
|
222 | - } |
|
223 | - |
|
224 | - if($_component->instructions !== null) { |
|
225 | - $size += $font->write($_component->instructions, strlen($_component->instructions)); |
|
226 | - } |
|
227 | - |
|
228 | - return $size; |
|
140 | + $font = $this->getFont(); |
|
141 | + |
|
142 | + $gids = $font->getSubset(); |
|
143 | + |
|
144 | + $size = $font->writeInt16(-1); |
|
145 | + $size += $font->writeFWord($this->xMin); |
|
146 | + $size += $font->writeFWord($this->yMin); |
|
147 | + $size += $font->writeFWord($this->xMax); |
|
148 | + $size += $font->writeFWord($this->yMax); |
|
149 | + |
|
150 | + foreach ($this->components as $_i => $_component) { |
|
151 | + $flags = 0; |
|
152 | + if ($_component->point_component === null && $_component->point_compound === null) { |
|
153 | + $flags |= self::ARGS_ARE_XY_VALUES; |
|
154 | + |
|
155 | + if (abs($_component->e) > 0x7F || abs($_component->f) > 0x7F) { |
|
156 | + $flags |= self::ARG_1_AND_2_ARE_WORDS; |
|
157 | + } |
|
158 | + } |
|
159 | + elseif ($_component->point_component > 0xFF || $_component->point_compound > 0xFF) { |
|
160 | + $flags |= self::ARG_1_AND_2_ARE_WORDS; |
|
161 | + } |
|
162 | + |
|
163 | + if ($_component->b == 0 && $_component->c == 0) { |
|
164 | + if ($_component->a == $_component->d) { |
|
165 | + if ($_component->a != 1.0) { |
|
166 | + $flags |= self::WE_HAVE_A_SCALE; |
|
167 | + } |
|
168 | + } |
|
169 | + else { |
|
170 | + $flags |= self::WE_HAVE_AN_X_AND_Y_SCALE; |
|
171 | + } |
|
172 | + } |
|
173 | + else { |
|
174 | + $flags |= self::WE_HAVE_A_TWO_BY_TWO; |
|
175 | + } |
|
176 | + |
|
177 | + if ($_i < count($this->components) - 1) { |
|
178 | + $flags |= self::MORE_COMPONENTS; |
|
179 | + } elseif($_component->instructions !== null) { |
|
180 | + $flags |= self::WE_HAVE_INSTRUCTIONS; |
|
181 | + } |
|
182 | + |
|
183 | + $size += $font->writeUInt16($flags); |
|
184 | + |
|
185 | + $new_gid = array_search($_component->glyphIndex, $gids); |
|
186 | + $size += $font->writeUInt16($new_gid); |
|
187 | + |
|
188 | + if ($flags & self::ARG_1_AND_2_ARE_WORDS) { |
|
189 | + if ($flags & self::ARGS_ARE_XY_VALUES) { |
|
190 | + $size += $font->writeInt16($_component->e); |
|
191 | + $size += $font->writeInt16($_component->f); |
|
192 | + } |
|
193 | + else { |
|
194 | + $size += $font->writeUInt16($_component->point_compound); |
|
195 | + $size += $font->writeUInt16($_component->point_component); |
|
196 | + } |
|
197 | + } |
|
198 | + else { |
|
199 | + if ($flags & self::ARGS_ARE_XY_VALUES) { |
|
200 | + $size += $font->writeInt8($_component->e); |
|
201 | + $size += $font->writeInt8($_component->f); |
|
202 | + } |
|
203 | + else { |
|
204 | + $size += $font->writeUInt8($_component->point_compound); |
|
205 | + $size += $font->writeUInt8($_component->point_component); |
|
206 | + } |
|
207 | + } |
|
208 | + |
|
209 | + if ($flags & self::WE_HAVE_A_SCALE) { |
|
210 | + $size += $font->writeInt16($_component->a); |
|
211 | + } |
|
212 | + elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) { |
|
213 | + $size += $font->writeInt16($_component->a); |
|
214 | + $size += $font->writeInt16($_component->d); |
|
215 | + } |
|
216 | + elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) { |
|
217 | + $size += $font->writeInt16($_component->a); |
|
218 | + $size += $font->writeInt16($_component->b); |
|
219 | + $size += $font->writeInt16($_component->c); |
|
220 | + $size += $font->writeInt16($_component->d); |
|
221 | + } |
|
222 | + } |
|
223 | + |
|
224 | + if($_component->instructions !== null) { |
|
225 | + $size += $font->write($_component->instructions, strlen($_component->instructions)); |
|
226 | + } |
|
227 | + |
|
228 | + return $size; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | public function getSVGContours() { |
232 | - $contours = array(); |
|
232 | + $contours = array(); |
|
233 | 233 | |
234 | - /** @var \FontLib\Table\Type\glyf $glyph_data */ |
|
235 | - $glyph_data = $this->getFont()->getTableObject("glyf"); |
|
234 | + /** @var \FontLib\Table\Type\glyf $glyph_data */ |
|
235 | + $glyph_data = $this->getFont()->getTableObject("glyf"); |
|
236 | 236 | |
237 | - /** @var Outline[] $glyphs */ |
|
238 | - $glyphs = $glyph_data->data; |
|
237 | + /** @var Outline[] $glyphs */ |
|
238 | + $glyphs = $glyph_data->data; |
|
239 | 239 | |
240 | - foreach ($this->components as $component) { |
|
241 | - $_glyph = $glyphs[$component->glyphIndex]; |
|
240 | + foreach ($this->components as $component) { |
|
241 | + $_glyph = $glyphs[$component->glyphIndex]; |
|
242 | 242 | |
243 | - if ($_glyph !== $this) { |
|
244 | - $contours[] = array( |
|
245 | - "contours" => $_glyph->getSVGContours(), |
|
246 | - "transform" => $component->getMatrix(), |
|
247 | - ); |
|
248 | - } |
|
249 | - } |
|
243 | + if ($_glyph !== $this) { |
|
244 | + $contours[] = array( |
|
245 | + "contours" => $_glyph->getSVGContours(), |
|
246 | + "transform" => $component->getMatrix(), |
|
247 | + ); |
|
248 | + } |
|
249 | + } |
|
250 | 250 | |
251 | - return $contours; |
|
251 | + return $contours; |
|
252 | 252 | } |
253 | 253 | } |
254 | 254 | \ No newline at end of file |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | foreach ($this->components as $_component) { |
41 | 41 | $glyphIDs[] = $_component->glyphIndex; |
42 | 42 | |
43 | - $_glyph = $this->table->data[$_component->glyphIndex]; |
|
43 | + $_glyph = $this->table->data[$_component->glyphIndex]; |
|
44 | 44 | |
45 | 45 | if ($_glyph !== $this) { |
46 | 46 | $glyphIDs = array_merge($glyphIDs, $_glyph->getGlyphIDs()); |
@@ -128,11 +128,11 @@ discard block |
||
128 | 128 | $component->instructions = $instructions; |
129 | 129 | |
130 | 130 | $this->components[] = $component; |
131 | - } while ($flags & self::MORE_COMPONENTS); |
|
131 | + }while ($flags & self::MORE_COMPONENTS); |
|
132 | 132 | if ($flags & self::WE_HAVE_INSTRUCTIONS) { |
133 | 133 | $numInstr = $font->readUInt16(); |
134 | 134 | $instr = $font->read($numInstr); |
135 | - $this->components[count($this->components) - 1]->instructions = pack('n', $numInstr) . $instr; |
|
135 | + $this->components[count($this->components) - 1]->instructions = pack('n', $numInstr).$instr; |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | |
177 | 177 | if ($_i < count($this->components) - 1) { |
178 | 178 | $flags |= self::MORE_COMPONENTS; |
179 | - } elseif($_component->instructions !== null) { |
|
179 | + } elseif ($_component->instructions !== null) { |
|
180 | 180 | $flags |= self::WE_HAVE_INSTRUCTIONS; |
181 | 181 | } |
182 | 182 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | } |
222 | 222 | } |
223 | 223 | |
224 | - if($_component->instructions !== null) { |
|
224 | + if ($_component->instructions !== null) { |
|
225 | 225 | $size += $font->write($_component->instructions, strlen($_component->instructions)); |
226 | 226 | } |
227 | 227 |
@@ -24,66 +24,66 @@ |
||
24 | 24 | * @return TrueType\File|null $file |
25 | 25 | */ |
26 | 26 | public static function load($file) { |
27 | - if(!file_exists($file)){ |
|
28 | - throw new FontNotFoundException($file); |
|
29 | - } |
|
27 | + if(!file_exists($file)){ |
|
28 | + throw new FontNotFoundException($file); |
|
29 | + } |
|
30 | 30 | |
31 | - $header = file_get_contents($file, false, null, 0, 4); |
|
32 | - $class = null; |
|
31 | + $header = file_get_contents($file, false, null, 0, 4); |
|
32 | + $class = null; |
|
33 | 33 | |
34 | - switch ($header) { |
|
35 | - case "\x00\x01\x00\x00": |
|
36 | - case "true": |
|
37 | - case "typ1": |
|
38 | - $class = "TrueType\\File"; |
|
39 | - break; |
|
34 | + switch ($header) { |
|
35 | + case "\x00\x01\x00\x00": |
|
36 | + case "true": |
|
37 | + case "typ1": |
|
38 | + $class = "TrueType\\File"; |
|
39 | + break; |
|
40 | 40 | |
41 | - case "OTTO": |
|
42 | - $class = "OpenType\\File"; |
|
43 | - break; |
|
41 | + case "OTTO": |
|
42 | + $class = "OpenType\\File"; |
|
43 | + break; |
|
44 | 44 | |
45 | - case "wOFF": |
|
46 | - $class = "WOFF\\File"; |
|
47 | - break; |
|
45 | + case "wOFF": |
|
46 | + $class = "WOFF\\File"; |
|
47 | + break; |
|
48 | 48 | |
49 | - case "ttcf": |
|
50 | - $class = "TrueType\\Collection"; |
|
51 | - break; |
|
49 | + case "ttcf": |
|
50 | + $class = "TrueType\\Collection"; |
|
51 | + break; |
|
52 | 52 | |
53 | - // Unknown type or EOT |
|
54 | - default: |
|
55 | - $magicNumber = file_get_contents($file, false, null, 34, 2); |
|
53 | + // Unknown type or EOT |
|
54 | + default: |
|
55 | + $magicNumber = file_get_contents($file, false, null, 34, 2); |
|
56 | 56 | |
57 | - if ($magicNumber === "LP") { |
|
58 | - $class = "EOT\\File"; |
|
59 | - } |
|
60 | - } |
|
57 | + if ($magicNumber === "LP") { |
|
58 | + $class = "EOT\\File"; |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - if ($class) { |
|
63 | - $class = "FontLib\\$class"; |
|
62 | + if ($class) { |
|
63 | + $class = "FontLib\\$class"; |
|
64 | 64 | |
65 | - /** @var TrueType\File $obj */ |
|
66 | - $obj = new $class; |
|
67 | - $obj->load($file); |
|
65 | + /** @var TrueType\File $obj */ |
|
66 | + $obj = new $class; |
|
67 | + $obj->load($file); |
|
68 | 68 | |
69 | - return $obj; |
|
70 | - } |
|
69 | + return $obj; |
|
70 | + } |
|
71 | 71 | |
72 | - return null; |
|
72 | + return null; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | static function d($str) { |
76 | - if (!self::$debug) { |
|
77 | - return; |
|
78 | - } |
|
79 | - echo "$str\n"; |
|
76 | + if (!self::$debug) { |
|
77 | + return; |
|
78 | + } |
|
79 | + echo "$str\n"; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | static function UTF16ToUTF8($str) { |
83 | - return mb_convert_encoding($str, "utf-8", "utf-16"); |
|
83 | + return mb_convert_encoding($str, "utf-8", "utf-16"); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | static function UTF8ToUTF16($str) { |
87 | - return mb_convert_encoding($str, "utf-16", "utf-8"); |
|
87 | + return mb_convert_encoding($str, "utf-16", "utf-8"); |
|
88 | 88 | } |
89 | 89 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @return TrueType\File|null $file |
25 | 25 | */ |
26 | 26 | public static function load($file) { |
27 | - if(!file_exists($file)){ |
|
27 | + if ( ! file_exists($file)) { |
|
28 | 28 | throw new FontNotFoundException($file); |
29 | 29 | } |
30 | 30 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | static function d($str) { |
76 | - if (!self::$debug) { |
|
76 | + if ( ! self::$debug) { |
|
77 | 77 | return; |
78 | 78 | } |
79 | 79 | echo "$str\n"; |
@@ -17,81 +17,81 @@ |
||
17 | 17 | */ |
18 | 18 | class post extends Table { |
19 | 19 | protected $def = array( |
20 | - "format" => self::Fixed, |
|
21 | - "italicAngle" => self::Fixed, |
|
22 | - "underlinePosition" => self::FWord, |
|
23 | - "underlineThickness" => self::FWord, |
|
24 | - "isFixedPitch" => self::uint32, |
|
25 | - "minMemType42" => self::uint32, |
|
26 | - "maxMemType42" => self::uint32, |
|
27 | - "minMemType1" => self::uint32, |
|
28 | - "maxMemType1" => self::uint32, |
|
20 | + "format" => self::Fixed, |
|
21 | + "italicAngle" => self::Fixed, |
|
22 | + "underlinePosition" => self::FWord, |
|
23 | + "underlineThickness" => self::FWord, |
|
24 | + "isFixedPitch" => self::uint32, |
|
25 | + "minMemType42" => self::uint32, |
|
26 | + "maxMemType42" => self::uint32, |
|
27 | + "minMemType1" => self::uint32, |
|
28 | + "maxMemType1" => self::uint32, |
|
29 | 29 | ); |
30 | 30 | |
31 | 31 | protected function _parse() { |
32 | - $font = $this->getFont(); |
|
33 | - $data = $font->unpack($this->def); |
|
32 | + $font = $this->getFont(); |
|
33 | + $data = $font->unpack($this->def); |
|
34 | 34 | |
35 | - $names = array(); |
|
35 | + $names = array(); |
|
36 | 36 | |
37 | - switch ($data["format"]) { |
|
38 | - case 1: |
|
39 | - $names = File::$macCharNames; |
|
40 | - break; |
|
37 | + switch ($data["format"]) { |
|
38 | + case 1: |
|
39 | + $names = File::$macCharNames; |
|
40 | + break; |
|
41 | 41 | |
42 | - case 2: |
|
43 | - $data["numberOfGlyphs"] = $font->readUInt16(); |
|
42 | + case 2: |
|
43 | + $data["numberOfGlyphs"] = $font->readUInt16(); |
|
44 | 44 | |
45 | - $glyphNameIndex = $font->readUInt16Many($data["numberOfGlyphs"]); |
|
45 | + $glyphNameIndex = $font->readUInt16Many($data["numberOfGlyphs"]); |
|
46 | 46 | |
47 | - $data["glyphNameIndex"] = $glyphNameIndex; |
|
47 | + $data["glyphNameIndex"] = $glyphNameIndex; |
|
48 | 48 | |
49 | - $namesPascal = array(); |
|
50 | - for ($i = 0; $i < $data["numberOfGlyphs"]; $i++) { |
|
51 | - $len = $font->readUInt8(); |
|
52 | - $namesPascal[] = $font->read($len); |
|
53 | - } |
|
49 | + $namesPascal = array(); |
|
50 | + for ($i = 0; $i < $data["numberOfGlyphs"]; $i++) { |
|
51 | + $len = $font->readUInt8(); |
|
52 | + $namesPascal[] = $font->read($len); |
|
53 | + } |
|
54 | 54 | |
55 | - foreach ($glyphNameIndex as $g => $index) { |
|
56 | - if ($index < 258) { |
|
57 | - $names[$g] = File::$macCharNames[$index]; |
|
58 | - } |
|
59 | - else { |
|
60 | - if (array_key_exists($index - 258, $namesPascal)) { |
|
61 | - $names[$g] = $namesPascal[$index - 258]; |
|
62 | - } |
|
63 | - } |
|
64 | - } |
|
55 | + foreach ($glyphNameIndex as $g => $index) { |
|
56 | + if ($index < 258) { |
|
57 | + $names[$g] = File::$macCharNames[$index]; |
|
58 | + } |
|
59 | + else { |
|
60 | + if (array_key_exists($index - 258, $namesPascal)) { |
|
61 | + $names[$g] = $namesPascal[$index - 258]; |
|
62 | + } |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - break; |
|
66 | + break; |
|
67 | 67 | |
68 | - case 2.5: |
|
69 | - // TODO |
|
70 | - break; |
|
68 | + case 2.5: |
|
69 | + // TODO |
|
70 | + break; |
|
71 | 71 | |
72 | - case 3: |
|
73 | - // nothing |
|
74 | - break; |
|
72 | + case 3: |
|
73 | + // nothing |
|
74 | + break; |
|
75 | 75 | |
76 | - case 4: |
|
77 | - // TODO |
|
78 | - break; |
|
79 | - } |
|
76 | + case 4: |
|
77 | + // TODO |
|
78 | + break; |
|
79 | + } |
|
80 | 80 | |
81 | - $data["names"] = $names; |
|
81 | + $data["names"] = $names; |
|
82 | 82 | |
83 | - $this->data = $data; |
|
83 | + $this->data = $data; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | function _encode() { |
87 | - $font = $this->getFont(); |
|
88 | - $data = $this->data; |
|
89 | - $data["format"] = 3; |
|
87 | + $font = $this->getFont(); |
|
88 | + $data = $this->data; |
|
89 | + $data["format"] = 3; |
|
90 | 90 | |
91 | - $length = $font->pack($this->def, $data); |
|
91 | + $length = $font->pack($this->def, $data); |
|
92 | 92 | |
93 | - return $length; |
|
94 | - /* |
|
93 | + return $length; |
|
94 | + /* |
|
95 | 95 | $subset = $font->getSubset(); |
96 | 96 | |
97 | 97 | switch($data["format"]) { |
@@ -55,8 +55,7 @@ |
||
55 | 55 | foreach ($glyphNameIndex as $g => $index) { |
56 | 56 | if ($index < 258) { |
57 | 57 | $names[$g] = File::$macCharNames[$index]; |
58 | - } |
|
59 | - else { |
|
58 | + } else { |
|
60 | 59 | if (array_key_exists($index - 258, $namesPascal)) { |
61 | 60 | $names[$g] = $namesPascal[$index - 258]; |
62 | 61 | } |
@@ -16,27 +16,27 @@ |
||
16 | 16 | */ |
17 | 17 | class maxp extends Table { |
18 | 18 | protected $def = array( |
19 | - "version" => self::Fixed, |
|
20 | - "numGlyphs" => self::uint16, |
|
21 | - "maxPoints" => self::uint16, |
|
22 | - "maxContours" => self::uint16, |
|
23 | - "maxComponentPoints" => self::uint16, |
|
24 | - "maxComponentContours" => self::uint16, |
|
25 | - "maxZones" => self::uint16, |
|
26 | - "maxTwilightPoints" => self::uint16, |
|
27 | - "maxStorage" => self::uint16, |
|
28 | - "maxFunctionDefs" => self::uint16, |
|
29 | - "maxInstructionDefs" => self::uint16, |
|
30 | - "maxStackElements" => self::uint16, |
|
31 | - "maxSizeOfInstructions" => self::uint16, |
|
32 | - "maxComponentElements" => self::uint16, |
|
33 | - "maxComponentDepth" => self::uint16, |
|
19 | + "version" => self::Fixed, |
|
20 | + "numGlyphs" => self::uint16, |
|
21 | + "maxPoints" => self::uint16, |
|
22 | + "maxContours" => self::uint16, |
|
23 | + "maxComponentPoints" => self::uint16, |
|
24 | + "maxComponentContours" => self::uint16, |
|
25 | + "maxZones" => self::uint16, |
|
26 | + "maxTwilightPoints" => self::uint16, |
|
27 | + "maxStorage" => self::uint16, |
|
28 | + "maxFunctionDefs" => self::uint16, |
|
29 | + "maxInstructionDefs" => self::uint16, |
|
30 | + "maxStackElements" => self::uint16, |
|
31 | + "maxSizeOfInstructions" => self::uint16, |
|
32 | + "maxComponentElements" => self::uint16, |
|
33 | + "maxComponentDepth" => self::uint16, |
|
34 | 34 | ); |
35 | 35 | |
36 | 36 | function _encode() { |
37 | - $font = $this->getFont(); |
|
38 | - $this->data["numGlyphs"] = count($font->getSubset()); |
|
37 | + $font = $this->getFont(); |
|
38 | + $this->data["numGlyphs"] = count($font->getSubset()); |
|
39 | 39 | |
40 | - return parent::_encode(); |
|
40 | + return parent::_encode(); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | \ No newline at end of file |
@@ -16,65 +16,65 @@ |
||
16 | 16 | */ |
17 | 17 | class loca extends Table { |
18 | 18 | protected function _parse() { |
19 | - $font = $this->getFont(); |
|
20 | - $offset = $font->pos(); |
|
19 | + $font = $this->getFont(); |
|
20 | + $offset = $font->pos(); |
|
21 | 21 | |
22 | - $indexToLocFormat = $font->getData("head", "indexToLocFormat"); |
|
23 | - $numGlyphs = $font->getData("maxp", "numGlyphs"); |
|
22 | + $indexToLocFormat = $font->getData("head", "indexToLocFormat"); |
|
23 | + $numGlyphs = $font->getData("maxp", "numGlyphs"); |
|
24 | 24 | |
25 | - $font->seek($offset); |
|
25 | + $font->seek($offset); |
|
26 | 26 | |
27 | - $data = array(); |
|
27 | + $data = array(); |
|
28 | 28 | |
29 | - // 2 bytes |
|
30 | - if ($indexToLocFormat == 0) { |
|
31 | - $d = $font->read(($numGlyphs + 1) * 2); |
|
32 | - $loc = unpack("n*", $d); |
|
29 | + // 2 bytes |
|
30 | + if ($indexToLocFormat == 0) { |
|
31 | + $d = $font->read(($numGlyphs + 1) * 2); |
|
32 | + $loc = unpack("n*", $d); |
|
33 | 33 | |
34 | - for ($i = 0; $i <= $numGlyphs; $i++) { |
|
35 | - $data[] = isset($loc[$i + 1]) ? $loc[$i + 1] * 2 : 0; |
|
36 | - } |
|
37 | - } |
|
34 | + for ($i = 0; $i <= $numGlyphs; $i++) { |
|
35 | + $data[] = isset($loc[$i + 1]) ? $loc[$i + 1] * 2 : 0; |
|
36 | + } |
|
37 | + } |
|
38 | 38 | |
39 | - // 4 bytes |
|
40 | - else { |
|
41 | - if ($indexToLocFormat == 1) { |
|
42 | - $d = $font->read(($numGlyphs + 1) * 4); |
|
43 | - $loc = unpack("N*", $d); |
|
39 | + // 4 bytes |
|
40 | + else { |
|
41 | + if ($indexToLocFormat == 1) { |
|
42 | + $d = $font->read(($numGlyphs + 1) * 4); |
|
43 | + $loc = unpack("N*", $d); |
|
44 | 44 | |
45 | - for ($i = 0; $i <= $numGlyphs; $i++) { |
|
46 | - $data[] = isset($loc[$i + 1]) ? $loc[$i + 1] : 0; |
|
47 | - } |
|
48 | - } |
|
49 | - } |
|
45 | + for ($i = 0; $i <= $numGlyphs; $i++) { |
|
46 | + $data[] = isset($loc[$i + 1]) ? $loc[$i + 1] : 0; |
|
47 | + } |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - $this->data = $data; |
|
51 | + $this->data = $data; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | function _encode() { |
55 | - $font = $this->getFont(); |
|
56 | - $data = $this->data; |
|
55 | + $font = $this->getFont(); |
|
56 | + $data = $this->data; |
|
57 | 57 | |
58 | - $indexToLocFormat = $font->getData("head", "indexToLocFormat"); |
|
59 | - $numGlyphs = $font->getData("maxp", "numGlyphs"); |
|
60 | - $length = 0; |
|
58 | + $indexToLocFormat = $font->getData("head", "indexToLocFormat"); |
|
59 | + $numGlyphs = $font->getData("maxp", "numGlyphs"); |
|
60 | + $length = 0; |
|
61 | 61 | |
62 | - // 2 bytes |
|
63 | - if ($indexToLocFormat == 0) { |
|
64 | - for ($i = 0; $i <= $numGlyphs; $i++) { |
|
65 | - $length += $font->writeUInt16($data[$i] / 2); |
|
66 | - } |
|
67 | - } |
|
62 | + // 2 bytes |
|
63 | + if ($indexToLocFormat == 0) { |
|
64 | + for ($i = 0; $i <= $numGlyphs; $i++) { |
|
65 | + $length += $font->writeUInt16($data[$i] / 2); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | - // 4 bytes |
|
70 | - else { |
|
71 | - if ($indexToLocFormat == 1) { |
|
72 | - for ($i = 0; $i <= $numGlyphs; $i++) { |
|
73 | - $length += $font->writeUInt32($data[$i]); |
|
74 | - } |
|
75 | - } |
|
76 | - } |
|
69 | + // 4 bytes |
|
70 | + else { |
|
71 | + if ($indexToLocFormat == 1) { |
|
72 | + for ($i = 0; $i <= $numGlyphs; $i++) { |
|
73 | + $length += $font->writeUInt32($data[$i]); |
|
74 | + } |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - return $length; |
|
78 | + return $length; |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | \ No newline at end of file |
@@ -32,7 +32,7 @@ |
||
32 | 32 | $loc = unpack("n*", $d); |
33 | 33 | |
34 | 34 | for ($i = 0; $i <= $numGlyphs; $i++) { |
35 | - $data[] = isset($loc[$i + 1]) ? $loc[$i + 1] * 2 : 0; |
|
35 | + $data[] = isset($loc[$i + 1]) ? $loc[$i + 1] * 2 : 0; |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 |
@@ -16,65 +16,65 @@ |
||
16 | 16 | */ |
17 | 17 | class kern extends Table { |
18 | 18 | protected function _parse() { |
19 | - $font = $this->getFont(); |
|
20 | - |
|
21 | - $data = $font->unpack(array( |
|
22 | - "version" => self::uint16, |
|
23 | - "nTables" => self::uint16, |
|
24 | - |
|
25 | - // only the first subtable will be parsed |
|
26 | - "subtableVersion" => self::uint16, |
|
27 | - "length" => self::uint16, |
|
28 | - "coverage" => self::uint16, |
|
29 | - )); |
|
30 | - |
|
31 | - $data["format"] = ($data["coverage"] >> 8); |
|
32 | - |
|
33 | - $subtable = array(); |
|
34 | - |
|
35 | - switch ($data["format"]) { |
|
36 | - case 0: |
|
37 | - $subtable = $font->unpack(array( |
|
38 | - "nPairs" => self::uint16, |
|
39 | - "searchRange" => self::uint16, |
|
40 | - "entrySelector" => self::uint16, |
|
41 | - "rangeShift" => self::uint16, |
|
42 | - )); |
|
43 | - |
|
44 | - $pairs = array(); |
|
45 | - $tree = array(); |
|
46 | - |
|
47 | - $values = $font->readUInt16Many($subtable["nPairs"] * 3); |
|
48 | - for ($i = 0, $idx = 0; $i < $subtable["nPairs"]; $i++) { |
|
49 | - $left = $values[$idx++]; |
|
50 | - $right = $values[$idx++]; |
|
51 | - $value = $values[$idx++]; |
|
52 | - |
|
53 | - if ($value >= 0x8000) { |
|
54 | - $value -= 0x10000; |
|
55 | - } |
|
56 | - |
|
57 | - $pairs[] = array( |
|
58 | - "left" => $left, |
|
59 | - "right" => $right, |
|
60 | - "value" => $value, |
|
61 | - ); |
|
62 | - |
|
63 | - $tree[$left][$right] = $value; |
|
64 | - } |
|
65 | - |
|
66 | - //$subtable["pairs"] = $pairs; |
|
67 | - $subtable["tree"] = $tree; |
|
68 | - break; |
|
69 | - |
|
70 | - case 1: |
|
71 | - case 2: |
|
72 | - case 3: |
|
73 | - break; |
|
74 | - } |
|
75 | - |
|
76 | - $data["subtable"] = $subtable; |
|
77 | - |
|
78 | - $this->data = $data; |
|
19 | + $font = $this->getFont(); |
|
20 | + |
|
21 | + $data = $font->unpack(array( |
|
22 | + "version" => self::uint16, |
|
23 | + "nTables" => self::uint16, |
|
24 | + |
|
25 | + // only the first subtable will be parsed |
|
26 | + "subtableVersion" => self::uint16, |
|
27 | + "length" => self::uint16, |
|
28 | + "coverage" => self::uint16, |
|
29 | + )); |
|
30 | + |
|
31 | + $data["format"] = ($data["coverage"] >> 8); |
|
32 | + |
|
33 | + $subtable = array(); |
|
34 | + |
|
35 | + switch ($data["format"]) { |
|
36 | + case 0: |
|
37 | + $subtable = $font->unpack(array( |
|
38 | + "nPairs" => self::uint16, |
|
39 | + "searchRange" => self::uint16, |
|
40 | + "entrySelector" => self::uint16, |
|
41 | + "rangeShift" => self::uint16, |
|
42 | + )); |
|
43 | + |
|
44 | + $pairs = array(); |
|
45 | + $tree = array(); |
|
46 | + |
|
47 | + $values = $font->readUInt16Many($subtable["nPairs"] * 3); |
|
48 | + for ($i = 0, $idx = 0; $i < $subtable["nPairs"]; $i++) { |
|
49 | + $left = $values[$idx++]; |
|
50 | + $right = $values[$idx++]; |
|
51 | + $value = $values[$idx++]; |
|
52 | + |
|
53 | + if ($value >= 0x8000) { |
|
54 | + $value -= 0x10000; |
|
55 | + } |
|
56 | + |
|
57 | + $pairs[] = array( |
|
58 | + "left" => $left, |
|
59 | + "right" => $right, |
|
60 | + "value" => $value, |
|
61 | + ); |
|
62 | + |
|
63 | + $tree[$left][$right] = $value; |
|
64 | + } |
|
65 | + |
|
66 | + //$subtable["pairs"] = $pairs; |
|
67 | + $subtable["tree"] = $tree; |
|
68 | + break; |
|
69 | + |
|
70 | + case 1: |
|
71 | + case 2: |
|
72 | + case 3: |
|
73 | + break; |
|
74 | + } |
|
75 | + |
|
76 | + $data["subtable"] = $subtable; |
|
77 | + |
|
78 | + $this->data = $data; |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | \ No newline at end of file |