4 * Copyright (c) 2004 Zach Gorman
5 * Copyright 2007 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
30 #define MODIFIED(rect) (rect.left == 10 && rect.right != 100 && rect.top == 10 && rect.bottom != 100)
31 #define EMPTY(rect) (rect.left == rect.right && rect.bottom == rect.top)
33 static void test_DrawTextCalcRect(void)
37 HFONT hFont
, hOldFont
;
39 static CHAR text
[] = "Example text for testing DrawText in "
41 static WCHAR textW
[] = {'W','i','d','e',' ','c','h','a','r',' ',
42 's','t','r','i','n','g','\0'};
43 static CHAR emptystring
[] = "";
44 static WCHAR emptystringW
[] = { 0 };
45 static CHAR wordbreak_text
[] = "line1 line2";
46 static WCHAR wordbreak_textW
[] = {'l','i','n','e','1',' ','l','i','n','e','2',0};
47 INT textlen
, textheight
, heightcheck
;
48 RECT rect
= { 0, 0, 100, 0 };
51 BOOL conform_xp
= TRUE
;
54 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
55 0, 0, 200, 200, 0, 0, 0, NULL
);
56 ok(hwnd
!= 0, "CreateWindowExA error %u\n", GetLastError());
58 ok(hdc
!= 0, "GetDC error %u\n", GetLastError());
59 trace("hdc %p\n", hdc
);
60 textlen
= lstrlenA(text
);
62 /* LOGFONT initialization */
63 memset(&lf
, 0, sizeof(lf
));
64 lf
.lfCharSet
= ANSI_CHARSET
;
65 lf
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
66 lf
.lfWeight
= FW_DONTCARE
;
67 lf
.lfHeight
= 0; /* mapping mode dependent */
68 lf
.lfQuality
= DEFAULT_QUALITY
;
69 lstrcpyA(lf
.lfFaceName
, "Arial");
71 /* DrawText in MM_HIENGLISH with DT_CALCRECT */
72 SetMapMode(hdc
, MM_HIENGLISH
);
73 lf
.lfHeight
= 100 * 9 / 72; /* 9 point */
74 hFont
= CreateFontIndirectA(&lf
);
75 ok(hFont
!= 0, "CreateFontIndirectA error %u\n",
77 hOldFont
= SelectObject(hdc
, hFont
);
79 textheight
= DrawTextA(hdc
, text
, textlen
, &rect
, DT_CALCRECT
|
80 DT_EXTERNALLEADING
| DT_WORDBREAK
| DT_NOCLIP
| DT_LEFT
|
82 ok( textheight
, "DrawTextA error %u\n", GetLastError());
84 trace("MM_HIENGLISH rect.bottom %d\n", rect
.bottom
);
85 ok(rect
.bottom
< 0, "In MM_HIENGLISH, DrawText with "
86 "DT_CALCRECT should return a negative rectangle bottom. "
87 "(bot=%d)\n", rect
.bottom
);
89 SelectObject(hdc
, hOldFont
);
90 ret
= DeleteObject(hFont
);
91 ok( ret
, "DeleteObject error %u\n", GetLastError());
94 /* DrawText in MM_TEXT with DT_CALCRECT */
95 SetMapMode(hdc
, MM_TEXT
);
96 lf
.lfHeight
= -MulDiv(9, GetDeviceCaps(hdc
,
97 LOGPIXELSY
), 72); /* 9 point */
98 hFont
= CreateFontIndirectA(&lf
);
99 ok(hFont
!= 0, "CreateFontIndirectA error %u\n",
101 hOldFont
= SelectObject(hdc
, hFont
);
103 textheight
= DrawTextA(hdc
, text
, textlen
, &rect
, DT_CALCRECT
|
104 DT_EXTERNALLEADING
| DT_WORDBREAK
| DT_NOCLIP
| DT_LEFT
|
106 ok( textheight
, "DrawTextA error %u\n", GetLastError());
108 trace("MM_TEXT rect.bottom %d\n", rect
.bottom
);
109 ok(rect
.bottom
> 0, "In MM_TEXT, DrawText with DT_CALCRECT "
110 "should return a positive rectangle bottom. (bot=%d)\n",
113 /* empty or null text should in some cases calc an empty rectangle */
115 SetRect( &rect
, 10,10, 100, 100);
116 heightcheck
= textheight
= DrawTextExA(hdc
, text
, 0, &rect
, DT_CALCRECT
, NULL
);
117 ok( !EMPTY(rect
) && !MODIFIED(rect
),
118 "rectangle should NOT be empty got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
119 ok(textheight
==0,"Got textheight from DrawTextExA\n");
121 SetRect( &rect
, 10,10, 100, 100);
122 textheight
= DrawTextA(hdc
, text
, 0, &rect
, DT_CALCRECT
);
123 ok( !EMPTY(rect
) && !MODIFIED(rect
),
124 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
125 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
127 ok(textheight
==0,"Got textheight from DrawTextA\n");
128 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
130 SetRect( &rect
, 10,10, 100, 100);
132 heightcheck
= textheight
= DrawTextExA(hdc
, emptystring
, -1, &rect
, DT_CALCRECT
, NULL
);
134 "rectangle should be empty got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
135 ok(textheight
!=0,"Failed to get textheight from DrawTextExA\n");
137 SetRect( &rect
, 10,10, 100, 100);
138 textheight
= DrawTextA(hdc
, emptystring
, -1, &rect
, DT_CALCRECT
);
140 "rectangle should be empty got %d,%d-%d,%d\n",
141 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
142 ok(textheight
!=0,"Failed to get textheight from DrawTextA\n");
143 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
145 SetRect( &rect
, 10,10, 100, 100);
147 heightcheck
= textheight
= DrawTextExA(hdc
, NULL
, -1, &rect
, DT_CALCRECT
, NULL
);
148 ok( EMPTY(rect
) || !MODIFIED(rect
),
149 "rectangle should be empty or not modified got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
150 if (!textheight
) /* Windows NT 4 */
153 win_skip("XP conformity failed, skipping XP tests. Probably winNT\n");
157 ok(textheight
!=0,"Failed to get textheight from DrawTextExA\n");
159 SetRect( &rect
, 10,10, 100, 100);
160 textheight
= DrawTextA(hdc
, NULL
, -1, &rect
, DT_CALCRECT
);
161 ok( EMPTY(rect
) || !MODIFIED(rect
),
162 "rectangle should be empty or NOT modified got %d,%d-%d,%d\n",
163 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
165 ok(textheight
!=0,"Failed to get textheight from DrawTextA\n");
166 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
168 SetRect( &rect
, 10,10, 100, 100);
169 heightcheck
= textheight
= DrawTextExA(hdc
, NULL
, 0, &rect
, DT_CALCRECT
, NULL
);
170 ok( !EMPTY(rect
) && !MODIFIED(rect
),
171 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
173 ok(textheight
==0,"Got textheight from DrawTextExA\n");
175 SetRect( &rect
, 10,10, 100, 100);
176 textheight
= DrawTextA(hdc
, NULL
, 0, &rect
, DT_CALCRECT
);
177 ok( !EMPTY(rect
) && !MODIFIED(rect
),
178 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
179 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
181 ok(textheight
==0,"Got textheight from DrawTextA\n");
182 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
184 /* DT_SINGLELINE tests */
186 SetRect( &rect
, 10,10, 100, 100);
187 heightcheck
= textheight
= DrawTextExA(hdc
, text
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
188 ok( !EMPTY(rect
) && !MODIFIED(rect
),
189 "rectangle should NOT be empty got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
191 ok(textheight
==0,"Got textheight from DrawTextExA\n");
193 SetRect( &rect
, 10,10, 100, 100);
194 textheight
= DrawTextA(hdc
, text
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
195 ok( !EMPTY(rect
) && !MODIFIED(rect
),
196 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
197 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
199 ok(textheight
==0,"Got textheight from DrawTextA\n");
200 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
202 SetRect( &rect
, 10,10, 100, 100);
204 heightcheck
= textheight
= DrawTextExA(hdc
, emptystring
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
205 ok( !EMPTY(rect
) && MODIFIED(rect
),
206 "rectangle should be modified got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
207 ok(textheight
!=0,"Failed to get textheight from DrawTextExA\n");
209 SetRect( &rect
, 10,10, 100, 100);
210 textheight
= DrawTextA(hdc
, emptystring
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
211 ok( !EMPTY(rect
) && MODIFIED (rect
),
212 "rectangle should be modified got %d,%d-%d,%d\n",
213 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
214 ok(textheight
!=0,"Failed to get textheight from DrawTextA\n");
215 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
217 SetRect( &rect
, 10,10, 100, 100);
219 heightcheck
= textheight
= DrawTextExA(hdc
, NULL
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
220 ok( (!EMPTY(rect
) && MODIFIED(rect
)) || !MODIFIED(rect
),
221 "rectangle should be modified got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
223 ok(textheight
!=0,"Failed to get textheight from DrawTextExA\n");
225 SetRect( &rect
, 10,10, 100, 100);
226 textheight
= DrawTextA(hdc
, NULL
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
227 ok( (!EMPTY(rect
) && MODIFIED(rect
)) || !MODIFIED(rect
),
228 "rectangle should be modified got %d,%d-%d,%d\n",
229 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
231 ok(textheight
!=0,"Failed to get textheight from DrawTextA\n");
232 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
234 SetRect( &rect
, 10,10, 100, 100);
235 heightcheck
= textheight
= DrawTextExA(hdc
, NULL
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
236 ok( !EMPTY(rect
) && !MODIFIED(rect
),
237 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
239 ok(textheight
==0,"Got textheight from DrawTextExA\n");
241 SetRect( &rect
, 10,10, 100, 100);
242 textheight
= DrawTextA(hdc
, NULL
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
243 ok( !EMPTY(rect
) && !MODIFIED(rect
),
244 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
245 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
247 ok(textheight
==0,"Got textheight from DrawTextA\n");
248 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
250 /* further tests with 0 count, NULL and empty strings */
251 heightcheck
= textheight
= DrawTextA(hdc
, text
, 0, &rect
, 0);
253 ok(textheight
==0,"Got textheight from DrawTextA\n");
254 textheight
= DrawTextExA(hdc
, text
, 0, &rect
, 0, NULL
);
256 ok(textheight
==0,"Got textheight from DrawTextExA\n");
257 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
258 heightcheck
= textheight
= DrawTextA(hdc
, emptystring
, 0, &rect
, 0);
260 ok(textheight
==0,"Got textheight from DrawTextA\n");
261 textheight
= DrawTextExA(hdc
, emptystring
, 0, &rect
, 0, NULL
);
263 ok(textheight
==0,"Got textheight from DrawTextExA\n");
264 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
265 heightcheck
= textheight
= DrawTextA(hdc
, NULL
, 0, &rect
, 0);
267 ok(textheight
==0,"Got textheight from DrawTextA\n");
268 textheight
= DrawTextExA(hdc
, NULL
, 0, &rect
, 0, NULL
);
270 ok(textheight
==0,"Got textheight from DrawTextExA\n");
271 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
272 heightcheck
= textheight
= DrawTextA(hdc
, emptystring
, -1, &rect
, 0);
273 ok(textheight
!=0,"Failed to get textheight from DrawTextA\n");
274 textheight
= DrawTextExA(hdc
, emptystring
, -1, &rect
, 0, NULL
);
275 ok(textheight
!=0,"Failed to get textheight from DrawTextExA\n");
276 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
277 heightcheck
= textheight
= DrawTextA(hdc
, NULL
, -1, &rect
, 0);
279 ok(textheight
!=0,"Failed to get textheight from DrawTextA\n");
280 textheight
= DrawTextExA(hdc
, NULL
, -1, &rect
, 0, NULL
);
282 ok(textheight
!=0,"Failed to get textheight from DrawTextExA\n");
283 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
284 heightcheck
= textheight
= DrawTextA(hdc
, NULL
, 10, &rect
, 0);
285 ok(textheight
==0,"Got textheight from DrawTextA\n");
286 textheight
= DrawTextExA(hdc
, NULL
, 10, &rect
, 0, NULL
);
287 ok(textheight
==0,"Got textheight from DrawTextA\n");
288 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
291 /* invalid dtp size test */
292 dtp
.cbSize
= -1; /* Invalid */
293 dtp
.uiLengthDrawn
= 1337;
294 textheight
= DrawTextExA(hdc
, text
, 0, &rect
, 0, &dtp
);
295 ok(textheight
==0,"Got textheight from DrawTextExA\n");
296 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
297 dtp
.uiLengthDrawn
= 1337;
298 textheight
= DrawTextExA(hdc
, emptystring
, 0, &rect
, 0, &dtp
);
299 ok(textheight
==0,"Got textheight from DrawTextExA\n");
300 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
301 dtp
.uiLengthDrawn
= 1337;
302 textheight
= DrawTextExA(hdc
, NULL
, 0, &rect
, 0, &dtp
);
303 ok(textheight
==0,"Got textheight from DrawTextExA\n");
304 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
305 dtp
.uiLengthDrawn
= 1337;
306 textheight
= DrawTextExA(hdc
, emptystring
, -1, &rect
, 0, &dtp
);
307 ok(textheight
==0,"Got textheight from DrawTextExA\n");
308 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
309 dtp
.uiLengthDrawn
= 1337;
310 textheight
= DrawTextExA(hdc
, NULL
, -1, &rect
, 0, &dtp
);
311 ok(textheight
==0,"Got textheight from DrawTextExA\n");
312 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
314 /* Margin calculations */
315 dtp
.cbSize
= sizeof(dtp
);
317 dtp
.iRightMargin
= 0;
318 SetRect( &rect
, 0, 0, 0, 0);
319 DrawTextExA(hdc
, text
, -1, &rect
, DT_CALCRECT
, &dtp
);
320 textlen
= rect
.right
; /* Width without margin */
322 SetRect( &rect
, 0, 0, 0, 0);
323 DrawTextExA(hdc
, text
, -1, &rect
, DT_CALCRECT
, &dtp
);
324 ok(rect
.right
==dtp
.iLeftMargin
+textlen
,"Incorrect left margin calculated rc(%d,%d)\n", rect
.left
, rect
.right
);
326 dtp
.iRightMargin
= 8;
327 SetRect( &rect
, 0, 0, 0, 0);
328 DrawTextExA(hdc
, text
, -1, &rect
, DT_CALCRECT
, &dtp
);
329 ok(rect
.right
==dtp
.iRightMargin
+textlen
,"Incorrect right margin calculated rc(%d,%d)\n", rect
.left
, rect
.right
);
331 /* Wide char versions */
332 SetRect( &rect
, 10,10, 100, 100);
334 heightcheck
= textheight
= DrawTextExW(hdc
, textW
, 0, &rect
, DT_CALCRECT
, NULL
);
335 if( GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
) {
336 ok( !EMPTY(rect
) && !MODIFIED(rect
),
337 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
338 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
339 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
341 SetRect( &rect
, 10,10, 100, 100);
342 textheight
= DrawTextW(hdc
, textW
, 0, &rect
, DT_CALCRECT
);
343 ok( !EMPTY(rect
) && !MODIFIED(rect
),
344 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
345 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
346 ok(textheight
!=0,"Failed to get textheight from DrawTextW\n");
347 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
349 SetRect( &rect
, 10,10, 100, 100);
350 heightcheck
= textheight
= DrawTextExW(hdc
, emptystringW
, -1, &rect
, DT_CALCRECT
, NULL
);
352 "rectangle should be empty got %d,%d-%d,%d\n",
353 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
354 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
356 SetRect( &rect
, 10,10, 100, 100);
357 textheight
= DrawTextW(hdc
, emptystringW
, -1, &rect
, DT_CALCRECT
);
359 "rectangle should be empty got %d,%d-%d,%d\n",
360 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
361 ok(textheight
!=0,"Failed to get textheight from DrawTextW\n");
362 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
364 SetRect( &rect
, 10,10, 100, 100);
365 heightcheck
= textheight
= DrawTextExW(hdc
, NULL
, 0, &rect
, DT_CALCRECT
, NULL
);
366 ok( !EMPTY(rect
) && !MODIFIED(rect
),
367 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
368 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
369 if (textheight
) /* windows 2000 */
372 win_skip("XP conformity failed, skipping XP tests. Probably win 2000\n");
376 ok(textheight
==0,"Got textheight from DrawTextExW\n");
378 SetRect( &rect
, 10,10, 100, 100);
379 textheight
= DrawTextW(hdc
, NULL
, 0, &rect
, DT_CALCRECT
);
380 ok( !EMPTY(rect
) && !MODIFIED(rect
),
381 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
382 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
384 ok(textheight
==0,"Got textheight from DrawTextW\n");
385 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
389 SetRect( &rect
, 10,10, 100, 100);
390 heightcheck
= textheight
= DrawTextExW(hdc
, NULL
, -1, &rect
, DT_CALCRECT
, NULL
);
391 ok( !EMPTY(rect
) && !MODIFIED(rect
),
392 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
393 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
394 ok(textheight
==0,"Got textheight from DrawTextExW\n");
396 SetRect( &rect
, 10,10, 100, 100);
397 textheight
= DrawTextW(hdc
, NULL
, -1, &rect
, DT_CALCRECT
);
398 ok( !EMPTY(rect
) && !MODIFIED(rect
),
399 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
400 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
401 ok(textheight
==0,"Got textheight from DrawTextW\n");
402 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
406 /* DT_SINGLELINE tests */
408 heightcheck
= textheight
= DrawTextExW(hdc
, textW
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
409 ok( !EMPTY(rect
) && !MODIFIED(rect
),
410 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
411 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
412 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
414 SetRect( &rect
, 10,10, 100, 100);
415 textheight
= DrawTextW(hdc
, textW
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
416 ok( !EMPTY(rect
) && !MODIFIED(rect
),
417 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
418 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
419 ok(textheight
!=0,"Failed to get textheight from DrawTextW\n");
420 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
422 SetRect( &rect
, 10,10, 100, 100);
423 heightcheck
= textheight
= DrawTextExW(hdc
, emptystringW
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
424 ok( !EMPTY(rect
) && MODIFIED(rect
),
425 "rectangle should be modified got %d,%d-%d,%d\n",
426 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
427 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
429 SetRect( &rect
, 10,10, 100, 100);
430 textheight
= DrawTextW(hdc
, emptystringW
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
431 ok( !EMPTY(rect
) && MODIFIED(rect
),
432 "rectangle should be modified got %d,%d-%d,%d\n",
433 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
434 ok(textheight
!=0,"Failed to get textheight from DrawTextW\n");
435 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
439 SetRect( &rect
, 10,10, 100, 100);
440 heightcheck
= textheight
= DrawTextExW(hdc
, NULL
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
441 ok( !EMPTY(rect
) && !MODIFIED(rect
),
442 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
443 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
444 ok(textheight
==0,"Got textheight from DrawTextExW\n");
446 SetRect( &rect
, 10,10, 100, 100);
447 textheight
= DrawTextW(hdc
, NULL
, -1, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
448 ok( !EMPTY(rect
) && !MODIFIED(rect
),
449 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
450 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
451 ok(textheight
==0,"Got textheight from DrawTextW\n");
452 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
455 SetRect( &rect
, 10,10, 100, 100);
456 heightcheck
= textheight
= DrawTextExW(hdc
, NULL
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
, NULL
);
457 ok( !EMPTY(rect
) && !MODIFIED(rect
),
458 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
459 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
461 ok(textheight
==0,"Got textheight from DrawTextExW\n");
463 SetRect( &rect
, 10,10, 100, 100);
464 textheight
= DrawTextW(hdc
, NULL
, 0, &rect
, DT_CALCRECT
|DT_SINGLELINE
);
465 ok( !EMPTY(rect
) && !MODIFIED(rect
),
466 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
467 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
469 ok(textheight
==0,"Got textheight from DrawTextW\n");
470 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
472 /* further tests with NULL and empty strings */
473 heightcheck
= textheight
= DrawTextW(hdc
, textW
, 0, &rect
, 0);
474 ok(textheight
!=0,"Failed to get textheight from DrawTextW\n");
475 textheight
= DrawTextExW(hdc
, textW
, 0, &rect
, 0, NULL
);
476 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
477 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
478 heightcheck
= textheight
= DrawTextW(hdc
, emptystringW
, 0, &rect
, 0);
479 ok(textheight
!=0,"Failed to get textheight from DrawTextW\n");
480 textheight
= DrawTextExW(hdc
, emptystringW
, 0, &rect
, 0, NULL
);
481 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
482 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
483 heightcheck
= textheight
= DrawTextW(hdc
, NULL
, 0, &rect
, 0);
485 ok(textheight
==0,"Got textheight from DrawTextW\n");
486 textheight
= DrawTextExW(hdc
, NULL
, 0, &rect
, 0, NULL
);
488 ok(textheight
==0,"Got textheight from DrawTextExW\n");
489 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
490 heightcheck
= textheight
= DrawTextW(hdc
, emptystringW
, -1, &rect
, 0);
491 ok(textheight
!=0,"Failed to get textheight from DrawTextW\n");
492 textheight
= DrawTextExW(hdc
, emptystringW
, -1, &rect
, 0, NULL
);
493 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
494 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
497 heightcheck
= textheight
= DrawTextW(hdc
, NULL
, -1, &rect
, 0);
498 ok(textheight
==0,"Got textheight from DrawTextW\n");
499 textheight
= DrawTextExW(hdc
, NULL
, -1, &rect
, 0, NULL
);
500 ok(textheight
==0,"Got textheight from DrawTextExW\n");
501 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
502 heightcheck
= textheight
= DrawTextW(hdc
, NULL
, 10, &rect
, 0);
503 ok(textheight
==0,"Got textheight from DrawTextW\n");
504 textheight
= DrawTextExW(hdc
, NULL
, 10, &rect
, 0, NULL
);
505 ok(textheight
==0,"Got textheight from DrawTextW\n");
506 ok(textheight
== heightcheck
,"DrawTextEx and DrawText differ in return\n");
509 dtp
.cbSize
= -1; /* Invalid */
510 dtp
.uiLengthDrawn
= 1337;
511 textheight
= DrawTextExW(hdc
, textW
, 0, &rect
, 0, &dtp
);
512 ok(textheight
!=0,"Failed to get textheight from DrawTextExW\n");
513 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
514 dtp
.uiLengthDrawn
= 1337;
515 textheight
= DrawTextExW(hdc
, emptystringW
, 0, &rect
, 0, &dtp
);
517 ok(textheight
==0,"Got textheight from DrawTextExW\n");
518 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
519 dtp
.uiLengthDrawn
= 1337;
520 textheight
= DrawTextExW(hdc
, NULL
, 0, &rect
, 0, &dtp
);
522 ok(textheight
==0,"Got textheight from DrawTextExW\n");
523 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
524 dtp
.uiLengthDrawn
= 1337;
525 textheight
= DrawTextExW(hdc
, emptystringW
, -1, &rect
, 0, &dtp
);
526 ok(textheight
==0,"Got textheight from DrawTextExW\n");
527 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
530 dtp
.uiLengthDrawn
= 1337;
531 textheight
= DrawTextExW(hdc
, NULL
, -1, &rect
, 0, &dtp
);
532 ok(textheight
==0,"Got textheight from DrawTextExW\n");
533 ok(dtp
.uiLengthDrawn
==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp
.uiLengthDrawn
);
537 /* More test cases from bug 12226 */
538 SetRect(&rect
, 0, 0, 0, 0);
539 textheight
= DrawTextA(hdc
, emptystring
, -1, &rect
, DT_CALCRECT
| DT_LEFT
| DT_SINGLELINE
);
540 ok(textheight
, "DrawTextA error %u\n", GetLastError());
541 ok(0 == rect
.left
, "expected 0, got %d\n", rect
.left
);
542 ok(0 == rect
.right
, "expected 0, got %d\n", rect
.right
);
543 ok(0 == rect
.top
, "expected 0, got %d\n", rect
.top
);
544 ok(rect
.bottom
, "rect.bottom should not be 0\n");
546 SetRect(&rect
, 0, 0, 0, 0);
547 textheight
= DrawTextW(hdc
, emptystringW
, -1, &rect
, DT_CALCRECT
| DT_LEFT
| DT_SINGLELINE
);
548 if (!textheight
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
550 win_skip( "DrawTextW not implemented\n" );
554 ok(textheight
, "DrawTextW error %u\n", GetLastError());
555 ok(0 == rect
.left
, "expected 0, got %d\n", rect
.left
);
556 ok(0 == rect
.right
, "expected 0, got %d\n", rect
.right
);
557 ok(0 == rect
.top
, "expected 0, got %d\n", rect
.top
);
558 ok(rect
.bottom
, "rect.bottom should not be 0\n");
561 SetRect(&rect
, 0, 0, 1, 1);
562 heightcheck
= DrawTextA(hdc
, wordbreak_text
, -1, &rect
, DT_CALCRECT
);
563 SetRect(&rect
, 0, 0, 1, 1);
564 textheight
= DrawTextA(hdc
, wordbreak_text
, -1, &rect
, DT_CALCRECT
| DT_WORDBREAK
);
565 ok(textheight
== heightcheck
* 2, "Got unexpected textheight %d, expected %d.\n",
566 textheight
, heightcheck
* 2);
568 SetRect(&rect
, 0, 0, 1, 1);
569 heightcheck
= DrawTextW(hdc
, wordbreak_textW
, -1, &rect
, DT_CALCRECT
);
570 SetRect(&rect
, 0, 0, 1, 1);
571 textheight
= DrawTextW(hdc
, wordbreak_textW
, -1, &rect
, DT_CALCRECT
| DT_WORDBREAK
);
572 ok(textheight
== heightcheck
* 2, "Got unexpected textheight %d, expected %d.\n",
573 textheight
, heightcheck
* 2);
575 SelectObject(hdc
, hOldFont
);
576 ret
= DeleteObject(hFont
);
577 ok( ret
, "DeleteObject error %u\n", GetLastError());
580 ret
= ReleaseDC(hwnd
, hdc
);
581 ok( ret
, "ReleaseDC error %u\n", GetLastError());
582 ret
= DestroyWindow(hwnd
);
583 ok( ret
, "DestroyWindow error %u\n", GetLastError());
586 /* replace tabs by \t */
587 static void strfmt( const char *str
, char *strout
)
590 for(i
=0,j
=0;i
<=strlen(str
);i
++,j
++)
591 if((strout
[j
]=str
[i
])=='\t') {
598 #define TABTEST( tabval, tabcount, string, _exp) \
599 { int i,x_act, x_exp; char strdisp[64];\
600 for(i=0;i<8;i++) tabs[i]=(i+1)*(tabval); \
601 extent = GetTabbedTextExtentA( hdc, string, strlen( string), (tabcount), tabs); \
602 strfmt( string, strdisp); \
603 /* trace( "Extent is %08lx\n", extent); */\
604 x_act = LOWORD( extent); \
606 ok( x_act == x_exp, "Test case \"%s\". Text extent is %d, expected %d tab %d tabcount %d\n", \
607 strdisp, x_act, x_exp, tabval, tabcount); \
611 static void test_TabbedText(void)
618 INT tabs
[8], cx
, cy
, tab
, tabcount
,t
,align
;
621 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
622 0, 0, 200, 200, 0, 0, 0, NULL
);
623 ok(hwnd
!= 0, "CreateWindowExA error %u\n", GetLastError());
625 ok(hdc
!= 0, "GetDC error %u\n", GetLastError());
627 ret
= GetTextMetricsA( hdc
, &tm
);
628 ok( ret
, "GetTextMetrics error %u\n", GetLastError());
630 extent
= GetTabbedTextExtentA( hdc
, "x", 0, 1, tabs
);
631 ok( extent
== 0, "GetTabbedTextExtentA returned non-zero on nCount == 0\n");
633 extent
= GetTabbedTextExtentA( hdc
, "x", 1, 1, tabs
);
634 cx
= LOWORD( extent
);
635 cy
= HIWORD( extent
);
636 trace( "cx is %d cy is %d\n", cx
, cy
);
639 for( t
=-1; t
<=1; t
++) { /* slightly adjust the 4 char tabstop, to
640 catch the one off errors */
642 /* test the special case tabcount =1 and the general array (80 of tabs */
643 for( tabcount
= 1; tabcount
<= 8; tabcount
+=7) {
644 TABTEST( align
* tab
, tabcount
, "\t", tab
)
645 TABTEST( align
* tab
, tabcount
, "xxx\t", tab
)
646 TABTEST( align
* tab
, tabcount
, "\tx", tab
+cx
)
647 TABTEST( align
* tab
, tabcount
, "\t\t", tab
*2)
648 TABTEST( align
* tab
, tabcount
, "\tx\t", tab
*2)
649 TABTEST( align
* tab
, tabcount
, "x\tx", tab
+cx
)
650 TABTEST( align
* tab
, tabcount
, "xx\tx", tab
+cx
)
651 TABTEST( align
* tab
, tabcount
, "xxx\tx", tab
+cx
)
652 TABTEST( align
* tab
, tabcount
, "xxxx\tx", t
>0 ? tab
+ cx
: 2*tab
+cx
)
653 TABTEST( align
* tab
, tabcount
, "xxxxx\tx", 2*tab
+cx
)
657 for( t
=-1; t
<=1; t
++) { /* slightly adjust the 4 char tabstop, to
658 catch the one off errors */
660 /* test the special case tabcount =1 and the general array (8) of tabs */
661 for( tabcount
= 1; tabcount
<= 8; tabcount
+=7) {
662 TABTEST( align
* tab
, tabcount
, "\t", tab
)
663 TABTEST( align
* tab
, tabcount
, "xxx\t", tab
)
664 TABTEST( align
* tab
, tabcount
, "\tx", tab
)
665 TABTEST( align
* tab
, tabcount
, "\t\t", tab
*2)
666 TABTEST( align
* tab
, tabcount
, "\tx\t", tab
*2)
667 TABTEST( align
* tab
, tabcount
, "x\tx", tab
)
668 TABTEST( align
* tab
, tabcount
, "xx\tx", tab
)
669 TABTEST( align
* tab
, tabcount
, "xxx\tx", 4 * cx
>= tab
? 2*tab
:tab
)
670 TABTEST( align
* tab
, tabcount
, "xxxx\tx", 2*tab
)
671 TABTEST( align
* tab
, tabcount
, "xxxxx\tx", 2*tab
)
675 ReleaseDC( hwnd
, hdc
);
676 DestroyWindow( hwnd
);
679 static void test_DrawState(void)
681 static const char text
[] = "Sample text string";
686 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
687 0, 0, 200, 200, 0, 0, 0, NULL
);
693 SetLastError(0xdeadbeef);
694 ret
= DrawStateA(hdc
, GetStockObject(DKGRAY_BRUSH
), NULL
, (LPARAM
)text
, strlen(text
),
695 0, 0, 10, 10, DST_TEXT
);
696 ok(ret
, "DrawState error %u\n", GetLastError());
698 SetLastError(0xdeadbeef);
699 ret
= DrawStateA(hdc
, GetStockObject(DKGRAY_BRUSH
), NULL
, (LPARAM
)text
, 0,
700 0, 0, 10, 10, DST_TEXT
);
701 ok(ret
, "DrawState error %u\n", GetLastError());
703 SetLastError(0xdeadbeef);
704 ret
= DrawStateA(hdc
, GetStockObject(DKGRAY_BRUSH
), NULL
, 0, strlen(text
),
705 0, 0, 10, 10, DST_TEXT
);
706 ok(!ret
|| broken(ret
) /* win98 */, "DrawState succeeded\n");
707 ok(GetLastError() == 0xdeadbeef, "not expected error %u\n", GetLastError());
709 SetLastError(0xdeadbeef);
710 ret
= DrawStateA(hdc
, GetStockObject(DKGRAY_BRUSH
), NULL
, 0, 0,
711 0, 0, 10, 10, DST_TEXT
);
712 ok(!ret
|| broken(ret
) /* win98 */, "DrawState succeeded\n");
713 ok(GetLastError() == 0xdeadbeef, "not expected error %u\n", GetLastError());
715 ReleaseDC(hwnd
, hdc
);
722 test_DrawTextCalcRect();