From 98ce55c148bcad1122a85df7dd1c2229074ee1ee Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Sun, 7 Oct 2012 17:13:29 -0400 Subject: [PATCH] dwrite: Add family name to string array. --- dlls/dwrite/dwrite_private.h | 11 +++++++++ dlls/dwrite/font.c | 10 ++++++-- dlls/dwrite/main.c | 47 +++++++++++++++++++++++++++++++++--- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h index cba81309b2a..a754f4264e9 100644 --- a/dlls/dwrite/dwrite_private.h +++ b/dlls/dwrite/dwrite_private.h @@ -23,6 +23,16 @@ static inline void *heap_alloc(size_t len) return HeapAlloc(GetProcessHeap(), 0, len); } +static inline void *heap_alloc_zero(size_t len) +{ + return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len); +} + +static inline void *heap_realloc(void *mem, size_t len) +{ + return HeapReAlloc(GetProcessHeap(), 0, mem, len); +} + static inline BOOL heap_free(void *mem) { return HeapFree(GetProcessHeap(), 0, mem); @@ -47,3 +57,4 @@ extern HRESULT create_font_from_logfont(const LOGFONTW*, IDWriteFont**) DECLSPEC extern HRESULT create_textlayout(IDWriteTextLayout**) DECLSPEC_HIDDEN; extern HRESULT create_gdiinterop(IDWriteGdiInterop**) DECLSPEC_HIDDEN; extern HRESULT create_localizedstrings(IDWriteLocalizedStrings**) DECLSPEC_HIDDEN; +extern HRESULT add_localizedstring(IDWriteLocalizedStrings*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN; diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index 3890f892ae1..4acd35fdc12 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -471,9 +471,15 @@ static HRESULT WINAPI dwritefontfamily_GetFont(IDWriteFontFamily *iface, UINT32 static HRESULT WINAPI dwritefontfamily_GetFamilyNames(IDWriteFontFamily *iface, IDWriteLocalizedStrings **names) { struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface); + static const WCHAR enusW[] = {'e','n','-','u','s',0}; + HRESULT hr; - FIXME("(%p)->(%p): stub\n", This, names); - return create_localizedstrings(names); + TRACE("(%p)->(%p)\n", This, names); + + hr = create_localizedstrings(names); + if (FAILED(hr)) return hr; + + return add_localizedstring(*names, enusW, This->familyname); } static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily *iface, DWRITE_FONT_WEIGHT weight, diff --git a/dlls/dwrite/main.c b/dlls/dwrite/main.c index 679416b4ac1..b056cb101e1 100644 --- a/dlls/dwrite/main.c +++ b/dlls/dwrite/main.c @@ -172,9 +172,18 @@ static HRESULT create_renderingparams(FLOAT gamma, FLOAT enhancedContrast, FLOAT return S_OK; } +struct localizedpair { + WCHAR *locale; + WCHAR *string; +}; + struct localizedstrings { IDWriteLocalizedStrings IDWriteLocalizedStrings_iface; LONG ref; + + struct localizedpair *data; + UINT32 count; + UINT32 alloc; }; static inline struct localizedstrings *impl_from_IDWriteLocalizedStrings(IDWriteLocalizedStrings *iface) @@ -215,8 +224,17 @@ static ULONG WINAPI localizedstrings_Release(IDWriteLocalizedStrings *iface) TRACE("(%p)->(%d)\n", This, ref); - if (!ref) + if (!ref) { + int i; + + for (i = 0; i < This->count; i++) { + heap_free(This->data[i].locale); + heap_free(This->data[i].string); + } + + heap_free(This->data); heap_free(This); + } return S_OK; } @@ -224,8 +242,8 @@ static ULONG WINAPI localizedstrings_Release(IDWriteLocalizedStrings *iface) static UINT32 WINAPI localizedstrings_GetCount(IDWriteLocalizedStrings *iface) { struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface); - FIXME("(%p): stub\n", This); - return 0; + TRACE("(%p)\n", This); + return This->count; } static HRESULT WINAPI localizedstrings_FindLocaleName(IDWriteLocalizedStrings *iface, @@ -287,12 +305,35 @@ HRESULT create_localizedstrings(IDWriteLocalizedStrings **strings) This->IDWriteLocalizedStrings_iface.lpVtbl = &localizedstringsvtbl; This->ref = 1; + This->count = 0; + This->data = heap_alloc_zero(sizeof(struct localizedpair)); + if (!This->data) { + heap_free(This); + return E_OUTOFMEMORY; + } + This->alloc = 1; *strings = &This->IDWriteLocalizedStrings_iface; return S_OK; } +HRESULT add_localizedstring(IDWriteLocalizedStrings *iface, const WCHAR *locale, const WCHAR *string) +{ + struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface); + + if (This->count == This->alloc) { + This->alloc *= 2; + This->data = heap_realloc(This->data, This->alloc*sizeof(struct localizedpair)); + } + + This->data[This->count].locale = heap_strdupW(locale); + This->data[This->count].string = heap_strdupW(string); + This->count++; + + return S_OK; +} + static HRESULT WINAPI dwritefactory_QueryInterface(IDWriteFactory *iface, REFIID riid, void **obj) { TRACE("(%s %p)\n", debugstr_guid(riid), obj);