Crate subsetter

source ·
Expand description

Reduces the size and coverage of OpenType fonts with TrueType or CFF outlines.


In the example below, we remove all glyphs except the ones with IDs 68, 69, 70. Those correspond to the letters ‘a’, ‘b’ and ‘c’.

use subsetter::{subset, Profile};

// Read the raw font data.
let data = std::fs::read("fonts/NotoSans-Regular.ttf")?;

// Keep only three glyphs and the OpenType tables
// required for embedding the font in a PDF file.
let glyphs = &[68, 69, 70];
let profile = Profile::pdf(glyphs);
let sub = subset(&data, 0, profile)?;

// Write the resulting file.
std::fs::write("target/Noto-Small.ttf", sub)?;

Notably, this subsetter does not really remove glyphs, just their outlines. This means that you don’t have to worry about changed glyphs IDs. However, it also means that the resulting font won’t always be as small as possible. To somewhat remedy this, this crate sometimes at least zeroes out unused data that it cannot fully remove. This helps if the font gets compressed, for example when embedding it in a PDF file.

In the above example, the original font was 375 KB (188 KB zipped) while the resulting font is 36 KB (5 KB zipped).


  • Defines which things to keep in the font.
  • A 4-byte OpenType tag.


  • Parsing failed because the font face is malformed.


  • Subset a font face to include less glyphs and tables.