Signed-off-by: Sven Baars sbaars@codeweavers.com --- v2: Also added an extra test here.
dlls/d3dx9_36/font.c | 22 +++++++++++++++++++++- dlls/d3dx9_36/tests/core.c | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index 56efb11dfd..937421ed17 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -687,6 +687,13 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite, D3DXVECTOR3 pos; unsigned int i;
+ if (format & DT_CENTER) + x = (calcrect.left + calcrect.right - size.cx) / 2; + else if (format & DT_RIGHT) + x = calcrect.right - size.cx; + else + x = calcrect.left; + memset(&results, 0, sizeof(results)); results.nGlyphs = line_len;
@@ -739,7 +746,20 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite, *rect = calcrect;
rect->bottom = y; - rect->right = rect->left + max_width; + + if (format & DT_CENTER) + { + rect->left += (rect->right - rect->left - max_width) / 2; + rect->right = rect->left + max_width; + } + else if (format & DT_RIGHT) + { + rect->left = rect->right - max_width; + } + else + { + rect->right = rect->left + max_width; + } }
ret = y - textrect.top; diff --git a/dlls/d3dx9_36/tests/core.c b/dlls/d3dx9_36/tests/core.c index 9916fa9bc2..0d3023d323 100644 --- a/dlls/d3dx9_36/tests/core.c +++ b/dlls/d3dx9_36/tests/core.c @@ -878,6 +878,26 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) ok(height == 32, "Got unexpected height %d.\n", height); check_rect(&rect, 10, 18, 30, 42);
+ SetRect(&rect, 10, 10, 50, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_RIGHT | DT_CALCRECT, 0xff00ff); + ok(height == 24, "Got unexpected height %d.\n", height); + check_rect(&rect, 30, 10, 50, 34); + + SetRect(&rect, 10, 10, 50, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER | DT_CALCRECT, 0xff00ff); + ok(height == 24, "Got unexpected height %d.\n", height); + check_rect(&rect, 20, 10, 40, 34); + + SetRect(&rect, 10, 10, 50, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_CALCRECT, 0xff00ff); + ok(height == 32, "Got unexpected height %d.\n", height); + check_rect(&rect, 20, 18, 40, 42); + + SetRect(&rect, 10, 10, 50, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == 32, "Got unexpected height %d.\n", height); + check_rect(&rect, 20, 18, 40, 42); + ID3DXFont_Release(font); }