patch 9.2.0008: MS-Windows: font size calculation may be wrong

Commit: 
https://github.com/vim/vim/commit/13223921e0e80e5ecd472e4db4cba60301b03530
Author: Char <[email protected]>
Date:   Sun Feb 15 16:27:52 2026 +0000

    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 <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/gui_dwrite.cpp b/src/gui_dwrite.cpp
index 39a39938b..c71358717 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 0b693e562..7615dbdb3 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,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1vrfF3-00DjDC-B5%40256bit.org.

Raspunde prin e-mail lui