Signed-off-by: Sven Baars sbaars@codeweavers.com --- dlls/d3dx9_36/font.c | 21 ++++- dlls/d3dx9_36/tests/core.c | 152 ++++++++++++++++++++++++++++++++++++- 2 files changed, 169 insertions(+), 4 deletions(-)
diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index 47d44a914e..20757ae839 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -624,7 +624,19 @@ static int compute_rect(struct d3dx_font *font, const WCHAR *string, INT count, }
rect->right = rect->left + max_width; - rect->bottom = y; + if (format & DT_VCENTER) + { + rect->top += (rect->bottom - y) / 2; + rect->bottom = rect->top + y - top; + } + else if (format & DT_BOTTOM) + { + rect->top += rect->bottom - y; + } + else + { + rect->bottom = y; + }
return rect->bottom - top; } @@ -661,13 +673,18 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite, if (!line) return 0;
- if (!rect || format & DT_CALCRECT) + if (!rect || format & (DT_CALCRECT | DT_VCENTER | DT_BOTTOM)) { if (!rect) { rect = &r; format |= DT_NOCLIP; } + else if (!(format & DT_CALCRECT)) + { + r = *rect; + rect = &r; + }
top = rect->top;
diff --git a/dlls/d3dx9_36/tests/core.c b/dlls/d3dx9_36/tests/core.c index fb55a547a0..9de91b2b08 100644 --- a/dlls/d3dx9_36/tests/core.c +++ b/dlls/d3dx9_36/tests/core.c @@ -770,6 +770,9 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) height = ID3DXFont_DrawTextW(font, NULL, long_textW, -1, &rect, DT_WORDBREAK | DT_NOCLIP, 0xff00ff); ok(height == 96, "Got unexpected height %d.\n", height);
+ height = ID3DXFont_DrawTextW(font, NULL, L"a\na", -1, NULL, 0, 0xff00ff); + ok(height == 24, "Got unexpected height %d.\n", height); + height = ID3DXFont_DrawTextW(font, NULL, L"a\na", -1, &rect, 0, 0xff00ff); ok(height == 24, "Got unexpected height %d.\n", height);
@@ -843,10 +846,10 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) ok(height == 36, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM, 0xff00ff); - todo_wine ok(height == 40, "Got unexpected height %d.\n", height); + ok(height == 40, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER, 0xff00ff); - todo_wine ok(height == 32, "Got unexpected height %d.\n", height); + ok(height == 32, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_RIGHT, 0xff00ff); ok(height == 24, "Got unexpected height %d.\n", height); @@ -859,6 +862,151 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) ok(height == 24, "Got unexpected height %d.\n", height); check_rect(&rect, 10, 10, 30, 34);
+ SetRect(&rect, -10, 10, 30, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CALCRECT, 0xff00ff); + ok(height == 24, "Got unexpected height %d.\n", height); + check_rect(&rect, -10, 10, 10, 34); + + SetRect(&rect, 10, -10, 50, 30); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CALCRECT, 0xff00ff); + ok(height == 24, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, -10, 30, 14); + + SetRect(&rect, 10, 10, -30, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CALCRECT, 0xff00ff); + ok(height == 24, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, 10, 30, 34); + + SetRect(&rect, 10, 10, 50, -30); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CALCRECT, 0xff00ff); + ok(height == 24, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, 10, 30, 34); + + SetRect(&rect, 10, 10, 50, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == 24, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, 10, 30, 34); + + SetRect(&rect, -10, 10, 30, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == 24, "Got unexpected height %d.\n", height); + check_rect(&rect, -10, 10, 10, 34); + + SetRect(&rect, 10, -10, 50, 30); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == 24, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, -10, 30, 14); + + SetRect(&rect, 10, 10, -30, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == 12, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, 10, 53, 22); + + SetRect(&rect, 10, 10, 50, -30); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == 24, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, 10, 30, 34); + + SetRect(&rect, 10, 10, 50, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM | DT_CALCRECT, 0xff00ff); + ok(height == 40, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, 26, 30, 50); + + SetRect(&rect, -10, 10, 30, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM | DT_CALCRECT, 0xff00ff); + ok(height == 40, "Got unexpected height %d.\n", height); + check_rect(&rect, -10, 26, 10, 50); + + SetRect(&rect, 10, -10, 50, 30); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM | DT_CALCRECT, 0xff00ff); + ok(height == 40, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, 6, 30, 30); + + SetRect(&rect, 10, 10, -30, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM | DT_CALCRECT, 0xff00ff); + ok(height == 40, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, 26, 30, 50); + + SetRect(&rect, 10, 10, 50, -30); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM | DT_CALCRECT, 0xff00ff); + ok(height == -40, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, -54, 30, -30); + + SetRect(&rect, 10, 10, 50, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_BOTTOM | DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == 40, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, 26, 30, 50); + + SetRect(&rect, -10, 10, 30, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_BOTTOM | DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == 40, "Got unexpected height %d.\n", height); + check_rect(&rect, -10, 26, 10, 50); + + SetRect(&rect, 10, -10, 50, 30); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_BOTTOM | DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == 40, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, 6, 30, 30); + + SetRect(&rect, 10, 10, -30, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_BOTTOM | DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == 40, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, 38, 53, 50); + + SetRect(&rect, 10, 10, 50, -30); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_BOTTOM | DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == -40, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, -54, 30, -30); + + SetRect(&rect, 10, 10, 50, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER | DT_CALCRECT, 0xff00ff); + ok(height == 32, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, 18, 30, 42); + + SetRect(&rect, -10, 10, 30, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER | DT_CALCRECT, 0xff00ff); + ok(height == 32, "Got unexpected height %d.\n", height); + check_rect(&rect, -10, 18, 10, 42); + + SetRect(&rect, 10, -10, 50, 30); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER | DT_CALCRECT, 0xff00ff); + ok(height == 32, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, -2, 30, 22); + + SetRect(&rect, 10, 10, -30, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER | DT_CALCRECT, 0xff00ff); + ok(height == 32, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, 18, 30, 42); + + SetRect(&rect, 10, 10, 50, -30); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER | DT_CALCRECT, 0xff00ff); + ok(height == -8, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, -22, 30, 2); + + SetRect(&rect, 10, 10, 50, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == 32, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, 18, 30, 42); + + SetRect(&rect, -10, 10, 30, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == 32, "Got unexpected height %d.\n", height); + check_rect(&rect, -10, 18, 10, 42); + + SetRect(&rect, 10, -10, 50, 30); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == 32, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, -2, 30, 22); + + SetRect(&rect, 10, 10, -30, 50); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == 26, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, 24, 53, 36); + + SetRect(&rect, 10, 10, 50, -30); + height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff); + ok(height == -8, "Got unexpected height %d.\n", height); + check_rect(&rect, 10, -22, 30, 2); + ID3DXFont_Release(font); }