From: Tingzhong Luo luotingzhong@uniontech.com
Signed-off-by: Tingzhong Luo luotingzhong@uniontech.com --- dlls/dwrite/gdiinterop.c | 10 +++++---- dlls/dwrite/tests/font.c | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/dlls/dwrite/gdiinterop.c b/dlls/dwrite/gdiinterop.c index 5b542d93e32..764ddf1a4df 100644 --- a/dlls/dwrite/gdiinterop.c +++ b/dlls/dwrite/gdiinterop.c @@ -347,7 +347,7 @@ static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget1 *ifac DWRITE_RENDERING_MODE1 rendermode; DWRITE_GRID_FIT_MODE gridfitmode; DWRITE_TEXTURE_TYPE texturetype; - DWRITE_GLYPH_RUN scaled_run; + DWRITE_MATRIX scaled_matrix; IDWriteFontFace3 *fontface; RECT target_rect, bounds; HRESULT hr; @@ -429,9 +429,10 @@ static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget1 *ifac return hr; }
- scaled_run = *run; - scaled_run.fontEmSize *= target->ppdip; - hr = IDWriteFactory7_CreateGlyphRunAnalysis(target->factory, &scaled_run, &target->m, rendermode, measuring_mode, + scaled_matrix = target->m; + scaled_matrix.m11 *= target->ppdip; + scaled_matrix.m22 *= target->ppdip; + hr = IDWriteFactory7_CreateGlyphRunAnalysis(target->factory, run, &scaled_matrix, rendermode, measuring_mode, gridfitmode, target->antialiasmode, originX, originY, &analysis); if (FAILED(hr)) { @@ -451,6 +452,7 @@ static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget1 *ifac } texturetype = DWRITE_TEXTURE_CLEARTYPE_3x1; } + if (bbox_ret) *bbox_ret = bounds;
if (IntersectRect(&target_rect, &target_rect, &bounds)) { diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index 81008db6f23..535c67558bd 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -1225,6 +1225,7 @@ static void test_CreateBitmapRenderTarget(void) SIZE size; ULONG ref; UINT32 ch; + RECT box; HDC hdc; int ret;
@@ -1507,6 +1508,49 @@ static void test_CreateBitmapRenderTarget(void) &run, params, RGB(255, 0, 0), NULL); ok(hr == S_OK, "Failed to draw a run, hr %#lx.\n", hr);
+ hr = IDWriteBitmapRenderTarget_SetPixelsPerDip(target, 1.0); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + /* Got render bounds if not intersect to render target */ + memset(&box, 0, sizeof(box)); + hr = IDWriteBitmapRenderTarget_DrawGlyphRun(target, 0.0f, 0.0f, DWRITE_MEASURING_MODE_GDI_NATURAL, + &run, params, RGB(255, 0, 0), &box); + ok(hr == S_OK, "Failed to draw a run, hr %#lx.\n", hr); + ok(box.right - box.left > 0, "got %ld\n", box.right - box.left); + ok(box.bottom - box.top > 0, "got %ld\n", box.bottom - box.top); + + /* Check glyph position */ + run.fontEmSize = 30.0f; + hdc = IDWriteBitmapRenderTarget_GetMemoryDC(target); + ok(hdc != NULL, "got %p\n", hdc); + + hr = IDWriteBitmapRenderTarget_Resize(target, 400, 400); + ok(hr == S_OK, "Failed to resize target, hr %#lx.\n", hr); + + SetDCBrushColor(hdc, 0); + SelectObject(hdc, GetStockObject(DC_BRUSH)); + Rectangle(hdc, 0, 0, 400, 400); + hr = IDWriteBitmapRenderTarget_DrawGlyphRun(target, 30.0f, 65.0f, DWRITE_MEASURING_MODE_GDI_NATURAL, + &run, params, RGB(255, 0, 0), &box); + ok(hr == S_OK, "Failed to draw a run, hr %#lx.\n", hr); + c = GetPixel(hdc, 30 + 2, 65 - 2); + ok(c == RGB(255, 0, 0), "got 0x%08lx\n", c); + + /* Doubled ppdip */ + hr = IDWriteBitmapRenderTarget_SetPixelsPerDip(target, 2.0); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + SetDCBrushColor(hdc, 0); + SelectObject(hdc, GetStockObject(DC_BRUSH)); + Rectangle(hdc, 0, 0, 400, 400); + hr = IDWriteBitmapRenderTarget_DrawGlyphRun(target, 30.0f, 65.0f, DWRITE_MEASURING_MODE_GDI_NATURAL, + &run, params, RGB(255, 0, 0), &box); + ok(hr == S_OK, "Failed to draw a run, hr %#lx.\n", hr); + c = GetPixel(hdc, 30 + 2, 65 - 2); + ok(c == RGB(0, 0, 0), "got 0x%08lx\n", c); + c = GetPixel(hdc, 30 * 2 + 2, 65 * 2 - 2); + ok(c == RGB(255, 0, 0), "got 0x%08lx\n", c); + IDWriteRenderingParams_Release(params);
/* Zero sized target returns earlier. */