Way to reduce size of .ttf fonts?
Asked Answered
O

7

45

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.

Occupational answered 14/4, 2010 at 6:56 Comment(0)
T
28

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.

FontSquirrel Webfont Generator

Tomkins answered 21/6, 2018 at 18:47 Comment(4)
Click the Custom Subsetting... radio box to further enable reducing the file size.Plasmolysis
This link is not working now. Giving 502 errorDeglutinate
Worked great for me. A google font I was using for a react native application which was originally 4.8MB got reduced to 40KB.Munro
cool, material icon font reduced from 808 -> 12 kbSartorius
T
18

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

Thyrotoxicosis answered 20/5, 2012 at 3:35 Comment(2)
Neat trick, didn't know that. You can also request certain weights in the paramater as well. (e.g. only bold, no italic or normal)Nonreturnable
This does not address the actual question of how to reduce the filesize of a truetype font that you already have, specifically by removing glyphs that you are not using. It addresses a different question "How do you remove all excess glyphs from a Google Web Font?" Google fonts are not woff2 format, not ttf, and you cannot use this method if you already have a font that you want to use.Veneer
S
16

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.

Swordsman answered 17/2, 2021 at 9:7 Comment(2)
by far the easiest and most flexible option. Also works under cygwin without needing to install pipChivalrous
Cool and impressive! I've just used this tool to reduce Iosevkas size from 6MB to 64KB (!) by selecting the subset, that is required by my use case: 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
B
8

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/

Bonny answered 19/1, 2011 at 13:12 Comment(0)
W
6

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

Wharve answered 8/6, 2017 at 16:23 Comment(0)
N
3

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.

Northeasterly answered 1/6, 2016 at 5:36 Comment(0)
N
1

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.

Natalienatalina answered 25/8, 2010 at 14:51 Comment(4)
Complex .ttf fonts can easily get up to 1MB or more.Middlebrooks
@Mark: Maybe Big5 or GB fonts or others with large character sets, but these are edge cases. Otherwise, even very elaborate Western fonts rarely get above 500KB, and the few that are 500KB are whales that could probably be optimized.Cantrell
But you asked for the application. :) I'm dealing with the exact problem right now.Middlebrooks
Fonts in Chinese, for instance, regularly run 8-12MB. They contain 20K-40K individual glyphs.Unbridled

© 2022 - 2024 — McMap. All rights reserved.