dwrite/layout: Fail to create layouts with negative size.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2021-01-20 08:44:12 +03:00 committed by Alexandre Julliard
parent 9c138562fe
commit 9ec274083f
2 changed files with 38 additions and 2 deletions

View File

@ -5207,6 +5207,9 @@ HRESULT create_textlayout(const struct textlayout_desc *desc, IDWriteTextLayout
*layout = NULL;
if (desc->max_width < 0.0f || desc->max_height < 0.0f)
return E_INVALIDARG;
if (!desc->format || !desc->string)
return E_INVALIDARG;

View File

@ -908,7 +908,7 @@ static void test_CreateTextLayout(void)
factory = create_factory();
layout = (void*)0xdeadbeef;
hr = IDWriteFactory_CreateTextLayout(factory, NULL, 0, NULL, 0.0, 0.0, &layout);
hr = IDWriteFactory_CreateTextLayout(factory, NULL, 0, NULL, 0.0f, 0.0f, &layout);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
@ -941,6 +941,21 @@ static void test_CreateTextLayout(void)
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
layout = (void *)0xdeadbeef;
hr = IDWriteFactory_CreateTextLayout(factory, L"string", 6, format, -100.0f, 100.0f, &layout);
ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
ok(layout == NULL, "Unexpected pointer %p.\n", layout);
layout = (void *)0xdeadbeef;
hr = IDWriteFactory_CreateTextLayout(factory, L"string", 6, format, 100.0f, -100.0f, &layout);
ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
ok(layout == NULL, "Unexpected pointer %p.\n", layout);
layout = (void *)0xdeadbeef;
hr = IDWriteFactory_CreateTextLayout(factory, L"string", 6, format, -100.0f, -100.0f, &layout);
ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
ok(layout == NULL, "Unexpected pointer %p.\n", layout);
hr = IDWriteFactory_CreateTextLayout(factory, L"string", 0, format, 0.0f, 0.0f, &layout);
ok(hr == S_OK, "Failed to create text layout, hr %#x.\n", hr);
IDWriteTextLayout_Release(layout);
@ -1031,7 +1046,7 @@ static void test_CreateGdiCompatibleTextLayout(void)
factory = create_factory();
layout = (void*)0xdeadbeef;
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, NULL, 0, NULL, 0.0, 0.0, 0.0, NULL, FALSE, &layout);
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, NULL, 0, NULL, 0.0f, 0.0f, 0.0f, NULL, FALSE, &layout);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
@ -1070,6 +1085,24 @@ static void test_CreateGdiCompatibleTextLayout(void)
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
layout = (void *)0xdeadbeef;
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, L"string", 6, format, -100.0f, 100.0f, 1.0f,
NULL, FALSE, &layout);
ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
ok(layout == NULL, "Unexpected pointer %p.\n", layout);
layout = (void *)0xdeadbeef;
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, L"string", 6, format, 100.0f, -100.0f, 1.0f,
NULL, FALSE, &layout);
ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
ok(layout == NULL, "Unexpected pointer %p.\n", layout);
layout = (void *)0xdeadbeef;
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, L"string", 6, format, -100.0f, -100.0f, 1.0f,
NULL, FALSE, &layout);
ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
ok(layout == NULL, "Unexpected pointer %p.\n", layout);
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, L"string", 6, format, 100.0f, 100.0f, 1.0f, NULL,
FALSE, &layout);
ok(hr == S_OK, "Failed to create text layout, hr %#x.\n", hr);