0
0
mirror of https://github.com/vim/vim.git synced 2025-10-05 05:34:07 -04:00

patch 8.1.1081: MS-Windows: cannot use some fonts

Problem:    MS-Windows: cannot use fonts whose name cannot be represented in
            the current code page.
Solution:   Use wide font functions. (Ken Takata, closes #4000)
This commit is contained in:
Bram Moolenaar
2019-03-30 16:24:16 +01:00
parent ef7f0e367e
commit 433a5eb9de
5 changed files with 132 additions and 120 deletions

View File

@@ -253,7 +253,7 @@ typedef int HBITMAP;
typedef int HBRUSH;
typedef int HDROP;
typedef int INT;
typedef int LOGFONT[];
typedef int LOGFONTW[];
typedef int LPARAM;
typedef int LPCREATESTRUCT;
typedef int LPCSTR;
@@ -501,15 +501,15 @@ static void TrackUserActivity(UINT uMsg);
/*
* For control IME.
*
* These LOGFONT used for IME.
* These LOGFONTW used for IME.
*/
#if defined(FEAT_MBYTE_IME) || defined(GLOBAL_IME)
/* holds LOGFONT for 'guifontwide' if available, otherwise 'guifont' */
static LOGFONT norm_logfont;
/* holds LOGFONTW for 'guifontwide' if available, otherwise 'guifont' */
static LOGFONTW norm_logfont;
#endif
#ifdef FEAT_MBYTE_IME
/* holds LOGFONT for 'guifont' always. */
static LOGFONT sub_logfont;
/* holds LOGFONTW for 'guifont' always. */
static LOGFONTW sub_logfont;
#endif
#ifdef FEAT_MBYTE_IME
@@ -1520,12 +1520,12 @@ gui_mch_adjust_charheight(void)
}
static GuiFont
get_font_handle(LOGFONT *lf)
get_font_handle(LOGFONTW *lf)
{
HFONT font = NULL;
/* Load the font */
font = CreateFontIndirect(lf);
font = CreateFontIndirectW(lf);
if (font == NULL)
return NOFONT;
@@ -1556,7 +1556,7 @@ gui_mch_get_font(
char_u *name,
int giveErrorIfMissing)
{
LOGFONT lf;
LOGFONTW lf;
GuiFont font = NOFONT;
if (get_logfont(&lf, name, NULL, giveErrorIfMissing) == OK)
@@ -3201,23 +3201,18 @@ gui_mch_exit(int rc UNUSED)
}
static char_u *
logfont2name(LOGFONT lf)
logfont2name(LOGFONTW lf)
{
char *p;
char *res;
char *charset_name;
char *quality_name;
char *font_name = lf.lfFaceName;
char *font_name;
font_name = (char *)utf16_to_enc(lf.lfFaceName, NULL);
if (font_name == NULL)
return NULL;
charset_name = charset_id2name((int)lf.lfCharSet);
/* Convert a font name from the current codepage to 'encoding'.
* TODO: Use Wide APIs (including LOGFONTW) instead of ANSI APIs. */
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
{
int len;
acp_to_enc((char_u *)lf.lfFaceName, (int)strlen(lf.lfFaceName),
(char_u **)&font_name, &len);
}
quality_name = quality_id2name((int)lf.lfQuality);
res = (char *)alloc((unsigned)(strlen(font_name) + 20
@@ -3254,25 +3249,24 @@ logfont2name(LOGFONT lf)
}
}
if (font_name != lf.lfFaceName)
vim_free(font_name);
vim_free(font_name);
return (char_u *)res;
}
#ifdef FEAT_MBYTE_IME
/*
* Set correct LOGFONT to IME. Use 'guifontwide' if available, otherwise use
* Set correct LOGFONTW to IME. Use 'guifontwide' if available, otherwise use
* 'guifont'
*/
static void
update_im_font(void)
{
LOGFONT lf_wide;
LOGFONTW lf_wide;
if (p_guifontwide != NULL && *p_guifontwide != NUL
&& gui.wide_font != NOFONT
&& GetObject((HFONT)gui.wide_font, sizeof(lf_wide), &lf_wide))
&& GetObjectW((HFONT)gui.wide_font, sizeof(lf_wide), &lf_wide))
norm_logfont = lf_wide;
else
norm_logfont = sub_logfont;
@@ -3286,7 +3280,7 @@ update_im_font(void)
void
gui_mch_wide_font_changed(void)
{
LOGFONT lf;
LOGFONTW lf;
#ifdef FEAT_MBYTE_IME
update_im_font();
@@ -3300,7 +3294,7 @@ gui_mch_wide_font_changed(void)
gui.wide_boldital_font = NOFONT;
if (gui.wide_font
&& GetObject((HFONT)gui.wide_font, sizeof(lf), &lf))
&& GetObjectW((HFONT)gui.wide_font, sizeof(lf), &lf))
{
if (!lf.lfItalic)
{
@@ -3328,7 +3322,7 @@ gui_mch_wide_font_changed(void)
int
gui_mch_init_font(char_u *font_name, int fontset UNUSED)
{
LOGFONT lf;
LOGFONTW lf;
GuiFont font = NOFONT;
char_u *p;
@@ -4225,8 +4219,8 @@ static HIMC (WINAPI *pImmAssociateContext)(HWND, HIMC);
static BOOL (WINAPI *pImmReleaseContext)(HWND, HIMC);
static BOOL (WINAPI *pImmGetOpenStatus)(HIMC);
static BOOL (WINAPI *pImmSetOpenStatus)(HIMC, BOOL);
static BOOL (WINAPI *pImmGetCompositionFont)(HIMC, LPLOGFONTA);
static BOOL (WINAPI *pImmSetCompositionFont)(HIMC, LPLOGFONTA);
static BOOL (WINAPI *pImmGetCompositionFontW)(HIMC, LPLOGFONTW);
static BOOL (WINAPI *pImmSetCompositionFontW)(HIMC, LPLOGFONTW);
static BOOL (WINAPI *pImmSetCompositionWindow)(HIMC, LPCOMPOSITIONFORM);
static BOOL (WINAPI *pImmGetConversionStatus)(HIMC, LPDWORD, LPDWORD);
static BOOL (WINAPI *pImmSetConversionStatus)(HIMC, DWORD, DWORD);
@@ -4239,8 +4233,8 @@ static void dyn_imm_load(void);
# define pImmReleaseContext ImmReleaseContext
# define pImmGetOpenStatus ImmGetOpenStatus
# define pImmSetOpenStatus ImmSetOpenStatus
# define pImmGetCompositionFont ImmGetCompositionFontA
# define pImmSetCompositionFont ImmSetCompositionFontA
# define pImmGetCompositionFontW ImmGetCompositionFontW
# define pImmSetCompositionFontW ImmSetCompositionFontW
# define pImmSetCompositionWindow ImmSetCompositionWindow
# define pImmGetConversionStatus ImmGetConversionStatus
# define pImmSetConversionStatus ImmSetConversionStatus
@@ -4379,14 +4373,14 @@ _OnMouseWheel(
* Return OK or FAIL.
*/
static int
gui_w32_get_menu_font(LOGFONT *lf)
gui_w32_get_menu_font(LOGFONTW *lf)
{
NONCLIENTMETRICS nm;
NONCLIENTMETRICSW nm;
nm.cbSize = sizeof(NONCLIENTMETRICS);
if (!SystemParametersInfo(
nm.cbSize = sizeof(NONCLIENTMETRICSW);
if (!SystemParametersInfoW(
SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS),
sizeof(NONCLIENTMETRICSW),
&nm,
0))
return FAIL;
@@ -4403,7 +4397,7 @@ gui_w32_get_menu_font(LOGFONT *lf)
static void
set_tabline_font(void)
{
LOGFONT lfSysmenu;
LOGFONTW lfSysmenu;
HFONT font;
HWND hwnd;
HDC hdc;
@@ -4413,7 +4407,7 @@ set_tabline_font(void)
if (gui_w32_get_menu_font(&lfSysmenu) != OK)
return;
font = CreateFontIndirect(&lfSysmenu);
font = CreateFontIndirectW(&lfSysmenu);
SendMessage(s_tabhwnd, WM_SETFONT, (WPARAM)font, TRUE);
@@ -5562,7 +5556,7 @@ _OnImeNotify(HWND hWnd, DWORD dwCommand, DWORD dwData UNUSED)
case IMN_SETOPENSTATUS:
if (pImmGetOpenStatus(hImc))
{
pImmSetCompositionFont(hImc, &norm_logfont);
pImmSetCompositionFontW(hImc, &norm_logfont);
im_set_position(gui.row, gui.col);
/* Disable langmap */
@@ -5703,13 +5697,13 @@ GetResultStr(HWND hwnd, int GCS, int *lenp)
* set font to IM.
*/
void
im_set_font(LOGFONT *lf)
im_set_font(LOGFONTW *lf)
{
HIMC hImc;
if (pImmGetContext && (hImc = pImmGetContext(s_hwnd)) != (HIMC)0)
{
pImmSetCompositionFont(hImc, lf);
pImmSetCompositionFontW(hImc, lf);
pImmReleaseContext(s_hwnd, hImc);
}
}
@@ -6829,7 +6823,7 @@ gui_mch_dialog(
int dlgPaddingX;
int dlgPaddingY;
#ifdef USE_SYSMENU_FONT
LOGFONT lfSysmenu;
LOGFONTW lfSysmenu;
int use_lfSysmenu = FALSE;
#endif
garray_T ga;
@@ -6894,7 +6888,7 @@ gui_mch_dialog(
#ifdef USE_SYSMENU_FONT
if (gui_w32_get_menu_font(&lfSysmenu) == OK)
{
font = CreateFontIndirect(&lfSysmenu);
font = CreateFontIndirectW(&lfSysmenu);
use_lfSysmenu = TRUE;
}
else
@@ -7123,7 +7117,8 @@ gui_mch_dialog(
/* point size */
*p++ = -MulDiv(lfSysmenu.lfHeight, 72,
GetDeviceCaps(hdc, LOGPIXELSY));
nchar = nCopyAnsiToWideChar(p, lfSysmenu.lfFaceName, FALSE);
wcscpy(p, lfSysmenu.lfFaceName);
nchar = (int)wcslen(lfSysmenu.lfFaceName) + 1;
}
else
#endif
@@ -7488,14 +7483,14 @@ get_dialog_font_metrics(void)
DWORD dlgFontSize;
SIZE size;
#ifdef USE_SYSMENU_FONT
LOGFONT lfSysmenu;
LOGFONTW lfSysmenu;
#endif
s_usenewlook = FALSE;
#ifdef USE_SYSMENU_FONT
if (gui_w32_get_menu_font(&lfSysmenu) == OK)
hfontTools = CreateFontIndirect(&lfSysmenu);
hfontTools = CreateFontIndirectW(&lfSysmenu);
else
#endif
hfontTools = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0,
@@ -7563,7 +7558,7 @@ gui_mch_tearoff(
int x;
int y;
#ifdef USE_SYSMENU_FONT
LOGFONT lfSysmenu;
LOGFONTW lfSysmenu;
int use_lfSysmenu = FALSE;
#endif
@@ -7599,7 +7594,7 @@ gui_mch_tearoff(
#ifdef USE_SYSMENU_FONT
if (gui_w32_get_menu_font(&lfSysmenu) == OK)
{
font = CreateFontIndirect(&lfSysmenu);
font = CreateFontIndirectW(&lfSysmenu);
use_lfSysmenu = TRUE;
}
else
@@ -7708,7 +7703,8 @@ gui_mch_tearoff(
/* point size */
*p++ = -MulDiv(lfSysmenu.lfHeight, 72,
GetDeviceCaps(hdc, LOGPIXELSY));
nchar = nCopyAnsiToWideChar(p, lfSysmenu.lfFaceName, FALSE);
wcscpy(p, lfSysmenu.lfFaceName);
nchar = (int)wcslen(lfSysmenu.lfFaceName) + 1;
}
else
#endif
@@ -8136,10 +8132,10 @@ dyn_imm_load(void)
= (void *)GetProcAddress(hLibImm, "ImmGetOpenStatus");
pImmSetOpenStatus
= (void *)GetProcAddress(hLibImm, "ImmSetOpenStatus");
pImmGetCompositionFont
= (void *)GetProcAddress(hLibImm, "ImmGetCompositionFontA");
pImmSetCompositionFont
= (void *)GetProcAddress(hLibImm, "ImmSetCompositionFontA");
pImmGetCompositionFontW
= (void *)GetProcAddress(hLibImm, "ImmGetCompositionFontW");
pImmSetCompositionFontW
= (void *)GetProcAddress(hLibImm, "ImmSetCompositionFontW");
pImmSetCompositionWindow
= (void *)GetProcAddress(hLibImm, "ImmSetCompositionWindow");
pImmGetConversionStatus
@@ -8154,8 +8150,8 @@ dyn_imm_load(void)
|| pImmReleaseContext == NULL
|| pImmGetOpenStatus == NULL
|| pImmSetOpenStatus == NULL
|| pImmGetCompositionFont == NULL
|| pImmSetCompositionFont == NULL
|| pImmGetCompositionFontW == NULL
|| pImmSetCompositionFontW == NULL
|| pImmSetCompositionWindow == NULL
|| pImmGetConversionStatus == NULL
|| pImmSetConversionStatus == NULL)