[WINESYNC] 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>

wine commit id d511853d45bc3302b2a4501b1aa0097a4e78b3d9 by Sven Baars <sbaars@codeweavers.com>
This commit is contained in:
winesync 2020-09-21 23:07:33 +02:00 committed by Jérôme Gardou
parent 69ca9a5852
commit 4ff131d352
3 changed files with 183 additions and 4 deletions

View file

@ -628,7 +628,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;
@ -703,7 +716,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;
@ -722,6 +734,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);
}

View file

@ -15,4 +15,4 @@ files: {include/d3dx9.h: sdk/include/dxsdk/d3dx9.h, include/d3dx9anim.h: sdk/inc
include/d3dx9mesh.h: sdk/include/dxsdk/d3dx9mesh.h, include/d3dx9of.h: sdk/include/dxsdk/d3dx9of.h,
include/d3dx9shader.h: sdk/include/dxsdk/d3dx9shader.h, include/d3dx9shape.h: sdk/include/dxsdk/d3dx9shape.h,
include/d3dx9tex.h: sdk/include/dxsdk/d3dx9tex.h, include/d3dx9xof.h: sdk/include/dxsdk/d3dx9xof.h}
tags: {wine: fd9808b45af4bf4c6771fe2932e3169cb193bf44}
tags: {wine: d511853d45bc3302b2a4501b1aa0097a4e78b3d9}