From debc356afd026a9e4c75fa3ffefbf628088f2e02 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Sat, 25 Aug 2012 13:11:31 +0400 Subject: [PATCH] dwrite: Added IDWriteFontFamily stub. --- dlls/dwrite/font.c | 146 +++++++++++++++++++++++++++++++++++++++++++++-- dlls/dwrite/tests/font.c | 56 ++++++++++++++++++ 2 files changed, 198 insertions(+), 4 deletions(-) diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index e73ef445e1f..892ee728a7a 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -27,10 +27,16 @@ WINE_DEFAULT_DEBUG_CHANNEL(dwrite); +struct dwrite_fontfamily { + IDWriteFontFamily IDWriteFontFamily_iface; + LONG ref; +}; + struct dwrite_font { IDWriteFont IDWriteFont_iface; LONG ref; + IDWriteFontFamily *family; DWRITE_FONT_STYLE style; }; @@ -39,6 +45,11 @@ static inline struct dwrite_font *impl_from_IDWriteFont(IDWriteFont *iface) return CONTAINING_RECORD(iface, struct dwrite_font, IDWriteFont_iface); } +static inline struct dwrite_fontfamily *impl_from_IDWriteFontFamily(IDWriteFontFamily *iface) +{ + return CONTAINING_RECORD(iface, struct dwrite_fontfamily, IDWriteFontFamily_iface); +} + static HRESULT WINAPI dwritefont_QueryInterface(IDWriteFont *iface, REFIID riid, void **obj) { struct dwrite_font *This = impl_from_IDWriteFont(iface); @@ -72,7 +83,10 @@ static ULONG WINAPI dwritefont_Release(IDWriteFont *iface) TRACE("(%p)->(%d)\n", This, ref); if (!ref) + { + IDWriteFontFamily_Release(This->family); heap_free(This); + } return S_OK; } @@ -80,8 +94,11 @@ static ULONG WINAPI dwritefont_Release(IDWriteFont *iface) static HRESULT WINAPI dwritefont_GetFontFamily(IDWriteFont *iface, IDWriteFontFamily **family) { struct dwrite_font *This = impl_from_IDWriteFont(iface); - FIXME("(%p)->(%p): stub\n", This, family); - return E_NOTIMPL; + TRACE("(%p)->(%p)\n", This, family); + + *family = This->family; + IDWriteFontFamily_AddRef(*family); + return S_OK; } static DWRITE_FONT_WEIGHT WINAPI dwritefont_GetWeight(IDWriteFont *iface) @@ -171,18 +188,139 @@ static const IDWriteFontVtbl dwritefontvtbl = { dwritefont_CreateFontFace }; +static HRESULT WINAPI dwritefontfamily_QueryInterface(IDWriteFontFamily *iface, REFIID riid, void **obj) +{ + struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface); + TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj); + + if (IsEqualIID(riid, &IID_IUnknown) || + IsEqualIID(riid, &IID_IDWriteFontList) || + IsEqualIID(riid, &IID_IDWriteFontFamily)) + { + *obj = iface; + IDWriteFontFamily_AddRef(iface); + return S_OK; + } + + *obj = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI dwritefontfamily_AddRef(IDWriteFontFamily *iface) +{ + struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface); + ULONG ref = InterlockedIncrement(&This->ref); + TRACE("(%p)->(%d)\n", This, ref); + return ref; +} + +static ULONG WINAPI dwritefontfamily_Release(IDWriteFontFamily *iface) +{ + struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface); + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p)->(%d)\n", This, ref); + + if (!ref) + heap_free(This); + + return S_OK; +} + +static HRESULT WINAPI dwritefontfamily_GetFontCollection(IDWriteFontFamily *iface, IDWriteFontCollection **collection) +{ + struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface); + FIXME("(%p)->(%p): stub\n", This, collection); + return E_NOTIMPL; +} + +static UINT32 WINAPI dwritefontfamily_GetFontCount(IDWriteFontFamily *iface) +{ + struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface); + FIXME("(%p): stub\n", This); + return 0; +} + +static HRESULT WINAPI dwritefontfamily_GetFont(IDWriteFontFamily *iface, UINT32 index, IDWriteFont **font) +{ + struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface); + FIXME("(%p)->(%u %p): stub\n", This, index, font); + return E_NOTIMPL; +} + +static HRESULT WINAPI dwritefontfamily_GetFamilyNames(IDWriteFontFamily *iface, IDWriteLocalizedStrings **names) +{ + struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface); + FIXME("(%p)->(%p): stub\n", This, names); + return E_NOTIMPL; +} + +static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily *iface, DWRITE_FONT_WEIGHT weight, + DWRITE_FONT_STRETCH stretch, DWRITE_FONT_STYLE style, IDWriteFont **font) +{ + struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface); + FIXME("(%p)->(%d %d %d %p): stub\n", This, weight, stretch, style, font); + return E_NOTIMPL; +} + +static HRESULT WINAPI dwritefontfamily_GetMatchingFonts(IDWriteFontFamily *iface, DWRITE_FONT_WEIGHT weight, + DWRITE_FONT_STRETCH stretch, DWRITE_FONT_STYLE style, IDWriteFontList **fonts) +{ + struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface); + FIXME("(%p)->(%d %d %d %p): stub\n", This, weight, stretch, style, fonts); + return E_NOTIMPL; +} + +static const IDWriteFontFamilyVtbl fontfamilyvtbl = { + dwritefontfamily_QueryInterface, + dwritefontfamily_AddRef, + dwritefontfamily_Release, + dwritefontfamily_GetFontCollection, + dwritefontfamily_GetFontCount, + dwritefontfamily_GetFont, + dwritefontfamily_GetFamilyNames, + dwritefontfamily_GetFirstMatchingFont, + dwritefontfamily_GetMatchingFonts +}; + +static HRESULT create_fontfamily(IDWriteFontFamily **family) +{ + struct dwrite_fontfamily *This; + + *family = NULL; + + This = heap_alloc(sizeof(struct dwrite_fontfamily)); + if (!This) return E_OUTOFMEMORY; + + This->IDWriteFontFamily_iface.lpVtbl = &fontfamilyvtbl; + This->ref = 1; + + *family = &This->IDWriteFontFamily_iface; + + return S_OK; +} + HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font) { struct dwrite_font *This; + IDWriteFontFamily *family; + HRESULT hr; *font = NULL; + hr = create_fontfamily(&family); + if (hr != S_OK) return hr; + This = heap_alloc(sizeof(struct dwrite_font)); - if (!This) return E_OUTOFMEMORY; + if (!This) + { + IDWriteFontFamily_Release(family); + return E_OUTOFMEMORY; + } This->IDWriteFont_iface.lpVtbl = &dwritefontvtbl; This->ref = 1; - + This->family = family; This->style = logfont->lfItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL; *font = &This->IDWriteFont_iface; diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index ccaba88026a..64fe390f32c 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -30,6 +30,14 @@ #define EXPECT_HR(hr,hr_exp) \ ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp) +#define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__) +static void _expect_ref(IUnknown* obj, ULONG ref, int line) +{ + ULONG rc = IUnknown_AddRef(obj); + IUnknown_Release(obj); + ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1); +} + static IDWriteFactory *factory; static void test_CreateFontFromLOGFONT(void) @@ -234,6 +242,53 @@ if (0) /* crashes on native */ IDWriteGdiInterop_Release(interop); } +static void test_GetFontFamily(void) +{ + static const WCHAR arialW[] = {'A','r','i','a','l',0}; + IDWriteFontFamily *family, *family2; + IDWriteGdiInterop *interop; + IDWriteFont *font; + LOGFONTW logfont; + HRESULT hr; + + hr = IDWriteFactory_GetGdiInterop(factory, &interop); + EXPECT_HR(hr, S_OK); + + memset(&logfont, 0, sizeof(logfont)); + logfont.lfHeight = 12; + logfont.lfWidth = 12; + logfont.lfWeight = FW_NORMAL; + logfont.lfItalic = 1; + lstrcpyW(logfont.lfFaceName, arialW); + + hr = IDWriteGdiInterop_CreateFontFromLOGFONT(interop, &logfont, &font); + EXPECT_HR(hr, S_OK); + +if (0) /* crashes on native */ + hr = IDWriteFont_GetFontFamily(font, NULL); + + EXPECT_REF(font, 1); + hr = IDWriteFont_GetFontFamily(font, &family); + EXPECT_HR(hr, S_OK); + EXPECT_REF(font, 1); + EXPECT_REF(family, 2); + + hr = IDWriteFont_GetFontFamily(font, &family2); + EXPECT_HR(hr, S_OK); + ok(family2 == family, "got %p, previous %p\n", family2, family); + EXPECT_REF(font, 1); + EXPECT_REF(family, 3); + IDWriteFontFamily_Release(family2); + + hr = IDWriteFont_QueryInterface(font, &IID_IDWriteFontFamily, (void**)&family2); + EXPECT_HR(hr, E_NOINTERFACE); + ok(family2 == NULL, "got %p\n", family2); + + IDWriteFontFamily_Release(family); + IDWriteFont_Release(font); + IDWriteGdiInterop_Release(interop); +} + START_TEST(font) { HRESULT hr; @@ -248,6 +303,7 @@ START_TEST(font) test_CreateFontFromLOGFONT(); test_CreateBitmapRenderTarget(); + test_GetFontFamily(); IDWriteFactory_Release(factory); } -- 2.11.4.GIT