This commit is contained in:
Bruno Herfst 2026-09-22 16:23:40 +12:00 • committed by GitHub
commit 77fdff150b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View file

@ -4105,6 +4105,9 @@ struct ImFont
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
float Scale; // 4 // in // Legacy base font scale (~1.0f), multiplied by the per-window font scale which you can adjust with SetWindowFontScale()
#endif
// Optional pair kerning. Extra advance in pixels at 'size'. NULL = advance only (no extra cost).
float (*KerningFn)(ImFont* font, ImWchar left, ImWchar right, float size, void* user);
void* KerningUserData;
// Methods
IMGUI_API ImFont();

View file

@ -5696,6 +5696,7 @@ ImVec2 ImFontCalcTextSizeEx(ImFont* font, float size, float max_width, float wra
ImVec2 text_size = ImVec2(0, 0);
float line_width = 0.0f;
ImWchar prev_c = 0;
const bool word_wrap_enabled = (wrap_width > 0.0f);
const char* word_wrap_eol = NULL;
@ -5716,6 +5717,7 @@ ImVec2 ImFontCalcTextSizeEx(ImFont* font, float size, float max_width, float wra
text_size.x = line_width;
text_size.y += line_height;
line_width = 0.0f;
prev_c = 0;
s = ImTextCalcWordWrapNextLineStart(s, text_end, flags); // Wrapping skips upcoming blanks
if (flags & ImDrawTextFlags_StopOnNewLine)
break;
@ -5737,6 +5739,7 @@ ImVec2 ImFontCalcTextSizeEx(ImFont* font, float size, float max_width, float wra
text_size.x = ImMax(text_size.x, line_width);
text_size.y += line_height;
line_width = 0.0f;
prev_c = 0;
if (flags & ImDrawTextFlags_StopOnNewLine)
break;
continue;
@ -5749,6 +5752,8 @@ ImVec2 ImFontCalcTextSizeEx(ImFont* font, float size, float max_width, float wra
if (char_width < 0.0f)
char_width = BuildLoadGlyphGetAdvanceOrFallback(baked, c);
char_width *= scale;
if (prev_c && font->KerningFn)
char_width += font->KerningFn(font, prev_c, (ImWchar)c, size, font->KerningUserData);
if (line_width + char_width >= max_width)
{
@ -5757,6 +5762,7 @@ ImVec2 ImFontCalcTextSizeEx(ImFont* font, float size, float max_width, float wra
}
line_width += char_width;
prev_c = (ImWchar)c;
}
if (text_size.x < line_width)
@ -5900,6 +5906,7 @@ begin:
const ImU32 col_untinted = col | ~IM_COL32_A_MASK;
const char* word_wrap_eol = NULL;
ImWchar prev_c = 0;
while (s < text_end)
{
@ -5913,6 +5920,7 @@ begin:
{
x = origin_x;
y += line_height;
prev_c = 0;
if (y > clip_rect.w)
break; // break out of main loop
word_wrap_eol = NULL;
@ -5934,6 +5942,7 @@ begin:
{
x = origin_x;
y += line_height;
prev_c = 0;
if (y > clip_rect.w)
break; // break out of main loop
continue;
@ -5946,6 +5955,8 @@ begin:
//if (glyph == NULL)
// continue;
if (prev_c && KerningFn)
x += KerningFn(this, prev_c, (ImWchar)c, size, KerningUserData);
float char_width = glyph->AdvanceX * scale;
if (glyph->Visible)
{
@ -5988,6 +5999,7 @@ begin:
if (y1 >= y2)
{
x += char_width;
prev_c = (ImWchar)c;
continue;
}
}
@ -6010,6 +6022,7 @@ begin:
}
}
x += char_width;
prev_c = (ImWchar)c;
}
// Edge case: calling RenderText() with unloaded glyphs triggering texture change. It doesn't happen via ImGui:: calls because CalcTextSize() is always used.