Mirror of the Vim source from https://github.com/vim/vim
Revision | 251cae25bb4962ecf6b8cf2c7835b4d747e0af4f (tree) |
---|---|
Zeit | 2022-01-24 01:30:04 |
Autor | Bram Moolenaar <Bram@vim....> |
Commiter | Bram Moolenaar |
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
@@ -1511,6 +1511,20 @@ | ||
1511 | 1511 | } |
1512 | 1512 | |
1513 | 1513 | /* |
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 | +/* | |
1514 | 1528 | * Get the character size of a font. |
1515 | 1529 | */ |
1516 | 1530 | static void |
@@ -1523,13 +1537,9 @@ | ||
1523 | 1537 | TEXTMETRIC tm; |
1524 | 1538 | |
1525 | 1539 | 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; | |
1533 | 1543 | gui.char_height = tm.tmHeight + p_linespace; |
1534 | 1544 | |
1535 | 1545 | SelectFont(hdc, hfntOld); |
@@ -7563,17 +7573,10 @@ | ||
7563 | 7573 | |
7564 | 7574 | hdc = GetDC(s_hwnd); |
7565 | 7575 | 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); | |
7574 | 7577 | ReleaseDC(s_hwnd, hdc); |
7575 | 7578 | |
7576 | - s_dlgfntwidth = (WORD)((size.cx / 26 + 1) / 2); | |
7579 | + s_dlgfntwidth = (WORD)size.cx; | |
7577 | 7580 | s_dlgfntheight = (WORD)size.cy; |
7578 | 7581 | } |
7579 | 7582 |
@@ -751,6 +751,8 @@ | ||
751 | 751 | static int included_patches[] = |
752 | 752 | { /* Add new patch number below this line */ |
753 | 753 | /**/ |
754 | + 4194, | |
755 | +/**/ | |
754 | 756 | 4193, |
755 | 757 | /**/ |
756 | 758 | 4192, |