dwrite: Validate CreateTextFormat() arguments.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
84a36f27b8
commit
fee64bed45
|
@ -5133,6 +5133,14 @@ HRESULT create_textformat(const WCHAR *family_name, IDWriteFontCollection *colle
|
|||
|
||||
*format = NULL;
|
||||
|
||||
if (size <= 0.0f)
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (((UINT32)weight > DWRITE_FONT_WEIGHT_ULTRA_BLACK) ||
|
||||
((UINT32)stretch > DWRITE_FONT_STRETCH_ULTRA_EXPANDED) ||
|
||||
((UINT32)style > DWRITE_FONT_STYLE_ITALIC))
|
||||
return E_INVALIDARG;
|
||||
|
||||
This = heap_alloc(sizeof(struct dwrite_textformat));
|
||||
if (!This) return E_OUTOFMEMORY;
|
||||
|
||||
|
|
|
@ -933,6 +933,7 @@ static void test_CreateGdiCompatibleTextLayout(void)
|
|||
|
||||
static void test_CreateTextFormat(void)
|
||||
{
|
||||
static const WCHAR emptyW[] = {0};
|
||||
IDWriteFontCollection *collection, *syscoll;
|
||||
DWRITE_PARAGRAPH_ALIGNMENT paralign;
|
||||
DWRITE_READING_DIRECTION readdir;
|
||||
|
@ -949,6 +950,34 @@ static void test_CreateTextFormat(void)
|
|||
|
||||
factory = create_factory();
|
||||
|
||||
/* zero/negative font size */
|
||||
hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
|
||||
DWRITE_FONT_STRETCH_NORMAL, 0.0f, enusW, &format);
|
||||
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
||||
|
||||
hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
|
||||
DWRITE_FONT_STRETCH_NORMAL, -10.0f, enusW, &format);
|
||||
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
||||
|
||||
/* invalid font properties */
|
||||
hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, 1000, DWRITE_FONT_STYLE_NORMAL,
|
||||
DWRITE_FONT_STRETCH_NORMAL, 10.0f, enusW, &format);
|
||||
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
||||
|
||||
hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_ITALIC + 1,
|
||||
DWRITE_FONT_STRETCH_NORMAL, 10.0f, enusW, &format);
|
||||
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
||||
|
||||
hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_ITALIC,
|
||||
10, 10.0f, enusW, &format);
|
||||
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
||||
|
||||
/* empty family name */
|
||||
hr = IDWriteFactory_CreateTextFormat(factory, emptyW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
|
||||
DWRITE_FONT_STRETCH_NORMAL, 10.0f, enusW, &format);
|
||||
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||
IDWriteTextFormat_Release(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);
|
||||
|
|
Loading…
Reference in New Issue