web engine - experimental web browser

Glyph cache: HashMap of rasterized bitmaps #27

open opened by pierrelf.com

Phase 2: Pure Rust Font Engine#

Implement a glyph cache that stores rasterized glyph bitmaps to avoid re-rasterizing the same glyphs repeatedly.

Depends on: Glyph rasterizer

Cache design#

  • Key: (glyph_id: u16, size_px: u16) — size quantized to integer pixels to bound cache size
  • Value: GlyphBitmap (the rasterized bitmap from the rasterizer)
  • Storage: HashMap<(u16, u16), GlyphBitmap>
  • Keep it simple — no eviction policy for now (Phase 12 will add a texture atlas with LRU)

Integration with Font#

  • Font::get_glyph_bitmap(glyph_id: u16, size_px: f32) -> Option<&GlyphBitmap>
    • Check cache first
    • On miss: rasterize, insert into cache, return reference
  • Cache is per-font (stored in the Font struct, behind RefCell or similar for interior mutability)

Text rendering helper#

  • Font::render_text(text: &str, size_px: f32) -> Vec<PositionedGlyph>
    • Combines shaping (from kern/shaping issue) with cached bitmap lookup
    • Each PositionedGlyph has: x/y position, reference to bitmap data
    • This is the main entry point for the rendering pipeline

Acceptance criteria#

  • Cache hit avoids re-rasterization (test by checking bitmap pointer equality or call count)
  • Multiple sizes of the same glyph are cached independently
  • Cache integrates cleanly with Font struct
  • render_text produces a complete positioned+rasterized glyph run
  • All existing tests continue to pass
  • cargo clippy --workspace -- -D warnings passes
  • cargo fmt --all --check passes
sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:meotu43t6usg4qdwzenk4s2t/sh.tangled.repo.issue/3mflhkonun42x