daegun

The Rust API

Open a font, shape a string, rasterize what comes back. That is the whole loop.

use daegun::Font;

let bytes = std::fs::read("Inter.ttf")?;
let font = Font::from_bytes(&bytes)?;

let shaped = font.shape("Wave", &[], false).expect("shapes");
// glyphs [459, 507, 980, 614], advances [934.6, 546.9, 542.5, 583.0]

let glyph = font.rasterize_glyph(shaped.glyphs[0], 32.0, &[]).expect("has ink");
// 31x24 coverage bytes at (0, 0), one per pixel, advance 15.4px

The one thing to read twice

Advances come back on a 1000 unit em whatever the font's own units are, so a pen position isadvance * px / 1000.0. Outlines are in the font's units instead, whichFont::upm reports. That difference is deliberate.

Variable axes

Every call that takes axes takes them the same way, as (tag, value):

let bold = font.shape("Wave", &[("wght", 700.0)], false).expect("shapes");
let glyph = font.rasterize_glyph(gid, 32.0, &[("wght", 700.0), ("opsz", 28.0)]);

Type to search.