31 releases

0.7.12 Feb 21, 2025
0.7.11 Oct 20, 2024
0.7.10 Aug 28, 2024
0.7.9 Jun 22, 2024
0.2.2 Nov 9, 2018

#4 in #true-type-font

Download history 10526/week @ 2025-01-14 6550/week @ 2025-01-21 6182/week @ 2025-01-28 11664/week @ 2025-02-04 7854/week @ 2025-02-11 5138/week @ 2025-02-18 6856/week @ 2025-02-25 4164/week @ 2025-03-04 9159/week @ 2025-03-11 9916/week @ 2025-03-18 7765/week @ 2025-03-25 3229/week @ 2025-04-01 5321/week @ 2025-04-08 4106/week @ 2025-04-15 9827/week @ 2025-04-22 7949/week @ 2025-04-29

27,661 downloads per month
Used in 169 crates (29 directly)

Apache-2.0

235KB
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.6–2.3MB
~44K SLoC