Module: wine Branch: master Commit: 1e5b9d369bbb312a22b73513b9afc1aaf7041f99 URL: http://source.winehq.org/git/wine.git/?a=commit;h=1e5b9d369bbb312a22b73513b9...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Mon Jul 17 23:18:44 2017 +0300
dwrite: Use antialias mode set for bitmap render target.
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/dwrite/gdiinterop.c | 37 +++++++++++++++-------------- dlls/dwrite/tests/font.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 18 deletions(-)
diff --git a/dlls/dwrite/gdiinterop.c b/dlls/dwrite/gdiinterop.c index b870448..aa2e3a6 100644 --- a/dlls/dwrite/gdiinterop.c +++ b/dlls/dwrite/gdiinterop.c @@ -43,7 +43,7 @@ struct rendertarget { ID2D1SimplifiedGeometrySink ID2D1SimplifiedGeometrySink_iface; LONG ref;
- IDWriteFactory *factory; + IDWriteFactory5 *factory; DWRITE_TEXT_ANTIALIAS_MODE antialiasmode; FLOAT ppdip; DWRITE_MATRIX m; @@ -243,7 +243,7 @@ static ULONG WINAPI rendertarget_Release(IDWriteBitmapRenderTarget1 *iface)
if (!ref) { - IDWriteFactory_Release(This->factory); + IDWriteFactory5_Release(This->factory); DeleteDC(This->hdc); heap_free(This); } @@ -313,8 +313,10 @@ static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget1 *ifac struct rendertarget *This = impl_from_IDWriteBitmapRenderTarget1(iface); IDWriteGlyphRunAnalysis *analysis; DWRITE_RENDERING_MODE rendermode; + DWRITE_GRID_FIT_MODE gridfitmode; DWRITE_TEXTURE_TYPE texturetype; - IDWriteFontFace1 *fontface1; + IDWriteFontFace2 *fontface2; + DWRITE_GLYPH_RUN scaled_run; RECT target, bounds; HRESULT hr;
@@ -326,17 +328,15 @@ static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget1 *ifac if (!This->dib.ptr) return S_OK;
- hr = IDWriteFontFace_QueryInterface(run->fontFace, &IID_IDWriteFontFace1, (void**)&fontface1); - if (hr == S_OK) { - hr = IDWriteFontFace1_GetRecommendedRenderingMode(fontface1, run->fontEmSize, This->ppdip * 96.0f, - This->ppdip * 96.0f, NULL, run->isSideways, DWRITE_OUTLINE_THRESHOLD_ALIASED, measuring_mode, - &rendermode); - IDWriteFontFace1_Release(fontface1); + if (FAILED(hr = IDWriteFontFace_QueryInterface(run->fontFace, &IID_IDWriteFontFace2, (void **)&fontface2))) { + WARN("Failed to get IDWriteFontFace2 interface, hr %#x.\n", hr); + return hr; } - else - hr = IDWriteFontFace_GetRecommendedRenderingMode(run->fontFace, run->fontEmSize, - This->ppdip, measuring_mode, params, &rendermode);
+ hr = IDWriteFontFace2_GetRecommendedRenderingMode(fontface2, run->fontEmSize, This->ppdip * 96.0f, + This->ppdip * 96.0f, NULL /* FIXME */, run->isSideways, DWRITE_OUTLINE_THRESHOLD_ALIASED, measuring_mode, + params, &rendermode, &gridfitmode); + IDWriteFontFace2_Release(fontface2); if (FAILED(hr)) return hr;
@@ -392,9 +392,10 @@ static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget1 *ifac return hr; }
- hr = IDWriteFactory_CreateGlyphRunAnalysis(This->factory, - run, This->ppdip, &This->m, rendermode, measuring_mode, - originX, originY, &analysis); + scaled_run = *run; + scaled_run.fontEmSize *= This->ppdip; + hr = IDWriteFactory5_CreateGlyphRunAnalysis(This->factory, &scaled_run, &This->m, rendermode, measuring_mode, + gridfitmode, This->antialiasmode, originX, originY, &analysis); if (FAILED(hr)) { WARN("failed to create analysis instance, 0x%08x\n", hr); return hr; @@ -549,7 +550,7 @@ static const IDWriteBitmapRenderTarget1Vtbl rendertargetvtbl = { rendertarget_SetTextAntialiasMode };
-static HRESULT create_rendertarget(IDWriteFactory *factory, HDC hdc, UINT32 width, UINT32 height, IDWriteBitmapRenderTarget **ret) +static HRESULT create_rendertarget(IDWriteFactory5 *factory, HDC hdc, UINT32 width, UINT32 height, IDWriteBitmapRenderTarget **ret) { struct rendertarget *target; HRESULT hr; @@ -575,7 +576,7 @@ static HRESULT create_rendertarget(IDWriteFactory *factory, HDC hdc, UINT32 widt target->ppdip = GetDeviceCaps(target->hdc, LOGPIXELSX) / 96.0f; target->antialiasmode = DWRITE_TEXT_ANTIALIAS_MODE_CLEARTYPE; target->factory = factory; - IDWriteFactory_AddRef(factory); + IDWriteFactory5_AddRef(factory);
*ret = (IDWriteBitmapRenderTarget*)&target->IDWriteBitmapRenderTarget1_iface;
@@ -779,7 +780,7 @@ static HRESULT WINAPI gdiinterop_CreateBitmapRenderTarget(IDWriteGdiInterop1 *if { struct gdiinterop *This = impl_from_IDWriteGdiInterop1(iface); TRACE("(%p)->(%p %u %u %p)\n", This, hdc, width, height, target); - return create_rendertarget((IDWriteFactory*)This->factory, hdc, width, height, target); + return create_rendertarget(This->factory, hdc, width, height, target); }
static HRESULT WINAPI gdiinterop1_CreateFontFromLOGFONT(IDWriteGdiInterop1 *iface, diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index dc88e2c..52ce9f0 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -1053,9 +1053,13 @@ static void test_CreateBitmapRenderTarget(void) { IDWriteBitmapRenderTarget *target, *target2; IDWriteBitmapRenderTarget1 *target1; + IDWriteRenderingParams *params; IDWriteGdiInterop *interop; + IDWriteFontFace *fontface; IDWriteFactory *factory; + DWRITE_GLYPH_RUN run; HBITMAP hbm, hbm2; + UINT16 glyphs[2]; DWRITE_MATRIX m; DIBSECTION ds; XFORM xform; @@ -1064,6 +1068,7 @@ static void test_CreateBitmapRenderTarget(void) FLOAT pdip; SIZE size; ULONG ref; + UINT32 ch; HDC hdc; int ret;
@@ -1307,6 +1312,62 @@ static void test_CreateBitmapRenderTarget(void) else win_skip("IDWriteBitmapRenderTarget1 is not supported.\n");
+ /* DrawGlyphRun() argument validation. */ + hr = IDWriteBitmapRenderTarget_Resize(target, 16, 16); + ok(hr == S_OK, "Failed to resize target, hr %#x.\n", hr); + + fontface = create_fontface(factory); + + ch = 'A'; + glyphs[0] = 0; + hr = IDWriteFontFace_GetGlyphIndices(fontface, &ch, 1, glyphs); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(glyphs[0] > 0, "got %u\n", glyphs[0]); + glyphs[1] = glyphs[0]; + + memset(&run, 0, sizeof(run)); + run.fontFace = fontface; + run.fontEmSize = 12.0f; + run.glyphCount = 2; + run.glyphIndices = glyphs; + + hr = IDWriteFactory_CreateCustomRenderingParams(factory, 1.0f, 0.0f, 0.0f, DWRITE_PIXEL_GEOMETRY_FLAT, + DWRITE_RENDERING_MODE_DEFAULT, ¶ms); + ok(hr == S_OK, "Failed to create rendering params, hr %#x.\n", hr); + + hr = IDWriteBitmapRenderTarget_DrawGlyphRun(target, 0.0f, 0.0f, DWRITE_MEASURING_MODE_NATURAL, + &run, NULL, RGB(255, 0, 0), NULL); +todo_wine + ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr); + + hr = IDWriteBitmapRenderTarget_DrawGlyphRun(target, 0.0f, 0.0f, DWRITE_MEASURING_MODE_GDI_NATURAL + 1, + &run, NULL, RGB(255, 0, 0), NULL); + ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr); + + hr = IDWriteBitmapRenderTarget_DrawGlyphRun(target, 0.0f, 0.0f, DWRITE_MEASURING_MODE_GDI_NATURAL + 1, + &run, params, RGB(255, 0, 0), NULL); + ok(hr == E_INVALIDARG || broken(hr == S_OK) /* Vista */, "Unexpected hr %#x.\n", hr); + + hr = IDWriteBitmapRenderTarget_DrawGlyphRun(target, 0.0f, 0.0f, DWRITE_MEASURING_MODE_GDI_NATURAL, + &run, params, RGB(255, 0, 0), NULL); + ok(hr == S_OK, "Failed to draw a run, hr %#x.\n", hr); + + IDWriteRenderingParams_Release(params); + + /* Zero sized target returns earlier. */ + hr = IDWriteBitmapRenderTarget_Resize(target, 0, 16); + ok(hr == S_OK, "Failed to resize target, hr %#x.\n", hr); + + hr = IDWriteBitmapRenderTarget_DrawGlyphRun(target, 0.0f, 0.0f, DWRITE_MEASURING_MODE_NATURAL, + &run, NULL, RGB(255, 0, 0), NULL); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IDWriteBitmapRenderTarget_DrawGlyphRun(target, 0.0f, 0.0f, DWRITE_MEASURING_MODE_GDI_NATURAL + 1, + &run, params, RGB(255, 0, 0), NULL); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + IDWriteFontFace_Release(fontface); + ref = IDWriteBitmapRenderTarget_Release(target); ok(ref == 0, "render target not released, %u\n", ref); ref = IDWriteGdiInterop_Release(interop);