#font #ttf #truetype #gfx #text

glyph_brush_draw_cache

Texture draw cache for ab_glyph

4 releases

0.1.3 Oct 17, 2020
0.1.2 Oct 3, 2020
0.1.1 Jul 11, 2020
0.1.0 May 23, 2020

#14 in Caching

Download history 835/week @ 2020-07-05 678/week @ 2020-07-12 712/week @ 2020-07-19 960/week @ 2020-07-26 494/week @ 2020-08-02 993/week @ 2020-08-09 1176/week @ 2020-08-16 1282/week @ 2020-08-23 1003/week @ 2020-08-30 1298/week @ 2020-09-06 1102/week @ 2020-09-13 929/week @ 2020-09-20 1774/week @ 2020-09-27 1961/week @ 2020-10-04 1608/week @ 2020-10-11 1276/week @ 2020-10-18

5,027 downloads per month
Used in 8 crates (via glyph_brush)

Apache-2.0

51KB
901 lines

glyph_brush_draw_cache crates.io Documentation

Rasterization cache for ab_glyph used in glyph_brush.

  • Manages a texture. Draws glyphs into it and provides texture rect lookup for glyphs.
  • Automatic re-use & reordering when needed.
use glyph_brush_draw_cache::DrawCache;

// build a cache with default settings
let mut draw_cache = DrawCache::builder().build();

// queue up some glyphs to store in the cache
for (font_id, glyph) in glyphs {
    draw_cache.queue_glyph(font_id, glyph);
}

// process everything in the queue, rasterizing & uploading as necessary
draw_cache.cache_queued(&fonts, |rect, tex_data| update_texture(rect, tex_data))?;

// access a given glyph's texture position & pixel position for the texture quad
match draw_cache.rect_for(font_id, &glyph) {
    Some((tex_coords, px_coords)) => {}
    None => {/* The glyph has no outline, or wasn't queued up to be cached */}
}

Example

See the draw_cache_guts example to see how it works (run it from the top level).

cargo run --example draw_cache_guts

Dependencies

~0.6–0.9MB
~19K SLoC