dwrite: Update matches list to IDWriteFontList2.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2019-10-09 11:04:56 +03:00 committed by Alexandre Julliard
parent cd4101dbba
commit 0159812e21
2 changed files with 79 additions and 60 deletions

View File

@ -135,9 +135,10 @@ struct dwrite_fontfamily
struct dwrite_fontcollection *collection; struct dwrite_fontcollection *collection;
}; };
struct dwrite_fontlist { struct dwrite_fontlist
IDWriteFontList1 IDWriteFontList1_iface; {
LONG ref; IDWriteFontList2 IDWriteFontList2_iface;
LONG refcount;
struct dwrite_font_data **fonts; struct dwrite_font_data **fonts;
UINT32 font_count; UINT32 font_count;
@ -313,9 +314,9 @@ static inline struct dwrite_colorglyphenum *impl_from_IDWriteColorGlyphRunEnumer
return CONTAINING_RECORD(iface, struct dwrite_colorglyphenum, IDWriteColorGlyphRunEnumerator_iface); return CONTAINING_RECORD(iface, struct dwrite_colorglyphenum, IDWriteColorGlyphRunEnumerator_iface);
} }
static inline struct dwrite_fontlist *impl_from_IDWriteFontList1(IDWriteFontList1 *iface) static inline struct dwrite_fontlist *impl_from_IDWriteFontList2(IDWriteFontList2 *iface)
{ {
return CONTAINING_RECORD(iface, struct dwrite_fontlist, IDWriteFontList1_iface); return CONTAINING_RECORD(iface, struct dwrite_fontlist, IDWriteFontList2_iface);
} }
static inline struct dwrite_fontfacereference *impl_from_IDWriteFontFaceReference1(IDWriteFontFaceReference1 *iface) static inline struct dwrite_fontfacereference *impl_from_IDWriteFontFaceReference1(IDWriteFontFaceReference1 *iface)
@ -1842,19 +1843,18 @@ static HRESULT create_font(struct dwrite_fontfamily *family, UINT32 index, IDWri
return S_OK; return S_OK;
} }
/* IDWriteFontList1 */ /* IDWriteFontList2 */
static HRESULT WINAPI dwritefontlist_QueryInterface(IDWriteFontList1 *iface, REFIID riid, void **obj) static HRESULT WINAPI dwritefontlist_QueryInterface(IDWriteFontList2 *iface, REFIID riid, void **obj)
{ {
struct dwrite_fontlist *This = impl_from_IDWriteFontList1(iface); TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj); if (IsEqualIID(riid, &IID_IDWriteFontList2) ||
IsEqualIID(riid, &IID_IDWriteFontList1) ||
if (IsEqualIID(riid, &IID_IDWriteFontList1) ||
IsEqualIID(riid, &IID_IDWriteFontList) || IsEqualIID(riid, &IID_IDWriteFontList) ||
IsEqualIID(riid, &IID_IUnknown)) IsEqualIID(riid, &IID_IUnknown))
{ {
*obj = iface; *obj = iface;
IDWriteFontList1_AddRef(iface); IDWriteFontList2_AddRef(iface);
return S_OK; return S_OK;
} }
@ -1864,102 +1864,104 @@ static HRESULT WINAPI dwritefontlist_QueryInterface(IDWriteFontList1 *iface, REF
return E_NOINTERFACE; return E_NOINTERFACE;
} }
static ULONG WINAPI dwritefontlist_AddRef(IDWriteFontList1 *iface) static ULONG WINAPI dwritefontlist_AddRef(IDWriteFontList2 *iface)
{ {
struct dwrite_fontlist *This = impl_from_IDWriteFontList1(iface); struct dwrite_fontlist *fontlist = impl_from_IDWriteFontList2(iface);
ULONG ref = InterlockedIncrement(&This->ref); ULONG refcount = InterlockedIncrement(&fontlist->refcount);
TRACE("(%p)->(%d)\n", This, ref);
return ref; TRACE("%p, refcount %u.\n", iface, refcount);
return refcount;
} }
static ULONG WINAPI dwritefontlist_Release(IDWriteFontList1 *iface) static ULONG WINAPI dwritefontlist_Release(IDWriteFontList2 *iface)
{ {
struct dwrite_fontlist *This = impl_from_IDWriteFontList1(iface); struct dwrite_fontlist *fontlist = impl_from_IDWriteFontList2(iface);
ULONG ref = InterlockedDecrement(&This->ref); ULONG refcount = InterlockedDecrement(&fontlist->refcount);
TRACE("(%p)->(%d)\n", This, ref); TRACE("%p, refcount %u.\n", iface, refcount);
if (!ref) { if (!refcount)
{
UINT32 i; UINT32 i;
for (i = 0; i < This->font_count; i++) for (i = 0; i < fontlist->font_count; i++)
release_font_data(This->fonts[i]); release_font_data(fontlist->fonts[i]);
IDWriteFontFamily2_Release(&This->family->IDWriteFontFamily2_iface); IDWriteFontFamily2_Release(&fontlist->family->IDWriteFontFamily2_iface);
heap_free(This->fonts); heap_free(fontlist->fonts);
heap_free(This); heap_free(fontlist);
} }
return ref; return refcount;
} }
static HRESULT WINAPI dwritefontlist_GetFontCollection(IDWriteFontList1 *iface, IDWriteFontCollection **collection) static HRESULT WINAPI dwritefontlist_GetFontCollection(IDWriteFontList2 *iface, IDWriteFontCollection **collection)
{ {
struct dwrite_fontlist *This = impl_from_IDWriteFontList1(iface); struct dwrite_fontlist *fontlist = impl_from_IDWriteFontList2(iface);
return IDWriteFontFamily2_GetFontCollection(&This->family->IDWriteFontFamily2_iface, collection); return IDWriteFontFamily2_GetFontCollection(&fontlist->family->IDWriteFontFamily2_iface, collection);
} }
static UINT32 WINAPI dwritefontlist_GetFontCount(IDWriteFontList1 *iface) static UINT32 WINAPI dwritefontlist_GetFontCount(IDWriteFontList2 *iface)
{ {
struct dwrite_fontlist *This = impl_from_IDWriteFontList1(iface); struct dwrite_fontlist *fontlist = impl_from_IDWriteFontList2(iface);
TRACE("(%p)\n", This);
return This->font_count; TRACE("%p.\n", iface);
return fontlist->font_count;
} }
static HRESULT WINAPI dwritefontlist_GetFont(IDWriteFontList1 *iface, UINT32 index, IDWriteFont **font) static HRESULT WINAPI dwritefontlist_GetFont(IDWriteFontList2 *iface, UINT32 index, IDWriteFont **font)
{ {
struct dwrite_fontlist *This = impl_from_IDWriteFontList1(iface); struct dwrite_fontlist *fontlist = impl_from_IDWriteFontList2(iface);
TRACE("(%p)->(%u %p)\n", This, index, font); TRACE("%p, %u, %p.\n", iface, index, font);
*font = NULL; *font = NULL;
if (This->font_count == 0) if (fontlist->font_count == 0)
return S_FALSE; return S_FALSE;
if (index >= This->font_count) if (index >= fontlist->font_count)
return E_INVALIDARG; return E_INVALIDARG;
return create_font(This->family, index, (IDWriteFont3 **)font); return create_font(fontlist->family, index, (IDWriteFont3 **)font);
} }
static DWRITE_LOCALITY WINAPI dwritefontlist1_GetFontLocality(IDWriteFontList1 *iface, UINT32 index) static DWRITE_LOCALITY WINAPI dwritefontlist1_GetFontLocality(IDWriteFontList2 *iface, UINT32 index)
{ {
struct dwrite_fontlist *This = impl_from_IDWriteFontList1(iface); FIXME("%p, %u.\n", iface, index);
FIXME("(%p)->(%u): stub\n", This, index);
return DWRITE_LOCALITY_LOCAL; return DWRITE_LOCALITY_LOCAL;
} }
static HRESULT WINAPI dwritefontlist1_GetFont(IDWriteFontList1 *iface, UINT32 index, IDWriteFont3 **font) static HRESULT WINAPI dwritefontlist1_GetFont(IDWriteFontList2 *iface, UINT32 index, IDWriteFont3 **font)
{ {
struct dwrite_fontlist *This = impl_from_IDWriteFontList1(iface); struct dwrite_fontlist *fontlist = impl_from_IDWriteFontList2(iface);
TRACE("(%p)->(%u %p)\n", This, index, font); TRACE("%p, %u, %p.\n", iface, index, font);
*font = NULL; *font = NULL;
if (This->font_count == 0) if (fontlist->font_count == 0)
return S_FALSE; return S_FALSE;
if (index >= This->font_count) if (index >= fontlist->font_count)
return E_FAIL; return E_FAIL;
return create_font(This->family, index, font); return create_font(fontlist->family, index, font);
} }
static HRESULT WINAPI dwritefontlist1_GetFontFaceReference(IDWriteFontList1 *iface, UINT32 index, static HRESULT WINAPI dwritefontlist1_GetFontFaceReference(IDWriteFontList2 *iface, UINT32 index,
IDWriteFontFaceReference **reference) IDWriteFontFaceReference **reference)
{ {
struct dwrite_fontlist *This = impl_from_IDWriteFontList1(iface);
IDWriteFont3 *font; IDWriteFont3 *font;
HRESULT hr; HRESULT hr;
TRACE("(%p)->(%u %p)\n", This, index, reference); TRACE("%p, %u, %p.\n", iface, index, reference);
*reference = NULL; *reference = NULL;
hr = IDWriteFontList1_GetFont(iface, index, &font); hr = IDWriteFontList2_GetFont(iface, index, &font);
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
@ -1969,7 +1971,15 @@ static HRESULT WINAPI dwritefontlist1_GetFontFaceReference(IDWriteFontList1 *ifa
return hr; return hr;
} }
static const IDWriteFontList1Vtbl dwritefontlistvtbl = { static HRESULT WINAPI dwritefontlist2_GetFontSet(IDWriteFontList2 *iface, IDWriteFontSet1 **fontset)
{
FIXME("%p, %p.\n", iface, fontset);
return E_NOTIMPL;
}
static const IDWriteFontList2Vtbl dwritefontlistvtbl =
{
dwritefontlist_QueryInterface, dwritefontlist_QueryInterface,
dwritefontlist_AddRef, dwritefontlist_AddRef,
dwritefontlist_Release, dwritefontlist_Release,
@ -1978,7 +1988,8 @@ static const IDWriteFontList1Vtbl dwritefontlistvtbl = {
dwritefontlist_GetFont, dwritefontlist_GetFont,
dwritefontlist1_GetFontLocality, dwritefontlist1_GetFontLocality,
dwritefontlist1_GetFont, dwritefontlist1_GetFont,
dwritefontlist1_GetFontFaceReference dwritefontlist1_GetFontFaceReference,
dwritefontlist2_GetFontSet,
}; };
static HRESULT WINAPI dwritefontfamily_QueryInterface(IDWriteFontFamily2 *iface, REFIID riid, void **obj) static HRESULT WINAPI dwritefontfamily_QueryInterface(IDWriteFontFamily2 *iface, REFIID riid, void **obj)
@ -2207,8 +2218,8 @@ static HRESULT WINAPI dwritefontfamily_GetMatchingFonts(IDWriteFontFamily2 *ifac
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
fonts->IDWriteFontList1_iface.lpVtbl = &dwritefontlistvtbl; fonts->IDWriteFontList2_iface.lpVtbl = &dwritefontlistvtbl;
fonts->ref = 1; fonts->refcount = 1;
fonts->family = family; fonts->family = family;
IDWriteFontFamily2_AddRef(&fonts->family->IDWriteFontFamily2_iface); IDWriteFontFamily2_AddRef(&fonts->family->IDWriteFontFamily2_iface);
fonts->font_count = 0; fonts->font_count = 0;
@ -2237,7 +2248,7 @@ static HRESULT WINAPI dwritefontfamily_GetMatchingFonts(IDWriteFontFamily2 *ifac
init_font_prop_vec(weight, stretch, style, &req); init_font_prop_vec(weight, stretch, style, &req);
matchingfonts_sort(fonts, &req); matchingfonts_sort(fonts, &req);
*ret = (IDWriteFontList *)&fonts->IDWriteFontList1_iface; *ret = (IDWriteFontList *)&fonts->IDWriteFontList2_iface;
return S_OK; return S_OK;
} }

View File

@ -3897,6 +3897,7 @@ static void test_GetMatchingFonts(void)
IDWriteFactory *factory; IDWriteFactory *factory;
IDWriteFontList *fontlist, *fontlist2; IDWriteFontList *fontlist, *fontlist2;
IDWriteFontList1 *fontlist1; IDWriteFontList1 *fontlist1;
IDWriteFontList2 *fontlist3;
HRESULT hr; HRESULT hr;
ULONG ref; ULONG ref;
@ -3971,6 +3972,13 @@ static void test_GetMatchingFonts(void)
else else
win_skip("IDWriteFontList1 is not supported.\n"); win_skip("IDWriteFontList1 is not supported.\n");
if (SUCCEEDED(IDWriteFontList_QueryInterface(fontlist, &IID_IDWriteFontList2, (void **)&fontlist3)))
{
IDWriteFontList2_Release(fontlist3);
}
else
win_skip("IDWriteFontList2 is not supported.\n");
IDWriteFontList_Release(fontlist); IDWriteFontList_Release(fontlist);
IDWriteFontFamily_Release(family); IDWriteFontFamily_Release(family);