]> granicus.if.org Git - vim/commitdiff
patch 8.2.4194: MS-Windows: code for calculating font size is duplicated v8.2.4194
authorK.Takata <kentkt@csc.jp>
Sun, 23 Jan 2022 16:25:17 +0000 (16:25 +0000)
committerBram Moolenaar <Bram@vim.org>
Sun, 23 Jan 2022 16:25:17 +0000 (16:25 +0000)
Problem:    MS-Windows: code for calculating font size is duplicated.
Solution:   Move the code to a function. (Ken Takata, closes #9603)

src/gui_w32.c
src/version.c

index 061319177b222d0f00bfc7d4b6aa788c647753ff..50ea8f9cd1a54e1fc9c1cf91437a0069a59237e3 100644 (file)
@@ -1510,6 +1510,20 @@ update_scrollbar_size(void)
     gui.scrollbar_height = pGetSystemMetricsForDpi(SM_CYHSCROLL, s_dpi);
 }
 
+/*
+ * 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.
  */
@@ -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;
 }
 
index a5bb606e60bbe6bc1f8e7be17c04dbd2cf15a8d1..5eacff8af26d3e4e351d7e852e064dc517a2b6bd 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4194,
 /**/
     4193,
 /**/