#text #ttf #truetype #otf #opentype

ab_glyph

API for loading, scaling, positioning and rasterizing OpenType font glyphs

16 releases

0.2.13 Dec 30, 2021
0.2.12 Nov 13, 2021
0.2.11 May 27, 2021
0.2.10 Feb 20, 2021
0.2.5 Jul 24, 2020

#57 in Text processing

Download history 14026/week @ 2021-09-26 13859/week @ 2021-10-03 14226/week @ 2021-10-10 15766/week @ 2021-10-17 14981/week @ 2021-10-24 12459/week @ 2021-10-31 11245/week @ 2021-11-07 9717/week @ 2021-11-14 10275/week @ 2021-11-21 11848/week @ 2021-11-28 11028/week @ 2021-12-05 10949/week @ 2021-12-12 9489/week @ 2021-12-19 10409/week @ 2021-12-26 15799/week @ 2022-01-02 14150/week @ 2022-01-09

51,289 downloads per month
Used in 219 crates (14 directly)

Apache-2.0

67KB
1K SLoC

ab_glyph crates.io Documentation

Fast API for loading, scaling, positioning and rasterizing OpenType font glyphs.

use ab_glyph::{FontRef, Font, Glyph, point};

let font = FontRef::try_from_slice(include_bytes!("../../dev/fonts/Exo2-Light.otf"))?;

// Get a glyph for 'q' with a scale & position.
let q_glyph: Glyph = font.glyph_id('q').with_scale_and_position(24.0, point(100.0, 0.0));

// Draw it.
if let Some(q) = font.outline_glyph(q_glyph) {
    q.draw(|x, y, c| { /* draw pixel `(x, y)` with coverage: `c` */ });
}

no_std

no_std environments are supported using alloc & libm.

ab_glyph = { default-features = false, features = ["libm"] }

Comparison with rusttype

ab_glyph is a rewrite of rusttype made after I added .otf support for the latter and saw some performance issue's with the rusttype API.

ab_glyph is a more focussed API concentrating on high performance for both .ttf & .otf fonts.

When laying out glyphs into paragraph, ab_glyph is faster than rusttype using .ttf fonts & much faster for .otf fonts.

group                               ab-glyph                    rusttype 0.9
-----                               --------                    ------------
layout_a_sentence (exo2-ttf)        1.00     11.1±0.08µs        1.56     17.3±0.14µs
layout_a_sentence (exo2-otf)        1.00     11.1±0.12µs        8.85     98.1±1.17µs

Note: Numbers from May-2020 benchmarks, ab-glyph performance is also expected to have improved since then.

Dependencies

~585KB
~13K SLoC