dwrite: Add family name to string array.

This commit is contained in:
Nikolay Sivov 2012-10-07 17:13:29 -04:00 committed by Alexandre Julliard
parent 41df37f17d
commit 98ce55c148
3 changed files with 63 additions and 5 deletions

View File

@ -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;

View File

@ -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,

View File

@ -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);