summaryrefslogtreecommitdiffstats
path: root/src/gui_w48.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2004-12-12 11:33:30 +0000
committerBram Moolenaar <Bram@vim.org>2004-12-12 11:33:30 +0000
commitd8b0cf1cc5231e19116cc3208b680a07f842bfe9 (patch)
treeef1ddd7a76427ea943296528bce82c73d5c34a1d /src/gui_w48.c
parent293ee4d421cd55f4a3c014c1c26edf02f718cc83 (diff)
updated for version 7.0022
Diffstat (limited to 'src/gui_w48.c')
-rw-r--r--src/gui_w48.c112
1 files changed, 73 insertions, 39 deletions
diff --git a/src/gui_w48.c b/src/gui_w48.c
index 516d070eb3..b3948ce317 100644
--- a/src/gui_w48.c
+++ b/src/gui_w48.c
@@ -1240,14 +1240,29 @@ gui_mch_get_font(
int giveErrorIfMissing)
{
LOGFONT lf;
- GuiFont font;
+ GuiFont font = NOFONT;
- get_logfont(&lf, name, NULL);
- font = get_font_handle(&lf);
+ if (get_logfont(&lf, name, NULL, giveErrorIfMissing) == OK)
+ font = get_font_handle(&lf);
if (font == NOFONT && giveErrorIfMissing)
EMSG2(_(e_font), name);
return font;
}
+
+/*
+ * Return the name of font "font" in allocated memory.
+ * Don't know how to get the actual name, thus use the provided name.
+ */
+ char_u *
+gui_mch_get_fontname(font, name)
+ GuiFont font;
+ char_u *name;
+{
+ if (name == NULL)
+ return NULL;
+ return vim_strsave(name);
+}
+
void
gui_mch_free_font(GuiFont font)
{
@@ -2600,21 +2615,65 @@ gui_mch_exit(int rc)
#endif
}
+ static char_u *
+logfont2name(LOGFONT lf)
+{
+ char *p;
+ char *res;
+ char *charset_name;
+
+ charset_name = charset_id2name((int)lf.lfCharSet);
+ res = alloc((unsigned)(strlen(lf.lfFaceName) + 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(
+ lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight, TRUE));
+ while (*p)
+ {
+ if (*p == ' ')
+ *p = '_';
+ ++p;
+ }
+#ifndef MSWIN16_FASTTEXT
+ if (lf.lfItalic)
+ STRCAT(p, ":i");
+ if (lf.lfWeight >= FW_BOLD)
+ STRCAT(p, ":b");
+#endif
+ if (lf.lfUnderline)
+ STRCAT(p, ":u");
+ if (lf.lfStrikeOut)
+ STRCAT(p, ":s");
+ if (charset_name != NULL)
+ {
+ STRCAT(p, ":c");
+ STRCAT(p, charset_name);
+ }
+ }
+
+ return res;
+}
+
/*
- * Initialise vim to use the font with the given name. Return FAIL if the font
- * could not be loaded, OK otherwise.
+ * Initialise vim to use the font with the given name.
+ * Return FAIL if the font could not be loaded, OK otherwise.
*/
int
gui_mch_init_font(char_u *font_name, int fontset)
{
LOGFONT lf;
GuiFont font = NOFONT;
+ char_u *p;
/* Load the font */
- if (get_logfont(&lf, font_name, NULL))
+ if (get_logfont(&lf, font_name, NULL, TRUE) == OK)
font = get_font_handle(&lf);
if (font == NOFONT)
return FAIL;
+
if (font_name == NULL)
font_name = lf.lfFaceName;
#if defined(FEAT_MBYTE_IME) || defined(GLOBAL_IME)
@@ -2627,46 +2686,21 @@ gui_mch_init_font(char_u *font_name, int fontset)
gui.norm_font = font;
current_font_height = lf.lfHeight;
GetFontSize(font);
- hl_set_font_name(lf.lfFaceName);
- /* When setting 'guifont' to "*" replace it with the actual font name. */
- if (STRCMP(font_name, "*") == 0 && STRCMP(p_guifont, "*") == 0)
+ p = logfont2name(lf);
+ if (p != NULL)
{
- char *charset_name;
- char_u *p;
+ hl_set_font_name(p);
- charset_name = charset_id2name((int)lf.lfCharSet);
- p = alloc((unsigned)(strlen(lf.lfFaceName) + 20
- + (charset_name == NULL ? 0 : strlen(charset_name) + 2)));
- if (p != NULL)
+ /* When setting 'guifont' to "*" replace it with the actual font name.
+ * */
+ if (STRCMP(font_name, "*") == 0 && STRCMP(p_guifont, "*") == 0)
{
- /* make a normal font string out of the lf thing:*/
- sprintf((char *)p, "%s:h%d", lf.lfFaceName, pixels_to_points(
- lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight, TRUE));
vim_free(p_guifont);
p_guifont = p;
- while (*p)
- {
- if (*p == ' ')
- *p = '_';
- ++p;
- }
-#ifndef MSWIN16_FASTTEXT
- if (lf.lfItalic)
- STRCAT(p, ":i");
- if (lf.lfWeight >= FW_BOLD)
- STRCAT(p, ":b");
-#endif
- if (lf.lfUnderline)
- STRCAT(p, ":u");
- if (lf.lfStrikeOut)
- STRCAT(p, ":s");
- if (charset_name != NULL)
- {
- STRCAT(p, ":c");
- STRCAT(p, charset_name);
- }
}
+ else
+ vim_free(p);
}
#ifndef MSWIN16_FASTTEXT