Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/subset/Subset.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default class Subset {
this.font = font;
this.glyphs = [];
this.mapping = {};
this.tables = [];

// always include the missing glyph
this.includeGlyph(0);
Expand All @@ -24,4 +25,11 @@ export default class Subset {

return this.mapping[glyph];
}

includeTable(table) {
if (typeof table === 'string' && table.length === 4) {
this.tables.push(table);
}
}

}
37 changes: 19 additions & 18 deletions src/subset/TTFSubset.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,24 @@ export default class TTFSubset extends Subset {
// ]

// TODO: subset prep, cvt, fpgm?
return Directory.toBuffer({
tables: {
head,
hhea,
loca: this.loca,
maxp,
'cvt ': this.font['cvt '],
prep: this.font.prep,
glyf: this.glyf,
hmtx: this.hmtx,
fpgm: this.font.fpgm

// name: clone @font.name
// 'OS/2': clone @font['OS/2']
// post: clone @font.post
// cmap: cmap
}
});
// The following is the minimum set of tables.
let t = {
head,
hhea,
loca: this.loca,
maxp,
'cvt ': this.font['cvt '],
prep: this.font.prep,
glyf: this.glyf,
hmtx: this.hmtx,
fpgm: this.font.fpgm,
}

for (const i in this.tables) {
const table = this.tables[i];
t[table] = cloneDeep(this.font[table]);
}

return Directory.toBuffer({tables: t});
}
}
13 changes: 13 additions & 0 deletions test/subset.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ describe('font subsetting', function () {
// must test also second glyph which has an odd loca index
assert.equal(f.getGlyph(2).path.toSVG(), font.glyphsForString('b')[0].path.toSVG());
});

it('should produce a subset including font table OS/2', function () {
let subset = font.createSubset();
for (let glyph of font.glyphsForString('hello')) {
subset.includeGlyph(glyph);
}
subset.includeTable('OS/2');

let buf = subset.encode();
let f = fontkit.create(buf);
assert.equal(f.hasOwnProperty('OS/2'), true);
});

});

describe('CFF subsetting', function () {
Expand Down