Pure Rust font subsetting library powered by klippa.
use fontcull::{subset_font_to_woff2, decompress_font};
use std::collections::HashSet;
// Subset a font to only include specific characters
let font_data = std::fs::read("font.ttf").unwrap();
let chars: HashSet<char> = "Hello World".chars().collect();
let woff2 = subset_font_to_woff2(&font_data, &chars).unwrap();
std::fs::write("font-subset.woff2", woff2).unwrap();
// Can also decompress WOFF/WOFF2 to TTF
let woff2_data = std::fs::read("font.woff2").unwrap();
let ttf_data = decompress_font(&woff2_data).unwrap();static-analysis: Static HTML/CSS parsing for font usage detection
The fontcull-cli crate provides a command-line tool that:
- Opens URLs in a headless browser (via chromiumoxide)
- Extracts all glyphs/characters used on the page (including
::before/::afterpseudo-elements) - Optionally spiders the site to find more pages
- Subsets font files to only include the characters actually used
cargo install fontcull-cliRequires Chrome/Chromium installed (uses your system browser, no specific version needed).
# Just get the unicode range of characters used
fontcull https://example.com
# Subset fonts based on page content
fontcull https://example.com --subset=fonts/*.ttf
# Spider multiple pages
fontcull https://example.com --spider-limit=10 --subset=fonts/*.ttf
# Filter by font family
fontcull https://example.com --subset=fonts/*.ttf --family="My Font"
# Add extra characters to always include
fontcull https://example.com --subset=fonts/*.ttf --whitelist="0123456789"Thanks to all individual sponsors:
...along with corporate sponsors:
...without whom this work could not exist.