Mercurial > vim
diff src/gui_w32.c @ 16582:9a7d98e11954 v8.1.1294
patch 8.1.1294: MS-Windows: Some fonts return wrong average char width
commit https://github.com/vim/vim/commit/93d77b2cbec08518ee426d0c44c50cf505732443
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 7 22:52:50 2019 +0200
patch 8.1.1294: MS-Windows: Some fonts return wrong average char width
Problem: MS-Windows: Some fonts return wrong average char width.
Solution: Compute the average ourselves. (Ken Takata, closes https://github.com/vim/vim/issues/4356)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 07 May 2019 23:00:06 +0200 |
parents | 045ab97fe320 |
children | 2f86ca0c1e6b |
line wrap: on
line diff
--- a/src/gui_w32.c +++ b/src/gui_w32.c @@ -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;