]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0008: MS-Windows: font size calculation may be wrong v9.2.0008
authorChar <peacech@gmail.com>
Sun, 15 Feb 2026 16:27:52 +0000 (16:27 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 15 Feb 2026 16:27:52 +0000 (16:27 +0000)
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 <peacech@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/gui_dwrite.cpp
src/version.c

index 39a39938b84b72a07b5f6606e30e9a47f626886a..c71358717ab1de383c2184c3636d82dbf8cb94aa 100644 (file)
@@ -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,
index 0b693e562ce65629de868a7e0e8ca7f74393481a..7615dbdb34d59fd7d1ce80c20d54ca328be638c9 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    8,
 /**/
     7,
 /**/