changeset 27332:251cae25bb49 v8.2.4194

patch 8.2.4194: MS-Windows: code for calculating font size is duplicated Commit: https://github.com/vim/vim/commit/abe628e1bd92ecb85a526348f376891d56bf3ea8 Author: K.Takata <kentkt@csc.jp> Date: Sun Jan 23 16:25:17 2022 +0000 patch 8.2.4194: MS-Windows: code for calculating font size is duplicated Problem: MS-Windows: code for calculating font size is duplicated. Solution: Move the code to a function. (Ken Takata, closes https://github.com/vim/vim/issues/9603)
author Bram Moolenaar <Bram@vim.org>
date Sun, 23 Jan 2022 17:30:04 +0100
parents 4c48fffadb81
children 6782ee766b6c
files src/gui_w32.c src/version.c
diffstat 2 files changed, 21 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }
 
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4194,
+/**/
     4193,
 /**/
     4192,