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 --- dlls/user32/tests/text.c | 15 +++++++++++++++ dlls/user32/text.c | 1 + 2 files changed, 16 insertions(+)
diff --git a/dlls/user32/tests/text.c b/dlls/user32/tests/text.c index 3cc9571521..c5bcd50716 100644 --- a/dlls/user32/tests/text.c +++ b/dlls/user32/tests/text.c @@ -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 */ diff --git a/dlls/user32/text.c b/dlls/user32/text.c index 8a2c247d8d..286c4f52d0 100644 --- a/dlls/user32/text.c +++ b/dlls/user32/text.c @@ -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;