From ad69c7bf6d574e75456c0d92ee200ce2ecab7eae Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Tue, 4 Nov 2014 22:53:19 +0300 Subject: [PATCH] dwrite: Implement GetFaceNames(). --- dlls/dwrite/font.c | 52 ++++++++++++++++++++++++++++++++--- dlls/dwrite/tests/font.c | 59 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 4 deletions(-) diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index 165e39513af..95fbdc6911a 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -85,7 +85,7 @@ struct dwrite_font { IDWriteFontFamily *family; - DWRITE_FONT_SIMULATIONS simulations; + USHORT simulations; struct dwrite_font_data *data; }; @@ -111,7 +111,7 @@ struct dwrite_fontface { UINT32 file_count; UINT32 index; - DWRITE_FONT_SIMULATIONS simulations; + USHORT simulations; DWRITE_FONT_FACE_TYPE type; struct dwrite_fonttable cmap; @@ -812,9 +812,53 @@ static BOOL WINAPI dwritefont_IsSymbolFont(IDWriteFont2 *iface) static HRESULT WINAPI dwritefont_GetFaceNames(IDWriteFont2 *iface, IDWriteLocalizedStrings **names) { + static const WCHAR boldobliqueW[] = {'B','o','l','d',' ','O','b','l','i','q','u','e',0}; + static const WCHAR obliqueW[] = {'O','b','l','i','q','u','e',0}; + static const WCHAR boldW[] = {'B','o','l','d',0}; + static const WCHAR enusW[] = {'e','n','-','u','s',0}; + struct dwrite_font *This = impl_from_IDWriteFont2(iface); - FIXME("(%p)->(%p): stub\n", This, names); - return E_NOTIMPL; + IDWriteLocalizedStrings *strings; + const WCHAR *name; + HRESULT hr; + + TRACE("(%p)->(%p)\n", This, names); + + *names = NULL; + + if (This->simulations == DWRITE_FONT_SIMULATIONS_NONE) { + BOOL exists; + return IDWriteFont2_GetInformationalStrings(iface, DWRITE_INFORMATIONAL_STRING_WIN32_SUBFAMILY_NAMES, + names, &exists); + } + + switch (This->simulations) { + case DWRITE_FONT_SIMULATIONS_BOLD|DWRITE_FONT_SIMULATIONS_OBLIQUE: + name = boldobliqueW; + break; + case DWRITE_FONT_SIMULATIONS_BOLD: + name = boldW; + break; + case DWRITE_FONT_SIMULATIONS_OBLIQUE: + name = obliqueW; + break; + default: + ERR("unknown simulations %d\n", This->simulations); + return E_FAIL; + } + + hr = create_localizedstrings(&strings); + if (FAILED(hr)) return hr; + + hr = add_localizedstring(strings, enusW, name); + if (FAILED(hr)) { + IDWriteLocalizedStrings_Release(strings); + return hr; + } + + *names = strings; + + return S_OK; } static HRESULT WINAPI dwritefont_GetInformationalStrings(IDWriteFont2 *iface, diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index a93ee33a7ce..dec90fe4041 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -2048,6 +2048,64 @@ todo_wine IDWriteFactory_Release(factory); } +static void test_GetFaceNames(void) +{ + static const WCHAR obliqueW[] = {'O','b','l','i','q','u','e',0}; + static const WCHAR enusW[] = {'e','n','-','u','s',0}; + IDWriteLocalizedStrings *strings, *strings2; + IDWriteGdiInterop *interop; + IDWriteFactory *factory; + IDWriteFont *font; + LOGFONTW logfont; + WCHAR buffW[255]; + UINT32 count; + HRESULT hr; + + factory = create_factory(); + + hr = IDWriteFactory_GetGdiInterop(factory, &interop); + ok(hr == S_OK, "got 0x%08x\n", hr); + + memset(&logfont, 0, sizeof(logfont)); + logfont.lfHeight = 12; + logfont.lfWidth = 12; + logfont.lfWeight = FW_NORMAL; + logfont.lfItalic = 1; + lstrcpyW(logfont.lfFaceName, tahomaW); + + hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IDWriteFont_GetFaceNames(font, &strings); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IDWriteFont_GetFaceNames(font, &strings2); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(strings != strings2, "got %p, %p\n", strings2, strings); + IDWriteLocalizedStrings_Release(strings2); + + count = IDWriteLocalizedStrings_GetCount(strings); + ok(count == 1, "got %d\n", count); + + /* for simulated faces names are also simulated */ + buffW[0] = 0; + hr = IDWriteLocalizedStrings_GetLocaleName(strings, 0, buffW, sizeof(buffW)/sizeof(WCHAR)); +todo_wine { + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(!lstrcmpW(buffW, enusW), "got %s\n", wine_dbgstr_w(buffW)); +} + + buffW[0] = 0; + hr = IDWriteLocalizedStrings_GetString(strings, 0, buffW, sizeof(buffW)/sizeof(WCHAR)); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(!lstrcmpW(buffW, obliqueW), "got %s\n", wine_dbgstr_w(buffW)); + IDWriteLocalizedStrings_Release(strings); + + IDWriteFont_Release(font); + IDWriteGdiInterop_Release(interop); + IDWriteFactory_Release(factory); +} + START_TEST(font) { IDWriteFactory *factory; @@ -2076,6 +2134,7 @@ START_TEST(font) test_GetGdiInterop(); test_CreateFontFaceFromHdc(); test_GetSimulations(); + test_GetFaceNames(); IDWriteFactory_Release(factory); }