foliojs / fontkit

An advanced font engine for Node and the browser
1.46k stars 219 forks source link

Fix Noto font bug #230

Closed canda closed 2 years ago

canda commented 4 years ago

A little bit of context. While working with pdfkit we found this error. https://github.com/foliojs/pdfkit/issues/1106 We narrowed down the repro to fontkit with this little script

const fs = require('fs');
const notosans = require('fontkit').openSync('./NotoSansCJKsc-Bold.otf');
const subsetFor = (text, file) => {
  const run = notosans.layout(text);
  const subset = notosans.createSubset();
  run.glyphs.forEach((glyph) => subset.includeGlyph(glyph));
  subset.encodeStream().pipe(fs.createWriteStream(file));
};
subsetFor('间。楼', 'output.ttf');

With this script you can see that glyphs were missing on the subset font if you opened the font with something like fontforge

Regarding the logic behind this fix, when !used_fds[fd] was false, last items in topDict.FDArray and used_subrs weren't really the ones corresponding to the current fd. So we are saving a dictionary to find the real index were those values were stored.

What do you think about this fix?

blikblum commented 4 years ago

LGTM. The only thing i think is missing is a test. You can look at existing ones as a base

canda commented 4 years ago

🤙 Added a test to check this case @blikblum

jordonbiondo commented 4 years ago

@blikblum bump, we're forking fontkit and pdfkit for now so we can use this fix, any word on merge and release so pdfkit can be updated?

blikblum commented 4 years ago

I dont have rights to commit to fontkit, only pdfkit

jichang commented 3 years ago

@devongovett can help to merge this and release a new version ?

calvin-oen commented 3 years ago

we need this to support Noto

liborm85 commented 3 years ago

@calvin-oen You can use up-to-date fork https://github.com/foliojs-fork/fontkit.