mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
updated for version 7.4.202
Problem: MS-Windows: non-ASCII font names don't work. Solution: Convert between the current code page and 'encoding'. (Ken Takata)
This commit is contained in:
@@ -3069,15 +3069,26 @@ logfont2name(LOGFONT lf)
|
|||||||
char *p;
|
char *p;
|
||||||
char *res;
|
char *res;
|
||||||
char *charset_name;
|
char *charset_name;
|
||||||
|
char *font_name = lf.lfFaceName;
|
||||||
|
|
||||||
charset_name = charset_id2name((int)lf.lfCharSet);
|
charset_name = charset_id2name((int)lf.lfCharSet);
|
||||||
res = alloc((unsigned)(strlen(lf.lfFaceName) + 20
|
#ifdef FEAT_MBYTE
|
||||||
|
/* 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(lf.lfFaceName, strlen(lf.lfFaceName),
|
||||||
|
(char_u **)&font_name, &len);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
res = alloc((unsigned)(strlen(font_name) + 20
|
||||||
+ (charset_name == NULL ? 0 : strlen(charset_name) + 2)));
|
+ (charset_name == NULL ? 0 : strlen(charset_name) + 2)));
|
||||||
if (res != NULL)
|
if (res != NULL)
|
||||||
{
|
{
|
||||||
p = res;
|
p = res;
|
||||||
/* make a normal font string out of the lf thing:*/
|
/* make a normal font string out of the lf thing:*/
|
||||||
sprintf((char *)p, "%s:h%d", lf.lfFaceName, pixels_to_points(
|
sprintf((char *)p, "%s:h%d", font_name, pixels_to_points(
|
||||||
lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight, TRUE));
|
lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight, TRUE));
|
||||||
while (*p)
|
while (*p)
|
||||||
{
|
{
|
||||||
@@ -3102,6 +3113,10 @@ logfont2name(LOGFONT lf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef FEAT_MBYTE
|
||||||
|
if (font_name != lf.lfFaceName)
|
||||||
|
vim_free(font_name);
|
||||||
|
#endif
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2867,12 +2867,27 @@ get_logfont(
|
|||||||
{
|
{
|
||||||
char_u *p;
|
char_u *p;
|
||||||
int i;
|
int i;
|
||||||
|
int ret = FAIL;
|
||||||
static LOGFONT *lastlf = NULL;
|
static LOGFONT *lastlf = NULL;
|
||||||
|
#ifdef FEAT_MBYTE
|
||||||
|
char_u *acpname = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
*lf = s_lfDefault;
|
*lf = s_lfDefault;
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
|
#ifdef FEAT_MBYTE
|
||||||
|
/* Convert 'name' from 'encoding' to the current codepage, because
|
||||||
|
* lf->lfFaceName uses the current codepage.
|
||||||
|
* TODO: Use Wide APIs instead of ANSI APIs. */
|
||||||
|
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
enc_to_acp(name, strlen(name), &acpname, &len);
|
||||||
|
name = acpname;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (STRCMP(name, "*") == 0)
|
if (STRCMP(name, "*") == 0)
|
||||||
{
|
{
|
||||||
#if defined(FEAT_GUI_W32)
|
#if defined(FEAT_GUI_W32)
|
||||||
@@ -2887,10 +2902,9 @@ get_logfont(
|
|||||||
cf.lpLogFont = lf;
|
cf.lpLogFont = lf;
|
||||||
cf.nFontType = 0 ; //REGULAR_FONTTYPE;
|
cf.nFontType = 0 ; //REGULAR_FONTTYPE;
|
||||||
if (ChooseFont(&cf))
|
if (ChooseFont(&cf))
|
||||||
goto theend;
|
ret = OK;
|
||||||
#else
|
|
||||||
return FAIL;
|
|
||||||
#endif
|
#endif
|
||||||
|
goto theend;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2899,7 +2913,7 @@ get_logfont(
|
|||||||
for (p = name; *p && *p != ':'; p++)
|
for (p = name; *p && *p != ':'; p++)
|
||||||
{
|
{
|
||||||
if (p - name + 1 > LF_FACESIZE)
|
if (p - name + 1 > LF_FACESIZE)
|
||||||
return FAIL; /* Name too long */
|
goto theend; /* Name too long */
|
||||||
lf->lfFaceName[p - name] = *p;
|
lf->lfFaceName[p - name] = *p;
|
||||||
}
|
}
|
||||||
if (p != name)
|
if (p != name)
|
||||||
@@ -2927,7 +2941,7 @@ get_logfont(
|
|||||||
did_replace = TRUE;
|
did_replace = TRUE;
|
||||||
}
|
}
|
||||||
if (!did_replace || init_logfont(lf) == FAIL)
|
if (!did_replace || init_logfont(lf) == FAIL)
|
||||||
return FAIL;
|
goto theend;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*p == ':')
|
while (*p == ':')
|
||||||
@@ -2988,25 +3002,27 @@ get_logfont(
|
|||||||
p[-1], name);
|
p[-1], name);
|
||||||
EMSG(IObuff);
|
EMSG(IObuff);
|
||||||
}
|
}
|
||||||
return FAIL;
|
goto theend;
|
||||||
}
|
}
|
||||||
while (*p == ':')
|
while (*p == ':')
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
ret = OK;
|
||||||
|
|
||||||
#if defined(FEAT_GUI_W32)
|
|
||||||
theend:
|
theend:
|
||||||
#endif
|
|
||||||
/* ron: init lastlf */
|
/* ron: init lastlf */
|
||||||
if (printer_dc == NULL)
|
if (ret == OK && printer_dc == NULL)
|
||||||
{
|
{
|
||||||
vim_free(lastlf);
|
vim_free(lastlf);
|
||||||
lastlf = (LOGFONT *)alloc(sizeof(LOGFONT));
|
lastlf = (LOGFONT *)alloc(sizeof(LOGFONT));
|
||||||
if (lastlf != NULL)
|
if (lastlf != NULL)
|
||||||
mch_memmove(lastlf, lf, sizeof(LOGFONT));
|
mch_memmove(lastlf, lf, sizeof(LOGFONT));
|
||||||
}
|
}
|
||||||
|
#ifdef FEAT_MBYTE
|
||||||
|
vim_free(acpname);
|
||||||
|
#endif
|
||||||
|
|
||||||
return OK;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* defined(FEAT_GUI) || defined(FEAT_PRINTER) */
|
#endif /* defined(FEAT_GUI) || defined(FEAT_PRINTER) */
|
||||||
|
@@ -11,4 +11,5 @@ void clip_mch_set_selection __ARGS((VimClipboard *cbd));
|
|||||||
short_u *enc_to_utf16 __ARGS((char_u *str, int *lenp));
|
short_u *enc_to_utf16 __ARGS((char_u *str, int *lenp));
|
||||||
char_u *utf16_to_enc __ARGS((short_u *str, int *lenp));
|
char_u *utf16_to_enc __ARGS((short_u *str, int *lenp));
|
||||||
void acp_to_enc __ARGS((char_u *str, int str_size, char_u **out, int *outlen));
|
void acp_to_enc __ARGS((char_u *str, int str_size, char_u **out, int *outlen));
|
||||||
|
void enc_to_acp __ARGS((char_u *str, int str_size, char_u **out, int *outlen));
|
||||||
/* vim: set ft=c : */
|
/* vim: set ft=c : */
|
||||||
|
@@ -738,6 +738,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 */
|
||||||
|
/**/
|
||||||
|
202,
|
||||||
/**/
|
/**/
|
||||||
201,
|
201,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -797,4 +797,29 @@ acp_to_enc(str, str_size, out, outlen)
|
|||||||
vim_free(widestr);
|
vim_free(widestr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert from 'encoding' to the active codepage.
|
||||||
|
* Input is "str[str_size]".
|
||||||
|
* The result is in allocated memory: "out[outlen]". With terminating NUL.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
enc_to_acp(str, str_size, out, outlen)
|
||||||
|
char_u *str;
|
||||||
|
int str_size;
|
||||||
|
char_u **out;
|
||||||
|
int *outlen;
|
||||||
|
|
||||||
|
{
|
||||||
|
LPWSTR widestr;
|
||||||
|
int len = str_size;
|
||||||
|
|
||||||
|
widestr = (WCHAR *)enc_to_utf16(str, &len);
|
||||||
|
if (widestr != NULL)
|
||||||
|
{
|
||||||
|
WideCharToMultiByte_alloc(GetACP(), 0, widestr, len,
|
||||||
|
(LPSTR *)out, outlen, 0, 0);
|
||||||
|
vim_free(widestr);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user