Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Noto font bug #230

Merged
merged 1 commit into from
May 20, 2022
Merged

Fix Noto font bug #230

merged 1 commit into from
May 20, 2022

Conversation

canda
Copy link
Contributor

@canda canda commented May 21, 2020

A little bit of context.
While working with pdfkit we found this error.
foliojs/pdfkit#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
Copy link
Member

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

@canda
Copy link
Contributor Author

canda commented May 26, 2020

🤙
Added a test to check this case @blikblum

A little bit of context.
While working with pdfkit we found this error.
foliojs/pdfkit#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?
@jordonbiondo
Copy link

@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
Copy link
Member

blikblum commented Jun 3, 2020

I dont have rights to commit to fontkit, only pdfkit

e01306821 added a commit to e01306821/umlet that referenced this pull request Dec 10, 2020
e01306821 added a commit to e01306821/umlet that referenced this pull request Dec 17, 2020
e01306821 added a commit to e01306821/umlet that referenced this pull request Dec 17, 2020
afdia pushed a commit to umlet/umlet that referenced this pull request Dec 19, 2020
@jichang
Copy link

jichang commented Jul 31, 2021

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

@calvin-oen
Copy link

we need this to support Noto

@liborm85
Copy link
Contributor

liborm85 commented Aug 2, 2021

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

@devongovett devongovett merged commit 35b5f34 into foliojs:master May 20, 2022
devongovett added a commit that referenced this pull request May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants