text/glyphcache.rs#
Source: lib/text/glyphcache.rs
glyphcache -- rasterized glyph masks, cached by (font, glyph, size, x phase)
[src/text/glyphcache.s]
gc_get(font, glyph, size_fx, phase) -> Entry / None (nothing to draw) / Direct (too
large to cache: draw it with glyph_path + fill). size_fx: pixel size (em height)
in 24.8; phase: 0..3 quarter pixels. Entry: left, top (relative to pen x /
baseline y), w, h, w*h coverage bytes. An empty glyph is an entry of 0 x 0.
gc_get_bitmap(font, glyph, size_fx) -> colour bitmap entry (CBDT fonts): w*h PARGB
pixels; bitmaps larger than GC_BIGBMP bytes are not cached (valid until the next one)
gc_get_lcd(font, glyph, size_fx, phase, vertical) -> the subpixel mask (lcd.rs): w*h*3
coverage bytes in the physical order of the subpixels, one pixel more on each side
across them than gc_get's mask; Direct when too large (draw it greyscale)
gc_box(font, glyph, size_fx, phase) -> {left, top, w, h} as gc_get computes it
gc_flush() gc_scale(font, size_fx) -> (sx, sy) pixels per font unit (sy snapped)
gc_usage() -> (entries, entry limit, bytes, arena bytes): how full the cache is
Hinting-free: for sizes up to 24 px the vertical scale is adjusted so the x-height lands
on a whole pixel; horizontally only quarter-pixel phases. Key: 1<<63 | colour<<62 |
font<<40 (22 bits) | mode<<38 (0 grey, 1 subpixel columns, 2 subpixel rows) | phase<<36 |
size<<16 (20 bits) | glyph (16 bits). Like the
assembly the cache starts over when it holds GC_SLOTS / 2 entries or its 2 MB arena is
full.
struct GcEntrya cached glyph: placement relative to the pen x / baseline, w x h coverage bytes (masks) or PARGB pixels (bitmaps)left: i32top: i32w: i32h: i32px: Vec<u8>
enum GcRef<'a>NoneDirectEntry(&'a GcEntry)
impl Text
fn gc_flush(&mut self)gc_flush(): forget every cached glyphfn gc_usage(&self) -> (usize, usize, usize, usize)gc_usage() -> (entries, the entries at which it starts over, bytes, its arena's bytes)fn gc_scale(&self, font: u32, size_fx: i32) -> (f32, f32)gc_scale(font, size_fx) -> (sx, sy): pixels per font unit, sy snapped so the x-height is whole up to 24 pxfn gc_box(&mut self, font: u32, g: u32, size: i32, phase: i32) -> Option<[i32; 4]>gc_box(font, glyph, size_fx, phase) -> {left, top, w, h} (not cached)fn set_antialias(&mut self, on: bool)smoothed glyph masks (true, the default) or black-and-white ones (the system's font smoothing off); a change empties the cachefn antialias(&self) -> boolwhether glyph masks are smoothedfn gc_get(&mut self, font: u32, g: u32, size: i32, phase: i32) -> GcRef<'_>gc_get(font, glyph, size_fx, phase): the cached mask, rendered on first usefn gc_get_lcd(&mut self, font: u32, g: u32, size: i32, phase: i32, vertical: bool) -> GcRef<'_>gc_get_lcd(font, glyph, size_fx, phase, vertical): the cached subpixel mask (w x h pixels of 3 coverage bytes: left to right, or top to bottom when vertical), rendered on first use; Direct when it is too large for the cache (draw the glyph greyscale)fn gc_get_bitmap(&mut self, font: u32, g: u32, size: i32) -> Option<&GcEntry>gc_get_bitmap(font, glyph, size_fx): the PARGB colour bitmap entry or None