Skip to main content

Crate webfont_generator

Crate webfont_generator 

Source
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 cli

Then run:

webfont-generator --dest ./dist/fonts ./icons/

§Feature flags

  • cli: Builds the webfont-generator CLI binary (adds clap dependency). Not enabled by default — use cargo install webfont-generator --features cli.
  • napi: Enables Node.js NAPI bindings for use as a native addon.

Structs§

FormatOptions
GenerateWebfontsOptions
GenerateWebfontsResult
SvgFormatOptions
TtfFormatOptions
WoffFormatOptions

Enums§

FontType

Functions§

generate
Generate webfonts from SVG files.
generate_sync
Synchronous version of generate. Spawns a tokio runtime internally.

Type Aliases§

RenameFn
A glyph rename function that maps file stems to custom glyph names.