From 5a318c3e8badda11b2a00884e6de2c0367616525 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Thu, 19 Feb 2015 11:43:15 +0300 Subject: [PATCH] dwrite: Set facename field of a LOGFONT in ConvertFontFaceToLOGFONT(). --- dlls/dwrite/dwrite_private.h | 1 + dlls/dwrite/font.c | 59 +++++++++------------------------- dlls/dwrite/gdiinterop.c | 61 +++++++++++++++++++++++++++++++++++- dlls/dwrite/tests/font.c | 1 - 4 files changed, 75 insertions(+), 47 deletions(-) diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h index 674e9f088c8..9a27a5e1739 100644 --- a/dlls/dwrite/dwrite_private.h +++ b/dlls/dwrite/dwrite_private.h @@ -121,6 +121,7 @@ extern BOOL is_system_collection(IDWriteFontCollection*) DECLSPEC_HIDDEN; extern HRESULT get_local_refkey(const WCHAR*,const FILETIME*,void**,UINT32*) DECLSPEC_HIDDEN; extern HRESULT get_filestream_from_file(IDWriteFontFile*,IDWriteFontFileStream**) DECLSPEC_HIDDEN; extern BOOL is_face_type_supported(DWRITE_FONT_FACE_TYPE) DECLSPEC_HIDDEN; +extern HRESULT get_family_names_from_stream(IDWriteFontFileStream*,UINT32,DWRITE_FONT_FACE_TYPE,IDWriteLocalizedStrings**) DECLSPEC_HIDDEN; /* Opentype font table functions */ extern HRESULT opentype_analyze_font(IDWriteFontFileStream*,UINT32*,DWRITE_FONT_FILE_TYPE*,DWRITE_FONT_FACE_TYPE*,BOOL*) DECLSPEC_HIDDEN; diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index 527fa5d9420..2092576831b 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -773,45 +773,22 @@ static const IDWriteFontFace2Vtbl dwritefontfacevtbl = { dwritefontface2_GetRecommendedRenderingMode }; -HRESULT convert_fontface_to_logfont(IDWriteFontFace *face, LOGFONTW *logfont) +HRESULT get_family_names_from_stream(IDWriteFontFileStream *stream, UINT32 index, DWRITE_FONT_FACE_TYPE facetype, + IDWriteLocalizedStrings **names) { - DWRITE_FONT_SIMULATIONS simulations; - DWRITE_FONT_FACE_TYPE face_type; - IDWriteFontFileStream *stream; - DWRITE_FONT_STRETCH stretch; - DWRITE_FONT_STYLE style; - DWRITE_FONT_WEIGHT weight; - IDWriteFontFile *file = NULL; - UINT32 index; - HRESULT hr; + const void *name_table = NULL; + void *name_context; + HRESULT hr = S_OK; - memset(logfont, 0, sizeof(*logfont)); - - index = 1; - hr = IDWriteFontFace_GetFiles(face, &index, &file); - if (FAILED(hr) || !file) - return hr; - - hr = get_filestream_from_file(file, &stream); - if (FAILED(hr)) { - IDWriteFontFile_Release(file); - return hr; + opentype_get_font_table(stream, facetype, index, MS_NAME_TAG, &name_table, &name_context, NULL, NULL); + if (name_table) { + hr = opentype_get_font_strings_from_id(name_table, DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES, names); + IDWriteFontFileStream_ReleaseFileFragment(stream, name_context); } + else + names = NULL; - index = IDWriteFontFace_GetIndex(face); - face_type = IDWriteFontFace_GetType(face); - opentype_get_font_properties(stream, face_type, index, &stretch, &weight, &style); - IDWriteFontFileStream_Release(stream); - - simulations = IDWriteFontFace_GetSimulations(face); - - logfont->lfCharSet = DEFAULT_CHARSET; - logfont->lfWeight = weight; - logfont->lfItalic = style == DWRITE_FONT_STYLE_ITALIC || (simulations & DWRITE_FONT_SIMULATIONS_OBLIQUE); - logfont->lfOutPrecision = OUT_OUTLINE_PRECIS; - /* TODO: set facename */ - - return S_OK; + return hr; } static HRESULT get_fontface_from_font(struct dwrite_font *font, IDWriteFontFace2 **fontface) @@ -1730,8 +1707,6 @@ HRESULT create_font_collection(IDWriteFactory2* factory, IDWriteFontFileEnumerat for (i = 0; i < face_count; i++) { IDWriteLocalizedStrings *family_name = NULL; struct dwrite_font_data *font_data; - const void *name_table; - void *name_context; IDWriteFontFileStream *stream; WCHAR buffer[255]; UINT32 index; @@ -1742,15 +1717,9 @@ HRESULT create_font_collection(IDWriteFactory2* factory, IDWriteFontFileEnumerat break; /* get family name from font file */ - name_table = NULL; - opentype_get_font_table(stream, face_type, i, MS_NAME_TAG, &name_table, &name_context, NULL, NULL); - if (name_table) { - hr = opentype_get_font_strings_from_id(name_table, DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES, &family_name); - IDWriteFontFileStream_ReleaseFileFragment(stream, name_context); - } + hr = get_family_names_from_stream(stream, i, face_type, &family_name); IDWriteFontFileStream_Release(stream); - - if (FAILED(hr) || !family_name) { + if (FAILED(hr)) { WARN("unable to get family name from font\n"); release_font_data(font_data); continue; diff --git a/dlls/dwrite/gdiinterop.c b/dlls/dwrite/gdiinterop.c index bead01d778d..8f91ded815e 100644 --- a/dlls/dwrite/gdiinterop.c +++ b/dlls/dwrite/gdiinterop.c @@ -406,9 +406,68 @@ static HRESULT WINAPI gdiinterop_ConvertFontToLOGFONT(IDWriteGdiInterop *iface, static HRESULT WINAPI gdiinterop_ConvertFontFaceToLOGFONT(IDWriteGdiInterop *iface, IDWriteFontFace *fontface, LOGFONTW *logfont) { + static const WCHAR enusW[] = {'e','n','-','u','s',0}; struct gdiinterop *This = impl_from_IDWriteGdiInterop(iface); + IDWriteLocalizedStrings *familynames; + DWRITE_FONT_SIMULATIONS simulations; + DWRITE_FONT_FACE_TYPE face_type; + IDWriteFontFileStream *stream; + DWRITE_FONT_STRETCH stretch; + DWRITE_FONT_STYLE style; + DWRITE_FONT_WEIGHT weight; + IDWriteFontFile *file = NULL; + UINT32 index; + BOOL exists; + HRESULT hr; + TRACE("(%p)->(%p %p)\n", This, fontface, logfont); - return convert_fontface_to_logfont(fontface, logfont); + + memset(logfont, 0, sizeof(*logfont)); + + index = 1; + hr = IDWriteFontFace_GetFiles(fontface, &index, &file); + if (FAILED(hr) || !file) + return hr; + + hr = get_filestream_from_file(file, &stream); + if (FAILED(hr)) { + IDWriteFontFile_Release(file); + return hr; + } + + index = IDWriteFontFace_GetIndex(fontface); + face_type = IDWriteFontFace_GetType(fontface); + opentype_get_font_properties(stream, face_type, index, &stretch, &weight, &style); + hr = get_family_names_from_stream(stream, index, face_type, &familynames); + IDWriteFontFile_Release(file); + IDWriteFontFileStream_Release(stream); + if (FAILED(hr)) + return hr; + + simulations = IDWriteFontFace_GetSimulations(fontface); + + logfont->lfCharSet = DEFAULT_CHARSET; + logfont->lfWeight = weight; + logfont->lfItalic = style == DWRITE_FONT_STYLE_ITALIC || (simulations & DWRITE_FONT_SIMULATIONS_OBLIQUE); + logfont->lfOutPrecision = OUT_OUTLINE_PRECIS; + logfont->lfFaceName[0] = 0; + + exists = FALSE; + hr = IDWriteLocalizedStrings_FindLocaleName(familynames, enusW, &index, &exists); + if (FAILED(hr) || !exists) { + /* fallback to 0 index */ + if (IDWriteLocalizedStrings_GetCount(familynames) > 0) + index = 0; + else { + IDWriteLocalizedStrings_Release(familynames); + return E_FAIL; + } + } + + hr = IDWriteLocalizedStrings_GetString(familynames, index, logfont->lfFaceName, sizeof(logfont->lfFaceName)/sizeof(WCHAR)); + IDWriteLocalizedStrings_Release(familynames); + + return hr; } static HRESULT WINAPI gdiinterop_CreateFontFaceFromHdc(IDWriteGdiInterop *iface, diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index e00e78854dc..d1714118142 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -1467,7 +1467,6 @@ if (0) /* crashes on native */ ok(logfont.lfItalic == 1, "got %d\n", logfont.lfItalic); ok(logfont.lfUnderline == 0, "got %d\n", logfont.lfUnderline); ok(logfont.lfStrikeOut == 0, "got %d\n", logfont.lfStrikeOut); -todo_wine ok(!lstrcmpW(logfont.lfFaceName, tahomaW), "got %s\n", wine_dbgstr_w(logfont.lfFaceName)); IDWriteGdiInterop_Release(interop);