#font #ttf #truetype #text

glyph_brush

Fast cached text render library using rusttype

16 releases (5 breaking)

✓ Uses Rust 2018 edition

0.5.3 Jun 21, 2019
0.5.0 May 3, 2019
0.4.1 Feb 15, 2019
0.2.4 Dec 21, 2018
0.2.2 Nov 9, 2018

#18 in Rendering

Download history 892/week @ 2019-03-01 846/week @ 2019-03-08 790/week @ 2019-03-15 914/week @ 2019-03-22 699/week @ 2019-03-29 875/week @ 2019-04-05 1299/week @ 2019-04-12 1353/week @ 2019-04-19 1105/week @ 2019-04-26 1191/week @ 2019-05-03 1271/week @ 2019-05-10 1327/week @ 2019-05-17 1266/week @ 2019-05-24 886/week @ 2019-05-31 1686/week @ 2019-06-07

5,252 downloads per month
Used in 25 crates (8 directly)

Apache-2.0

145KB
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(
    |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

~1MB
~22K SLoC