Recently I’m tring to add custom font to blog for visual consistency on different browser. You may already know this CSS property:

@font-face {
  font-family: "FontName";
  src: url("/assets/FontFile.ttf");
}

But for some specific conditions, we only need a small part of font file(alphabet or special symbols), but font creators do not supply a small font set version. We can manual reducing font file size by using Python library fonttools, here’s a minimal record:

mkdir font-reduce && cd font-reduce
# Create python environment, this can be skipped.
python3 -m venv env
. env/bin/activate
# Install fonttools, I'm using 4.32.0
pip install fonttools
pyftsubset Input.ttf --output-file=Output.ttf --unicodes=U+0000-007F

fontTools library focus on merging, subset, and converting font file. To reduce font file size, we use pyftsubset with 2 parameters:

--output-file=: The output file name.

--unicodes=: Specify Unicode ranges in hex numbers. U+0000-0007F means ASCII.

To see more options, visit fontTools docs.

Reducing Result

The result has no meaning because it depends on Unicode ranges size, here’s the result base on RobotoCondensed-Bold.ttf.

Input.ttf   162K
Output.ttf   22K

Where to find font file?

Note modifying font file is not always allowed by creators, be careful to see font user license.

Where to find Unicode number?