From: chenjiangyi chenjiangyi@uniontech.com
uiLengthDrawn should represent the number of characters that have been processed. However, the original implementation uses len (the count of displayed characters in the current line), which is not accurate. When text requires line breaks or special processing (such as adding an ellipsis), the actual number of processed characters may differ from the number of displayed characters. When the DT_CALCRECT flag is absent, len gets decremented to 0 during the drawing loop. Consequently, uiLengthDrawn becomes inaccurate since it relies on len's value for statistics.
Signed-off-by: chenjiangyi chenjiangyi@uniontech.com --- dlls/user32/tests/text.c | 29 +++++++++++++++++++++++++++++ dlls/user32/text.c | 7 ++++--- 2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/dlls/user32/tests/text.c b/dlls/user32/tests/text.c index d3228eae1e0..c60a4e1e1a0 100644 --- a/dlls/user32/tests/text.c +++ b/dlls/user32/tests/text.c @@ -656,6 +656,35 @@ 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, "Unexpected uiLengthDrawn %d\n", dtp.uiLengthDrawn ); + + memset(&dtp, 0, sizeof(dtp)); + dtp.cbSize = sizeof(dtp); + textheight = DrawTextExW(hdc, textW, lstrlenW(textW), &rect, DT_EDITCONTROL | DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT, &dtp); + ok(dtp.uiLengthDrawn == 16, "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, "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 | DT_CALCRECT, &dtp); + ok(dtp.uiLengthDrawn == 8, "Unexpected uiLengthDrawn %d\n", dtp.uiLengthDrawn );
SelectObject(hdc, hOldFont); ret = DeleteObject(hFont); diff --git a/dlls/user32/text.c b/dlls/user32/text.c index 1896627c893..b026ca7b4ed 100644 --- a/dlls/user32/text.c +++ b/dlls/user32/text.c @@ -871,7 +871,7 @@ INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count, WCHAR *retstr; size_t size_retstr; WCHAR line[MAX_BUFFER]; - int len, lh, count=i_count; + int len, lh, old_count, count=i_count; TEXTMETRICW tm; int lmargin = 0, rmargin = 0; int x, y, width; @@ -978,7 +978,10 @@ INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count, last_line = !(flags & DT_NOCLIP) && y - ((flags & DT_EDITCONTROL) ? 2*lh-1 : lh) < rect->bottom; else last_line = !(flags & DT_NOCLIP) && y + ((flags & DT_EDITCONTROL) ? 2*lh-1 : lh) > rect->bottom; + + old_count = count; strPtr = TEXT_NextLineW(hdc, strPtr, &count, line, &len, width, flags, &size, last_line, retstr, tabwidth, &prefix_offset, &ellip); + if (dtp) dtp->uiLengthDrawn += old_count - count;
if (flags & DT_CENTER) x = (rect->left + lmargin + rect->right - rmargin - size.cx) / 2; @@ -1051,8 +1054,6 @@ INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count, y -= lh; else y += lh; - if (dtp) - dtp->uiLengthDrawn += len; } while (strPtr && !last_line);