From 43cc3fc8b1a426cdf5cfa9a420c670ca3526ede6 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 29 Nov 2024 17:34:52 +0100 Subject: [PATCH] Fonts: optimization bake FallbackAdvanceX into IndexAdvanceX[]. --- imgui_draw.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index a15bf0a60..c461accde 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -3820,7 +3820,7 @@ ImFontGlyph* ImFont::BuildLoadGlyph(ImWchar codepoint) { // Mark index as not found, so we don't attempt the search twice BuildGrowIndex(codepoint + 1); - IndexAdvanceX[codepoint] = (float)IM_FONTGLYPH_INDEX_NOT_FOUND; + IndexAdvanceX[codepoint] = FallbackAdvanceX; IndexLookup[codepoint] = IM_FONTGLYPH_INDEX_NOT_FOUND; return NULL; } @@ -4546,11 +4546,10 @@ float ImFont::GetCharAdvance(ImWchar c) { if (c < (size_t)IndexAdvanceX.Size) { + // Missing glyphs fitting inside index will have stored FallbackAdvanceX already. const float x = IndexAdvanceX.Data[c]; if (x >= 0.0f) return x; - if (x == (float)IM_FONTGLYPH_INDEX_NOT_FOUND) // FIXME-NEWATLAS: could bake in index - return FallbackAdvanceX; } const ImFontGlyph* glyph = BuildLoadGlyph(c); return glyph ? glyph->AdvanceX : FallbackAdvanceX;