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

font.namedVariations fails on some fonts #272

Open
guidoferreyra opened this issue Apr 21, 2022 · 8 comments
Open

font.namedVariations fails on some fonts #272

guidoferreyra opened this issue Apr 21, 2022 · 8 comments

Comments

@guidoferreyra
Copy link

guidoferreyra commented Apr 21, 2022

When parsing some fonts and trying to get namedVariation. it throws the following error:

TypeError: Cannot read property 'en' of undefined

When printing the instance where the undefined is raised it shows the following, name is missing.
{ nameID: 2, flags: 0, coord: [ 0, 400, 100, 0 ], postscriptNameID: 6 }

I dug a bit and the issue is cause because when getting the instance name is not fnding id 2 since name.records.fontFeatures starts at ID 256. When instance name matches with font ID 2 will use that, it seems this is very common and allowed by the spec:

The subfamilyNameID field provides a name ID that can be used to obtain strings from the 'name' table that can be treated as equivalent to name ID 17 (typographic subfamily) strings for the given instance. Values of 2 or 17 can be used; otherwise, values must be greater than 255 and less than 32768. The values 2 or 17 should only be used if the named instance corresponds to the font’s default instance.

@guidoferreyra
Copy link
Author

guidoferreyra commented Apr 21, 2022

By changing

let key = record.nameID >= 256 ? 'fontFeatures' : (NAMES[record.nameID] || record.nameID);

and
if (record.nameID >= 256) {

to:
record.nameID >= 256 || record.nameID == 2 || record.nameID == 17 will solve the issue.
Is there a reason to create the name array fontFeatures? Why when looking for a name just dont search on the full list?

@ptoussai
Copy link

ptoussai commented Dec 2, 2022

I have the same problem. Glyphs uses nameID: 2 in some cases.
@guidoferreyra do you want to create a PR? Otherwise I can do it.

@quitequinn
Copy link

Can we get this merged?

@quitequinn
Copy link

Font Subfamily name is Name ID Code 2. This means you could search and replace any named instances with nameID: 2 with the Subfamily name.

@freder
Copy link

freder commented Apr 5, 2023

also getting this error. — if there is a fix, please merge 🙏

@Typogram
Copy link

Typogram commented Sep 20, 2023

I also run into this issue, it is actually quite common.
The fix PR above seem to have an error at least in the PR description, so please double check before merge: #317 (comment)

@quitequinn
Copy link

This also happens with other references (eg. ID 17 was known as “Preferred Subfamily”)

@quitequinn
Copy link

Have you found a work around @Typogram ?

Even just a way to lookup by name id without having to create a dictionary via https://learn.microsoft.com/en-us/typography/opentype/spec/name

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

No branches or pull requests

5 participants