Crate fontcull

Crate fontcull 

Source
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 detection
  • browser: 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§

FontFormat
The format of a font file
SubsetError
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)