开发者

Way to reduce size of .ttf fonts?

开发者 https://www.devze.com 2022-12-26 14:27 出处:网络
Is there any way to reduce the 开发者_StackOverflowsize of the .ttf fonts? i.e. if we want to remove some glyps which we are not using.FontSquirrel\'s Webfont generator makes it very easy to reduce a

Is there any way to reduce the 开发者_StackOverflowsize of the .ttf fonts? i.e. if we want to remove some glyps which we are not using.


FontSquirrel's Webfont generator makes it very easy to reduce a font's filesize.

  • Upload your font
  • Choose Expert...
  • Choose which glyphs to include
  • Press Download Your Kit

I was able to take a 263kb font down to 34kb.

Way to reduce size of .ttf fonts?


With Google Web Fonts, you can limit the character set like:

//fonts.googleapis.com/css?family=FontName&text=Lorem%20Ipsum

This would be particularly useful if Google had icon fonts like Font Awesome


You can use fontforge to reduce the file size

This is explained at http://www.cnx-software.com/2010/02/19/reducing-truetype-font-file-size-for-embedded-systems/


You can use fonttools to remove unwanted glyphs from a font.

pip install fonttools
pyftsubset myFont.ttf --output-file=mySmallerFont.ttf --unicodes=U+0020-007E

mySmallerFont.ttf will contain only unicode characters ranging from U+0020 to U+007E (basic latin).

Full documentation is available here.

For the list of unicode characters, you can check Wikipedia.


I did the following to remove all Cyrillic glyphs (letters) from a font, hence cutting file size in half as I only needed the Latin letters.

  1. get FontForge (https://fontforge.github.io/en-US/)
  2. start FontForge and open your ttf font file
  3. go to Edit -> Select -> Select By Script
  4. on the pop up selection window chose Cyrillic from the drop down menu. As you might have guessed this will mark only the Cyrillic letters.
  5. go to Encoding -> Detach & Remove Glyphs, confirm the question. See how the Cyrillic letters disappear?
  6. go to Encoding -> Compact to get a better overview of the remaining letters which makes it easier to select more deleting candidates. (But I did not dare to manually delete/remove them.)
  7. go to File -> Generate Fonts and don't forget to chose ttf as output format.

Please consider that I am not a pro in this. But I needed a fast solution.

Here you can read more on this topic: http://wiki.unity3d.com/index.php?title=Create_a_new_TrueType_font_using_a_subset_of_characters_from_an_existing_TrueType_font


I was using fontmin to remove glyph from ttf fonts.

It succeeded to reduce Noto Sans (weight=medium) from 20MB to less than 10, yet still cover common Chinese/Japanese characters.


What is the application for this? Most fonts are relatively lightweight. TTFs store vector data instead of bitmap data, so it takes relatively few bytes to describe the shape of each glyph. Even very busy fonts can be kept below 100kb. Many modern fonts come with ClearType hinting, but even this adds very little file size.

If you really want to take certain glyphs out of a font, then you will need a font editing tool (Macromedia had one called Fontographer that is now owned by FontLab). But you're probably better off just picking a lighter font. For example, OCR A Std is only 30kb and includes ClearType hinting as well as all US ASCII characters. Try to avoid Unicode fonts since full Unicode support requires a ton of glyphs. But most fonts don't offer full Unicode support.

Lastly, if you do decide to modify a font, make sure you name it something else. A naming conflict could result in some really annoying surprises for users.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号