Skip to content

Commit 1e9e053

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 401ec47 + 3ec8b5d commit 1e9e053

File tree

9 files changed

+76
-25
lines changed

9 files changed

+76
-25
lines changed

.travis.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ env:
77
php:
88
- 5.4
99
- 5.5
10+
- 5.6
11+
- 7.0
12+
- hhvm
1013

14+
matrix:
15+
allow_failures:
16+
- php: hhvm
17+
fast_finish: true
18+
1119
before_script:
1220
- composer dump-autoload
1321
- composer self-update
@@ -18,4 +26,4 @@ script: bin/phpunit
1826

1927
# Use Travis' new container-based infrastructure.
2028
# See http://docs.travis-ci.com/user/migrating-from-legacy/#How-can-I-use-container-based-infrastructure%3F
21-
sudo: false
29+
sudo: false

src/FontLib/BinaryStream.php

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ public function readUInt8() {
157157
return ord($this->read(1));
158158
}
159159

160+
public function readUInt8Many($count) {
161+
return array_values(unpack("C*", $this->read($count)));
162+
}
163+
160164
public function writeUInt8($data) {
161165
return $this->write(chr($data), 1);
162166
}
@@ -171,6 +175,10 @@ public function readInt8() {
171175
return $v;
172176
}
173177

