Module: wine Branch: master Commit: 17586e308251fe96ce6304f1798142f1797c99ae URL: http://source.winehq.org/git/wine.git/?a=commit;h=17586e308251fe96ce6304f179...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Sun Dec 4 19:22:16 2016 +0300
dwrite: Improve face name returned by ConvertFontToLOGFONT().
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/dwrite/dwrite_private.h | 2 +- dlls/dwrite/font.c | 2 +- dlls/dwrite/gdiinterop.c | 14 -------------- dlls/dwrite/opentype.c | 26 ++++++++++++++++++++++++-- dlls/dwrite/tests/font.c | 29 ++++++++++++++++++++++++++++- 5 files changed, 54 insertions(+), 19 deletions(-)
diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h index 77b6c4a..1e46498 100644 --- a/dlls/dwrite/dwrite_private.h +++ b/dlls/dwrite/dwrite_private.h @@ -224,7 +224,7 @@ extern void opentype_get_font_properties(struct file_stream_desc*,struct dwrite_ extern void opentype_get_font_metrics(struct file_stream_desc*,DWRITE_FONT_METRICS1*,DWRITE_CARET_METRICS*) DECLSPEC_HIDDEN; extern HRESULT opentype_get_font_info_strings(const void*,DWRITE_INFORMATIONAL_STRING_ID,IDWriteLocalizedStrings**) DECLSPEC_HIDDEN; extern HRESULT opentype_get_font_familyname(struct file_stream_desc*,IDWriteLocalizedStrings**) DECLSPEC_HIDDEN; -extern HRESULT opentype_get_font_facename(struct file_stream_desc*,IDWriteLocalizedStrings**) DECLSPEC_HIDDEN; +extern HRESULT opentype_get_font_facename(struct file_stream_desc*,WCHAR*,IDWriteLocalizedStrings**) DECLSPEC_HIDDEN; extern HRESULT opentype_get_typographic_features(IDWriteFontFace*,UINT32,UINT32,UINT32,UINT32*,DWRITE_FONT_FEATURE_TAG*) DECLSPEC_HIDDEN; extern BOOL opentype_get_vdmx_size(const void*,INT,UINT16*,UINT16*) DECLSPEC_HIDDEN; extern UINT32 opentype_get_cpal_palettecount(const void*) DECLSPEC_HIDDEN; diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index 47ebd11..17bea89 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -3247,7 +3247,7 @@ static HRESULT init_font_data(const struct fontface_desc *desc, IDWriteLocalized stream_desc.face_index = desc->index; opentype_get_font_properties(&stream_desc, &props); opentype_get_font_metrics(&stream_desc, &data->metrics, NULL); - opentype_get_font_facename(&stream_desc, &data->names); + opentype_get_font_facename(&stream_desc, props.lf.lfFaceName, &data->names);
/* get family name from font file */ hr = opentype_get_font_familyname(&stream_desc, family_name); diff --git a/dlls/dwrite/gdiinterop.c b/dlls/dwrite/gdiinterop.c index 5034ad7..3675875 100644 --- a/dlls/dwrite/gdiinterop.c +++ b/dlls/dwrite/gdiinterop.c @@ -623,12 +623,8 @@ static HRESULT WINAPI gdiinterop_ConvertFontToLOGFONT(IDWriteGdiInterop1 *iface, IDWriteFont *font, LOGFONTW *logfont, BOOL *is_systemfont) { struct gdiinterop *This = impl_from_IDWriteGdiInterop1(iface); - static const WCHAR enusW[] = {'e','n','-','u','s',0}; IDWriteFontCollection *collection; - IDWriteLocalizedStrings *name; IDWriteFontFamily *family; - UINT32 index; - BOOL exists; HRESULT hr;
TRACE("(%p)->(%p %p %p)\n", This, font, logfont, is_systemfont); @@ -655,17 +651,7 @@ static HRESULT WINAPI gdiinterop_ConvertFontToLOGFONT(IDWriteGdiInterop1 *iface, get_logfont_from_font(font, logfont); logfont->lfCharSet = DEFAULT_CHARSET; logfont->lfOutPrecision = OUT_OUTLINE_PRECIS; - logfont->lfFaceName[0] = 0; - - exists = FALSE; - hr = IDWriteFont_GetInformationalStrings(font, DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES, &name, &exists); - if (FAILED(hr) || !exists) - return hr;
- hr = IDWriteLocalizedStrings_FindLocaleName(name, enusW, &index, &exists); - if (hr == S_OK) - hr = IDWriteLocalizedStrings_GetString(name, index, logfont->lfFaceName, sizeof(logfont->lfFaceName)/sizeof(WCHAR)); - IDWriteLocalizedStrings_Release(name); return hr; }
diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c index 7f6ccd1..4a6d62c 100644 --- a/dlls/dwrite/opentype.c +++ b/dlls/dwrite/opentype.c @@ -1612,10 +1612,11 @@ HRESULT opentype_get_font_familyname(struct file_stream_desc *stream_desc, IDWri
/* FaceName locating order is WWS Face Name -> Preferred Face Name -> Face Name. If font claims to have 'Preferred Face Name' in WWS format, then WWS name is not used. */ -HRESULT opentype_get_font_facename(struct file_stream_desc *stream_desc, IDWriteLocalizedStrings **names) +HRESULT opentype_get_font_facename(struct file_stream_desc *stream_desc, WCHAR *lfname, IDWriteLocalizedStrings **names) { - const TT_OS2_V2 *tt_os2; + IDWriteLocalizedStrings *lfnames; void *os2_context, *name_context; + const TT_OS2_V2 *tt_os2; const void *name_table; HRESULT hr;
@@ -1635,6 +1636,27 @@ HRESULT opentype_get_font_facename(struct file_stream_desc *stream_desc, IDWrite if (FAILED(hr)) hr = opentype_get_font_strings_from_id(name_table, OPENTYPE_STRING_SUBFAMILY_NAME, names);
+ /* User locale is preferred, with fallback to en-us. */ + *lfname = 0; + if (SUCCEEDED(opentype_get_font_strings_from_id(name_table, OPENTYPE_STRING_FAMILY_NAME, &lfnames))) { + static const WCHAR enusW[] = {'e','n','-','u','s',0}; + WCHAR localeW[LOCALE_NAME_MAX_LENGTH]; + UINT32 index; + BOOL exists; + + exists = FALSE; + if (GetUserDefaultLocaleName(localeW, sizeof(localeW)/sizeof(WCHAR))) + IDWriteLocalizedStrings_FindLocaleName(lfnames, localeW, &index, &exists); + + if (!exists) + IDWriteLocalizedStrings_FindLocaleName(lfnames, enusW, &index, &exists); + + if (exists) + IDWriteLocalizedStrings_GetString(lfnames, index, lfname, LF_FACESIZE); + + IDWriteLocalizedStrings_Release(lfnames); + } + if (tt_os2) IDWriteFontFileStream_ReleaseFileFragment(stream_desc->stream, os2_context); if (name_context) diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index ca35324..987eac9 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -3459,6 +3459,7 @@ static void test_TryGetFontTable(void) static void get_logfont_from_font(IDWriteFont *font, LOGFONTW *logfont) { void *os2_context, *head_context; + IDWriteLocalizedStrings *names; DWRITE_FONT_SIMULATIONS sim; IDWriteFontFace *fontface; const TT_OS2_V2 *tt_os2; @@ -3531,6 +3532,31 @@ static void get_logfont_from_font(IDWriteFont *font, LOGFONTW *logfont) } }
+ /* lfFaceName */ + exists = FALSE; + logfont->lfFaceName[0] = 0; + hr = IDWriteFont_GetInformationalStrings(font, DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES, &names, &exists); + if (SUCCEEDED(hr)) { + if (exists) { + static const WCHAR enusW[] = {'e','n','-','u','s',0}; + WCHAR localeW[LOCALE_NAME_MAX_LENGTH]; + UINT32 index; + + /* Fallback to en-us if there's no string for user locale. */ + exists = FALSE; + if (GetUserDefaultLocaleName(localeW, sizeof(localeW)/sizeof(WCHAR))) + IDWriteLocalizedStrings_FindLocaleName(names, localeW, &index, &exists); + + if (!exists) + IDWriteLocalizedStrings_FindLocaleName(names, enusW, &index, &exists); + + if (exists) + IDWriteLocalizedStrings_GetString(names, index, logfont->lfFaceName, sizeof(logfont->lfFaceName)/sizeof(WCHAR)); + } + + IDWriteLocalizedStrings_Release(names); + } + if (tt_os2) IDWriteFontFace_ReleaseFontTable(fontface, os2_context); if (tt_head) @@ -3631,6 +3657,8 @@ if (0) { /* crashes on native */ sim & DWRITE_FONT_SIMULATIONS_BOLD ? "yes" : "no"); ok(logfont.lfItalic == lf.lfItalic, "%s: unexpected italic flag %d, oblique simulation %s\n", wine_dbgstr_w(nameW), logfont.lfItalic, sim & DWRITE_FONT_SIMULATIONS_OBLIQUE ? "yes" : "no"); + ok(!lstrcmpW(logfont.lfFaceName, lf.lfFaceName), "%s: unexpected facename %s, expected %s\n", + wine_dbgstr_w(nameW), wine_dbgstr_w(logfont.lfFaceName), wine_dbgstr_w(lf.lfFaceName));
ok(logfont.lfOutPrecision == OUT_OUTLINE_PRECIS, "%s: unexpected output precision %d\n", wine_dbgstr_w(nameW), logfont.lfOutPrecision); @@ -3639,7 +3667,6 @@ if (0) { /* crashes on native */ ok(logfont.lfQuality == DEFAULT_QUALITY, "%s: unexpected quality %d\n", wine_dbgstr_w(nameW), logfont.lfQuality); ok(logfont.lfPitchAndFamily == DEFAULT_PITCH, "%s: unexpected pitch %d\n", wine_dbgstr_w(nameW), logfont.lfPitchAndFamily); - ok(logfont.lfFaceName[0] != 0, "got face name %s\n", wine_dbgstr_w(logfont.lfFaceName));
IDWriteFont_Release(font); }