#font #ttf #truetype #text

glyph_brush

Fast cached text render library using rusttype

7 releases

✓ Uses Rust 2018 edition

0.2.4 Dec 21, 2018
0.2.3 Dec 14, 2018
0.2.2 Nov 9, 2018
0.2.1 Sep 28, 2018
0.0.1 Sep 1, 2018

#6 in Rendering

Download history 448/week @ 2018-10-11 889/week @ 2018-10-18 574/week @ 2018-10-25 601/week @ 2018-11-01 519/week @ 2018-11-08 1163/week @ 2018-11-15 724/week @ 2018-11-22 793/week @ 2018-11-29 530/week @ 2018-12-06 680/week @ 2018-12-13 649/week @ 2018-12-20 812/week @ 2018-12-27 739/week @ 2019-01-03

3,082 downloads per month
Used in 15 crates (5 directly)

Apache-2.0

115KB
2.5K SLoC

glyph_brush crates.io Documentation

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

Makes use of three kinds 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.
  • Caches draw calculations to avoid repeated cost of identical text rendering on sequential frames.

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

extern crate glyph_brush;

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

~777KB
~13K SLoC