Commit 51d0f612 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

dwrite: Added GetLocaleNameLength/GetLocaleName for text format and layout.

parent fcae48a0
...@@ -35,6 +35,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(dwrite); ...@@ -35,6 +35,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
struct dwrite_textformat_data { struct dwrite_textformat_data {
WCHAR *family_name; WCHAR *family_name;
WCHAR *locale; WCHAR *locale;
UINT32 locale_len;
DWRITE_FONT_WEIGHT weight; DWRITE_FONT_WEIGHT weight;
DWRITE_FONT_STYLE style; DWRITE_FONT_STYLE style;
...@@ -114,6 +115,7 @@ static ULONG WINAPI dwritetextlayout_Release(IDWriteTextLayout *iface) ...@@ -114,6 +115,7 @@ static ULONG WINAPI dwritetextlayout_Release(IDWriteTextLayout *iface)
if (!ref) if (!ref)
{ {
release_format_data(&This->format);
heap_free(This->str); heap_free(This->str);
heap_free(This); heap_free(This);
} }
...@@ -289,15 +291,19 @@ static FLOAT WINAPI dwritetextlayout_GetFontSize(IDWriteTextLayout *iface) ...@@ -289,15 +291,19 @@ static FLOAT WINAPI dwritetextlayout_GetFontSize(IDWriteTextLayout *iface)
static UINT32 WINAPI dwritetextlayout_GetLocaleNameLength(IDWriteTextLayout *iface) static UINT32 WINAPI dwritetextlayout_GetLocaleNameLength(IDWriteTextLayout *iface)
{ {
struct dwrite_textlayout *This = impl_from_IDWriteTextLayout(iface); struct dwrite_textlayout *This = impl_from_IDWriteTextLayout(iface);
FIXME("(%p): stub\n", This); TRACE("(%p)\n", This);
return 0; return This->format.locale_len;
} }
static HRESULT WINAPI dwritetextlayout_GetLocaleName(IDWriteTextLayout *iface, WCHAR *name, UINT32 size) static HRESULT WINAPI dwritetextlayout_GetLocaleName(IDWriteTextLayout *iface, WCHAR *name, UINT32 size)
{ {
struct dwrite_textlayout *This = impl_from_IDWriteTextLayout(iface); 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) static HRESULT WINAPI dwritetextlayout_SetMaxWidth(IDWriteTextLayout *iface, FLOAT maxWidth)
...@@ -668,6 +674,7 @@ static const IDWriteTextLayoutVtbl dwritetextlayoutvtbl = { ...@@ -668,6 +674,7 @@ static const IDWriteTextLayoutVtbl dwritetextlayoutvtbl = {
HRESULT create_textlayout(const WCHAR *str, UINT32 len, IDWriteTextFormat *format, IDWriteTextLayout **layout) HRESULT create_textlayout(const WCHAR *str, UINT32 len, IDWriteTextFormat *format, IDWriteTextLayout **layout)
{ {
struct dwrite_textlayout *This; struct dwrite_textlayout *This;
UINT32 locale_len;
*layout = NULL; *layout = NULL;
...@@ -682,6 +689,13 @@ HRESULT create_textlayout(const WCHAR *str, UINT32 len, IDWriteTextFormat *forma ...@@ -682,6 +689,13 @@ HRESULT create_textlayout(const WCHAR *str, UINT32 len, IDWriteTextFormat *forma
/* reference is not kept here, instead copy all underlying data */ /* reference is not kept here, instead copy all underlying data */
IDWriteTextFormat_GetFontCollection(format, &This->format.collection); 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.weight = IDWriteTextFormat_GetFontWeight(format);
This->format.style = IDWriteTextFormat_GetFontStyle(format); This->format.style = IDWriteTextFormat_GetFontStyle(format);
This->format.stretch = IDWriteTextFormat_GetFontStretch(format); This->format.stretch = IDWriteTextFormat_GetFontStretch(format);
...@@ -908,15 +922,19 @@ static FLOAT WINAPI dwritetextformat_GetFontSize(IDWriteTextFormat *iface) ...@@ -908,15 +922,19 @@ static FLOAT WINAPI dwritetextformat_GetFontSize(IDWriteTextFormat *iface)
static UINT32 WINAPI dwritetextformat_GetLocaleNameLength(IDWriteTextFormat *iface) static UINT32 WINAPI dwritetextformat_GetLocaleNameLength(IDWriteTextFormat *iface)
{ {
struct dwrite_textformat *This = impl_from_IDWriteTextFormat(iface); struct dwrite_textformat *This = impl_from_IDWriteTextFormat(iface);
FIXME("(%p): stub\n", This); TRACE("(%p)\n", This);
return 0; return This->format.locale_len;
} }
static HRESULT WINAPI dwritetextformat_GetLocaleName(IDWriteTextFormat *iface, WCHAR *name, UINT32 size) static HRESULT WINAPI dwritetextformat_GetLocaleName(IDWriteTextFormat *iface, WCHAR *name, UINT32 size)
{ {
struct dwrite_textformat *This = impl_from_IDWriteTextFormat(iface); 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 = { static const IDWriteTextFormatVtbl dwritetextformatvtbl = {
...@@ -964,6 +982,7 @@ HRESULT create_textformat(const WCHAR *family_name, IDWriteFontCollection *colle ...@@ -964,6 +982,7 @@ HRESULT create_textformat(const WCHAR *family_name, IDWriteFontCollection *colle
This->ref = 1; This->ref = 1;
This->format.family_name = heap_strdupW(family_name); This->format.family_name = heap_strdupW(family_name);
This->format.locale = heap_strdupW(locale); This->format.locale = heap_strdupW(locale);
This->format.locale_len = strlenW(locale);
This->format.weight = weight; This->format.weight = weight;
This->format.style = style; This->format.style = style;
This->format.size = size; This->format.size = size;
......
...@@ -134,6 +134,41 @@ if (0) /* crashes on native */ ...@@ -134,6 +134,41 @@ if (0) /* crashes on native */
IDWriteTextFormat_Release(format); 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) START_TEST(layout)
{ {
HRESULT hr; HRESULT hr;
...@@ -149,6 +184,7 @@ START_TEST(layout) ...@@ -149,6 +184,7 @@ START_TEST(layout)
test_CreateTextLayout(); test_CreateTextLayout();
test_CreateGdiCompatibleTextLayout(); test_CreateGdiCompatibleTextLayout();
test_CreateTextFormat(); test_CreateTextFormat();
test_GetLocaleName();
IDWriteFactory_Release(factory); IDWriteFactory_Release(factory);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment