Expand description
§webfont-generator
Generate webfonts (SVG, TTF, EOT, WOFF, WOFF2) from SVG icon files.
§Library usage
use webfont_generator::{GenerateWebfontsOptions, FontType};
// Async API (requires a tokio runtime)
let options = GenerateWebfontsOptions {
dest: "output".to_owned(),
files: vec!["icons/add.svg".to_owned(), "icons/remove.svg".to_owned()],
font_name: Some("my-icons".to_owned()),
types: Some(vec![FontType::Woff2, FontType::Woff]),
..Default::default()
};
let result = webfont_generator::generate(options, None).await?;
if let Some(woff2) = result.woff2_bytes() {
println!("Generated WOFF2: {} bytes", woff2.len());
}use webfont_generator::{GenerateWebfontsOptions, FontType};
// Synchronous API
let options = GenerateWebfontsOptions {
dest: "output".to_owned(),
files: vec!["icons/add.svg".to_owned()],
write_files: Some(false),
..Default::default()
};
let result = webfont_generator::generate_sync(options, None).unwrap();§CLI
Install the CLI binary with:
cargo install webfont-generator --features cliThen run:
webfont-generator --dest ./dist/fonts ./icons/§Feature flags
cli: Builds thewebfont-generatorCLI binary (addsclapdependency). Not enabled by default — usecargo install webfont-generator --features cli.napi: Enables Node.js NAPI bindings for use as a native addon.
Structs§
- CssContext
- Guaranteed fields supplied to a
cssContextcallback. Additional keys from user-suppliedtemplateOptionsare merged into the same object at runtime, so the JS-side type widens this with an open-ended index signature. - Format
Options - Per-format configuration object. Each field carries options that only apply to the corresponding output format.
- Generate
Webfonts Options - Top-level options controlling webfont generation. Only
destandfilesare required; every other field has a sensible default. See the per-field docs for defaults and units. - Generate
Webfonts Result - Result of a successful
generateWebfontscall. Exposes the generated font bytes (ornullfor formats that were not requested) and methods to render the CSS and HTML preview. - Html
Context - Guaranteed fields supplied to an
htmlContextcallback. Additional keys from user-suppliedtemplateOptionsare merged into the same object at runtime, so the JS-side type widens this with an open-ended index signature. - SvgFormat
Options - SVG-format–specific options for the intermediate SVG font and the per-glyph path processing that feeds every other format.
- TtfFormat
Options - TTF-format–specific options. Populates fields in the generated TTF
nameandheadtables. - Woff
Format Options - WOFF-format–specific options. Affects only WOFF1 output; WOFF2 ignores these.
Enums§
- Font
Type - Font output format. Used in the
typesandorderoptions to control which formats are generated and the order they appear in the CSS@font-facesrc:descriptor.
Functions§
- generate
- Generate webfonts from SVG files.
- generate_
sync - Synchronous version of
generate. Spawns a tokio runtime internally.
Type Aliases§
- Rename
Fn - A glyph rename function that maps file stems to custom glyph names.