user32: Return 1 in DrawTextEx() when calculated offset is 0.

The return value 0 in DrawTextEx() indicates failure.
Should the offset from the bottom of the drawn text to top of
the rectangle happens to be 0, return 1 instead. So that it doesn't
indicate failure incidentally.

Signed-off-by: Zhiyi Zhang <zzhang@codeweavers.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zhiyi Zhang 2018-06-04 19:54:16 +08:00 committed by Alexandre Julliard
parent 5da1f82620
commit 5dfacee5cc
2 changed files with 16 additions and 0 deletions

View File

@ -277,6 +277,21 @@ static void test_DrawTextCalcRect(void)
ok(textheight==0,"Got textheight from DrawTextA\n");
ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
/* When offset to top is zero, return 1 */
SetRectEmpty(&rect);
textheight = DrawTextExW(hdc, textW, -1, &rect, DT_SINGLELINE | DT_CALCRECT | DT_BOTTOM, NULL);
ok(textheight == 1, "Expect returned height:1 got:%d\n", textheight);
SetRect(&rect, 0, 100, 0, 100);
textheight = DrawTextExW(hdc, textW, -1, &rect, DT_SINGLELINE | DT_CALCRECT | DT_BOTTOM, NULL);
ok(textheight == 1, "Expect returned height:1 got:%d\n", textheight);
SetRectEmpty(&rect);
textheight = DrawTextExW(hdc, textW, -1, &rect, DT_SINGLELINE | DT_CALCRECT | DT_TOP, NULL);
/* Set top to text height and bottom zero, so bottom of drawn text to top is zero when DT_VCENTER is used */
SetRect(&rect, 0, textheight, 0, 0);
textheight = DrawTextExW(hdc, textW, -1, &rect, DT_SINGLELINE | DT_CALCRECT | DT_VCENTER, NULL);
ok(textheight == 1, "Expect returned height:1 got:%d\n", textheight);
/* invalid dtp size test */
dtp.cbSize = -1; /* Invalid */

View File

@ -1064,6 +1064,7 @@ INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count,
if (retstr) memcpy(str, retstr, size_retstr);
ret = y - rect->top;
if (ret == 0) ret = 1;
done:
heap_free(retstr);
return ret;