From: Piotr Caban piotr@codeweavers.com
Otherwise, on systems with only Wine provided fonts, we end up selecting first non-vertical font. In case I'm trying to fix it happend to be marlett (symbol) font. --- programs/conhost/window.c | 79 ++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 47 deletions(-)
diff --git a/programs/conhost/window.c b/programs/conhost/window.c index ba96729314d..a3bd8a324e4 100644 --- a/programs/conhost/window.c +++ b/programs/conhost/window.c @@ -799,59 +799,48 @@ static BOOL set_console_font( struct console *console, const LOGFONTW *logfont ) struct font_chooser { struct console *console; - int pass; - unsigned int font_height; - unsigned int font_width; - BOOL done; + unsigned int best_score; + LOGFONTW lf; };
/* check if the font family described in lf is usable as a font for the renderer */ -static BOOL validate_font( struct console *console, const LOGFONTW *lf, const TEXTMETRICW *tm, int pass ) +static BOOL validate_font( struct console *console, const LOGFONTW *lf, const TEXTMETRICW *tm, int *score ) { - switch (pass) /* we get increasingly lenient in later passes */ - { - case 0: - if (lf->lfCharSet != DEFAULT_CHARSET && lf->lfCharSet != console->window->ui_charset) - return FALSE; - if (tm && tm->tmCharSet != DEFAULT_CHARSET && tm->tmCharSet != console->window->ui_charset) - return FALSE; - /* fall through */ - case 1: - if ((lf->lfPitchAndFamily & 3) != FIXED_PITCH) return FALSE; - if (tm && (tm->tmItalic || tm->tmUnderlined || tm->tmStruckOut)) return FALSE; - /* fall through */ - case 2: - if (lf->lfFaceName[0] == '@') return FALSE; - break; - } - return TRUE; + int tmp; + + if (!score) score = &tmp; + + *score = 0x1; + if ((lf->lfCharSet == DEFAULT_CHARSET || lf->lfCharSet == console->window->ui_charset) + && (!tm || tm->tmCharSet == DEFAULT_CHARSET || tm->tmCharSet == console->window->ui_charset)) + *score |= 0x2; + if ((lf->lfPitchAndFamily & 3) == FIXED_PITCH + && (!tm || (!tm->tmItalic && !tm->tmUnderlined && !tm->tmStruckOut))) + *score |= 0x4; + if (lf->lfFaceName[0] != '@') + *score |= 0x8; + return *score == 0xf; }
static int CALLBACK enum_first_font_proc( const LOGFONTW *lf, const TEXTMETRICW *tm, DWORD font_type, LPARAM lparam ) { struct font_chooser *fc = (struct font_chooser *)lparam; - LOGFONTW mlf; + int score; + BOOL ret;
if (font_type != TRUETYPE_FONTTYPE) return 1;
TRACE( "%s\n", debugstr_logfont( lf, font_type )); TRACE( "%s\n", debugstr_textmetric( tm, font_type ));
- if (!validate_font( fc->console, lf, tm, fc->pass )) - return 1; - - /* set default font size */ - mlf = *lf; - mlf.lfHeight = fc->font_height; - mlf.lfWidth = fc->font_width; - - if (!set_console_font( fc->console, &mlf )) - return 1; - - fc->done = TRUE; - - return 0; + ret = validate_font( fc->console, lf, tm, &score ); + if (score > fc->best_score) + { + fc->best_score = score; + fc->lf = *lf; + } + return !ret; }
static void set_first_font( struct console *console, struct console_config *config ) @@ -865,18 +854,14 @@ static void set_first_font( struct console *console, struct console_config *conf lf.lfCharSet = DEFAULT_CHARSET; lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
+ memset( &fc, 0, sizeof(fc) ); fc.console = console; - fc.font_height = config->cell_height; - fc.font_width = config->cell_width; - fc.done = FALSE;
- for (fc.pass = 0; fc.pass <= 3; fc.pass++) - { - EnumFontFamiliesExW( console->window->mem_dc, &lf, enum_first_font_proc, (LPARAM)&fc, 0); - if (fc.done) break; - } + EnumFontFamiliesExW( console->window->mem_dc, &lf, enum_first_font_proc, (LPARAM)&fc, 0);
- if (fc.pass > 3) + fc.lf.lfHeight = config->cell_height; + fc.lf.lfWidth = config->cell_width; + if (!fc.best_score || !set_console_font( console, &fc.lf )) ERR("Unable to find a valid console font\n");
/* Update active configuration */ @@ -1572,7 +1557,7 @@ static int CALLBACK enum_list_font_proc( const LOGFONTW *lf, const TEXTMETRICW *
TRACE( "%s\n", debugstr_logfont( lf, font_type ));
- if (validate_font( di->console, lf, NULL, 0 )) + if (validate_font( di->console, lf, NULL, NULL )) SendDlgItemMessageW( di->dialog, IDC_FNT_LIST_FONT, LB_ADDSTRING, 0, (LPARAM)lf->lfFaceName );
return 1;