bdusell / webfont-generator

Locally convert fonts to web formats and generate CSS rules
MIT License
190 stars 34 forks source link

Error with Google Font (Noto Sans TC) #20

Closed onassar closed 5 years ago

onassar commented 5 years ago

I've tried converting the new Google font Noto Sans TC font (found here) on versions 1.2.2 and 1.3.1. In both cases, it doesn't seem to convert (the source font is about 5.7mb, whereas the output fonts are 6.4kb and 3.1kb for the ttf and woff2 fonts, respectively).

I don't believe any errors are occurring (which is even more confusing).

If you want the font to download via wget for testing, I have it hosted here: https://s3-us-west-2.amazonaws.com/app.local.getstencil.com/upldghcnz0k4

onassar commented 5 years ago

Here's the verbose output when running the conversion against 1.3.1:

onassar commented 5 years ago

Following up on this to see if you were able to investigate.

bdusell commented 5 years ago

Sorry for the delay! I will look into it, but based on the chain of converters used, it looks like this is a bug in FontForge. What version of FontForge are you using?

onassar commented 5 years ago

Interesting; all good on the delay. Lives ;-) I believe I'm on 24-Sep-2017 version although their -version isn't very clear. Screenshot:

bdusell commented 5 years ago

Trying to debug this a bit further. I get the following messages when I open the font using the FontForge GUI, although I don't think they're relevant:

image

However, I get this message when converting the .otf file to .ttf, which is the crux of the issue:

image

So CID fonts have multiple sub-fonts, but when converting an .otf with multiple sub-fonts to a .ttf, the converter is arbitrarily choosing only one. After some Googling I found that FontForge offers a way to flatten the sub-fonts:

https://fontforge.github.io/cidmenu.html

Sure enough, flattening the file before generating the .ttf results in a .ttf file that includes the CJK characters. The size of the file is also 5.7M.

The solution seems to be to add the "flatten" step to the converter.

onassar commented 5 years ago

hmm okay. So are you saying that they should be flattened before your library is used? Do you have any examples of how to do that? And with which library? Appreciate you looking into this!

bdusell commented 5 years ago

It can be done beforehand using the FontForge API, but there's no reason it can't be integrated into the generator.

Here's the relevant FontForge function: https://fontforge.github.io/scripting-alpha.html#CIDFlatten

bdusell commented 5 years ago

I've implemented this in a new release, and the font converts correctly now.

onassar commented 5 years ago

Okay great I'll try that over the weekend. I appreciate your help on this.

onassar commented 5 years ago

I actually just tested and it's working great. Thanks a lot!