dwrite: Store text string in layout object.

This commit is contained in:
Nikolay Sivov 2012-10-20 17:02:25 -04:00 committed by Alexandre Julliard
parent 516731c861
commit 11d94a11b6
4 changed files with 61 additions and 5 deletions

View File

@ -38,7 +38,7 @@ static inline BOOL heap_free(void *mem)
return HeapFree(GetProcessHeap(), 0, mem);
}
static inline LPWSTR heap_strdupW(LPCWSTR str)
static inline LPWSTR heap_strdupW(const WCHAR *str)
{
LPWSTR ret = NULL;
@ -53,10 +53,24 @@ static inline LPWSTR heap_strdupW(LPCWSTR str)
return ret;
}
static inline LPWSTR heap_strdupnW(const WCHAR *str, UINT32 len)
{
WCHAR *ret = NULL;
if (len)
{
ret = heap_alloc((len+1)*sizeof(WCHAR));
memcpy(ret, str, len*sizeof(WCHAR));
ret[len] = 0;
}
return ret;
}
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,
FLOAT,const WCHAR*,IDWriteTextFormat**) DECLSPEC_HIDDEN;
extern HRESULT create_textlayout(IDWriteTextLayout**) DECLSPEC_HIDDEN;
extern HRESULT create_textlayout(const WCHAR*,UINT32,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

@ -35,6 +35,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
struct dwrite_textlayout {
IDWriteTextLayout IDWriteTextLayout_iface;
LONG ref;
WCHAR *str;
};
struct dwrite_textformat {
@ -97,7 +99,10 @@ static ULONG WINAPI dwritetextlayout_Release(IDWriteTextLayout *iface)
TRACE("(%p)->(%d)\n", This, ref);
if (!ref)
{
heap_free(This->str);
heap_free(This);
}
return S_OK;
}
@ -646,7 +651,7 @@ static const IDWriteTextLayoutVtbl dwritetextlayoutvtbl = {
dwritetextlayout_HitTestTextRange
};
HRESULT create_textlayout(IDWriteTextLayout **layout)
HRESULT create_textlayout(const WCHAR *str, UINT32 len, IDWriteTextLayout **layout)
{
struct dwrite_textlayout *This;
@ -657,6 +662,7 @@ HRESULT create_textlayout(IDWriteTextLayout **layout)
This->IDWriteTextLayout_iface.lpVtbl = &dwritetextlayoutvtbl;
This->ref = 1;
This->str = heap_strdupnW(str, len);
*layout = &This->IDWriteTextLayout_iface;

View File

@ -506,7 +506,7 @@ static HRESULT WINAPI dwritefactory_CreateTextLayout(IDWriteFactory *iface, WCHA
FIXME("(%s %u %p %f %f %p): stub\n", debugstr_w(string), len, format, max_width, max_height, layout);
if (!format) return E_INVALIDARG;
return create_textlayout(layout);
return create_textlayout(string, len, layout);
}
static HRESULT WINAPI dwritefactory_CreateGdiCompatibleTextLayout(IDWriteFactory *iface, WCHAR const* string,
@ -517,7 +517,7 @@ static HRESULT WINAPI dwritefactory_CreateGdiCompatibleTextLayout(IDWriteFactory
pixels_per_dip, transform, use_gdi_natural, layout);
if (!format) return E_INVALIDARG;
return create_textlayout(layout);
return create_textlayout(string, len, layout);
}
static HRESULT WINAPI dwritefactory_CreateEllipsisTrimmingSign(IDWriteFactory *iface, IDWriteTextFormat *format,

View File

@ -27,6 +27,16 @@
static IDWriteFactory *factory;
static const WCHAR tahomaW[] = {'T','a','h','o','m','a',0};
#define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
static void _expect_ref(IUnknown* obj, ULONG ref, int line)
{
ULONG rc = IUnknown_AddRef(obj);
IUnknown_Release(obj);
ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1);
}
static void test_CreateTextLayout(void)
{
static const WCHAR strW[] = {'s','t','r','i','n','g',0};
@ -52,7 +62,9 @@ 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;
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, NULL, 0, NULL, 0.0, 0.0, 0.0, NULL, FALSE, &layout);
@ -69,6 +81,30 @@ static void test_CreateGdiCompatibleTextLayout(void)
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, NULL, 1000.0, 1000.0, 1.0, NULL, FALSE, &layout);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
/* create with text format */
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);
EXPECT_REF(format, 1);
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, format, 100.0, 100.0, 1.0, NULL, FALSE, &layout);
ok(hr == S_OK, "got 0x%08x\n", hr);
EXPECT_REF(format, 1);
EXPECT_REF(layout, 1);
IDWriteTextLayout_AddRef(layout);
EXPECT_REF(format, 1);
EXPECT_REF(layout, 2);
IDWriteTextLayout_Release(layout);
IDWriteTextLayout_Release(layout);
/* zero length string is okay */
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 0, format, 100.0, 100.0, 1.0, NULL, FALSE, &layout);
ok(hr == S_OK, "got 0x%08x\n", hr);
IDWriteTextLayout_Release(layout);
IDWriteTextFormat_Release(format);
}
START_TEST(layout)