Skip to content

Commit

Permalink
Merge pull request #7 from canda/patch-1
Browse files Browse the repository at this point in the history
Fix Noto font bug
  • Loading branch information
liborm85 authored Jul 9, 2021
2 parents 253c09c + 2e4ccd2 commit 5317390
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/subset/CFFSubset.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default class CFFSubset extends Subset {

let used_fds = {};
let used_subrs = [];
let fd_select = {};
for (let gid of this.glyphs) {
let fd = this.cff.fdForGlyph(gid);
if (fd == null) {
Expand All @@ -64,15 +65,16 @@ export default class CFFSubset extends Subset {
if (!used_fds[fd]) {
topDict.FDArray.push(Object.assign({}, this.cff.topDict.FDArray[fd]));
used_subrs.push({});
fd_select[fd] = topDict.FDArray.length - 1;
}

used_fds[fd] = true;
topDict.FDSelect.fds.push(topDict.FDArray.length - 1);
topDict.FDSelect.fds.push(fd_select[fd]);

let glyph = this.font.getGlyph(gid);
let path = glyph.path; // this causes the glyph to be parsed
for (let subr in glyph._usedSubrs) {
used_subrs[used_subrs.length - 1][subr] = true;
used_subrs[fd_select[fd]][subr] = true;
}
}

Expand Down
22 changes: 22 additions & 0 deletions test/subset.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,27 @@ describe('font subsetting', function() {
return done();
}));
});

it('should produce a subset with asian punctuation corretly', function(done) {
const koreanFont = fontkit.openSync(__dirname + '/data/NotoSansCJK/NotoSansCJKkr-Regular.otf');
const subset = koreanFont.createSubset();
const iterable = koreanFont.glyphsForString('a。d');
for (let i = 0; i < iterable.length; i++) {
const glyph = iterable[i];
subset.includeGlyph(glyph);
}

return subset.encodeStream().pipe(concat(function(buf) {
const stream = new r.DecodeStream(buf);
const cff = new CFFFont(stream);
let glyph = new CFFGlyph(1, [], { stream, 'CFF ': cff });
assert.equal(glyph.path.toSVG(), koreanFont.glyphsForString('a')[0].path.toSVG());
glyph = new CFFGlyph(2, [], { stream, 'CFF ': cff });
assert.equal(glyph.path.toSVG(), koreanFont.glyphsForString('。')[0].path.toSVG());
glyph = new CFFGlyph(3, [], { stream, 'CFF ': cff });
assert.equal(glyph.path.toSVG(), koreanFont.glyphsForString('d')[0].path.toSVG());
return done();
}));
});
});
});

0 comments on commit 5317390

Please sign in to comment.