]> granicus.if.org Git - vim/commitdiff
patch 8.1.1294: MS-Windows: Some fonts return wrong average char width v8.1.1294
authorBram Moolenaar <Bram@vim.org>
Tue, 7 May 2019 20:52:50 +0000 (22:52 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 7 May 2019 20:52:50 +0000 (22:52 +0200)
Problem:    MS-Windows: Some fonts return wrong average char width.
Solution:   Compute the average ourselves. (Ken Takata, closes #4356)

src/gui_w32.c
src/version.c

index 3914733d7846cea5e94f135be25f13f213fcbeff..7bea58e97c2c5afa6b9a134a25ecfd0618be8771 100644 (file)
@@ -1455,10 +1455,16 @@ GetFontSize(GuiFont font)
     HWND    hwnd = GetDesktopWindow();
     HDC            hdc = GetWindowDC(hwnd);
     HFONT   hfntOld = SelectFont(hdc, (HFONT)font);
+    SIZE    size;
     TEXTMETRIC tm;
 
     GetTextMetrics(hdc, &tm);
-    gui.char_width = tm.tmAveCharWidth + tm.tmOverhang;
+    // GetTextMetrics() may not return the right value in tmAveCharWidth
+    // for some fonts.  Do our own average computation.
+    GetTextExtentPoint(hdc,
+           "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
+           52, &size);
+    gui.char_width = (size.cx / 26 + 1) / 2 + tm.tmOverhang;
 
     gui.char_height = tm.tmHeight + p_linespace;
 
index 21292fe26bf0e3d622febecd7d7fa335e39085a5..06a7a5f687826c5026715441adb3f78dfa63320d 100644 (file)
@@ -767,6 +767,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1294,
 /**/
     1293,
 /**/