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;