Commit 1e5b9d36 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

dwrite: Use antialias mode set for bitmap render target.

parent e1f191e3
...@@ -43,7 +43,7 @@ struct rendertarget { ...@@ -43,7 +43,7 @@ struct rendertarget {
ID2D1SimplifiedGeometrySink ID2D1SimplifiedGeometrySink_iface; ID2D1SimplifiedGeometrySink ID2D1SimplifiedGeometrySink_iface;
LONG ref; LONG ref;
IDWriteFactory *factory; IDWriteFactory5 *factory;
DWRITE_TEXT_ANTIALIAS_MODE antialiasmode; DWRITE_TEXT_ANTIALIAS_MODE antialiasmode;
FLOAT ppdip; FLOAT ppdip;
DWRITE_MATRIX m; DWRITE_MATRIX m;
...@@ -243,7 +243,7 @@ static ULONG WINAPI rendertarget_Release(IDWriteBitmapRenderTarget1 *iface) ...@@ -243,7 +243,7 @@ static ULONG WINAPI rendertarget_Release(IDWriteBitmapRenderTarget1 *iface)
if (!ref) if (!ref)
{ {
IDWriteFactory_Release(This->factory); IDWriteFactory5_Release(This->factory);
DeleteDC(This->hdc); DeleteDC(This->hdc);
heap_free(This); heap_free(This);
} }
...@@ -313,8 +313,10 @@ static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget1 *ifac ...@@ -313,8 +313,10 @@ static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget1 *ifac
struct rendertarget *This = impl_from_IDWriteBitmapRenderTarget1(iface); struct rendertarget *This = impl_from_IDWriteBitmapRenderTarget1(iface);
IDWriteGlyphRunAnalysis *analysis; IDWriteGlyphRunAnalysis *analysis;
DWRITE_RENDERING_MODE rendermode; DWRITE_RENDERING_MODE rendermode;
DWRITE_GRID_FIT_MODE gridfitmode;
DWRITE_TEXTURE_TYPE texturetype; DWRITE_TEXTURE_TYPE texturetype;
IDWriteFontFace1 *fontface1; IDWriteFontFace2 *fontface2;
DWRITE_GLYPH_RUN scaled_run;
RECT target, bounds; RECT target, bounds;
HRESULT hr; HRESULT hr;
...@@ -326,17 +328,15 @@ static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget1 *ifac ...@@ -326,17 +328,15 @@ static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget1 *ifac
if (!This->dib.ptr) if (!This->dib.ptr)
return S_OK; return S_OK;
hr = IDWriteFontFace_QueryInterface(run->fontFace, &IID_IDWriteFontFace1, (void**)&fontface1); if (FAILED(hr = IDWriteFontFace_QueryInterface(run->fontFace, &IID_IDWriteFontFace2, (void **)&fontface2))) {
if (hr == S_OK) { WARN("Failed to get IDWriteFontFace2 interface, hr %#x.\n", hr);
hr = IDWriteFontFace1_GetRecommendedRenderingMode(fontface1, run->fontEmSize, This->ppdip * 96.0f, return hr;
This->ppdip * 96.0f, NULL, run->isSideways, DWRITE_OUTLINE_THRESHOLD_ALIASED, measuring_mode,
&rendermode);
IDWriteFontFace1_Release(fontface1);
} }
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)) if (FAILED(hr))
return hr; return hr;
...@@ -392,9 +392,10 @@ static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget1 *ifac ...@@ -392,9 +392,10 @@ static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget1 *ifac
return hr; return hr;
} }
hr = IDWriteFactory_CreateGlyphRunAnalysis(This->factory, scaled_run = *run;
run, This->ppdip, &This->m, rendermode, measuring_mode, scaled_run.fontEmSize *= This->ppdip;
originX, originY, &analysis); hr = IDWriteFactory5_CreateGlyphRunAnalysis(This->factory, &scaled_run, &This->m, rendermode, measuring_mode,
gridfitmode, This->antialiasmode, originX, originY, &analysis);
if (FAILED(hr)) { if (FAILED(hr)) {
WARN("failed to create analysis instance, 0x%08x\n", hr); WARN("failed to create analysis instance, 0x%08x\n", hr);
return hr; return hr;
...@@ -549,7 +550,7 @@ static const IDWriteBitmapRenderTarget1Vtbl rendertargetvtbl = { ...@@ -549,7 +550,7 @@ static const IDWriteBitmapRenderTarget1Vtbl rendertargetvtbl = {
rendertarget_SetTextAntialiasMode 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; struct rendertarget *target;
HRESULT hr; HRESULT hr;
...@@ -575,7 +576,7 @@ static HRESULT create_rendertarget(IDWriteFactory *factory, HDC hdc, UINT32 widt ...@@ -575,7 +576,7 @@ static HRESULT create_rendertarget(IDWriteFactory *factory, HDC hdc, UINT32 widt
target->ppdip = GetDeviceCaps(target->hdc, LOGPIXELSX) / 96.0f; target->ppdip = GetDeviceCaps(target->hdc, LOGPIXELSX) / 96.0f;
target->antialiasmode = DWRITE_TEXT_ANTIALIAS_MODE_CLEARTYPE; target->antialiasmode = DWRITE_TEXT_ANTIALIAS_MODE_CLEARTYPE;
target->factory = factory; target->factory = factory;
IDWriteFactory_AddRef(factory); IDWriteFactory5_AddRef(factory);
*ret = (IDWriteBitmapRenderTarget*)&target->IDWriteBitmapRenderTarget1_iface; *ret = (IDWriteBitmapRenderTarget*)&target->IDWriteBitmapRenderTarget1_iface;
...@@ -779,7 +780,7 @@ static HRESULT WINAPI gdiinterop_CreateBitmapRenderTarget(IDWriteGdiInterop1 *if ...@@ -779,7 +780,7 @@ static HRESULT WINAPI gdiinterop_CreateBitmapRenderTarget(IDWriteGdiInterop1 *if
{ {
struct gdiinterop *This = impl_from_IDWriteGdiInterop1(iface); struct gdiinterop *This = impl_from_IDWriteGdiInterop1(iface);
TRACE("(%p)->(%p %u %u %p)\n", This, hdc, width, height, target); 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, static HRESULT WINAPI gdiinterop1_CreateFontFromLOGFONT(IDWriteGdiInterop1 *iface,
......
...@@ -1053,9 +1053,13 @@ static void test_CreateBitmapRenderTarget(void) ...@@ -1053,9 +1053,13 @@ static void test_CreateBitmapRenderTarget(void)
{ {
IDWriteBitmapRenderTarget *target, *target2; IDWriteBitmapRenderTarget *target, *target2;
IDWriteBitmapRenderTarget1 *target1; IDWriteBitmapRenderTarget1 *target1;
IDWriteRenderingParams *params;
IDWriteGdiInterop *interop; IDWriteGdiInterop *interop;
IDWriteFontFace *fontface;
IDWriteFactory *factory; IDWriteFactory *factory;
DWRITE_GLYPH_RUN run;
HBITMAP hbm, hbm2; HBITMAP hbm, hbm2;
UINT16 glyphs[2];
DWRITE_MATRIX m; DWRITE_MATRIX m;
DIBSECTION ds; DIBSECTION ds;
XFORM xform; XFORM xform;
...@@ -1064,6 +1068,7 @@ static void test_CreateBitmapRenderTarget(void) ...@@ -1064,6 +1068,7 @@ static void test_CreateBitmapRenderTarget(void)
FLOAT pdip; FLOAT pdip;
SIZE size; SIZE size;
ULONG ref; ULONG ref;
UINT32 ch;
HDC hdc; HDC hdc;
int ret; int ret;
...@@ -1307,6 +1312,62 @@ static void test_CreateBitmapRenderTarget(void) ...@@ -1307,6 +1312,62 @@ static void test_CreateBitmapRenderTarget(void)
else else
win_skip("IDWriteBitmapRenderTarget1 is not supported.\n"); 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, &params);
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); ref = IDWriteBitmapRenderTarget_Release(target);
ok(ref == 0, "render target not released, %u\n", ref); ok(ref == 0, "render target not released, %u\n", ref);
ref = IDWriteGdiInterop_Release(interop); ref = IDWriteGdiInterop_Release(interop);
......
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