dwrite: Improve face name returned by ConvertFontToLOGFONT().

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Nikolay Sivov 2016-12-04 19:22:16 +03:00 committed by Alexandre Julliard
parent 3ffa9ee082
commit 17586e3082
5 changed files with 54 additions and 19 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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)

View File

@ -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);
}