mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 9.0.1987: win32: font-size calculation can be improved
Problem: win32: font-size calculation can be improved Solution: calculate font size before the window size Support calculating the new size even if a bitmap font is used. Calculate the new font size before actually change the Window size. closes: #13280 related: #11812, #13252 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Ken Takata <kentkt@csc.jp>
This commit is contained in:
parent
c661e11e9c
commit
da5da654de
@ -1588,7 +1588,7 @@ GetAverageFontSize(HDC hdc, SIZE *size)
|
|||||||
* Get the character size of a font.
|
* Get the character size of a font.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
GetFontSize(GuiFont font)
|
GetFontSize(GuiFont font, int *char_width, int *char_height)
|
||||||
{
|
{
|
||||||
HWND hwnd = GetDesktopWindow();
|
HWND hwnd = GetDesktopWindow();
|
||||||
HDC hdc = GetWindowDC(hwnd);
|
HDC hdc = GetWindowDC(hwnd);
|
||||||
@ -1599,21 +1599,32 @@ GetFontSize(GuiFont font)
|
|||||||
GetTextMetrics(hdc, &tm);
|
GetTextMetrics(hdc, &tm);
|
||||||
GetAverageFontSize(hdc, &size);
|
GetAverageFontSize(hdc, &size);
|
||||||
|
|
||||||
gui.char_width = size.cx + tm.tmOverhang;
|
if (char_width)
|
||||||
gui.char_height = tm.tmHeight + p_linespace;
|
*char_width = size.cx + tm.tmOverhang;
|
||||||
|
if (char_height)
|
||||||
|
*char_height = tm.tmHeight + p_linespace;
|
||||||
|
|
||||||
SelectFont(hdc, hfntOld);
|
SelectFont(hdc, hfntOld);
|
||||||
|
|
||||||
ReleaseDC(hwnd, hdc);
|
ReleaseDC(hwnd, hdc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Update the character size in "gui" structure with the specified font.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
UpdateFontSize(GuiFont font)
|
||||||
|
{
|
||||||
|
GetFontSize(font, &gui.char_width, &gui.char_height);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adjust gui.char_height (after 'linespace' was changed).
|
* Adjust gui.char_height (after 'linespace' was changed).
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
gui_mch_adjust_charheight(void)
|
gui_mch_adjust_charheight(void)
|
||||||
{
|
{
|
||||||
GetFontSize(gui.norm_font);
|
UpdateFontSize(gui.norm_font);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3517,7 +3528,7 @@ gui_mch_init_font(char_u *font_name, int fontset UNUSED)
|
|||||||
gui_mch_free_font(gui.norm_font);
|
gui_mch_free_font(gui.norm_font);
|
||||||
gui.norm_font = font;
|
gui.norm_font = font;
|
||||||
current_font_height = lfOrig.lfHeight;
|
current_font_height = lfOrig.lfHeight;
|
||||||
GetFontSize(font);
|
UpdateFontSize(font);
|
||||||
|
|
||||||
p = logfont2name(lfOrig);
|
p = logfont2name(lfOrig);
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
@ -4742,16 +4753,33 @@ _OnMenuSelect(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|||||||
static BOOL
|
static BOOL
|
||||||
_OnGetDpiScaledSize(HWND hwnd, UINT dpi, SIZE *size)
|
_OnGetDpiScaledSize(HWND hwnd, UINT dpi, SIZE *size)
|
||||||
{
|
{
|
||||||
|
int old_width, old_height;
|
||||||
|
int new_width, new_height;
|
||||||
|
LOGFONTW lf;
|
||||||
|
HFONT font;
|
||||||
|
|
||||||
//TRACE("DPI: %d, SIZE=(%d,%d), s_dpi: %d", dpi, size->cx, size->cy, s_dpi);
|
//TRACE("DPI: %d, SIZE=(%d,%d), s_dpi: %d", dpi, size->cx, size->cy, s_dpi);
|
||||||
|
|
||||||
// Calculate new approximate size.
|
// Calculate new approximate size.
|
||||||
// FIXME: If a bitmap font (e.g. FixedSys) is used, the font size may not
|
GetFontSize(gui.norm_font, &old_width, &old_height); // Current size
|
||||||
// be changed. In that case, the calculated size can be wrong.
|
GetObjectW((HFONT)gui.norm_font, sizeof(lf), &lf);
|
||||||
size->cx = size->cx * dpi / s_dpi;
|
lf.lfHeight = lf.lfHeight * (int)dpi / s_dpi;
|
||||||
size->cy = size->cy * dpi / s_dpi;
|
font = CreateFontIndirectW(&lf);
|
||||||
|
if (font)
|
||||||
|
{
|
||||||
|
GetFontSize((GuiFont)font, &new_width, &new_height); // New size
|
||||||
|
DeleteFont(font);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new_width = old_width;
|
||||||
|
new_height = old_height;
|
||||||
|
}
|
||||||
|
size->cx = size->cx * new_width / old_width;
|
||||||
|
size->cy = size->cy * new_height / old_height;
|
||||||
//TRACE("New approx. SIZE=(%d,%d)", size->cx, size->cy);
|
//TRACE("New approx. SIZE=(%d,%d)", size->cx, size->cy);
|
||||||
|
|
||||||
return FALSE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static LRESULT
|
static LRESULT
|
||||||
|
@ -704,6 +704,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1987,
|
||||||
/**/
|
/**/
|
||||||
1986,
|
1986,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user