#font #ttf #truetype #text

glyph_brush

Fast cached text render library using rusttype

10 releases (4 breaking)

✓ Uses Rust 2018 edition

0.4.1 Feb 15, 2019
0.4.0 Feb 8, 2019
0.3.0 Feb 1, 2019
0.2.4 Dec 21, 2018
0.0.1 Sep 1, 2018

#8 in Rendering

Download history 651/week @ 2018-12-05 635/week @ 2018-12-12 772/week @ 2018-12-19 716/week @ 2018-12-26 780/week @ 2019-01-02 886/week @ 2019-01-09 850/week @ 2019-01-16 806/week @ 2019-01-23 556/week @ 2019-01-30 523/week @ 2019-02-06 1088/week @ 2019-02-13 861/week @ 2019-02-20 837/week @ 2019-02-27 939/week @ 2019-03-06 818/week @ 2019-03-13

3,036 downloads per month
Used in 18 crates (6 directly)

Apache-2.0

136KB
3K SLoC

glyph_brush crates.io Documentation

Fast caching text render library using rusttype. Provides render API agnostic rasterization & draw caching logic.

Makes extensive use of caching to optimise frame performance.

  • GPU texture cache logic to dynamically maintain a GPU texture of rendered glyphs.
  • Caching of glyph layout output to avoid repeated cost of identical text rendering on sequential frames.
  • Layouts are re-used to optimise similar layout calculation after a change.
  • Vertex generation is cached per section and re-assembled into the total vertex array on change.
  • Avoids any layout or vertex calculations when identical text is rendered on sequential frames.

The crate is designed to be easily wrapped to create a convenient render API specific version, for example gfx-glyph.

use glyph_brush::{BrushAction, BrushError, GlyphBrushBuilder, Section};

let dejavu: &[u8] = include_bytes!("DejaVuSans.ttf");
let mut glyph_brush = GlyphBrushBuilder::using_font_bytes(dejavu).build();

glyph_brush.queue(Section {
    text: "Hello glyph_brush",
    ..Section::default()
});
glyph_brush.queue(some_other_section);

match glyph_brush.process_queued(
    screen_dimensions,
    |rect, tex_data| update_texture(rect, tex_data),
    |vertex_data| into_vertex(vertex_data),
) {
    Ok(BrushAction::Draw(vertices)) => {
        // Draw new vertices.
    }
    Ok(BrushAction::ReDraw) => {
        // Re-draw last frame's vertices unmodified.
    }
    Err(BrushError::TextureTooSmall { suggested }) => {
        // Enlarge texture + glyph_brush texture cache and retry.
    }
}

Examples

Have a look at

  • cargo run --example opengl --release

Dependencies

~2.5MB
~37K SLoC