- Published on
Cutting Down Font File Sizes
- Authors
- Name
- Yair Mark
- @yairmark
Today I had to try to work out how to cut a huge font file down (3MB+). A colleague suggested that this file was likely this big due to non-English glyphs being included.
I confirmed this by installing the excellent open-source tool FontForge. On opening the font file, I saw many glyphs for non-English languages.
Now I needed to work out how to cut this down. I could use FontForge but clicking the fonts I wanted to remove would take ages. This sounded like the perfect job for a command-line tool.
After a bit more Googling I came across this Stackoverflow answer. Based on this I installed fonttools. This question also indicated how to whitelist fonts, the problem was I just wanted all English glyphs and not have to worry about working out each letter's exact Unicode value. A bit more Googling later I came across this CSS-tricks post. There is a flag on this command that lets you specify the Unicode range.
In the end, I ran the command as follows:
pyftsubset MyFontFile-Regular.ttf --unicodes="U+0020-007F"
This output a file with the following name format:
MyFontFile-Regular.subset.ttf