foliojs / fontkit

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

Issues with fontkit and Roboto Thin #203

Open DHTMLGoodies opened 5 years ago

DHTMLGoodies commented 5 years ago

We're experiencing some strange issues when using fontkit and the Google font "Roboto-Thin"

When working with this font locally(localhost - http), everything works fine, but once we deploy our app to a production server(https), i.e. minimize, package(zip) and upload, the letter "a" in the Roboto-Thin font is gone.

I have done some console.log of the Fontkit.font object returned from this font. The letter "a" has acii code 97. If I understand the fontkit.font properly, I can see that characterSet entry 68 refers to 97. Then, when I look into the _glyphs array, I can see that the entry 68 has codePoints set to [97] on my localhost. However, on the https production server, the same _glyphs entry has codePoints set to an empty array(codePoints: []). I assume this is the reason why we can't see the letter "a" there.

In summary:

I'm parsing the same Roboto-Thin.ttf file on my localhost and on the production server(xhr request to same url).- the font can be downloaded from Google fonts. On my localhost, I get correct Font data back from fontkit On a https production server, I get different font data for the same font where codePoints for _glyphs[68] is empty. It's a very strange problem. Have you experienced this before, and do you have any tip on what the cause could be?

The ttf for Roboto-Thin.ttf is attached.

Roboto-Thin.ttf.zip

Thanks

Pomax commented 5 years ago

It's going to be hard to say what causes it without exact details on that build system: does it touch fonts? (if so, definitely worth making it not do that: just use woff2 -or legacy woff- and leave it as is, instead of running it through a build system).

DHTMLGoodies commented 5 years ago

Thanks for your reply.

The build system(grunt) does not touch the fonts. It minimizes the Javascript files(including fontkit) and bundles them into one app.js.

I can imagine that this is a hard issue to debug. From what I have found so far, It seems like fontkit are returning different data for this font after fontkit has been minimized(using https://github.com/gruntjs/grunt-contrib-compress).

Our system retrieves the font from an url using xhr. Then it's passed to fontkit. I did an md5 checksum for the font, and it was exact match for the working version(localhost) and the non-working version(https production site). However, fontkit reported different data.

We managed to come around this problem now by using "otf" fonts instead ( we cannot use woff). Roboto-Thin.otf works.

Pomax commented 5 years ago

Can I suggest trying a different compressor first? If the code behaves differently after minimizing, something fishy is going on with that minimizer. The big one to try would be grunt-contrib-uglify, which is the default recommended minifier in the grunt ecosystem.

Yankovsky commented 4 years ago

Probably the same underlying problem https://github.com/Munter/subfont/issues/109