d3dx9: Handle horizontal 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>
feature/deterministic
Sven Baars 2020-03-27 17:48:34 +01:00 committed by Alexandre Julliard
parent fd9808b45a
commit d511853d45
2 changed files with 182 additions and 3 deletions

View File

@ -624,7 +624,20 @@ static int compute_rect(struct d3dx_font *font, const WCHAR *string, unsigned in
break;
}
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;
}
if (format & DT_VCENTER)
{
rect->top += (rect->bottom - y) / 2;
@ -699,7 +712,6 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite,
top = rect->top;
}
x = rect->left;
y = rect->top;
lh = font->metrics.tmHeight;
width = rect->right - rect->left;
@ -718,6 +730,13 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite,
string = read_line(font->hdc, string, &count, line, &line_len, width, format, &size);
if (format & DT_CENTER)
x = (rect->left + rect->right - size.cx) / 2;
else if (format & DT_RIGHT)
x = rect->right - size.cx;
else
x = rect->left;
memset(&results, 0, sizeof(results));
results.nGlyphs = line_len;

View File

@ -842,7 +842,7 @@ static void test_ID3DXFont(IDirect3DDevice9 *device)
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_RIGHT, 0xff00ff);
ok(height == 36, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_RIGHT, 0xff00ff);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_CENTER, 0xff00ff);
ok(height == 36, "Got unexpected height %d.\n", height);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM, 0xff00ff);
@ -1007,6 +1007,166 @@ static void test_ID3DXFont(IDirect3DDevice9 *device)
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\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, 30, 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, 10, 10, 30, 34);
SetRect(&rect, 10, -10, 50, 30);
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, 14);
SetRect(&rect, 10, 10, -30, 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, -50, 10, -30, 34);
SetRect(&rect, 10, 10, 50, -30);
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 aaaa", -1, &rect, DT_RIGHT | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
ok(height == 24, "Got unexpected height %d.\n", height);
check_rect(&rect, 30, 10, 50, 34);
SetRect(&rect, -10, 10, 30, 50);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_RIGHT | 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, 30);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_RIGHT | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
ok(height == 24, "Got unexpected height %d.\n", height);
check_rect(&rect, 30, -10, 50, 14);
SetRect(&rect, 10, 10, -30, 50);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_RIGHT | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
ok(height == 12, "Got unexpected height %d.\n", height);
check_rect(&rect, -73, 10, -30, 22);
SetRect(&rect, 10, 10, 50, -30);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_RIGHT | DT_WORDBREAK | 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, 30, 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, 0, 10, 20, 34);
SetRect(&rect, 10, -10, 50, 30);
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, 14);
SetRect(&rect, 10, 10, -30, 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, 0, 34);
SetRect(&rect, 10, 10, 50, -30);
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 aaaa", -1, &rect, DT_CENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
ok(height == 24, "Got unexpected height %d.\n", height);
check_rect(&rect, 20, 10, 40, 34);
SetRect(&rect, -10, 10, 30, 50);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
ok(height == 24, "Got unexpected height %d.\n", height);
check_rect(&rect, 0, 10, 20, 34);
SetRect(&rect, 10, -10, 50, 30);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
ok(height == 24, "Got unexpected height %d.\n", height);
check_rect(&rect, 20, -10, 40, 14);
SetRect(&rect, 10, 10, -30, 50);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
ok(height == 12, "Got unexpected height %d.\n", height);
check_rect(&rect, -31, 10, 12, 22);
SetRect(&rect, 10, 10, 50, -30);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_WORDBREAK | 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\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, 30, 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, 0, 18, 20, 42);
SetRect(&rect, 10, -10, 50, 30);
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, -2, 40, 22);
SetRect(&rect, 10, 10, -30, 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, 0, 42);
SetRect(&rect, 10, 10, 50, -30);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_CALCRECT, 0xff00ff);
ok(height == -8, "Got unexpected height %d.\n", height);
check_rect(&rect, 20, -22, 40, 2);
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);
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);
SetRect(&rect, -10, 10, 30, 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, 0, 18, 20, 42);
SetRect(&rect, 10, -10, 50, 30);
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, -2, 40, 22);
SetRect(&rect, 10, 10, -30, 50);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
ok(height == 26, "Got unexpected height %d.\n", height);
check_rect(&rect, -31, 24, 12, 36);
SetRect(&rect, 10, 10, 50, -30);
height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
ok(height == -8, "Got unexpected height %d.\n", height);
check_rect(&rect, 20, -22, 40, 2);
ID3DXFont_Release(font);
}