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

Alexandre Julliard julliard at winehq.org
Mon Jun 4 16:26:23 CDT 2018


Module: wine
Branch: master
Commit: 5dfacee5cccebf8fbb7012c7d0212e61e96390f2
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=5dfacee5cccebf8fbb7012c7d0212e61e96390f2

Author: Zhiyi Zhang <zzhang at codeweavers.com>
Date:   Mon Jun  4 19:54:16 2018 +0800

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 at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 3cc9571..c5bcd50 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 8a2c247..286c4f5 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;




More information about the wine-cvs mailing list