[perf][LOW] GetLineWidth/ScaleForSize recompute scale + per-glyph HMetrics uncached #57

Closed
opened 2026-06-16 16:51:32 +02:00 by jorijnvdgraaf · 0 comments

Subsystem: Font
Location: implementations/Crafter.Graphics-Font.cpp:61-86
Impact: LOW · Effort: Small · Not hot path (focused caret only)

Problem

GetLineWidth/ScaleForSize recompute scale + per-glyph HMetrics with no advance caching; duplicates the advance pipeline the FontAtlas already pays in Ensure.

Proposed fix

Per-Font codepoint -> advanceUnits cache (flat ASCII array or map), rescaled per call.

Correctness caveat

The "reuse Glyph::advance" suggestion is wrongGlyph::advance is baked at fixed kBaseSize, so it is incorrect at any other fontSize. Cache advance in font units and rescale. Preserve the per-glyph (int) truncation.

**Subsystem:** Font **Location:** `implementations/Crafter.Graphics-Font.cpp:61-86` **Impact:** LOW · **Effort:** Small · Not hot path (focused caret only) ### Problem `GetLineWidth`/`ScaleForSize` recompute scale + per-glyph HMetrics with no advance caching; duplicates the advance pipeline the FontAtlas already pays in `Ensure`. ### Proposed fix Per-Font codepoint -> **advanceUnits** cache (flat ASCII array or map), rescaled per call. ### Correctness caveat The "reuse `Glyph::advance`" suggestion is **wrong** — `Glyph::advance` is baked at fixed `kBaseSize`, so it is incorrect at any other `fontSize`. Cache advance in font *units* and rescale. Preserve the per-glyph `(int)` truncation.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Catcrafts/Crafter.Graphics#57
No description provided.