Skip to content

webfont-generator logo

Webfont Generator

@atlowchemi/webfont-generator is a native Rust NAPI addon that generates webfonts (SVG, TTF, EOT, WOFF, WOFF2) from SVG icon files. It is the engine that powers vite-svg-2-webfont.

Why a new engine

The JavaScript lineage started with webfonts-generator by sunflowerdeath, which the Vusion team forked as @vusion/webfonts-generator. Neither project has received updates in years, and both rely on a JavaScript pipeline spanning several separate packages. @atlowchemi/webfont-generator is a ground-up rewrite in Rust that keeps the familiar API while delivering better performance and long-term maintainability.

Owning the full pipeline made a new parallel architecture possible. The engine parses and normalizes glyphs once, then shares their prepared geometry between SVG output and binary font compilation. SVG serialization and font-table compilation can run in parallel, followed by parallel WOFF, WOFF2, and EOT generation. WOFF and WOFF2 consume the compiled tables directly, avoiding an intermediate TTF serialization and reparse. Together with parallel glyph processing, this reduces repeated work and makes better use of multiple CPU cores.

The result: over 6× faster on average than @vusion/webfonts-generator in our 100-, 300-, and 600-glyph, all-format benchmarks on an Apple M4 Max, both with the default settings and with optional SVG path optimization enabled. See Performance for the timings.

Attribution

The API design and Handlebars template system build on sunflowerdeath's original webfonts-generator and the Vusion team's @vusion/webfonts-generator fork. Credit to sunflowerdeath, the Vusion team, and the contributors to both projects for that foundation.

Architecture

Single-face fonts

For a single-face font, the generation pipeline works as follows:

  1. SVG loading -- Read and validate source SVG files in parallel
  2. Glyph preparation -- Parse glyph paths with usvg, process geometry with oxvg_path, and normalize metrics into a shared prepared glyph set
  3. Parallel SVG and table assembly -- Serialize the SVG font if requested, and compile prepared geometry into shared TrueType/OpenType tables using write-fonts when binary formats are needed
  4. Requested binary outputs -- Assemble TTF if requested; generate WOFF, WOFF2, and EOT in parallel from the shared tables. EOT embeds a lazily assembled TTF binary, while WOFF and WOFF2 use the tables directly
  5. Template rendering -- Render CSS and HTML previews via Handlebars when writing those files or calling the result's rendering methods

Multi-variant fonts

For a family such as light, regular, and bold, the engine combines the designs into one font file per requested format:

  1. Family assembly -- Load each variant's SVGs, match icons by name, assign shared codepoints, and apply the missing-glyph policy.
  2. Shared glyph preparation -- Parse the designs and normalize them using family-wide metrics and shared advance widths, keeping icons aligned when switching variants.
  3. Variant compilation -- Compile all designs into shared font tables with weight-axis metadata and glyph-substitution rules. Selecting a weight chooses one of the supplied designs rather than interpolating between outlines.
  4. Output and templates -- Assemble TTF if requested, encode requested WOFF and WOFF2 outputs in parallel, and render CSS/HTML with variant metadata and modifier classes.

This path supports TTF, WOFF, and WOFF2; SVG/EOT output is available only for single-face fonts. Multi-variant families also support incremental regeneration, reusing cached geometry for unchanged designs. See multi-variant fonts for usage.

Performance

The legacy @vusion/webfonts-generator engine does not support SVG path optimization. The Rust engine adds it through optimizeOutput and is still faster with optimization enabled. The tables show the Rust engine with path optimization disabled and enabled side by side.

All formats

Generating SVG, TTF, EOT, WOFF, and WOFF2:

Glyphs@vusion/webfonts-generatorRust engineRust engine (Optimized SVG)
10065.6 ms11.8 ms12.0 ms
300256.1 ms39.0 ms41.9 ms
600523.3 ms72.9 ms79.2 ms

Modern web formats

If you only need web delivery formats, the same comparison with WOFF2 only or WOFF + WOFF2 gives:

FormatsGlyphs@vusion/webfonts-generatorRust engineRust engine (Optimized SVG)
WOFF210064.0 ms11.6 ms12.6 ms
WOFF2300254.6 ms39.1 ms40.9 ms
WOFF2600510.1 ms71.5 ms77.9 ms
WOFF + WOFF210064.1 ms11.5 ms11.6 ms
WOFF + WOFF2300280.2 ms38.6 ms40.9 ms
WOFF + WOFF2600514.3 ms75.8 ms77.1 ms

With path optimization disabled (the default), the average speedup is 6.4× for WOFF2 only and 6.5× for WOFF + WOFF2. Enabling path optimization still delivers average speedups of 5.9× and 6.3×, respectively.

These builds skip SVG font serialization and TTF binary assembly in the Rust engine. In this benchmark, their total times remain close to the all-format builds: fewer output formats do not necessarily translate into a large reduction in elapsed time.

Avoiding repeated work

The shared-geometry pipeline avoids reparsing an SVG font to compile binary formats. Requesting only the formats you need also skips unnecessary output work: a WOFF2-only build does not serialize an SVG font or assemble a TTF binary.

For repeated builds—such as a dev server regenerating your icon font whenever you edit an SVG—incremental generation can reuse parsed glyphs, compiled glyphs, font tables, and WOFF compression or transform work from the previous build, giving you faster feedback while developing. In our 100–600-glyph benchmarks, a one-SVG edit rebuilt 1.5–1.8× faster than a full Rust build and 12–17× faster than Vusion, which always rebuilds the entire font.

Multi-weight families use a variant compilation path to produce TTF, WOFF, and WOFF2; see multi-variant fonts.

Compatibility

The API is largely compatible with upstream @vusion/webfonts-generator, with a few documented differences:

  • The cssContext and htmlContext callbacks receive only the context object; the additional options and Handlebars instance arguments are no longer available.
  • formatOptions is strictly typed, and the eot key is no longer accepted; EOT is derived from the TTF output.
  • optimizeOutput adds optional SVG path optimization, disabled by default.
  • formatOptions.woff2.compressionQuality controls WOFF2 compression quality from 0–11 (default 11), allowing faster encoding at the cost of slightly larger output.
  • incremental enables regeneration that reuses work from the previous build, disabled by default.
  • Font binaries differ at the byte level (different TTF compiler, different path normalization) but are valid and render identically
  • CSS, HTML, and template output is identical.
  • variants adds multi-weight families with discrete designs.

WARNING

If you are migrating from @vusion/webfonts-generator, review the Node.js usage page for the full options reference.

Available as

DistributionPackageInstall
npm@atlowchemi/webfont-generatornpm install @atlowchemi/webfont-generator
crates.iowebfont-generatorcargo add webfont-generator
CLIwebfont-generatorcargo install webfont-generator --features cli

Next steps

Released under the MIT License.