comparison 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
comparison
equal deleted inserted replaced
16581:7838221c524a 16582:9a7d98e11954
1453 GetFontSize(GuiFont font) 1453 GetFontSize(GuiFont font)
1454 { 1454 {
1455 HWND hwnd = GetDesktopWindow(); 1455 HWND hwnd = GetDesktopWindow();
1456 HDC hdc = GetWindowDC(hwnd); 1456 HDC hdc = GetWindowDC(hwnd);
1457 HFONT hfntOld = SelectFont(hdc, (HFONT)font); 1457 HFONT hfntOld = SelectFont(hdc, (HFONT)font);
1458 SIZE size;
1458 TEXTMETRIC tm; 1459 TEXTMETRIC tm;
1459 1460
1460 GetTextMetrics(hdc, &tm); 1461 GetTextMetrics(hdc, &tm);
1461 gui.char_width = tm.tmAveCharWidth + tm.tmOverhang; 1462 // GetTextMetrics() may not return the right value in tmAveCharWidth
1463 // for some fonts. Do our own average computation.
1464 GetTextExtentPoint(hdc,
1465 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
1466 52, &size);
1467 gui.char_width = (size.cx / 26 + 1) / 2 + tm.tmOverhang;
1462 1468
1463 gui.char_height = tm.tmHeight + p_linespace; 1469 gui.char_height = tm.tmHeight + p_linespace;
1464 1470
1465 SelectFont(hdc, hfntOld); 1471 SelectFont(hdc, hfntOld);
1466 1472