#true-type #opentype #otf

no-std ab_glyph

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

32 releases

0.2.29 Oct 5, 2024
0.2.28 Jul 4, 2024
0.2.27 Jun 28, 2024
0.2.23 Oct 30, 2023
0.2.5 Jul 24, 2020

#96 in Images

Download history 105167/week @ 2024-08-21 103250/week @ 2024-08-28 110760/week @ 2024-09-04 106256/week @ 2024-09-11 106642/week @ 2024-09-18 111607/week @ 2024-09-25 116586/week @ 2024-10-02 112062/week @ 2024-10-09 116508/week @ 2024-10-16 123847/week @ 2024-10-23 118778/week @ 2024-10-30 113469/week @ 2024-11-06 105079/week @ 2024-11-13 114941/week @ 2024-11-20 113756/week @ 2024-11-27 91086/week @ 2024-12-04

441,996 downloads per month
Used in 1,237 crates (51 directly)

Apache-2.0

88KB
1.5K 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

~1MB
~21K SLoC