#font #ttf #truetype #text

glyph_brush

Fast cached text render library using ab_glyph

19 releases

✓ Uses Rust 2018 edition

new 0.7.0 May 23, 2020
0.6.3 Feb 20, 2020
0.6.1 Oct 26, 2019
0.5.3 Jun 21, 2019
0.2.2 Nov 9, 2018

#3 in #font

Download history 2428/week @ 2020-01-25 2044/week @ 2020-02-01 2130/week @ 2020-02-08 2741/week @ 2020-02-15 2540/week @ 2020-02-22 2178/week @ 2020-02-29 1808/week @ 2020-03-07 2712/week @ 2020-03-14 2941/week @ 2020-03-21 2418/week @ 2020-03-28 2806/week @ 2020-04-04 2858/week @ 2020-04-11 2058/week @ 2020-04-18 2272/week @ 2020-04-25 3728/week @ 2020-05-02 2190/week @ 2020-05-09

10,721 downloads per month
Used in 61 crates (13 directly)

Apache-2.0

210KB
4.5K SLoC

glyph_brush crates.io Documentation

Fast caching text render library using ab_glyph. 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::{ab_glyph::FontArc, BrushAction, BrushError, GlyphBrushBuilder, Section, Text};

let dejavu = FontArc::try_from_slice(include_bytes!("../../fonts/DejaVuSans.ttf"))?;
let mut glyph_brush = GlyphBrushBuilder::using_font(dejavu).build();

glyph_brush.queue(Section::default().add_text(Text::new("Hello glyph_brush")));
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

~1.5MB
~25K SLoC