wineconsole: If necessary, fallback to a font without the right properties instead of failing.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2016-03-28 18:18:11 +09:00
parent 8f56702812
commit e1fc8dcdee
3 changed files with 48 additions and 27 deletions

View File

@ -303,7 +303,7 @@ static int CALLBACK font_enum_size2(const LOGFONTW* lf, const TEXTMETRICW* tm,
struct dialog_info* di = (struct dialog_info*)lParam; struct dialog_info* di = (struct dialog_info*)lParam;
WCUSER_DumpTextMetric(tm, FontType); WCUSER_DumpTextMetric(tm, FontType);
if (WCUSER_ValidateFontMetric(di->data, tm, FontType, TRUE)) if (WCUSER_ValidateFontMetric(di->data, tm, FontType, 0))
{ {
di->nFont++; di->nFont++;
} }
@ -317,7 +317,7 @@ static int CALLBACK font_enum(const LOGFONTW* lf, const TEXTMETRICW* tm,
struct dialog_info* di = (struct dialog_info*)lParam; struct dialog_info* di = (struct dialog_info*)lParam;
WCUSER_DumpLogFont("DlgFamily: ", lf, FontType); WCUSER_DumpLogFont("DlgFamily: ", lf, FontType);
if (WCUSER_ValidateFont(di->data, lf)) if (WCUSER_ValidateFont(di->data, lf, 0))
{ {
if (FontType & RASTER_FONTTYPE) if (FontType & RASTER_FONTTYPE)
{ {
@ -375,7 +375,7 @@ static int CALLBACK font_enum_size(const LOGFONTW* lf, const TEXTMETRICW* tm,
return 0; return 0;
} }
if (WCUSER_ValidateFontMetric(di->data, tm, FontType, TRUE)) if (WCUSER_ValidateFontMetric(di->data, tm, FontType, 0))
{ {
int idx = 0; int idx = 0;

View File

@ -333,7 +333,7 @@ static BOOL WCUSER_AreFontsEqual(const struct config_data* config, const LOGFONT
struct font_chooser struct font_chooser
{ {
struct inner_data* data; struct inner_data* data;
BOOL check_screen_size; int pass;
BOOL done; BOOL done;
}; };
@ -343,15 +343,26 @@ struct font_chooser
* Returns true if the font described in tm is usable as a font for the renderer * Returns true if the font described in tm is usable as a font for the renderer
*/ */
BOOL WCUSER_ValidateFontMetric(const struct inner_data* data, const TEXTMETRICW* tm, BOOL WCUSER_ValidateFontMetric(const struct inner_data* data, const TEXTMETRICW* tm,
DWORD type, BOOL check_screen_size) DWORD type, int pass)
{ {
BOOL ret = TRUE; switch (pass) /* we get increasingly lenient in later passes */
{
if (check_screen_size && (type & RASTER_FONTTYPE)) case 0:
ret = (tm->tmMaxCharWidth * data->curcfg.win_width < GetSystemMetrics(SM_CXSCREEN) && if (type & RASTER_FONTTYPE)
tm->tmHeight * data->curcfg.win_height < GetSystemMetrics(SM_CYSCREEN)); {
return ret && !tm->tmItalic && !tm->tmUnderlined && !tm->tmStruckOut && if (tm->tmMaxCharWidth * data->curcfg.win_width >= GetSystemMetrics(SM_CXSCREEN) ||
(tm->tmCharSet == DEFAULT_CHARSET || tm->tmCharSet == g_uiDefaultCharset); tm->tmHeight * data->curcfg.win_height >= GetSystemMetrics(SM_CYSCREEN))
return FALSE;
}
/* fall through */
case 1:
if (tm->tmCharSet != DEFAULT_CHARSET && tm->tmCharSet != g_uiDefaultCharset) return FALSE;
/* fall through */
case 2:
if (tm->tmItalic || tm->tmUnderlined || tm->tmStruckOut) return FALSE;
break;
}
return TRUE;
} }
/****************************************************************** /******************************************************************
@ -359,12 +370,22 @@ BOOL WCUSER_ValidateFontMetric(const struct inner_data* data, const TEXTMETRICW*
* *
* Returns true if the font family described in lf is usable as a font for the renderer * Returns true if the font family described in lf is usable as a font for the renderer
*/ */
BOOL WCUSER_ValidateFont(const struct inner_data* data, const LOGFONTW* lf) BOOL WCUSER_ValidateFont(const struct inner_data* data, const LOGFONTW* lf, int pass)
{ {
return (lf->lfPitchAndFamily & 3) == FIXED_PITCH && switch (pass) /* we get increasingly lenient in later passes */
/* (lf->lfPitchAndFamily & 0xF0) == FF_MODERN && */ {
lf->lfFaceName[0] != '@' && case 0:
(lf->lfCharSet == DEFAULT_CHARSET || lf->lfCharSet == g_uiDefaultCharset); case 1:
if (lf->lfCharSet != DEFAULT_CHARSET && lf->lfCharSet != g_uiDefaultCharset) return FALSE;
/* fall through */
case 2:
if ((lf->lfPitchAndFamily & 3) != FIXED_PITCH) return FALSE;
/* fall through */
case 3:
if (lf->lfFaceName[0] == '@') return FALSE;
break;
}
return TRUE;
} }
/****************************************************************** /******************************************************************
@ -379,7 +400,7 @@ static int CALLBACK get_first_font_enum_2(const LOGFONTW* lf, const TEXTMETRICW*
struct font_chooser* fc = (struct font_chooser*)lParam; struct font_chooser* fc = (struct font_chooser*)lParam;
WCUSER_DumpTextMetric(tm, FontType); WCUSER_DumpTextMetric(tm, FontType);
if (WCUSER_ValidateFontMetric(fc->data, tm, FontType, fc->check_screen_size)) if (WCUSER_ValidateFontMetric(fc->data, tm, FontType, fc->pass))
{ {
LOGFONTW mlf = *lf; LOGFONTW mlf = *lf;
@ -417,7 +438,7 @@ static int CALLBACK get_first_font_enum(const LOGFONTW* lf, const TEXTMETRICW* t
struct font_chooser* fc = (struct font_chooser*)lParam; struct font_chooser* fc = (struct font_chooser*)lParam;
WCUSER_DumpLogFont("InitFamily: ", lf, FontType); WCUSER_DumpLogFont("InitFamily: ", lf, FontType);
if (WCUSER_ValidateFont(fc->data, lf)) if (WCUSER_ValidateFont(fc->data, lf, fc->pass))
{ {
EnumFontFamiliesW(PRIVATE(fc->data)->hMemDC, lf->lfFaceName, EnumFontFamiliesW(PRIVATE(fc->data)->hMemDC, lf->lfFaceName,
get_first_font_enum_2, lParam); get_first_font_enum_2, lParam);
@ -537,13 +558,13 @@ static void WCUSER_SetFontPmt(struct inner_data* data, const WCHAR* font,
/* try to find an acceptable font */ /* try to find an acceptable font */
WINE_WARN("Couldn't match the font from registry... trying to find one\n"); WINE_WARN("Couldn't match the font from registry... trying to find one\n");
fc.data = data; fc.data = data;
fc.check_screen_size = TRUE;
fc.done = FALSE; fc.done = FALSE;
EnumFontFamiliesW(PRIVATE(data)->hMemDC, NULL, get_first_font_enum, (LPARAM)&fc); for (fc.pass = 0; fc.pass <= 4; fc.pass++)
if (fc.done) return; {
fc.check_screen_size = FALSE; EnumFontFamiliesW(PRIVATE(data)->hMemDC, NULL, get_first_font_enum, (LPARAM)&fc);
EnumFontFamiliesW(PRIVATE(data)->hMemDC, NULL, get_first_font_enum, (LPARAM)&fc); if (fc.done) return;
if (!fc.done) WINECON_Fatal("Couldn't find a decent font, aborting\n"); }
WINECON_Fatal("Couldn't find a decent font, aborting\n");
} }
/****************************************************************** /******************************************************************

View File

@ -45,9 +45,9 @@ struct inner_data_user {
/* from user.c */ /* from user.c */
extern const COLORREF WCUSER_ColorMap[16]; extern const COLORREF WCUSER_ColorMap[16];
extern BOOL WCUSER_GetProperties(struct inner_data*, BOOL); extern BOOL WCUSER_GetProperties(struct inner_data*, BOOL);
extern BOOL WCUSER_ValidateFont(const struct inner_data* data, const LOGFONTW* lf); extern BOOL WCUSER_ValidateFont(const struct inner_data* data, const LOGFONTW* lf, int pass);
extern BOOL WCUSER_ValidateFontMetric(const struct inner_data* data, const TEXTMETRICW* tm, extern BOOL WCUSER_ValidateFontMetric(const struct inner_data* data, const TEXTMETRICW* tm,
DWORD type, BOOL check_screen_size); DWORD type, int pass);
extern HFONT WCUSER_CopyFont(struct config_data* config, HWND hWnd, extern HFONT WCUSER_CopyFont(struct config_data* config, HWND hWnd,
const LOGFONTW* lf, LONG* el); const LOGFONTW* lf, LONG* el);
extern void WCUSER_FillLogFont(LOGFONTW* lf, const WCHAR* name, extern void WCUSER_FillLogFont(LOGFONTW* lf, const WCHAR* name,