• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revision251cae25bb4962ecf6b8cf2c7835b4d747e0af4f (tree)
Zeit2022-01-24 01:30:04
AutorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

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)

Ändern Zusammenfassung

Diff

diff -r 4c48fffadb81 -r 251cae25bb49 src/gui_w32.c
--- a/src/gui_w32.c Sun Jan 23 15:30:04 2022 +0100
+++ b/src/gui_w32.c Sun Jan 23 17:30:04 2022 +0100
@@ -1511,6 +1511,20 @@
15111511 }
15121512
15131513 /*
1514+ * Get the average character size of a font.
1515+ */
1516+ static void
1517+GetAverageFontSize(HDC hdc, SIZE *size)
1518+{
1519+ // GetTextMetrics() may not return the right value in tmAveCharWidth
1520+ // for some fonts. Do our own average computation.
1521+ GetTextExtentPoint(hdc,
1522+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
1523+ 52, size);
1524+ size->cx = (size->cx / 26 + 1) / 2;
1525+}
1526+
1527+/*
15141528 * Get the character size of a font.
15151529 */
15161530 static void
@@ -1523,13 +1537,9 @@
15231537 TEXTMETRIC tm;
15241538
15251539 GetTextMetrics(hdc, &tm);
1526- // GetTextMetrics() may not return the right value in tmAveCharWidth
1527- // for some fonts. Do our own average computation.
1528- GetTextExtentPoint(hdc,
1529- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
1530- 52, &size);
1531- gui.char_width = (size.cx / 26 + 1) / 2 + tm.tmOverhang;
1532-
1540+ GetAverageFontSize(hdc, &size);
1541+
1542+ gui.char_width = size.cx + tm.tmOverhang;
15331543 gui.char_height = tm.tmHeight + p_linespace;
15341544
15351545 SelectFont(hdc, hfntOld);
@@ -7563,17 +7573,10 @@
75637573
75647574 hdc = GetDC(s_hwnd);
75657575 SelectObject(hdc, hfontTools);
7566- /*
7567- * GetTextMetrics() doesn't return the right value in
7568- * tmAveCharWidth, so we have to figure out the dialog base units
7569- * ourselves.
7570- */
7571- GetTextExtentPoint(hdc,
7572- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
7573- 52, &size);
7576+ GetAverageFontSize(hdc, &size);
75747577 ReleaseDC(s_hwnd, hdc);
75757578
7576- s_dlgfntwidth = (WORD)((size.cx / 26 + 1) / 2);
7579+ s_dlgfntwidth = (WORD)size.cx;
75777580 s_dlgfntheight = (WORD)size.cy;
75787581 }
75797582
diff -r 4c48fffadb81 -r 251cae25bb49 src/version.c
--- a/src/version.c Sun Jan 23 15:30:04 2022 +0100
+++ b/src/version.c Sun Jan 23 17:30:04 2022 +0100
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 4194,
755+/**/
754756 4193,
755757 /**/
756758 4192,
Show on old repository browser