From b475309fa1e9d7a91825a169e243f9c4fa085f71 Mon Sep 17 00:00:00 2001 From: GamingMinds-DanielC Date: Thu, 14 Mar 2024 14:58:32 +0100 Subject: [PATCH] Fonts: Fixed font ascent and descent calculation when a font hits exact integer values. (#7399, #7404) --- docs/CHANGELOG.txt | 5 ++++- imgui_draw.cpp | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 189c9f5c..e4af7859 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -43,8 +43,11 @@ Breaking changes: Other changes: +- Fonts: Fixed font ascent and descent calculation when a font hits exact integer values. + It is possible that some prior manual use of ImFontConfig::GlyphOffset may become + duplicate with this fix. (#7399, #7404) [@GamingMinds-DanielC] - Text, DrawList: Improved handling of long single-line wrapped text. Faster and - mitigitate issues with reading vertex indexing limits with 16-bit indices. + mitigitate issues with reading vertex indexing limits with 16-bit indices. (#7496, #5720) - Backends: SDL3: Fixed text inputs. Re-enable calling SDL_StartTextInput()/SDL_StopTextInput() as SDL3 no longer enables it by default. (#7452, #6306, #6071, #1953) [@Green-Sky] diff --git a/imgui_draw.cpp b/imgui_draw.cpp index f3da3851..7861d4e2 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2984,8 +2984,8 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) int unscaled_ascent, unscaled_descent, unscaled_line_gap; stbtt_GetFontVMetrics(&src_tmp.FontInfo, &unscaled_ascent, &unscaled_descent, &unscaled_line_gap); - const float ascent = ImTrunc(unscaled_ascent * font_scale + ((unscaled_ascent > 0.0f) ? +1 : -1)); - const float descent = ImTrunc(unscaled_descent * font_scale + ((unscaled_descent > 0.0f) ? +1 : -1)); + const float ascent = ImCeil(unscaled_ascent * font_scale); + const float descent = ImFloor(unscaled_descent * font_scale); ImFontAtlasBuildSetupFont(atlas, dst_font, &cfg, ascent, descent); const float font_off_x = cfg.GlyphOffset.x; const float font_off_y = cfg.GlyphOffset.y + IM_ROUND(dst_font->Ascent);