d3dx9: Handle vertical alignment in ID3DXFont_DrawText.

Signed-off-by: Sven Baars <sbaars@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Sven Baars 2020-03-27 17:48:33 +01:00 committed by Alexandre Julliard
parent 53769e7bde
commit fd9808b45a
2 changed files with 169 additions and 4 deletions

View File

@ -625,7 +625,19 @@ static int compute_rect(struct d3dx_font *font, const WCHAR *string, unsigned in
}
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;
}
@ -662,13 +674,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;

View File

@ -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);
}