diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c index 55030bf95bf..47d52f6c3dc 100644 --- a/dlls/gdi32/font.c +++ b/dlls/gdi32/font.c @@ -1461,8 +1461,9 @@ static struct gdi_font_face *find_best_matching_face( const struct gdi_font_fami return best->scalable ? best : best_bitmap; } -struct gdi_font_face *find_matching_face_by_name( const WCHAR *name, const WCHAR *subst, const LOGFONTW *lf, - FONTSIGNATURE fs, BOOL can_use_bitmap ) +static struct gdi_font_face *find_matching_face_by_name( const WCHAR *name, const WCHAR *subst, + const LOGFONTW *lf, FONTSIGNATURE fs, + BOOL can_use_bitmap ) { struct gdi_font_family *family; struct gdi_font_face *face; @@ -1489,8 +1490,8 @@ struct gdi_font_face *find_matching_face_by_name( const WCHAR *name, const WCHAR return NULL; } -struct gdi_font_face *find_any_face( const LOGFONTW *lf, FONTSIGNATURE fs, - BOOL can_use_bitmap, BOOL want_vertical ) +static struct gdi_font_face *find_any_face( const LOGFONTW *lf, FONTSIGNATURE fs, + BOOL can_use_bitmap, BOOL want_vertical ) { struct gdi_font_family *family; struct gdi_font_face *face; @@ -1524,6 +1525,59 @@ struct gdi_font_face *find_any_face( const LOGFONTW *lf, FONTSIGNATURE fs, return NULL; } +struct gdi_font_face *find_matching_face( LOGFONTW *lf, CHARSETINFO *csi, BOOL can_use_bitmap, + const WCHAR **orig_name ) +{ + BOOL want_vertical = (lf->lfFaceName[0] == '@'); + struct gdi_font_face *face; + + if (!TranslateCharsetInfo( (DWORD *)(INT_PTR)lf->lfCharSet, csi, TCI_SRCCHARSET )) + { + if (lf->lfCharSet != DEFAULT_CHARSET) FIXME( "Untranslated charset %d\n", lf->lfCharSet ); + csi->fs.fsCsb[0] = 0; + } + + if (lf->lfFaceName[0]) + { + int subst_charset; + const WCHAR *subst = get_gdi_font_subst( lf->lfFaceName, lf->lfCharSet, &subst_charset ); + + if (subst) + { + TRACE( "substituting %s,%d -> %s,%d\n", debugstr_w(lf->lfFaceName), lf->lfCharSet, + debugstr_w(subst), (subst_charset != -1) ? subst_charset : lf->lfCharSet ); + if (subst_charset != -1) lf->lfCharSet = subst_charset; + *orig_name = lf->lfFaceName; + } + + if ((face = find_matching_face_by_name( lf->lfFaceName, subst, lf, csi->fs, can_use_bitmap ))) + return face; + } + *orig_name = NULL; /* substitution is no longer relevant */ + + /* If requested charset was DEFAULT_CHARSET then try using charset + corresponding to the current ansi codepage */ + if (!csi->fs.fsCsb[0]) + { + INT acp = GetACP(); + if (!TranslateCharsetInfo( (DWORD *)(INT_PTR)acp, csi, TCI_SRCCODEPAGE )) + { + FIXME( "TCI failed on codepage %d\n", acp ); + csi->fs.fsCsb[0] = 0; + } + else lf->lfCharSet = csi->ciCharset; + } + + if ((face = find_any_face( lf, csi->fs, can_use_bitmap, want_vertical ))) return face; + if (csi->fs.fsCsb[0]) + { + csi->fs.fsCsb[0] = 0; + if ((face = find_any_face( lf, csi->fs, can_use_bitmap, want_vertical ))) return face; + } + if (want_vertical && (face = find_any_face( lf, csi->fs, can_use_bitmap, FALSE ))) return face; + return NULL; +} + /* realized font objects */ #define FIRST_FONT_HANDLE 1 diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c index 464d58df09c..46ab0b9f6d7 100644 --- a/dlls/gdi32/freetype.c +++ b/dlls/gdi32/freetype.c @@ -2217,9 +2217,8 @@ static struct gdi_font * CDECL freetype_SelectFont( DC *dc, HFONT hfont ) { struct gdi_font *font; Face *face; - Family *family; INT height; - BOOL can_use_bitmap, want_vertical; + BOOL can_use_bitmap; LOGFONTW lf; CHARSETINFO csi; FMAT2 dcmat; @@ -2279,61 +2278,12 @@ static struct gdi_font * CDECL freetype_SelectFont( DC *dc, HFONT hfont ) if(!strcmpiW(lf.lfFaceName, SymbolW)) lf.lfCharSet = SYMBOL_CHARSET; - if(!TranslateCharsetInfo((DWORD*)(INT_PTR)lf.lfCharSet, &csi, TCI_SRCCHARSET)) { - switch(lf.lfCharSet) { - case DEFAULT_CHARSET: - csi.fs.fsCsb[0] = 0; - break; - default: - FIXME("Untranslated charset %d\n", lf.lfCharSet); - csi.fs.fsCsb[0] = 0; - break; - } - } - - family = NULL; - if(lf.lfFaceName[0] != '\0') { - LPWSTR FaceName = lf.lfFaceName; - int subst_charset; - const WCHAR *subst = get_gdi_font_subst( FaceName, lf.lfCharSet, &subst_charset ); - - if(subst) { - TRACE("substituting %s,%d -> %s,%d\n", debugstr_w(FaceName), lf.lfCharSet, - debugstr_w(subst), (subst_charset != -1) ? subst_charset : lf.lfCharSet); - if (subst_charset != -1) lf.lfCharSet = subst_charset; - orig_name = FaceName; - } - - if ((face = find_matching_face_by_name( FaceName, subst, &lf, csi.fs, can_use_bitmap ))) - goto found_face; - } - - orig_name = NULL; /* substitution is no longer relevant */ - - /* If requested charset was DEFAULT_CHARSET then try using charset - corresponding to the current ansi codepage */ - if (!csi.fs.fsCsb[0]) + if (!(face = find_matching_face( &lf, &csi, can_use_bitmap, &orig_name ))) { - INT acp = GetACP(); - if(!TranslateCharsetInfo((DWORD*)(INT_PTR)acp, &csi, TCI_SRCCODEPAGE)) { - FIXME("TCI failed on codepage %d\n", acp); - csi.fs.fsCsb[0] = 0; - } else - lf.lfCharSet = csi.ciCharset; + FIXME("can't find a single appropriate font - bailing\n"); + return NULL; } - - want_vertical = (lf.lfFaceName[0] == '@'); - - if ((face = find_any_face( &lf, csi.fs, can_use_bitmap, want_vertical ))) goto found_face; - csi.fs.fsCsb[0] = 0; - if ((face = find_any_face( &lf, csi.fs, can_use_bitmap, want_vertical ))) goto found_face; - if (want_vertical && (face = find_any_face( &lf, csi.fs, can_use_bitmap, FALSE ))) goto found_face; - FIXME("can't find a single appropriate font - bailing\n"); - return NULL; - -found_face: height = lf.lfHeight; - family = face->family; TRACE("not in cache\n"); font = create_gdi_font( face, orig_name, &lf ); @@ -2345,7 +2295,7 @@ found_face: font->codepage = csi.ciACP; } else - font->charset = get_nearest_charset( family->family_name, face, &font->codepage ); + font->charset = get_nearest_charset( face->family->family_name, face, &font->codepage ); TRACE( "Chosen: %s (%s/%p:%u)\n", debugstr_w(face->full_name), debugstr_w(face->file), face->data_ptr, face->face_index ); diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h index ef98fa0e8fd..48bf823ff92 100644 --- a/dlls/gdi32/gdi_private.h +++ b/dlls/gdi32/gdi_private.h @@ -459,10 +459,8 @@ extern int add_gdi_face( const WCHAR *family_name, const WCHAR *second_name, extern struct gdi_font_link *find_gdi_font_link( const WCHAR *name ) DECLSPEC_HIDDEN; extern void create_child_font_list( struct gdi_font *font ) DECLSPEC_HIDDEN; -extern struct gdi_font_face *find_matching_face_by_name( const WCHAR *name, const WCHAR *subst, const LOGFONTW *lf, - FONTSIGNATURE fs, BOOL can_use_bitmap ) DECLSPEC_HIDDEN; -extern struct gdi_font_face *find_any_face( const LOGFONTW *lf, FONTSIGNATURE fs, - BOOL can_use_bitmap, BOOL want_vertical ) DECLSPEC_HIDDEN; +extern struct gdi_font_face *find_matching_face( LOGFONTW *lf, CHARSETINFO *csi, BOOL can_use_bitmap, + const WCHAR **orig_name ) DECLSPEC_HIDDEN; extern void free_gdi_font( struct gdi_font *font ) DECLSPEC_HIDDEN; extern void cache_gdi_font( struct gdi_font *font ) DECLSPEC_HIDDEN;