diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h index a23a9d5af9..77834cd2d2 100644 --- a/dlls/dwrite/dwrite_private.h +++ b/dlls/dwrite/dwrite_private.h @@ -91,6 +91,7 @@ extern HRESULT create_trimmingsign(IDWriteInlineObject**) DECLSPEC_HIDDEN; extern HRESULT get_gdiinterop(IDWriteGdiInterop**) DECLSPEC_HIDDEN; extern HRESULT create_localizedstrings(IDWriteLocalizedStrings**) DECLSPEC_HIDDEN; extern HRESULT add_localizedstring(IDWriteLocalizedStrings*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN; +extern HRESULT clone_localizedstring(IDWriteLocalizedStrings *iface, IDWriteLocalizedStrings **strings) DECLSPEC_HIDDEN; extern HRESULT get_system_fontcollection(IDWriteFontCollection**) DECLSPEC_HIDDEN; extern HRESULT get_textanalyzer(IDWriteTextAnalyzer**) DECLSPEC_HIDDEN; extern HRESULT create_font_file(IDWriteFontFileLoader *loader, const void *reference_key, UINT32 key_size, IDWriteFontFile **font_file) DECLSPEC_HIDDEN; diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index c6fcf6a944..8b59a37f91 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -77,7 +77,7 @@ struct dwrite_fontfamily { IDWriteFontCollection* collection; - WCHAR *familyname; + IDWriteLocalizedStrings *familyname; }; struct dwrite_font { @@ -123,7 +123,7 @@ struct dwrite_fontfile { IDWriteFontFileStream *stream; }; -static HRESULT create_fontfamily(const WCHAR *familyname, IDWriteFontFamily **family); +static HRESULT create_fontfamily(IDWriteLocalizedStrings *familyname, IDWriteFontFamily **family); static HRESULT create_font_base(IDWriteFont **font); static HRESULT create_font_from_data(struct dwrite_font_data *data, IDWriteFont **font); @@ -744,7 +744,7 @@ static ULONG WINAPI dwritefontfamily_Release(IDWriteFontFamily *iface) if (!ref) { int i; - heap_free(This->familyname); + IDWriteLocalizedStrings_Release(This->familyname); if (This->collection) IDWriteFontCollection_Release(This->collection); @@ -803,15 +803,7 @@ 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; - - TRACE("(%p)->(%p)\n", This, names); - - hr = create_localizedstrings(names); - if (FAILED(hr)) return hr; - - return add_localizedstring(*names, enusW, This->familyname); + return clone_localizedstring(This->familyname, names); } static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily *iface, DWRITE_FONT_WEIGHT weight, @@ -828,7 +820,7 @@ static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily *i memset(&lf, 0, sizeof(lf)); lf.lfWeight = weight; lf.lfItalic = style == DWRITE_FONT_STYLE_ITALIC; - strcpyW(lf.lfFaceName, This->familyname); + IDWriteLocalizedStrings_GetString(This->familyname, 0, lf.lfFaceName, LF_FACESIZE); return create_font_from_logfont(&lf, font); } @@ -929,6 +921,9 @@ static UINT32 WINAPI dwritefontcollection_GetFontFamilyCount(IDWriteFontCollecti static HRESULT WINAPI dwritefontcollection_GetFontFamily(IDWriteFontCollection *iface, UINT32 index, IDWriteFontFamily **family) { struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection(iface); + HRESULT hr; + IDWriteLocalizedStrings *familyname; + static const WCHAR enusW[] = {'e','n','-','u','s',0}; TRACE("(%p)->(%u %p)\n", This, index, family); @@ -938,7 +933,12 @@ static HRESULT WINAPI dwritefontcollection_GetFontFamily(IDWriteFontCollection * return E_FAIL; } - return create_fontfamily(This->families[index], family); + hr = create_localizedstrings(&familyname); + if (FAILED(hr)) + return hr; + add_localizedstring(familyname, enusW, This->families[index]); + + return create_fontfamily(familyname, family); } static HRESULT WINAPI dwritefontcollection_FindFamilyName(IDWriteFontCollection *iface, const WCHAR *name, UINT32 *index, BOOL *exists) @@ -1035,7 +1035,7 @@ HRESULT get_system_fontcollection(IDWriteFontCollection **collection) return S_OK; } -static HRESULT create_fontfamily(const WCHAR *familyname, IDWriteFontFamily **family) +static HRESULT create_fontfamily(IDWriteLocalizedStrings *familyname, IDWriteFontFamily **family) { struct dwrite_fontfamily *This; @@ -1050,7 +1050,7 @@ static HRESULT create_fontfamily(const WCHAR *familyname, IDWriteFontFamily **fa This->alloc = 2; This->fonts = heap_alloc(sizeof(*This->fonts) * 2); This->collection = NULL; - This->familyname = heap_strdupW(familyname); + This->familyname = familyname; *family = &This->IDWriteFontFamily_iface; @@ -1098,6 +1098,7 @@ static HRESULT create_font_base(IDWriteFont **font) HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font) { const WCHAR* facename, *familyname; + IDWriteLocalizedStrings *name; struct dwrite_font *This; IDWriteFontFamily *family; OUTLINETEXTMETRICW *otm; @@ -1105,6 +1106,7 @@ HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font) HFONT hfont; HDC hdc; int ret; + static const WCHAR enusW[] = {'e','n','-','u','s',0}; LPVOID tt_os2 = NULL; LPVOID tt_head = NULL; LPVOID tt_post = NULL; @@ -1174,7 +1176,15 @@ HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font) familyname = (WCHAR*)((char*)otm + (ptrdiff_t)otm->otmpFamilyName); TRACE("facename=%s, familyname=%s\n", debugstr_w(facename), debugstr_w(familyname)); - hr = create_fontfamily(familyname, &family); + hr = create_localizedstrings(&name); + if (FAILED(hr)) + { + heap_free(This); + return hr; + } + add_localizedstring(name, enusW, familyname); + hr = create_fontfamily(name, &family); + heap_free(otm); if (hr != S_OK) { diff --git a/dlls/dwrite/main.c b/dlls/dwrite/main.c index 01394dcae1..bcddbba3b3 100644 --- a/dlls/dwrite/main.c +++ b/dlls/dwrite/main.c @@ -355,6 +355,37 @@ HRESULT add_localizedstring(IDWriteLocalizedStrings *iface, const WCHAR *locale, return S_OK; } +HRESULT clone_localizedstring(IDWriteLocalizedStrings *iface, IDWriteLocalizedStrings **strings) +{ + struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface); + struct localizedstrings *New; + int i; + + *strings = NULL; + + New = heap_alloc(sizeof(struct localizedstrings)); + if (!This) return E_OUTOFMEMORY; + + New->IDWriteLocalizedStrings_iface.lpVtbl = &localizedstringsvtbl; + New->ref = 1; + New->count = This->count; + New->data = heap_alloc(sizeof(struct localizedpair) * New->count); + if (!New->data) { + heap_free(New); + return E_OUTOFMEMORY; + } + for (i = 0; i < New->count; i++) + { + New->data[i].locale = heap_strdupW(This->data[i].locale); + New->data[i].string = heap_strdupW(This->data[i].string); + } + New->alloc = New->count; + + *strings = &New->IDWriteLocalizedStrings_iface; + + return S_OK; +} + struct dwritefactory{ IDWriteFactory IDWriteFactory_iface; LONG ref;