Skip to content

Commit

Permalink
win32: Fix average font width
Browse files Browse the repository at this point in the history
It seems that some kind of font doesn't return the right value in
tmAveCharWidth by GetTextMetrics(). It returns about the double width of the
expected value. So the screen width becomes wider. This patch works around it
by calculating the average character size. (The same method has already been
used in another part of gui_w32.c.)
  • Loading branch information
k-takata committed May 7, 2019
1 parent 4fa0687 commit 98284ca
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/gui_w32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
GetTextExtentPoint(hdc,
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
52, &size);
gui.char_width = (size.cx / 26 + 1) / 2 + tm.tmOverhang;

gui.char_height = tm.tmHeight + p_linespace;

Expand Down

0 comments on commit 98284ca

Please sign in to comment.