From: Char Date: Sun, 15 Feb 2026 16:27:52 +0000 (+0000) Subject: patch 9.2.0008: MS-Windows: font size calculation may be wrong X-Git-Tag: v9.2.0008^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13223921e0e80e5ecd472e4db4cba60301b03530;p=thirdparty%2Fvim.git patch 9.2.0008: MS-Windows: font size calculation may be wrong Problem: MS-Windows: font size calculation may be wrong when font does not specify a valid ascent value. (Char, after v9.1.2129) Solution: Calculate ascent as a ratio of ascent to total font height with a fallback if metrics are zero. Fallback to default value when font does not specify ascent value. As proposed in https://github.com/vim/vim/pull/19318#issuecomment-3864669253 related: #19318 closes: #19367 Signed-off-by: Char Signed-off-by: Christian Brabandt --- diff --git a/src/gui_dwrite.cpp b/src/gui_dwrite.cpp index 39a39938b8..c71358717a 100644 --- a/src/gui_dwrite.cpp +++ b/src/gui_dwrite.cpp @@ -865,8 +865,14 @@ DWriteContext::CreateTextFormatFromLOGFONT(const LOGFONTW &logFont, { *ppTextFormat = pTextFormat; if (pFontAscent != NULL && fontMetrics.designUnitsPerEm != 0) - *pFontAscent = fontSize * float(fontMetrics.ascent) - / float(fontMetrics.designUnitsPerEm); + { + // Calculate ascent ratio (0.0 to 1.0) relative to total font height + FLOAT totalHeight = float(fontMetrics.ascent + fontMetrics.descent); + if (totalHeight != 0.0f) + *pFontAscent = float(fontMetrics.ascent) / totalHeight; + else + *pFontAscent = 0.83f; // fallback + } } else SafeRelease(&pTextFormat); @@ -1086,7 +1092,7 @@ DWriteContext::DrawText(const WCHAR *text, int len, // font fallback, the metrics change). // Use the pre-calculated font ascent for all text to prevent // vertical shifts during redraw. - FLOAT baselineY = FLOAT(y) + mFontAscent; + FLOAT baselineY = roundf(FLOAT(y) + FLOAT(h) * mFontAscent + 0.5); TextRenderer renderer(this); TextRendererContext context = { color, FLOAT(cellWidth), lpDx, len, diff --git a/src/version.c b/src/version.c index 0b693e562c..7615dbdb34 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 8, /**/ 7, /**/