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.
Node.js bindings are built by the separate, unpublished webfont-generator-napi crate.
Structs§
- CssContext
- 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. - Font
Variant - One named SVG design in a multi-variant icon family.
- 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.
destand exactly one source, ordinaryfilesorvariants, are required. Every other field has a sensible default. With theclifeature, options deserialize from camelCase JSON with unknown fields rejected. - 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. - Glyph
Change Entry - One entry in the
changesarray passed to the Node binding’sregenerate. The complete ordered file list passed alongside it controls final glyph order; this only describes which files need re-reading, renaming, or removal. - Html
Context - 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. - Missing
Glyph Options - Family-wide missing-glyph policy for multi-variant generation.
- Regenerate
Error - Failure from asynchronous regeneration. Ordinary regeneration errors retain the input result
so callers can recover it with
RegenerateError::into_resultand retry. - SvgFormat
Options - SVG-format–specific options for the intermediate SVG font and the per-glyph path processing that feeds every other format.
- Template
Variant - Resolved variant metadata supplied to CSS and HTML template callbacks.
- TtfFormat
Options - TTF-format–specific options. Populates fields in the generated TTF
nameandheadtables. - Variant
File Set - Complete file set for one configured variant during regeneration.
- Woff2
Format Options - WOFF2-format–specific options. Affects only WOFF2 output.
- Woff
Format Options - WOFF-format–specific options. Affects only WOFF1 output; WOFF2 ignores these.
Enums§
- Color
Glyph Selection - Select logical glyphs whose solid SVG fills are preserved as COLR v1 paint. Names refer to the final names after rename hooks, across all variants.
- 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. - Glyph
Change - What happened to a file, for
crate::GenerateWebfontsResult::regenerate.nameis the caller-resolved glyph name (therenamecallback, if any, is applied by the caller). - Missing
Glyph Behavior - Family-wide behavior when a logical glyph is absent from a variant.
- Regeneration
Files - Complete ordered input membership for a regeneration operation. The case must match the result’s generation mode. Synchronous methods borrow this value; async methods consume it.
Traits§
- Generation
Hooks - Async hooks used by
crate::generate_with_hooks.
Functions§
- generate
- Generate webfonts from SVG files.
- generate_
sync - Synchronous version of
generate. Spawns a tokio runtime internally and has the same source preparation behavior for multi-variant input. - generate_
with_ hooks - Generate a webfont from a set of SVG files.
Type Aliases§
- Rename
Fn - A glyph rename function that maps file stems to custom glyph names.