weixin_39654751
weixin_39654751
2020-12-26 04:42

Issues with fontkit and Roboto Thin

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

该提问来源于开源项目:foliojs/fontkit

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39754267 weixin_39754267 3月前

    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.

    点赞 评论 复制链接分享
  • weixin_39561577 weixin_39561577 3月前

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

    点赞 评论 复制链接分享
  • weixin_39754267 weixin_39754267 3月前

    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).

    点赞 评论 复制链接分享
  • weixin_39654751 weixin_39654751 3月前

    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.

    点赞 评论 复制链接分享