Skip to content

bearcove/fontcull

Repository files navigation

fontcull

Crates.io Documentation License: MIT

Pure Rust font subsetting library powered by klippa.

Library usage

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();

Features

  • static-analysis: Static HTML/CSS parsing for font usage detection

CLI

The fontcull-cli crate provides a command-line tool that:

  1. Opens URLs in a headless browser (via chromiumoxide)
  2. Extracts all glyphs/characters used on the page (including ::before/::after pseudo-elements)
  3. Optionally spiders the site to find more pages
  4. Subsets font files to only include the characters actually used

Install

cargo install fontcull-cli

Requires Chrome/Chromium installed (uses your system browser, no specific version needed).

Usage

# 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"

Sponsors

Thanks to all individual sponsors:

GitHub Sponsors Patreon

...along with corporate sponsors:

Zed Depot

...without whom this work could not exist.

About

Font subsetting for Rust (C++ present only for woff2 compression)

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Languages