Commit c2257c07 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

d2d1: Enforce text antialias mode vs text rendering mode consistency.

parent 1ec12ec7
......@@ -1230,12 +1230,40 @@ static void STDMETHODCALLTYPE d2d_d3d_render_target_DrawGlyphRun(ID2D1RenderTarg
TRACE("iface %p, baseline_origin {%.8e, %.8e}, glyph_run %p, brush %p, measuring_mode %#x.\n",
iface, baseline_origin.x, baseline_origin.y, glyph_run, brush, measuring_mode);
if (FAILED(render_target->error.code))
return;
rendering_params = render_target->text_rendering_params ? render_target->text_rendering_params
: render_target->default_text_rendering_params;
rendering_mode = IDWriteRenderingParams_GetRenderingMode(rendering_params);
switch (render_target->drawing_state.textAntialiasMode)
{
case D2D1_TEXT_ANTIALIAS_MODE_ALIASED:
if (rendering_mode == DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL
|| rendering_mode == DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC
|| rendering_mode == DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL
|| rendering_mode == DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC)
{
render_target->error.code = E_INVALIDARG;
}
break;
case D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE:
if (rendering_mode == DWRITE_RENDERING_MODE_ALIASED
|| rendering_mode == DWRITE_RENDERING_MODE_OUTLINE)
{
render_target->error.code = E_INVALIDARG;
}
break;
case D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE:
if (rendering_mode == DWRITE_RENDERING_MODE_ALIASED)
render_target->error.code = E_INVALIDARG;
break;
default:
;
}
if (FAILED(render_target->error.code))
return;
rendering_mode = DWRITE_RENDERING_MODE_DEFAULT;
switch (render_target->drawing_state.textAntialiasMode)
{
......
......@@ -3765,6 +3765,37 @@ static void test_create_target(void)
static void test_draw_text_layout(void)
{
static const struct
{
D2D1_TEXT_ANTIALIAS_MODE aa_mode;
DWRITE_RENDERING_MODE rendering_mode;
HRESULT hr;
}
antialias_mode_tests[] =
{
{ D2D1_TEXT_ANTIALIAS_MODE_DEFAULT, DWRITE_RENDERING_MODE_ALIASED },
{ D2D1_TEXT_ANTIALIAS_MODE_ALIASED, DWRITE_RENDERING_MODE_ALIASED },
{ D2D1_TEXT_ANTIALIAS_MODE_ALIASED, DWRITE_RENDERING_MODE_DEFAULT },
{ D2D1_TEXT_ANTIALIAS_MODE_ALIASED, DWRITE_RENDERING_MODE_OUTLINE },
{ D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE, DWRITE_RENDERING_MODE_DEFAULT },
{ D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE, DWRITE_RENDERING_MODE_OUTLINE },
{ D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE, DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL },
{ D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE, DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC },
{ D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE, DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL },
{ D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE, DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC },
{ D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE, DWRITE_RENDERING_MODE_DEFAULT },
{ D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE, DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL },
{ D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE, DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC },
{ D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE, DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL },
{ D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE, DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC },
{ D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE, DWRITE_RENDERING_MODE_OUTLINE, E_INVALIDARG },
{ D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE, DWRITE_RENDERING_MODE_ALIASED, E_INVALIDARG },
{ D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE, DWRITE_RENDERING_MODE_ALIASED, E_INVALIDARG },
{ D2D1_TEXT_ANTIALIAS_MODE_ALIASED, DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL, E_INVALIDARG },
{ D2D1_TEXT_ANTIALIAS_MODE_ALIASED, DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC, E_INVALIDARG },
{ D2D1_TEXT_ANTIALIAS_MODE_ALIASED, DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL, E_INVALIDARG },
{ D2D1_TEXT_ANTIALIAS_MODE_ALIASED, DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC, E_INVALIDARG },
};
static const WCHAR tahomaW[] = {'T','a','h','o','m','a',0};
static const WCHAR textW[] = {'t','e','x','t',0};
static const WCHAR emptyW[] = {0};
......@@ -3785,6 +3816,7 @@ static void test_draw_text_layout(void)
ID2D1SolidColorBrush *brush, *brush2;
ID2D1RectangleGeometry *geometry;
D2D1_RECT_F rect;
unsigned int i;
if (!(device = create_device()))
{
......@@ -3868,6 +3900,28 @@ todo_wine
hr = ID2D1RenderTarget_EndDraw(rt, NULL, NULL);
ok(hr == S_OK, "EndDraw failure expected, hr %#x.\n", hr);
for (i = 0; i < sizeof(antialias_mode_tests)/sizeof(*antialias_mode_tests); i++)
{
IDWriteRenderingParams *rendering_params;
ID2D1RenderTarget_SetTextAntialiasMode(rt, antialias_mode_tests[i].aa_mode);
hr = IDWriteFactory_CreateCustomRenderingParams(dwrite_factory, 2.0f, 1.0f, 0.0f, DWRITE_PIXEL_GEOMETRY_FLAT,
antialias_mode_tests[i].rendering_mode, &rendering_params);
ok(SUCCEEDED(hr), "Failed to create custom rendering params, hr %#x.\n", hr);
ID2D1RenderTarget_SetTextRenderingParams(rt, rendering_params);
ID2D1RenderTarget_BeginDraw(rt);
ID2D1RenderTarget_DrawTextLayout(rt, origin, text_layout, (ID2D1Brush *)brush, D2D1_DRAW_TEXT_OPTIONS_NONE);
hr = ID2D1RenderTarget_EndDraw(rt, NULL, NULL);
ok(hr == antialias_mode_tests[i].hr, "%u: unexpected hr %#x.\n", i, hr);
IDWriteRenderingParams_Release(rendering_params);
}
IDWriteTextFormat_Release(text_format);
IDWriteTextLayout_Release(text_layout);
IDWriteFactory_Release(dwrite_factory);
......
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