summaryrefslogtreecommitdiffstats
path: root/src/gui_w32.c
diff options
context:
space:
mode:
authorK.Takata <kentkt@csc.jp>2022-01-23 16:25:17 +0000
committerBram Moolenaar <Bram@vim.org>2022-01-23 16:25:17 +0000
commitabe628e1bd92ecb85a526348f376891d56bf3ea8 (patch)
treeab7624beed8b64a835e5530cf4379b9daea6ca45 /src/gui_w32.c
parentf4e88f2152c5975a6f4cfa7ccd745575fe4d1c78 (diff)
patch 8.2.4194: MS-Windows: code for calculating font size is duplicatedv8.2.4194
Problem: MS-Windows: code for calculating font size is duplicated. Solution: Move the code to a function. (Ken Takata, closes #9603)
Diffstat (limited to 'src/gui_w32.c')
-rw-r--r--src/gui_w32.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/gui_w32.c b/src/gui_w32.c
index 061319177b..50ea8f9cd1 100644
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -1511,6 +1511,20 @@ update_scrollbar_size(void)
}
/*
+ * Get the average character size of a font.
+ */
+ static void
+GetAverageFontSize(HDC hdc, SIZE *size)
+{
+ // GetTextMetrics() may not return the right value in tmAveCharWidth
+ // for some fonts. Do our own average computation.
+ GetTextExtentPoint(hdc,
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
+ 52, size);
+ size->cx = (size->cx / 26 + 1) / 2;
+}
+
+/*
* Get the character size of a font.
*/
static void
@@ -1523,13 +1537,9 @@ GetFontSize(GuiFont font)
TEXTMETRIC tm;
GetTextMetrics(hdc, &tm);
- // 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;
+ GetAverageFontSize(hdc, &size);
+ gui.char_width = size.cx + tm.tmOverhang;
gui.char_height = tm.tmHeight + p_linespace;
SelectFont(hdc, hfntOld);
@@ -7563,17 +7573,10 @@ get_dialog_font_metrics(void)
hdc = GetDC(s_hwnd);
SelectObject(hdc, hfontTools);
- /*
- * GetTextMetrics() doesn't return the right value in
- * tmAveCharWidth, so we have to figure out the dialog base units
- * ourselves.
- */
- GetTextExtentPoint(hdc,
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
- 52, &size);
+ GetAverageFontSize(hdc, &size);
ReleaseDC(s_hwnd, hdc);
- s_dlgfntwidth = (WORD)((size.cx / 26 + 1) / 2);
+ s_dlgfntwidth = (WORD)size.cx;
s_dlgfntheight = (WORD)size.cy;
}