Hi,
2014/1/1 Wed 1:36:51 UTC+9 Bram Moolenaar wrote:
> Ken Takata wrote:
>
> > Hi,
> >
> > I wrote a patch to fix an issue from the todo.txt:
> >
> > > 8 non-ASCII font names don't work. Need to convert from 'encoding' and
> > > use
> > > the wide functions.
> >
> > How to reproduce:
> >
> > > gvim -u NONE -U NONE --cmd "set enc=utf-8"
> > :set guifont=* " Select a non-ASCII font name. E.g. ' $B#M#S (B $B%4%7%C%/
> > (B'.
> > :set guifont " The selected font name is not shown properly.
> > :set guifont= $B#M#S (B_ $B%4%7%C%/ (B:h11:cSHIFTJIS " Error occurs.
> >
> >
> > This patch still uses ANSI functions, not wide functions, and just converts
> > font names from 'encoding' to the current codepage. So a font name which
> > can not be handled by the current codepage can not be used even if this
> > patch is applied. Currently, this is a limitation. (Maybe hundreds of
> > lines should be changed when using wide functions.)
>
> Thanks. I'll move it up in the todo list.
I found that my previous patch causes a warning when compiled with GCC.
I have updated the patch.
Regards,
Ken Takata
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
# HG changeset patch
# Parent 21728c86c34920c171585a8a994832e800786c0e
diff --git a/src/gui_w48.c b/src/gui_w48.c
--- a/src/gui_w48.c
+++ b/src/gui_w48.c
@@ -3090,15 +3090,26 @@
char *p;
char *res;
char *charset_name;
+ char *font_name = lf.lfFaceName;
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)));
if (res != NULL)
{
p = res;
/* 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));
while (*p)
{
@@ -3123,6 +3134,10 @@
}
}
+#ifdef FEAT_MBYTE
+ if (font_name != lf.lfFaceName)
+ vim_free(font_name);
+#endif
return res;
}
diff --git a/src/os_mswin.c b/src/os_mswin.c
--- a/src/os_mswin.c
+++ b/src/os_mswin.c
@@ -2854,12 +2854,27 @@
{
char_u *p;
int i;
+ int ret = FAIL;
static LOGFONT *lastlf = NULL;
+#ifdef FEAT_MBYTE
+ char_u *acpname = NULL;
+#endif
*lf = s_lfDefault;
if (name == NULL)
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 defined(FEAT_GUI_W32)
@@ -2874,10 +2889,9 @@
cf.lpLogFont = lf;
cf.nFontType = 0 ; //REGULAR_FONTTYPE;
if (ChooseFont(&cf))
- goto theend;
-#else
- return FAIL;
+ ret = OK;
#endif
+ goto theend;
}
/*
@@ -2886,7 +2900,7 @@
for (p = name; *p && *p != ':'; p++)
{
if (p - name + 1 > LF_FACESIZE)
- return FAIL; /* Name too long */
+ goto theend; /* Name too long */
lf->lfFaceName[p - name] = *p;
}
if (p != name)
@@ -2914,7 +2928,7 @@
did_replace = TRUE;
}
if (!did_replace || init_logfont(lf) == FAIL)
- return FAIL;
+ goto theend;
}
while (*p == ':')
@@ -2975,25 +2989,27 @@
p[-1], name);
EMSG(IObuff);
}
- return FAIL;
+ goto theend;
}
while (*p == ':')
p++;
}
-
-#if defined(FEAT_GUI_W32)
+ ret = OK;
+
theend:
-#endif
/* ron: init lastlf */
- if (printer_dc == NULL)
+ if (ret == OK && printer_dc == NULL)
{
vim_free(lastlf);
lastlf = (LOGFONT *)alloc(sizeof(LOGFONT));
if (lastlf != NULL)
mch_memmove(lastlf, lf, sizeof(LOGFONT));
}
-
- return OK;
+#ifdef FEAT_MBYTE
+ vim_free(acpname);
+#endif
+
+ return ret;
}
#endif /* defined(FEAT_GUI) || defined(FEAT_PRINTER) */
diff --git a/src/proto/winclip.pro b/src/proto/winclip.pro
--- a/src/proto/winclip.pro
+++ b/src/proto/winclip.pro
@@ -11,4 +11,5 @@
short_u *enc_to_utf16 __ARGS((char_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 enc_to_acp __ARGS((char_u *str, int str_size, char_u **out, int *outlen));
/* vim: set ft=c : */
diff --git a/src/winclip.c b/src/winclip.c
--- a/src/winclip.c
+++ b/src/winclip.c
@@ -797,4 +797,29 @@
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