Is there any way to reduce the size 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.
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 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.
cygwin
without needing to install pip –
Chivalrous pyftsubset iosevka-medium.ttf --output-file=slim-iosevka-medium.ttf --unicodes=U+0020-007E,U+00A0-00FF
That command selects Basic Latin
and Latin-1 Supplement
. –
Rajewski 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/
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.
- get FontForge (https://fontforge.github.io/en-US/)
- start FontForge and open your ttf font file
- go to Edit -> Select -> Select By Script
- 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.
- go to Encoding -> Detach & Remove Glyphs, confirm the question. See how the Cyrillic letters disappear?
- 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.)
- 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.
© 2022 - 2024 — McMap. All rights reserved.