178+
public function readInt8Many($count) {
179+
return array_values(unpack("c*", $this->read($count)));
180+
}
181+
174182
public function writeInt8($data) {
175183
if ($data < 0) {
176184
$data += 0x100;
@@ -185,6 +193,10 @@ public function readUInt16() {
185193
return $a["n"];
186194
}
187195

196+
public function readUInt16Many($count) {
197+
return array_values(unpack("n*", $this->read($count * 2)));
198+
}
199+
188200
public function readUFWord() {
189201
return $this->readUInt16();
190202
}
@@ -198,7 +210,8 @@ public function writeUFWord($data) {
198210
}
199211

200212
public function readInt16() {
201-
$v = $this->readUInt16();
213+
$a = unpack("nn", $this->read(2));
214+
$v = $a["n"];
202215

203216
if ($v >= 0x8000) {
204217
$v -= 0x10000;
@@ -207,6 +220,17 @@ public function readInt16() {
207220
return $v;
208221
}
209222

223+
public function readInt16Many($count) {
224+
$vals = array_values(unpack("n*", $this->read($count * 2)));
225+
foreach ($vals as &$v) {
226+
if ($v >= 0x8000) {
227+
$v -= 0x10000;
228+
}
229+
}
230+
231+
return $vals;
232+
}
233+
210234
public function readFWord() {
211235
return $this->readInt16();
212236
}
@@ -251,6 +275,12 @@ public function readLongDateTime() {
251275
$this->readUInt32(); // ignored
252276
$date = $this->readUInt32() - 2082844800;
253277

278+
if ($date > PHP_INT_MAX) {
279+
$date = PHP_INT_MAX;
280+
} elseif ($date < PHP_INT_MIN) {
281+
$date = PHP_INT_MIN;
282+
}
283+
254284
return strftime("%Y-%m-%d %H:%M:%S", $date);
255285
}
256286

@@ -319,6 +349,18 @@ public function r($type) {
319349
if ($type[0] == self::char) {
320350
return $this->read($type[1]);
321351
}
352+
if ($type[0] == self::uint16) {
353+
return $this->readUInt16Many($type[1]);
354+
}
355+
if ($type[0] == self::int16) {
356+
return $this->readInt16Many($type[1]);
357+
}
358+
if ($type[0] == self::uint8) {
359+
return $this->readUInt8Many($type[1]);
360+
}
361+
if ($type[0] == self::int8) {
362+
return $this->readInt8Many($type[1]);
363+
}
322364

323365
$ret = array();
324366
for ($i = 0; $i < $type[1]; $i++) {

src/FontLib/Glyph/Outline.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class Outline extends BinaryStream {
4242
*
4343
* @return Outline
4444
*/
45-
static function init(glyf $table, $offset, $size) {
46-
$font = $table->getFont();
45+
static function init(glyf $table, $offset, $size, BinaryStream $font) {
4746
$font->seek($offset);
4847

4948
if ($font->readInt16() > -1) {
@@ -55,7 +54,7 @@ static function init(glyf $table, $offset, $size) {
5554
$glyph = new OutlineComposite($table, $offset, $size);
5655
}
5756

58-
$glyph->parse();
57+
$glyph->parse($font);
5958

6059
return $glyph;
6160
}
@@ -73,8 +72,7 @@ function __construct(glyf $table, $offset = null, $size = null) {
7372
$this->size = $size;
7473
}
7574

76-
function parse() {
77-
$font = $this->getFont();
75+
function parse(BinaryStream $font) {
7876
$font->seek($this->offset);
7977

8078
if (!$this->size) {

src/FontLib/Table/Type/cmap.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ protected function _parse() {
6464
$segCount = $subtable["segCountX2"] / 2;
6565
$subtable["segCount"] = $segCount;
6666

67-
$endCode = $font->r(array(self::uint16, $segCount));
67+
$endCode = $font->readUInt16Many($segCount);
6868

6969
$font->readUInt16(); // reservedPad
7070

71-
$startCode = $font->r(array(self::uint16, $segCount));
72-
$idDelta = $font->r(array(self::int16, $segCount));
71+
$startCode = $font->readUInt16Many($segCount);
72+
$idDelta = $font->readInt16Many($segCount);
7373

7474
$ro_start = $font->pos();
75-
$idRangeOffset = $font->r(array(self::uint16, $segCount));
75+
$idRangeOffset = $font->readUInt16Many($segCount);
7676

7777
$glyphIndexArray = array();
7878
for ($i = 0; $i < $segCount; $i++) {

src/FontLib/Table/Type/glyf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function _parse() {
3131
foreach ($real_loca as $gid => $location) {
3232
$_offset = $offset + $loca[$gid];
3333
$_size = $loca[$gid + 1] - $loca[$gid];
34-
$data[$gid] = Outline::init($this, $_offset, $_size);
34+
$data[$gid] = Outline::init($this, $_offset, $_size, $font);
3535
}
3636

3737
$this->data = $data;

src/FontLib/Table/Type/hmtx.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ protected function _parse() {
2525
$font->seek($offset);
2626

2727
$data = array();
28-
for ($gid = 0; $gid < $numOfLongHorMetrics; $gid++) {
29-
$advanceWidth = $font->readUInt16();
30-
$leftSideBearing = $font->readUInt16();
28+
$metrics = $font->readUInt16Many($numOfLongHorMetrics * 2);
29+
for ($gid = 0, $mid = 0; $gid < $numOfLongHorMetrics; $gid++) {
30+
$advanceWidth = $metrics[$mid++];
31+
$leftSideBearing = $metrics[$mid++];
3132
$data[$gid] = array($advanceWidth, $leftSideBearing);
3233
}
3334

src/FontLib/Table/Type/kern.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@ protected function _parse() {
4444
$pairs = array();
4545
$tree = array();
4646

47-
for ($i = 0; $i < $subtable["nPairs"]; $i++) {
48-
$left = $font->readUInt16();
49-
$right = $font->readUInt16();
50-
$value = $font->readInt16();
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+
}
5156

5257
$pairs[] = array(
5358
"left" => $left,

src/FontLib/Table/Type/name.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class name extends Table {
7373
3 => "Microsoft",
7474
);
7575

76-
static $plaformSpecific = array(
76+
static $platformSpecific = array(
7777
// Unicode
7878
0 => array(
7979
0 => "Default semantics",
@@ -190,4 +190,4 @@ protected function _encode() {
190190

191191
return $length;
192192
}
193-
}
193+
}

src/FontLib/Table/Type/post.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ protected function _parse() {
4242
case 2:
4343
$data["numberOfGlyphs"] = $font->readUInt16();
4444

45-
$glyphNameIndex = array();
46-
for ($i = 0; $i < $data["numberOfGlyphs"]; $i++) {
47-
$glyphNameIndex[] = $font->readUInt16();
48-
}
45+
$glyphNameIndex = $font->readUInt16Many($data["numberOfGlyphs"]);
4946

5047
$data["glyphNameIndex"] = $glyphNameIndex;
5148

0 commit comments

Comments
 (0)