foliojs / fontkit

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

Discussion: Better internationalization (i18n) support #193

Closed scottrippey closed 5 years ago

scottrippey commented 5 years ago

I was looking at https://github.com/foliojs/fontkit/blob/master/src/TTFFont.js#L93-L94, which looks up the postscriptName by "whatever language comes first".

I did find the utility font.getName("postscriptName", "en"), so that's probably what I'll use for the time being. However, it's certainly not intuitive, and was tricky to find. I'm wondering if we could support setting a default language, like font.setLanguage("en"), or even higher like fontkit.setDefaultLanguage("en") ... so that all font properties can be interpreted with that language, instead of just "whatever is first"?

FWIW, in most fonts I've looked at, the name.records.postscriptName object contains 2 entries, and they're usually the same. It usually looks like { "0-0": "Corbel", "en": "Corbel" }. In some fonts, though, specifically the Microsoft font "Corbel Light", the first entry is different than the second: { "0-0": "Corbel-Light", "en": "CorbelLight" }.

scottrippey commented 5 years ago

Well it was easier than I thought: https://github.com/foliojs/fontkit/pull/194