comparison src/gui_w32.c @ 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 574cd25f0962
children 41a940219183
comparison
equal deleted inserted replaced
27331:4c48fffadb81 27332:251cae25bb49
1509 gui.scrollbar_width = pGetSystemMetricsForDpi(SM_CXVSCROLL, s_dpi); 1509 gui.scrollbar_width = pGetSystemMetricsForDpi(SM_CXVSCROLL, s_dpi);
1510 gui.scrollbar_height = pGetSystemMetricsForDpi(SM_CYHSCROLL, s_dpi); 1510 gui.scrollbar_height = pGetSystemMetricsForDpi(SM_CYHSCROLL, s_dpi);
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 * Get the character size of a font. 1528 * Get the character size of a font.
1515 */ 1529 */
1516 static void 1530 static void
1517 GetFontSize(GuiFont font) 1531 GetFontSize(GuiFont font)
1518 { 1532 {
1521 HFONT hfntOld = SelectFont(hdc, (HFONT)font); 1535 HFONT hfntOld = SelectFont(hdc, (HFONT)font);
1522 SIZE size; 1536 SIZE size;
1523 TEXTMETRIC tm; 1537 TEXTMETRIC tm;
1524 1538
1525 GetTextMetrics(hdc, &tm); 1539 GetTextMetrics(hdc, &tm);
1526 // GetTextMetrics() may not return the right value in tmAveCharWidth 1540 GetAverageFontSize(hdc, &size);
1527 // for some fonts. Do our own average computation. 1541
1528 GetTextExtentPoint(hdc, 1542 gui.char_width = size.cx + tm.tmOverhang;
1529 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
1530 52, &size);
1531 gui.char_width = (size.cx / 26 + 1) / 2 + tm.tmOverhang;
1532
1533 gui.char_height = tm.tmHeight + p_linespace; 1543 gui.char_height = tm.tmHeight + p_linespace;
1534 1544
1535 SelectFont(hdc, hfntOld); 1545 SelectFont(hdc, hfntOld);
1536 1546
1537 ReleaseDC(hwnd, hdc); 1547 ReleaseDC(hwnd, hdc);
7561 hfontTools = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, 7571 hfontTools = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0,
7562 0, 0, 0, 0, VARIABLE_PITCH, DLG_FONT_NAME); 7572 0, 0, 0, 0, VARIABLE_PITCH, DLG_FONT_NAME);
7563 7573
7564 hdc = GetDC(s_hwnd); 7574 hdc = GetDC(s_hwnd);
7565 SelectObject(hdc, hfontTools); 7575 SelectObject(hdc, hfontTools);
7566 /* 7576 GetAverageFontSize(hdc, &size);
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);
7574 ReleaseDC(s_hwnd, hdc); 7577 ReleaseDC(s_hwnd, hdc);
7575 7578
7576 s_dlgfntwidth = (WORD)((size.cx / 26 + 1) / 2); 7579 s_dlgfntwidth = (WORD)size.cx;
7577 s_dlgfntheight = (WORD)size.cy; 7580 s_dlgfntheight = (WORD)size.cy;
7578 } 7581 }
7579 7582
7580 #if defined(FEAT_MENU) && defined(FEAT_TEAROFF) 7583 #if defined(FEAT_MENU) && defined(FEAT_TEAROFF)
7581 /* 7584 /*