Font::GetLineWidth called stbtt_GetCodepointHMetrics for every glyph on every invocation. InputField_HitTestCursor rescans the whole field once per character, making caret hit-testing O(n²) in HMetrics lookups. Memoise advances per Font via Font::AdvanceUnits: ASCII in a flat array, the rest in a map. Advances are cached in unscaled font *units* and rescaled per call — Glyph::advance in the FontAtlas is baked at kBaseSize and is wrong at any other size, so it cannot be reused. The per-glyph (int) truncation in GetLineWidth is preserved exactly. Adds the FontAdvanceCache CPU-only regression test covering size independence of the cached unit advance, the per-glyph-truncated rescale pipeline, cache-hit determinism, width scaling with size, and the non-ASCII map path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
607 KiB
607 KiB