user: fix DrawTextExA/W on empty strings.
Rein Klazes
wijn at wanadoo.nl
Wed Jan 25 07:31:10 CST 2006
Hi,
Changelog:
dlls/user : text.c
dlls/user/tests : text.c
DrawTextExA/W should calculate a rectangle of zero height and width in
some cases of null or empty supplied strings. With conformance tests.
Rein.
-------------- next part --------------
--- wine/dlls/user/text.c 2005-11-03 09:43:05.000000000 +0100
+++ mywine/dlls/user/text.c 2006-01-25 13:31:31.000000000 +0100
@@ -864,9 +864,15 @@ INT WINAPI DrawTextExW( HDC hdc, LPWSTR
if (dtp) TRACE("Params: iTabLength=%d, iLeftMargin=%d, iRightMargin=%d\n",
dtp->iTabLength, dtp->iLeftMargin, dtp->iRightMargin);
- if (!str) return 0;
+ if (!str || count == 0) return 0;
if (count == -1) count = strlenW(str);
- if (count == 0) return 0;
+ if (count == 0) {
+ if( flags & DT_CALCRECT) {
+ rect->right = rect->left;
+ rect->bottom = rect->top;
+ }
+ return 0;
+ }
strPtr = str;
if (flags & DT_SINGLELINE)
@@ -1020,9 +1026,14 @@ INT WINAPI DrawTextExA( HDC hdc, LPSTR s
DWORD wmax;
DWORD amax;
- if (!str) return 0;
- if (count == -1) count = strlen(str);
if (!count) return 0;
+ if( !str || ((count == -1) && !(count = strlen(str)))) {
+ if( flags & DT_CALCRECT) {
+ rect->right = rect->left;
+ rect->bottom = rect->top;
+ }
+ return 0;
+ }
wcount = MultiByteToWideChar( CP_ACP, 0, str, count, NULL, 0 );
wmax = wcount;
amax = count;
--- wine/dlls/user/tests/text.c 2005-11-03 09:43:08.000000000 +0100
+++ mywine/dlls/user/tests/text.c 2006-01-25 13:28:09.000000000 +0100
@@ -36,6 +36,9 @@ static void test_DrawTextCalcRect(void)
LOGFONTA lf;
const char text[] = "Example text for testing DrawText in "
"MM_HIENGLISH mode";
+ const WCHAR textW[] = {'W','i','d','e',' ','c','h','a','r',' ',
+ 's','t','r','i','n','g','\0'};
+ const WCHAR emptystringW[] = { 0 };
INT textlen,textheight;
RECT rect = { 0, 0, 100, 0 };
BOOL ret;
@@ -100,6 +103,41 @@ static void test_DrawTextCalcRect(void)
"should return a positive rectangle bottom. (bot=%ld)\n",
rect.bottom);
+ /* empty or null text should in some cases calc an empty rectangle */
+ /* note: testing the function's return value is useless, it differs
+ * ( 0 or 1) on every Windows version I tried */
+ SetRect( &rect, 10,10, 100, 100);
+ textheight = DrawTextExA(hdc, (char *) text, 0, &rect, DT_CALCRECT, NULL );
+ ok( !IsRectEmpty( &rect), "rectangle should NOT be empty.\n");
+ SetRect( &rect, 10,10, 100, 100);
+ SetLastError( 0);
+ textheight = DrawTextExA(hdc, "", -1, &rect, DT_CALCRECT, NULL );
+ ok( IsRectEmpty( &rect), "rectangle should be empty.\n");
+ SetRect( &rect, 10,10, 100, 100);
+ SetLastError( 0);
+ textheight = DrawTextExA(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
+ ok( IsRectEmpty( &rect), "rectangle should be empty.\n");
+ SetRect( &rect, 10,10, 100, 100);
+ textheight = DrawTextExA(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
+ ok( !IsRectEmpty( &rect), "rectangle should NOT be empty.\n");
+
+ /* Wide char versions */
+ SetRect( &rect, 10,10, 100, 100);
+ SetLastError( 0);
+ textheight = DrawTextExW(hdc, (WCHAR *) textW, 0, &rect, DT_CALCRECT, NULL );
+ if( GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) {
+ ok( !IsRectEmpty( &rect), "rectangle should NOT be empty.\n");
+ SetRect( &rect, 10,10, 100, 100);
+ textheight = DrawTextExW(hdc, (WCHAR *) emptystringW, -1, &rect, DT_CALCRECT, NULL );
+ ok( IsRectEmpty( &rect), "rectangle should be empty.\n");
+ SetRect( &rect, 10,10, 100, 100);
+ textheight = DrawTextExW(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
+ ok( !IsRectEmpty( &rect), "rectangle should NOT be empty.\n");
+ SetRect( &rect, 10,10, 100, 100);
+ textheight = DrawTextExW(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
+ ok( !IsRectEmpty( &rect), "rectangle should NOT be empty.\n");
+ }
+
SelectObject(hdc, hOldFont);
ret = DeleteObject(hFont);
ok( ret, "DeleteObject error %lu\n", GetLastError());
More information about the wine-patches
mailing list