Skip to content

Commit 05446c4

Browse files
authored
Fix composite glyph
Prior to this change, instructions from the glyf table instructing the font program how to render composite glyphs were not read from the font file. The lack of instructions caused incorrect rendering of the composite. Additionally, the cvt, fpgm, and prep tables were missing from the generated font.
1 parent 86cfdad commit 05446c4

File tree

5 files changed

+98
-2
lines changed

5 files changed

+98
-2
lines changed

src/FontLib/Glyph/OutlineComposite.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ function parseData() {
129129

130130
$this->components[] = $component;
131131
} 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+
}
132137
}
133138

134139
function encode() {
@@ -171,6 +176,8 @@ function encode() {
171176

172177
if ($_i < count($this->components) - 1) {
173178
$flags |= self::MORE_COMPONENTS;
179+
} elseif($_component->instructions !== null) {
180+
$flags |= self::WE_HAVE_INSTRUCTIONS;
174181
}
175182

176183
$size += $font->writeUInt16($flags);
@@ -214,6 +221,10 @@ function encode() {
214221
}
215222
}
216223

224+
if($_component->instructions !== null) {
225+
$size += $font->write($_component->instructions, strlen($_component->instructions));
226+
}
227+
217228
return $size;
218229
}
219230

src/FontLib/Table/Type/cvt.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
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
7+
*/
8+
9+
namespace FontLib\Table\Type;
10+
use FontLib\Table\Table;
11+
12+
/**
13+
* `cvt ` font table.
14+
*
15+
* @package php-font-lib
16+
*/
17+
class cvt extends Table {
18+
private $rawData;
19+
protected function _parse() {
20+
$font = $this->getFont();
21+
$font->seek($this->entry->offset);
22+
$this->rawData = $font->read($this->entry->length);
23+
}
24+
function _encode() {
25+
return $this->getFont()->write($this->rawData, $this->entry->length);
26+
}
27+
}

src/FontLib/Table/Type/fpgm.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
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
7+
*/
8+
9+
namespace FontLib\Table\Type;
10+
use FontLib\Table\Table;
11+
12+
/**
13+
* `fpgm` font table.
14+
*
15+
* @package php-font-lib
16+
*/
17+
class fpgm extends Table {
18+
private $rawData;
19+
protected function _parse() {
20+
$font = $this->getFont();
21+
$font->seek($this->entry->offset);
22+
$this->rawData = $font->read($this->entry->length);
23+
}
24+
function _encode() {
25+
return $this->getFont()->write($this->rawData, $this->entry->length);
26+
}
27+
}

src/FontLib/Table/Type/prep.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/**
4+
* @package php-font-lib
5+
* @link https://github.com/PhenX/php-font-lib
6+
* @author Fabien Ménager <fabien.menager@gmail.com>
7+
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
8+
*/
9+
10+
namespace FontLib\Table\Type;
11+
12+
use FontLib\Table\Table;
13+
14+
/**
15+
* `prep` font table.
16+
*
17+
* @package php-font-lib
18+
*/
19+
class prep extends Table
20+
{
21+
private $rawData;
22+
protected function _parse() {
23+
$font = $this->getFont();
24+
$font->seek($this->entry->offset);
25+
$this->rawData = $font->read($this->entry->length);
26+
}
27+
function _encode() {
28+
return $this->getFont()->write($this->rawData, $this->entry->length);
29+
}
30+
}

src/FontLib/TrueType/File.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,12 @@ function getSubset() {
217217

218218
function encode($tags = array()) {
219219
if (!self::$raw) {
220-
$tags = array_merge(array("head", "hhea", "cmap", "hmtx", "maxp", "glyf", "loca", "name", "post"), $tags);
220+
$tags = array_merge(array("head", "hhea", "cmap", "hmtx", "maxp", "glyf", "loca", "name", "post", "cvt ", "fpgm", "prep"), $tags);
221221
}
222222
else {
223223
$tags = array_keys($this->directory);
224224
}
225225

226-
$num_tables = count($tags);
227226
$n = 16; // @todo
228227

229228
Font::d("Tables : " . implode(", ", $tags));
@@ -239,6 +238,8 @@ function encode($tags = array()) {
239238
$entries[$tag] = $this->directory[$tag];
240239
}
241240

241+
$num_tables = count($entries);
242+
242243
$this->header->data["numTables"] = $num_tables;
243244
$this->header->encode();
244245

0 commit comments

Comments
 (0)