Expand description
fontcull - Font subsetting library
Subset fonts to only include glyphs that are actually used.
§Features
static-analysis: Static HTML/CSS parsing for font usage detectionbrowser: Browser-based glyph extraction with chromiumoxide (CLI only)
§Example (static analysis)
ⓘ
use fontcull::{analyze_fonts, subset_font_to_woff2, extract_css_from_html};
let html = r#"<html><head><style>body { font-family: "MyFont"; }</style></head>
<body><p>Hello World</p></body></html>"#;
let css = extract_css_from_html(html);
let analysis = analyze_fonts(html, &css);
// Get chars used by "MyFont"
if let Some(chars) = analysis.chars_per_font.get("MyFont") {
let font_data = std::fs::read("MyFont.ttf").unwrap();
let woff2 = subset_font_to_woff2(&font_data, chars).unwrap();
std::fs::write("MyFont-subset.woff2", woff2).unwrap();
}Enums§
- Font
Format - The format of a font file
- Subset
Error - Error type for font subsetting
Functions§
- compress_
to_ woff2 - Compress TTF/OTF font data to WOFF2
- decompress_
font - Decompress a WOFF font to TTF/OTF
- subset_
font_ data - Subset a font to only include the specified characters
- subset_
font_ data_ unicode - Subset a font using unicode codepoints (u32) instead of chars
- subset_
font_ to_ woff2 - Subset a font and compress to WOFF2
- subset_
font_ to_ woff2_ unicode - Subset a font to WOFF2 using unicode codepoints (u32)