Commit 7be11594 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

dwrite: Validate per-range attribute values.

parent 496aec11
......@@ -1937,6 +1937,9 @@ static HRESULT WINAPI dwritetextlayout_SetFontStyle(IDWriteTextLayout2 *iface, D
TRACE("(%p)->(%d %s)\n", This, style, debugstr_range(&range));
if ((UINT32)style > DWRITE_FONT_STYLE_ITALIC)
return E_INVALIDARG;
value.range = range;
value.u.style = style;
return set_layout_range_attr(This, LAYOUT_RANGE_ATTR_STYLE, &value);
......@@ -1949,6 +1952,9 @@ static HRESULT WINAPI dwritetextlayout_SetFontStretch(IDWriteTextLayout2 *iface,
TRACE("(%p)->(%d %s)\n", This, stretch, debugstr_range(&range));
if (stretch == DWRITE_FONT_STRETCH_UNDEFINED || (UINT32)stretch > DWRITE_FONT_STRETCH_ULTRA_EXPANDED)
return E_INVALIDARG;
value.range = range;
value.u.stretch = stretch;
return set_layout_range_attr(This, LAYOUT_RANGE_ATTR_STRETCH, &value);
......@@ -1961,6 +1967,9 @@ static HRESULT WINAPI dwritetextlayout_SetFontSize(IDWriteTextLayout2 *iface, FL
TRACE("(%p)->(%.2f %s)\n", This, size, debugstr_range(&range));
if (size <= 0.0)
return E_INVALIDARG;
value.range = range;
value.u.fontsize = size;
return set_layout_range_attr(This, LAYOUT_RANGE_ATTR_FONTSIZE, &value);
......
......@@ -1832,6 +1832,15 @@ static void test_SetFontSize(void)
hr = IDWriteFactory_CreateTextLayout(factory, strW, 4, format, 1000.0, 1000.0, &layout);
ok(hr == S_OK, "got 0x%08x\n", hr);
/* negative/zero size */
r.startPosition = 1;
r.length = 1;
hr = IDWriteTextLayout_SetFontSize(layout, -15.0, r);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
hr = IDWriteTextLayout_SetFontSize(layout, 0.0, r);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
r.startPosition = 1;
r.length = 0;
size = 0.0;
......@@ -1909,6 +1918,12 @@ static void test_SetFontFamilyName(void)
hr = IDWriteFactory_CreateTextLayout(factory, strW, 4, format, 1000.0, 1000.0, &layout);
ok(hr == S_OK, "got 0x%08x\n", hr);
/* NULL name */
r.startPosition = 1;
r.length = 1;
hr = IDWriteTextLayout_SetFontFamilyName(layout, NULL, r);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
r.startPosition = 1;
r.length = 0;
nameW[0] = 0;
......@@ -1961,6 +1976,12 @@ static void test_SetFontStyle(void)
hr = IDWriteFactory_CreateTextLayout(factory, strW, 4, format, 1000.0, 1000.0, &layout);
ok(hr == S_OK, "got 0x%08x\n", hr);
/* invalid style value */
r.startPosition = 1;
r.length = 1;
hr = IDWriteTextLayout_SetFontStyle(layout, DWRITE_FONT_STYLE_ITALIC+1, r);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
r.startPosition = 1;
r.length = 0;
hr = IDWriteTextLayout_GetFontStyle(layout, 0, &style, &r);
......@@ -2036,6 +2057,12 @@ static void test_SetFontStretch(void)
hr = IDWriteFactory_CreateTextLayout(factory, strW, 4, format, 1000.0, 1000.0, &layout);
ok(hr == S_OK, "got 0x%08x\n", hr);
/* invalid stretch value */
r.startPosition = 1;
r.length = 1;
hr = IDWriteTextLayout_SetFontStretch(layout, DWRITE_FONT_STRETCH_ULTRA_EXPANDED+1, r);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
r.startPosition = 1;
r.length = 0;
stretch = DWRITE_FONT_STRETCH_UNDEFINED;
......@@ -2093,7 +2120,6 @@ static void test_SetFontStretch(void)
r.startPosition = 0;
r.length = 2;
hr = IDWriteTextLayout_SetFontStretch(layout, DWRITE_FONT_STRETCH_UNDEFINED, r);
todo_wine
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
IDWriteTextLayout_Release(layout);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment