Description: When flags does not include DT_CALCRECT, since len is calculated in the middle, it will be reduced to zero. Resulting in the length of the processed string that is finally returned to zero and the non-processing string length is unchanged. But some application taking the non-processing string length to zero as the loop end condition.
Log:
Signed-off-by: chenjiangyi chenjiangyi@uniontech.com Change-Id: Icc0f250f5f4faba1bee8326fc911a4fc9cd7c012
-- v4: user32/tests: Add tests for DrawTextExW.
From: chenjiangyi chenjiangyi@uniontech.com
Description: When flags does not include DT_CALCRECT, since len is calculated in the middle, it will be reduced to zero. Resulting in the length of the processed string that is finally returned to zero and the non-processing string length is unchanged. But some application taking the non-processing string length to zero as the loop end condition.
Log:
Signed-off-by: chenjiangyi chenjiangyi@uniontech.com Change-Id: Icc0f250f5f4faba1bee8326fc911a4fc9cd7c012 --- dlls/user32/text.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/dlls/user32/text.c b/dlls/user32/text.c index 1896627c893..8bc393e3664 100644 --- a/dlls/user32/text.c +++ b/dlls/user32/text.c @@ -1021,10 +1021,13 @@ INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count, } len -= len_seg; str += len_seg; + if (dtp) dtp->uiLengthDrawn += len_seg; + if (len) { assert ((flags & DT_EXPANDTABS) && *str == TAB); len--; str++; + if (dtp) dtp->uiLengthDrawn++; xseg += ((size.cx/tabwidth)+1)*tabwidth; if (prefix_offset != -1) { @@ -1044,15 +1047,18 @@ INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count, } } } - else if (size.cx > max_width) - max_width = size.cx; + else + { + if (dtp) dtp->uiLengthDrawn += len; + + if (size.cx > max_width) + max_width = size.cx; + }
if (invert_y) y -= lh; else y += lh; - if (dtp) - dtp->uiLengthDrawn += len; } while (strPtr && !last_line);
From: chenjiangyi chenjiangyi@uniontech.com
Log:
Signed-off-by: chenjiangyi chenjiangyi@uniontech.com Change-Id: I64052ba8aa8161ad83c1811d642aedbe462ef5ea --- dlls/user32/tests/text.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
diff --git a/dlls/user32/tests/text.c b/dlls/user32/tests/text.c index d3228eae1e0..f8ebab89c8c 100644 --- a/dlls/user32/tests/text.c +++ b/dlls/user32/tests/text.c @@ -656,6 +656,30 @@ static void test_DrawTextCalcRect(void) ok(rect.top == rect2.top, "unexpected value %ld, got %ld\n", rect.top, rect2.top); ok(rect.bottom == rect2.bottom , "unexpected value %ld, got %ld\n", rect.bottom, rect2.bottom);
+ /* further tests for dtp */ + SelectObject(hdc, hOldFont); + ret = DeleteObject(hFont); + ok( ret, "DeleteObject error %lu\n", GetLastError()); + lf.lfHeight = 200 * 9 / 72; + hFont = CreateFontIndirectA(&lf); + ok(hFont != 0, "CreateFontIndirectA error %lu\n", GetLastError()); + hOldFont = SelectObject(hdc, hFont); + + SetRect( &rect, 0,0, 100, 25); + memset(&dtp, 0, sizeof(dtp)); + dtp.cbSize = sizeof(dtp); + textheight = DrawTextExW(hdc, textW, lstrlenW(textW), &rect, DT_EDITCONTROL | DT_NOPREFIX | DT_WORDBREAK, &dtp); + ok(dtp.uiLengthDrawn == 10, "Got unexpected uiLengthDrawn %d\n", dtp.uiLengthDrawn ); + + memset(&dtp, 0, sizeof(dtp)); + dtp.cbSize = sizeof(dtp); + textheight = DrawTextExW(hdc, (LPWSTR)L" a1b2c3", lstrlenW(L" a1b2c3"), &rect, DT_EDITCONTROL | DT_NOPREFIX | DT_WORDBREAK, &dtp); + ok(dtp.uiLengthDrawn == 7, "Got unexpected uiLengthDrawn %d\n", dtp.uiLengthDrawn ); + + memset(&dtp, 0, sizeof(dtp)); + dtp.cbSize = sizeof(dtp); + textheight = DrawTextExW(hdc, (LPWSTR)L"a 1\tb2c3", lstrlenW(L"a 1\tb2c3"), &rect, DT_EDITCONTROL | DT_NOPREFIX | DT_WORDBREAK, &dtp); + ok(dtp.uiLengthDrawn == 8, "Got unexpected uiLengthDrawn %d\n", dtp.uiLengthDrawn );
SelectObject(hdc, hOldFont); ret = DeleteObject(hFont);
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=141757
Your paranoid android.
=== debian11 (32 bit report) ===
user32: text.c:672: Test failed: Got unexpected uiLengthDrawn 9
=== debian11 (32 bit ar:MA report) ===
user32: text.c:672: Test failed: Got unexpected uiLengthDrawn 9
=== debian11 (32 bit de report) ===
user32: text.c:672: Test failed: Got unexpected uiLengthDrawn 9
=== debian11 (32 bit fr report) ===
user32: text.c:672: Test failed: Got unexpected uiLengthDrawn 9
=== debian11 (32 bit he:IL report) ===
user32: text.c:672: Test failed: Got unexpected uiLengthDrawn 9
=== debian11 (32 bit hi:IN report) ===
user32: text.c:672: Test failed: Got unexpected uiLengthDrawn 9
=== debian11 (32 bit ja:JP report) ===
user32: text.c:672: Test failed: Got unexpected uiLengthDrawn 9
=== debian11 (32 bit zh:CN report) ===
user32: text.c:672: Test failed: Got unexpected uiLengthDrawn 9
=== debian11b (32 bit WoW report) ===
user32: text.c:672: Test failed: Got unexpected uiLengthDrawn 9
=== debian11b (64 bit WoW report) ===
user32: text.c:672: Test failed: Got unexpected uiLengthDrawn 9
On Fri Jan 12 11:26:37 2024 +0000, Alex Henrie wrote:
Can you add a test please?
hi, a test have added !!
here is my demo on windows:
`#include <stdlib.h> #include <stdio.h> #include <Windows.h> #include <WinUser.h> #include <windef.h> #include <wingdi.h>
void main() { HDC hdc; HWND hwnd; HFONT hFont, hOldFont; LOGFONTA lf;
hwnd = CreateWindowExA(0,"static",NULL,WS_POPUP,500,20,800,800,0,0,0,NULL); if (!hwnd) printf("create window fail !!!\n"); hdc = GetDC(hwnd);
memset(&lf,0,sizeof(lf)); lf.lfCharSet = ANSI_CHARSET; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfWeight = FW_DONTCARE; lf.lfHeight = 0; lf.lfQuality = DEFAULT_QUALITY; lstrcpyA(lf.lfFaceName,"Arial");
SetMapMode(hdc,MM_TEXT); lf.lfHeight = 200 * 9 / 72; hFont = CreateFontIndirectA(&lf); if(!hFont) printf("create font fail !!!\n"); hOldFont = SelectObject(hdc, hFont);
ShowWindow(hwnd, SW_SHOW);
RECT rect = {0, 0, 319, 23}; DRAWTEXTPARAMS dtp; //static WCHAR teststr[] = L"企业同时开会数已达5场上限,当前正在限时免费使用不受限制。"; //static WCHAR teststr[] = L"a1b2c3d4f5g6h7i8j9A1B2C3D4F5G6H7I8J9 more tests for dtp."; //static WCHAR teststr[] = L" a1b2c3d4f5g6h7i8j9A1B2C3D4F5G6H7I8J9 more tests for dtp."; //static WCHAR teststr[] = L"a 1 b2c3d4f5g6h7i8j9A1B2C3D4F5G6H7I8J9 more tests for dtp."; //static WCHAR teststr[] = L"a 1\tb2c3d4f5g6h7i8j9A1B2C3D4F5G6H7I8J9 more tests for dtp."; static WCHAR teststr[] = { 'W','i','d','e',' ','c','h','a','r',' ', 's','t','r','i','n','g','\0' };
SetRect(&rect, 0, 0, 100, 25); memset(&dtp,0,sizeof(dtp)); dtp.cbSize = sizeof(dtp);
int ret = DrawTextExW(hdc, teststr, lstrlenW(teststr), &rect, DT_EDITCONTROL | DT_NOPREFIX | DT_WORDBREAK, &dtp); printf("--->%d %d\n", dtp.uiLengthDrawn, ret); ret = DrawTextExW(hdc, L" a1b2c3", lstrlenW(L" a1b2c3"), &rect, DT_EDITCONTROL | DT_NOPREFIX | DT_WORDBREAK, &dtp); printf("--->%d %d\n", dtp.uiLengthDrawn, ret); ret = DrawTextExW(hdc, L"a 1\tb2c3", lstrlenW(L"a 1\tb2c3"), &rect, DT_EDITCONTROL | DT_NOPREFIX | DT_WORDBREAK, &dtp); printf("--->%d %d\n", dtp.uiLengthDrawn, ret);
system("pause"); DeleteObject(hFont); ReleaseDC(hwnd, hdc); DestroyWindow(hwnd);
}`
Could you add the tests first and use todo_wine to mark the result that needs the fix?