From fa1fe44c342e1912d54b3cc02281877915735ec9 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Sun, 15 Mar 2015 03:52:35 +0300 Subject: [PATCH] dwrite: Implement SetFontFallback(). --- dlls/dwrite/layout.c | 26 ++++++++++++++++++-------- dlls/dwrite/tests/layout.c | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c index 8e8bc9dd3bc..7326aa3dc78 100644 --- a/dlls/dwrite/layout.c +++ b/dlls/dwrite/layout.c @@ -235,6 +235,16 @@ static HRESULT get_fontfallback_from_format(const struct dwrite_textformat_data return S_OK; } +static HRESULT set_fontfallback_for_format(struct dwrite_textformat_data *format, IDWriteFontFallback *fallback) +{ + if (format->fallback) + IDWriteFontFallback_Release(format->fallback); + format->fallback = fallback; + if (fallback) + IDWriteFontFallback_AddRef(fallback); + return S_OK; +} + static struct layout_run *alloc_layout_run(void) { struct layout_run *ret; @@ -1867,8 +1877,8 @@ static DWRITE_OPTICAL_ALIGNMENT WINAPI dwritetextlayout2_GetOpticalAlignment(IDW static HRESULT WINAPI dwritetextlayout2_SetFontFallback(IDWriteTextLayout2 *iface, IDWriteFontFallback *fallback) { struct dwrite_textlayout *This = impl_from_IDWriteTextLayout2(iface); - FIXME("(%p)->(%p): stub\n", This, fallback); - return E_NOTIMPL; + TRACE("(%p)->(%p)\n", This, fallback); + return set_fontfallback_for_format(&This->format, fallback); } static HRESULT WINAPI dwritetextlayout2_GetFontFallback(IDWriteTextLayout2 *iface, IDWriteFontFallback **fallback) @@ -2228,15 +2238,15 @@ static DWRITE_OPTICAL_ALIGNMENT WINAPI dwritetextformat1_layout_GetOpticalAlignm static HRESULT WINAPI dwritetextformat1_layout_SetFontFallback(IDWriteTextFormat1 *iface, IDWriteFontFallback *fallback) { struct dwrite_textlayout *This = impl_layout_form_IDWriteTextFormat1(iface); - FIXME("(%p)->(%p): stub\n", This, fallback); - return E_NOTIMPL; + TRACE("(%p)->(%p)\n", This, fallback); + return IDWriteTextLayout2_SetFontFallback(&This->IDWriteTextLayout2_iface, fallback); } static HRESULT WINAPI dwritetextformat1_layout_GetFontFallback(IDWriteTextFormat1 *iface, IDWriteFontFallback **fallback) { struct dwrite_textlayout *This = impl_layout_form_IDWriteTextFormat1(iface); - TRACE("(%p)->(%p): stub\n", This, fallback); - return E_NOTIMPL; + TRACE("(%p)->(%p)\n", This, fallback); + return IDWriteTextLayout2_GetFontFallback(&This->IDWriteTextLayout2_iface, fallback); } static const IDWriteTextFormat1Vtbl dwritetextformat1_layout_vtbl = { @@ -3055,8 +3065,8 @@ static DWRITE_OPTICAL_ALIGNMENT WINAPI dwritetextformat1_GetOpticalAlignment(IDW static HRESULT WINAPI dwritetextformat1_SetFontFallback(IDWriteTextFormat1 *iface, IDWriteFontFallback *fallback) { struct dwrite_textformat *This = impl_from_IDWriteTextFormat1(iface); - FIXME("(%p)->(%p): stub\n", This, fallback); - return E_NOTIMPL; + TRACE("(%p)->(%p)\n", This, fallback); + return set_fontfallback_for_format(&This->format, fallback); } static HRESULT WINAPI dwritetextformat1_GetFontFallback(IDWriteTextFormat1 *iface, IDWriteFontFallback **fallback) diff --git a/dlls/dwrite/tests/layout.c b/dlls/dwrite/tests/layout.c index b06c6bc858c..5b15c37e279 100644 --- a/dlls/dwrite/tests/layout.c +++ b/dlls/dwrite/tests/layout.c @@ -1204,10 +1204,12 @@ static void test_SetVerticalGlyphOrientation(void) static void test_fallback(void) { static const WCHAR strW[] = {'a','b','c','d',0}; - IDWriteFontFallback *fallback; + IDWriteFontFallback *fallback, *fallback2; IDWriteTextLayout2 *layout2; + IDWriteTextFormat1 *format1; IDWriteTextFormat *format; IDWriteTextLayout *layout; + IDWriteFactory2 *factory2; IDWriteFactory *factory; HRESULT hr; @@ -1238,6 +1240,43 @@ if (0) /* crashes on native */ ok(hr == S_OK, "got 0x%08x\n", hr); ok(fallback == NULL, "got %p\n", fallback); + hr = IDWriteTextLayout2_QueryInterface(layout2, &IID_IDWriteTextFormat1, (void**)&format1); + ok(hr == S_OK, "got 0x%08x\n", hr); + + fallback = (void*)0xdeadbeef; + hr = IDWriteTextFormat1_GetFontFallback(format1, &fallback); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(fallback == NULL, "got %p\n", fallback); + + hr = IDWriteFactory_QueryInterface(factory, &IID_IDWriteFactory2, (void**)&factory2); + ok(hr == S_OK, "got 0x%08x\n", hr); + + fallback = NULL; + hr = IDWriteFactory2_GetSystemFontFallback(factory2, &fallback); +todo_wine + ok(hr == S_OK, "got 0x%08x\n", hr); +if (hr == S_OK) { + ok(fallback != NULL, "got %p\n", fallback); + + hr = IDWriteTextFormat1_SetFontFallback(format1, fallback); + ok(hr == S_OK, "got 0x%08x\n", hr); + + fallback2 = (void*)0xdeadbeef; + hr = IDWriteTextLayout2_GetFontFallback(layout2, &fallback2); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(fallback2 == fallback, "got %p\n", fallback2); + + hr = IDWriteTextLayout2_SetFontFallback(layout2, NULL); + ok(hr == S_OK, "got 0x%08x\n", hr); + + fallback2 = (void*)0xdeadbeef; + hr = IDWriteTextFormat1_GetFontFallback(format1, &fallback2); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(fallback2 == NULL, "got %p\n", fallback2); + + IDWriteFontFallback_Release(fallback); +} + IDWriteTextFormat1_Release(format1); IDWriteTextLayout2_Release(layout2); IDWriteFactory_Release(factory); } -- 2.11.4.GIT