From 5dfacee5cccebf8fbb7012c7d0212e61e96390f2 Mon Sep 17 00:00:00 2001 From: Zhiyi Zhang Date: Mon, 4 Jun 2018 19:54:16 +0800 Subject: [PATCH] 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 Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- 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 3cc95715217..c5bcd507168 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 8a2c247d8df..286c4f52d08 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;