Module: wine Branch: master Commit: 51d0f61272cc2aeb3cc0aba2653174caa7dba8e9 URL: http://source.winehq.org/git/wine.git/?a=commit;h=51d0f61272cc2aeb3cc0aba265...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Fri Oct 26 12:50:12 2012 -0400
dwrite: Added GetLocaleNameLength/GetLocaleName for text format and layout.
---
dlls/dwrite/layout.c | 35 +++++++++++++++++++++++++++-------- dlls/dwrite/tests/layout.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 8 deletions(-)
diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c index 76c5adb..f6bc421 100644 --- a/dlls/dwrite/layout.c +++ b/dlls/dwrite/layout.c @@ -35,6 +35,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(dwrite); struct dwrite_textformat_data { WCHAR *family_name; WCHAR *locale; + UINT32 locale_len;
DWRITE_FONT_WEIGHT weight; DWRITE_FONT_STYLE style; @@ -114,6 +115,7 @@ static ULONG WINAPI dwritetextlayout_Release(IDWriteTextLayout *iface)
if (!ref) { + release_format_data(&This->format); heap_free(This->str); heap_free(This); } @@ -289,15 +291,19 @@ static FLOAT WINAPI dwritetextlayout_GetFontSize(IDWriteTextLayout *iface) static UINT32 WINAPI dwritetextlayout_GetLocaleNameLength(IDWriteTextLayout *iface) { struct dwrite_textlayout *This = impl_from_IDWriteTextLayout(iface); - FIXME("(%p): stub\n", This); - return 0; + TRACE("(%p)\n", This); + return This->format.locale_len; }
static HRESULT WINAPI dwritetextlayout_GetLocaleName(IDWriteTextLayout *iface, WCHAR *name, UINT32 size) { struct dwrite_textlayout *This = impl_from_IDWriteTextLayout(iface); - FIXME("(%p)->(%p %u): stub\n", This, name, size); - return E_NOTIMPL; + + TRACE("(%p)->(%p %u)\n", This, name, size); + + if (size <= This->format.locale_len) return E_NOT_SUFFICIENT_BUFFER; + strcpyW(name, This->format.locale); + return S_OK; }
static HRESULT WINAPI dwritetextlayout_SetMaxWidth(IDWriteTextLayout *iface, FLOAT maxWidth) @@ -668,6 +674,7 @@ static const IDWriteTextLayoutVtbl dwritetextlayoutvtbl = { HRESULT create_textlayout(const WCHAR *str, UINT32 len, IDWriteTextFormat *format, IDWriteTextLayout **layout) { struct dwrite_textlayout *This; + UINT32 locale_len;
*layout = NULL;
@@ -682,6 +689,13 @@ HRESULT create_textlayout(const WCHAR *str, UINT32 len, IDWriteTextFormat *forma
/* reference is not kept here, instead copy all underlying data */ IDWriteTextFormat_GetFontCollection(format, &This->format.collection); + + /* locale name and length */ + locale_len = IDWriteTextFormat_GetLocaleNameLength(format); + This->format.locale = heap_alloc((locale_len+1)*sizeof(WCHAR)); + IDWriteTextFormat_GetLocaleName(format, This->format.locale, locale_len+1); + This->format.locale_len = locale_len; + This->format.weight = IDWriteTextFormat_GetFontWeight(format); This->format.style = IDWriteTextFormat_GetFontStyle(format); This->format.stretch = IDWriteTextFormat_GetFontStretch(format); @@ -908,15 +922,19 @@ static FLOAT WINAPI dwritetextformat_GetFontSize(IDWriteTextFormat *iface) static UINT32 WINAPI dwritetextformat_GetLocaleNameLength(IDWriteTextFormat *iface) { struct dwrite_textformat *This = impl_from_IDWriteTextFormat(iface); - FIXME("(%p): stub\n", This); - return 0; + TRACE("(%p)\n", This); + return This->format.locale_len; }
static HRESULT WINAPI dwritetextformat_GetLocaleName(IDWriteTextFormat *iface, WCHAR *name, UINT32 size) { struct dwrite_textformat *This = impl_from_IDWriteTextFormat(iface); - FIXME("(%p)->(%p %u): stub\n", This, name, size); - return E_NOTIMPL; + + TRACE("(%p)->(%p %u)\n", This, name, size); + + if (size <= This->format.locale_len) return E_NOT_SUFFICIENT_BUFFER; + strcpyW(name, This->format.locale); + return S_OK; }
static const IDWriteTextFormatVtbl dwritetextformatvtbl = { @@ -964,6 +982,7 @@ HRESULT create_textformat(const WCHAR *family_name, IDWriteFontCollection *colle This->ref = 1; This->format.family_name = heap_strdupW(family_name); This->format.locale = heap_strdupW(locale); + This->format.locale_len = strlenW(locale); This->format.weight = weight; This->format.style = style; This->format.size = size; diff --git a/dlls/dwrite/tests/layout.c b/dlls/dwrite/tests/layout.c index 6b8dc62..9656ba6 100644 --- a/dlls/dwrite/tests/layout.c +++ b/dlls/dwrite/tests/layout.c @@ -134,6 +134,41 @@ if (0) /* crashes on native */ IDWriteTextFormat_Release(format); }
+static void test_GetLocaleName(void) +{ + static const WCHAR strW[] = {'s','t','r','i','n','g',0}; + static const WCHAR ruW[] = {'r','u',0}; + IDWriteTextLayout *layout; + IDWriteTextFormat *format; + WCHAR buff[10]; + UINT32 len; + HRESULT hr; + + hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, + DWRITE_FONT_STRETCH_NORMAL, 10.0, ruW, &format); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 0, format, 100.0, 100.0, 1.0, NULL, FALSE, &layout); + ok(hr == S_OK, "got 0x%08x\n", hr); + len = IDWriteTextLayout_GetLocaleNameLength(layout); + ok(len == 2, "got %u\n", len); + len = IDWriteTextFormat_GetLocaleNameLength(format); + ok(len == 2, "got %u\n", len); + hr = IDWriteTextLayout_GetLocaleName(layout, buff, len); + ok(hr == E_NOT_SUFFICIENT_BUFFER, "got 0x%08x\n", hr); + hr = IDWriteTextLayout_GetLocaleName(layout, buff, len+1); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(!lstrcmpW(buff, ruW), "got %s\n", wine_dbgstr_w(buff)); + hr = IDWriteTextFormat_GetLocaleName(format, buff, len); + ok(hr == E_NOT_SUFFICIENT_BUFFER, "got 0x%08x\n", hr); + hr = IDWriteTextFormat_GetLocaleName(format, buff, len+1); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(!lstrcmpW(buff, ruW), "got %s\n", wine_dbgstr_w(buff)); + + IDWriteTextLayout_Release(layout); + IDWriteTextFormat_Release(format); +} + START_TEST(layout) { HRESULT hr; @@ -149,6 +184,7 @@ START_TEST(layout) test_CreateTextLayout(); test_CreateGdiCompatibleTextLayout(); test_CreateTextFormat(); + test_GetLocaleName();
IDWriteFactory_Release(factory); }