diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c index e27858a2ce3..3645903367b 100644 --- a/dlls/d3dx9_36/font.c +++ b/dlls/d3dx9_36/font.c @@ -553,12 +553,11 @@ static void word_break(HDC hdc, const WCHAR *str, unsigned int *str_len, } static const WCHAR *read_line(HDC hdc, const WCHAR *str, int *count, - WCHAR *dest, unsigned int *dest_len, int width, DWORD format) + WCHAR *dest, unsigned int *dest_len, int width, DWORD format, SIZE *size) { unsigned int i = 0; int orig_count = *count; int num_fit; - SIZE size; *dest_len = 0; while (*count && (str[i] != '\n' || (format & DT_SINGLELINE))) @@ -570,7 +569,7 @@ static const WCHAR *read_line(HDC hdc, const WCHAR *str, int *count, } num_fit = 0; - GetTextExtentExPointW(hdc, dest, *dest_len, width, &num_fit, NULL, &size); + GetTextExtentExPointW(hdc, dest, *dest_len, width, &num_fit, NULL, size); if (num_fit < *dest_len) { @@ -578,7 +577,7 @@ static const WCHAR *read_line(HDC hdc, const WCHAR *str, int *count, { unsigned int chars_used; - word_break(hdc, dest, dest_len, num_fit, &chars_used, format, &size); + word_break(hdc, dest, dest_len, num_fit, &chars_used, format, size); *count = orig_count - chars_used; i = chars_used; } @@ -608,7 +607,9 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite, WCHAR *line; RECT textrect = {0}; int lh, x, y, width; + int max_width = 0; int ret = 0; + SIZE size; TRACE("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x.\n", iface, sprite, debugstr_wn(string, count), count, wine_dbgstr_rect(rect), format, color); @@ -660,7 +661,7 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite, { unsigned int line_len; - string = read_line(font->hdc, string, &count, line, &line_len, width, format); + string = read_line(font->hdc, string, &count, line, &line_len, width, format, &size); if (!(format & DT_CALCRECT)) { @@ -705,11 +706,24 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite, heap_free(results.lpCaretPos); heap_free(results.lpGlyphs); } + else if (size.cx > max_width) + { + max_width = size.cx; + } + y += lh; if (!(DT_NOCLIP & format) && (y > textrect.bottom)) break; } + if (format & DT_CALCRECT) + { + *rect = textrect; + + rect->bottom = y; + rect->right = rect->left + max_width; + } + ret = y - textrect.top; cleanup: diff --git a/dlls/d3dx9_36/tests/core.c b/dlls/d3dx9_36/tests/core.c index 2b5a868033f..6fae8bf8d5a 100644 --- a/dlls/d3dx9_36/tests/core.c +++ b/dlls/d3dx9_36/tests/core.c @@ -64,6 +64,15 @@ static inline void check_mat(D3DXMATRIX got, D3DXMATRIX exp) U(exp).m[3][0],U(exp).m[3][1],U(exp).m[3][2],U(exp).m[3][3]); } +#define check_rect(rect, left, top, right, bottom) _check_rect(__LINE__, rect, left, top, right, bottom) +static inline void _check_rect(unsigned int line, const RECT *rect, int left, int top, int right, int bottom) +{ + ok_(__FILE__, line)(rect->left == left, "Unexpected rect.left %d\n", rect->left); + ok_(__FILE__, line)(rect->top == top, "Unexpected rect.top %d\n", rect->top); + ok_(__FILE__, line)(rect->right == right, "Unexpected rect.right %d\n", rect->right); + ok_(__FILE__, line)(rect->bottom == bottom, "Unexpected rect.bottom %d\n", rect->bottom); +} + static void test_ID3DXBuffer(void) { ID3DXBuffer *buffer; @@ -667,8 +676,8 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) ok(height == tests[i].font_height, "Test %d: got unexpected height %u.\n", i, height); ok(!rect.left, "Test %d: got unexpected rect left %d.\n", i, rect.left); ok(!rect.top, "Test %d: got unexpected rect top %d.\n", i, rect.top); - todo_wine ok(rect.right, "Test %d: got unexpected rect right %d.\n", i, rect.right); - todo_wine ok(rect.bottom == tests[i].font_height, "Test %d: got unexpected rect bottom %d.\n", i, rect.bottom); + ok(rect.right, "Test %d: got unexpected rect right %d.\n", i, rect.right); + ok(rect.bottom == tests[i].font_height, "Test %d: got unexpected rect bottom %d.\n", i, rect.bottom); hr = ID3DXSprite_End(sprite); ok (hr == D3D_OK, "Test %d: got unexpected hr %#x.\n", i, hr); @@ -839,6 +848,11 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER, 0xff00ff); ok(height == 24, "Got unexpected height %d.\n", height); + SetRect(&rect, 10, 10, 50, 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); + ID3DXFont_Release(font); }