dwrite: Implement IDWriteTextFormat::GetFontCollection().

This commit is contained in:
Nikolay Sivov 2012-10-21 23:49:27 -04:00 committed by Alexandre Julliard
parent a291a7adf8
commit a30faec10e
4 changed files with 59 additions and 10 deletions

View File

@ -68,7 +68,7 @@ static inline LPWSTR heap_strdupnW(const WCHAR *str, UINT32 len)
}
extern HRESULT create_font_from_logfont(const LOGFONTW*, IDWriteFont**) DECLSPEC_HIDDEN;
extern HRESULT create_textformat(const WCHAR*,DWRITE_FONT_WEIGHT,DWRITE_FONT_STYLE,DWRITE_FONT_STRETCH,
extern HRESULT create_textformat(const WCHAR*,IDWriteFontCollection*,DWRITE_FONT_WEIGHT,DWRITE_FONT_STYLE,DWRITE_FONT_STRETCH,
FLOAT,const WCHAR*,IDWriteTextFormat**) DECLSPEC_HIDDEN;
extern HRESULT create_textlayout(const WCHAR*,UINT32,IDWriteTextLayout**) DECLSPEC_HIDDEN;
extern HRESULT create_gdiinterop(IDWriteGdiInterop**) DECLSPEC_HIDDEN;

View File

@ -51,6 +51,8 @@ struct dwrite_textformat {
DWRITE_FONT_STRETCH stretch;
FLOAT size;
IDWriteFontCollection *collection;
};
static inline struct dwrite_textlayout *impl_from_IDWriteTextLayout(IDWriteTextLayout *iface)
@ -705,6 +707,7 @@ static ULONG WINAPI dwritetextformat_Release(IDWriteTextFormat *iface)
if (!ref)
{
if (This->collection) IDWriteFontCollection_Release(This->collection);
heap_free(This->family_name);
heap_free(This->locale);
heap_free(This);
@ -832,8 +835,13 @@ static HRESULT WINAPI dwritetextformat_GetLineSpacing(IDWriteTextFormat *iface,
static HRESULT WINAPI dwritetextformat_GetFontCollection(IDWriteTextFormat *iface, IDWriteFontCollection **collection)
{
struct dwrite_textformat *This = impl_from_IDWriteTextFormat(iface);
FIXME("(%p)->(%p): stub\n", This, collection);
return E_NOTIMPL;
TRACE("(%p)->(%p)\n", This, collection);
*collection = This->collection;
IDWriteFontCollection_AddRef(*collection);
return S_OK;
}
static UINT32 WINAPI dwritetextformat_GetFontFamilyNameLength(IDWriteTextFormat *iface)
@ -923,11 +931,13 @@ static const IDWriteTextFormatVtbl dwritetextformatvtbl = {
dwritetextformat_GetLocaleName
};
HRESULT create_textformat(const WCHAR *family_name, DWRITE_FONT_WEIGHT weight, DWRITE_FONT_STYLE style,
HRESULT create_textformat(const WCHAR *family_name, IDWriteFontCollection *collection, DWRITE_FONT_WEIGHT weight, DWRITE_FONT_STYLE style,
DWRITE_FONT_STRETCH stretch, FLOAT size, const WCHAR *locale, IDWriteTextFormat **format)
{
struct dwrite_textformat *This;
*format = NULL;
This = heap_alloc(sizeof(struct dwrite_textformat));
if (!This) return E_OUTOFMEMORY;
@ -939,6 +949,21 @@ HRESULT create_textformat(const WCHAR *family_name, DWRITE_FONT_WEIGHT weight, D
This->style = style;
This->size = size;
if (collection)
{
This->collection = collection;
IDWriteFontCollection_AddRef(collection);
}
else
{
HRESULT hr = get_system_fontcollection(&This->collection);
if (hr != S_OK)
{
IDWriteTextFormat_Release(&This->IDWriteTextFormat_iface);
return hr;
}
}
*format = &This->IDWriteTextFormat_iface;
return S_OK;

View File

@ -488,11 +488,7 @@ static HRESULT WINAPI dwritefactory_CreateTextFormat(IDWriteFactory *iface, WCHA
{
TRACE("(%s %p %d %d %d %f %s %p)\n", debugstr_w(family_name), collection, weight, style, stretch,
size, debugstr_w(locale), format);
if (collection)
FIXME("font collection not supported\n");
return create_textformat(family_name, weight, style, stretch, size, locale, format);
return create_textformat(family_name, collection, weight, style, stretch, size, locale, format);
}
static HRESULT WINAPI dwritefactory_CreateTypography(IDWriteFactory *iface, IDWriteTypography **typography)

View File

@ -28,6 +28,7 @@
static IDWriteFactory *factory;
static const WCHAR tahomaW[] = {'T','a','h','o','m','a',0};
static const WCHAR enusW[] = {'e','n','-','u','s',0};
#define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
static void _expect_ref(IUnknown* obj, ULONG ref, int line)
@ -62,7 +63,6 @@ static void test_CreateTextLayout(void)
static void test_CreateGdiCompatibleTextLayout(void)
{
static const WCHAR strW[] = {'s','t','r','i','n','g',0};
static const WCHAR enusW[] = {'e','n','-','u','s',0};
IDWriteTextLayout *layout;
IDWriteTextFormat *format;
HRESULT hr;
@ -107,6 +107,33 @@ static void test_CreateGdiCompatibleTextLayout(void)
IDWriteTextFormat_Release(format);
}
static void test_CreateTextFormat(void)
{
IDWriteFontCollection *collection, *syscoll;
IDWriteTextFormat *format;
HRESULT hr;
hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL, 10.0, enusW, &format);
ok(hr == S_OK, "got 0x%08x\n", hr);
if (0) /* crashes on native */
hr = IDWriteTextFormat_GetFontCollection(format, NULL);
collection = NULL;
hr = IDWriteTextFormat_GetFontCollection(format, &collection);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(collection != NULL, "got %p\n", collection);
hr = IDWriteFactory_GetSystemFontCollection(factory, &syscoll, FALSE);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(collection == syscoll, "got %p, was %p\n", syscoll, collection);
IDWriteFontCollection_Release(syscoll);
IDWriteFontCollection_Release(collection);
IDWriteTextFormat_Release(format);
}
START_TEST(layout)
{
HRESULT hr;
@ -121,6 +148,7 @@ START_TEST(layout)
test_CreateTextLayout();
test_CreateGdiCompatibleTextLayout();
test_CreateTextFormat();
IDWriteFactory_Release(factory);
}