[GDI32_WINETEST] Sync everything except dib.c with Wine Staging 3.3. CORE-14434
[reactos.git] / modules / rostests / winetests / gdi32 / mapping.c
1 /*
2 * Unit tests for mapping functions
3 *
4 * Copyright (c) 2005 Huw Davies
5 * Copyright (c) 2008 Dmitry Timoshkov
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include <stdio.h>
23 #include <math.h>
24
25 #include "wine/test.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winerror.h"
30
31 static DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);
32 static DWORD (WINAPI *pGetLayout)(HDC hdc);
33 static INT (WINAPI *pGetRandomRgn)(HDC hDC, HRGN hRgn, INT iCode);
34 static BOOL (WINAPI *pGetTransform)(HDC, DWORD, XFORM *);
35 static BOOL (WINAPI *pSetVirtualResolution)(HDC, DWORD, DWORD, DWORD, DWORD);
36
37 #define rough_match(got, expected) (abs( MulDiv( (got) - (expected), 1000, (expected) )) <= 5)
38
39 #define expect_LPtoDP(_hdc, _x, _y) \
40 { \
41 POINT _pt = { 1000, 1000 }; \
42 LPtoDP(_hdc, &_pt, 1); \
43 ok(rough_match(_pt.x, _x), "expected x %d, got %d\n", (_x), _pt.x); \
44 ok(rough_match(_pt.y, _y), "expected y %d, got %d\n", (_y), _pt.y); \
45 }
46
47 #define expect_world_transform(_hdc, _em11, _em22) \
48 { \
49 BOOL _ret; \
50 XFORM _xform; \
51 SetLastError(0xdeadbeef); \
52 _ret = GetWorldTransform(_hdc, &_xform); \
53 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) \
54 { \
55 ok(_ret, "GetWorldTransform error %u\n", GetLastError()); \
56 ok(_xform.eM11 == (_em11), "expected %f, got %f\n", (_em11), _xform.eM11); \
57 ok(_xform.eM12 == 0.0, "expected 0.0, got %f\n", _xform.eM12); \
58 ok(_xform.eM21 == 0.0, "expected 0.0, got %f\n", _xform.eM21); \
59 ok(_xform.eM22 == (_em22), "expected %f, got %f\n", (_em22), _xform.eM22); \
60 ok(_xform.eDx == 0.0, "expected 0.0, got %f\n", _xform.eDx); \
61 ok(_xform.eDy == 0.0, "expected 0.0, got %f\n", _xform.eDy); \
62 } \
63 }
64
65 #define expect_dc_ext(_func, _hdc, _cx, _cy) \
66 { \
67 BOOL _ret; \
68 SIZE _size; \
69 SetLastError(0xdeadbeef); \
70 _ret = _func(_hdc, &_size); \
71 ok(_ret, #_func " error %u\n", GetLastError()); \
72 ok(_size.cx == (_cx), "expected cx %d, got %d\n", (_cx), _size.cx); \
73 ok(_size.cy == (_cy), "expected cy %d, got %d\n", (_cy), _size.cy); \
74 }
75
76 #define expect_viewport_ext(_hdc, _cx, _cy) expect_dc_ext(GetViewportExtEx, _hdc, _cx, _cy)
77 #define expect_window_ext(_hdc, _cx, _cy) expect_dc_ext(GetWindowExtEx, _hdc, _cx, _cy)
78
79 static void test_world_transform(void)
80 {
81 HDC hdc;
82 INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
83 XFORM xform;
84 SIZE size;
85
86 hdc = CreateCompatibleDC(0);
87
88 xform.eM11 = 1.0f;
89 xform.eM12 = 0.0f;
90 xform.eM21 = 0.0f;
91 xform.eM22 = 1.0f;
92 xform.eDx = 0.0f;
93 xform.eDy = 0.0f;
94 ret = SetWorldTransform(hdc, &xform);
95 ok(!ret, "SetWorldTransform should fail in GM_COMPATIBLE mode\n");
96
97 size_cx = GetDeviceCaps(hdc, HORZSIZE);
98 size_cy = GetDeviceCaps(hdc, VERTSIZE);
99 res_x = GetDeviceCaps(hdc, HORZRES);
100 res_y = GetDeviceCaps(hdc, VERTRES);
101 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
102 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
103 trace("dc size %d x %d, resolution %d x %d dpi %d x %d\n",
104 size_cx, size_cy, res_x, res_y, dpi_x, dpi_y );
105
106 expect_viewport_ext(hdc, 1, 1);
107 expect_window_ext(hdc, 1, 1);
108 expect_world_transform(hdc, 1.0, 1.0);
109 expect_LPtoDP(hdc, 1000, 1000);
110
111 SetLastError(0xdeadbeef);
112 ret = SetMapMode(hdc, MM_LOMETRIC);
113 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
114
115 expect_viewport_ext(hdc, res_x, -res_y);
116 ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
117 ok( rough_match( size.cx, size_cx * 10 ) ||
118 rough_match( size.cx, MulDiv( res_x, 254, dpi_x )), /* Vista uses a more precise method */
119 "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
120 ok( rough_match( size.cy, size_cy * 10 ) ||
121 rough_match( size.cy, MulDiv( res_y, 254, dpi_y )), /* Vista uses a more precise method */
122 "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
123 expect_world_transform(hdc, 1.0, 1.0);
124 expect_LPtoDP(hdc, MulDiv(1000 / 10, res_x, size_cx), -MulDiv(1000 / 10, res_y, size_cy));
125
126 SetLastError(0xdeadbeef);
127 ret = SetMapMode(hdc, MM_TEXT);
128 ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
129
130 expect_viewport_ext(hdc, 1, 1);
131 expect_window_ext(hdc, 1, 1);
132 expect_world_transform(hdc, 1.0, 1.0);
133 expect_LPtoDP(hdc, 1000, 1000);
134
135 ret = SetGraphicsMode(hdc, GM_ADVANCED);
136 if (!ret)
137 {
138 DeleteDC(hdc);
139 skip("GM_ADVANCED is not supported on this platform\n");
140 return;
141 }
142
143 expect_viewport_ext(hdc, 1, 1);
144 expect_window_ext(hdc, 1, 1);
145 expect_world_transform(hdc, 1.0, 1.0);
146 expect_LPtoDP(hdc, 1000, 1000);
147
148 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
149 xform.eM11 = 1.0f;
150 xform.eM12 = 2.0f;
151 xform.eM21 = 1.0f;
152 xform.eM22 = 2.0f;
153 xform.eDx = 0.0f;
154 xform.eDy = 0.0f;
155 ret = SetWorldTransform(hdc, &xform);
156 ok(!ret ||
157 broken(ret), /* NT4 */
158 "SetWorldTransform should fail with an invalid xform\n");
159
160 xform.eM11 = 20.0f;
161 xform.eM12 = 0.0f;
162 xform.eM21 = 0.0f;
163 xform.eM22 = 20.0f;
164 xform.eDx = 0.0f;
165 xform.eDy = 0.0f;
166 SetLastError(0xdeadbeef);
167 ret = SetWorldTransform(hdc, &xform);
168 ok(ret, "SetWorldTransform error %u\n", GetLastError());
169
170 expect_viewport_ext(hdc, 1, 1);
171 expect_window_ext(hdc, 1, 1);
172 expect_world_transform(hdc, 20.0, 20.0);
173 expect_LPtoDP(hdc, 20000, 20000);
174
175 SetLastError(0xdeadbeef);
176 ret = SetMapMode(hdc, MM_LOMETRIC);
177 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
178
179 expect_viewport_ext(hdc, res_x, -res_y);
180 ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
181 ok( rough_match( size.cx, size_cx * 10 ) ||
182 rough_match( size.cx, MulDiv( res_x, 254, dpi_x )), /* Vista uses a more precise method */
183 "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
184 ok( rough_match( size.cy, size_cy * 10 ) ||
185 rough_match( size.cy, MulDiv( res_y, 254, dpi_y )), /* Vista uses a more precise method */
186 "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
187 expect_world_transform(hdc, 20.0, 20.0);
188 expect_LPtoDP(hdc, MulDiv(20000, res_x, size.cx), -MulDiv(20000, res_y, size.cy));
189
190 SetLastError(0xdeadbeef);
191 ret = SetMapMode(hdc, MM_TEXT);
192 ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
193
194 expect_viewport_ext(hdc, 1, 1);
195 expect_window_ext(hdc, 1, 1);
196 expect_world_transform(hdc, 20.0, 20.0);
197 expect_LPtoDP(hdc, 20000, 20000);
198
199 size.cx = 0xdeadbeef;
200 size.cy = 0xdeadbeef;
201 ret = SetViewportExtEx(hdc, -1, -1, &size);
202 ok(ret, "SetViewportExtEx(-1, -1) failed\n");
203 ok(size.cx == 1 && size.cy == 1, "expected 1,1 got %d,%d\n", size.cx, size.cy);
204 expect_viewport_ext(hdc, 1, 1);
205 expect_window_ext(hdc, 1, 1);
206 expect_world_transform(hdc, 20.0, 20.0);
207 expect_LPtoDP(hdc, 20000, 20000);
208
209 ret = SetMapMode(hdc, MM_ANISOTROPIC);
210 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
211
212 expect_viewport_ext(hdc, 1, 1);
213 expect_window_ext(hdc, 1, 1);
214 expect_world_transform(hdc, 20.0, 20.0);
215 expect_LPtoDP(hdc, 20000, 20000);
216
217 size.cx = 0xdeadbeef;
218 size.cy = 0xdeadbeef;
219 ret = SetViewportExtEx(hdc, -1, -1, &size);
220 ok(ret, "SetViewportExtEx(-1, -1) failed\n");
221 ok(size.cx == 1 && size.cy == 1, "expected 1,1 got %d,%d\n", size.cx, size.cy);
222 expect_viewport_ext(hdc, -1, -1);
223 expect_window_ext(hdc, 1, 1);
224 expect_world_transform(hdc, 20.0, 20.0);
225 expect_LPtoDP(hdc, -20000, -20000);
226
227 ret = SetGraphicsMode(hdc, GM_COMPATIBLE);
228 ok(ret, "SetGraphicsMode(GM_COMPATIBLE) should not fail if DC has't an identity transform\n");
229 ret = GetGraphicsMode(hdc);
230 ok(ret == GM_COMPATIBLE, "expected GM_COMPATIBLE, got %d\n", ret);
231
232 expect_viewport_ext(hdc, -1, -1);
233 expect_window_ext(hdc, 1, 1);
234 expect_world_transform(hdc, 20.0, 20.0);
235 expect_LPtoDP(hdc, -20000, -20000);
236
237 DeleteDC(hdc);
238 }
239
240 static void test_dc_layout(void)
241 {
242 INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
243 SIZE size;
244 POINT pt;
245 HBITMAP bitmap;
246 RECT rc, ret_rc;
247 HDC hdc;
248 HRGN hrgn;
249
250 if (!pGetLayout || !pSetLayout)
251 {
252 win_skip( "Don't have SetLayout\n" );
253 return;
254 }
255
256 hdc = CreateCompatibleDC(0);
257 bitmap = CreateCompatibleBitmap( hdc, 100, 100 );
258 SelectObject( hdc, bitmap );
259
260 size_cx = GetDeviceCaps(hdc, HORZSIZE);
261 size_cy = GetDeviceCaps(hdc, VERTSIZE);
262 res_x = GetDeviceCaps(hdc, HORZRES);
263 res_y = GetDeviceCaps(hdc, VERTRES);
264 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
265 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
266
267 ret = GetMapMode( hdc );
268 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
269 expect_viewport_ext(hdc, 1, 1);
270 expect_window_ext(hdc, 1, 1);
271 expect_world_transform(hdc, 1.0, 1.0);
272 expect_LPtoDP(hdc, 1000, 1000);
273
274 pSetLayout( hdc, LAYOUT_RTL );
275 if (!pGetLayout( hdc ))
276 {
277 win_skip( "SetLayout not supported\n" );
278 DeleteDC(hdc);
279 return;
280 }
281
282 ret = GetMapMode( hdc );
283 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
284 expect_viewport_ext(hdc, 1, 1);
285 expect_window_ext(hdc, 1, 1);
286 expect_world_transform(hdc, 1.0, 1.0);
287 expect_LPtoDP(hdc, -1000 + 99, 1000);
288 GetViewportOrgEx( hdc, &pt );
289 ok( pt.x == 0 && pt.y == 0, "wrong origin %d,%d\n", pt.x, pt.y );
290 GetWindowOrgEx( hdc, &pt );
291 ok( pt.x == 0 && pt.y == 0, "wrong origin %d,%d\n", pt.x, pt.y );
292 GetDCOrgEx( hdc, &pt );
293 ok( pt.x == 0 && pt.y == 0, "wrong origin %d,%d\n", pt.x, pt.y );
294 if (pGetTransform)
295 {
296 XFORM xform;
297 BOOL ret = pGetTransform( hdc, 0x204, &xform ); /* World -> Device */
298 ok( ret, "got %d\n", ret );
299 ok( xform.eM11 == -1.0, "got %f\n", xform.eM11 );
300 ok( xform.eM12 == 0.0, "got %f\n", xform.eM12 );
301 ok( xform.eM21 == 0.0, "got %f\n", xform.eM21 );
302 ok( xform.eM22 == 1.0, "got %f\n", xform.eM22 );
303 ok( xform.eDx == 99.0, "got %f\n", xform.eDx );
304 ok( xform.eDy == 0.0, "got %f\n", xform.eDy );
305 }
306
307 SetRect( &rc, 10, 10, 20, 20 );
308 IntersectClipRect( hdc, 10, 10, 20, 20 );
309 hrgn = CreateRectRgn( 0, 0, 0, 0 );
310 GetClipRgn( hdc, hrgn );
311 GetRgnBox( hrgn, &ret_rc );
312 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
313 pSetLayout( hdc, LAYOUT_LTR );
314 SetRect( &rc, 80, 10, 90, 20 );
315 GetClipRgn( hdc, hrgn );
316 GetRgnBox( hrgn, &ret_rc );
317 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
318 GetClipBox( hdc, &ret_rc );
319 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
320 IntersectClipRect( hdc, 80, 10, 85, 20 );
321 pSetLayout( hdc, LAYOUT_RTL );
322 SetRect( &rc, 15, 10, 20, 20 );
323 GetClipRgn( hdc, hrgn );
324 GetRgnBox( hrgn, &ret_rc );
325 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
326 GetClipBox( hdc, &ret_rc );
327 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
328 SetRectRgn( hrgn, 60, 10, 80, 20 );
329 pSetLayout( hdc, LAYOUT_LTR );
330 ExtSelectClipRgn( hdc, hrgn, RGN_OR );
331 pSetLayout( hdc, LAYOUT_RTL );
332 SetRect( &rc, 15, 10, 40, 20 );
333 GetClipRgn( hdc, hrgn );
334 GetRgnBox( hrgn, &ret_rc );
335 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
336 GetClipBox( hdc, &ret_rc );
337 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
338
339 /* OffsetClipRgn mirrors too */
340 OffsetClipRgn( hdc, 5, 5 );
341 OffsetRect( &rc, 5, 5 );
342 GetClipRgn( hdc, hrgn );
343 GetRgnBox( hrgn, &ret_rc );
344 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
345
346 /* GetRandomRgn returns the raw region */
347 if (pGetRandomRgn)
348 {
349 SetRect( &rc, 55, 15, 80, 25 );
350 pGetRandomRgn( hdc, hrgn, 1 );
351 GetRgnBox( hrgn, &ret_rc );
352 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc ));
353 }
354
355 SetMapMode(hdc, MM_LOMETRIC);
356 ret = GetMapMode( hdc );
357 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
358
359 expect_viewport_ext(hdc, res_x, -res_y);
360 ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
361 ok( rough_match( size.cx, size_cx * 10 ) ||
362 rough_match( size.cx, MulDiv( res_x, 254, dpi_x )), /* Vista uses a more precise method */
363 "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
364 ok( rough_match( size.cy, size_cy * 10 ) ||
365 rough_match( size.cy, MulDiv( res_y, 254, dpi_y )), /* Vista uses a more precise method */
366 "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
367 expect_world_transform(hdc, 1.0, 1.0);
368 expect_LPtoDP(hdc, -MulDiv(1000 / 10, res_x, size_cx) + 99, -MulDiv(1000 / 10, res_y, size_cy));
369
370 SetMapMode(hdc, MM_TEXT);
371 ret = GetMapMode( hdc );
372 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
373 pSetLayout( hdc, LAYOUT_LTR );
374 ret = GetMapMode( hdc );
375 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
376 SetMapMode(hdc, MM_TEXT);
377 ret = GetMapMode( hdc );
378 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
379
380 DeleteDC(hdc);
381 DeleteObject( bitmap );
382 }
383
384 static void test_modify_world_transform(void)
385 {
386 HDC hdc = GetDC(0);
387 int ret;
388
389 ret = SetGraphicsMode(hdc, GM_ADVANCED);
390 ok(ret, "ret = %d\n", ret);
391
392 ret = ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
393 ok(ret, "ret = %d\n", ret);
394
395 ret = ModifyWorldTransform(hdc, NULL, MWT_LEFTMULTIPLY);
396 ok(!ret, "ret = %d\n", ret);
397
398 ret = ModifyWorldTransform(hdc, NULL, MWT_RIGHTMULTIPLY);
399 ok(!ret, "ret = %d\n", ret);
400
401 ReleaseDC(0, hdc);
402 }
403
404 static void test_SetWindowExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
405 {
406 SIZE windowExt, viewportExt;
407 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
408
409 GetWindowOrgEx(hdc, &windowOrg);
410 GetViewportOrgEx(hdc, &viewportOrg);
411
412 SetWindowExtEx(hdc, cx, cy, NULL);
413 GetWindowExtEx(hdc, &windowExt);
414 ok(windowExt.cx == cx && windowExt.cy == cy,
415 "Window extension: Expected %dx%d, got %dx%d\n",
416 cx, cy, windowExt.cx, windowExt.cy);
417
418 GetViewportExtEx(hdc, &viewportExt);
419 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
420 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
421 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
422
423 GetWindowOrgEx(hdc, &windowOrgAfter);
424 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
425 "Window origin changed from (%d,%d) to (%d,%d)\n",
426 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
427
428 GetViewportOrgEx(hdc, &viewportOrgAfter);
429 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
430 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
431 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
432 }
433
434 static void test_SetViewportExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
435 {
436 SIZE windowExt, windowExtAfter, viewportExt;
437 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
438
439 GetWindowOrgEx(hdc, &windowOrg);
440 GetViewportOrgEx(hdc, &viewportOrg);
441 GetWindowExtEx(hdc, &windowExt);
442
443 SetViewportExtEx(hdc, cx, cy, NULL);
444 GetViewportExtEx(hdc, &viewportExt);
445 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
446 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
447 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
448
449 GetWindowExtEx(hdc, &windowExtAfter);
450 ok(windowExt.cx == windowExtAfter.cx && windowExt.cy == windowExtAfter.cy,
451 "Window extension changed from %dx%d to %dx%d\n",
452 windowExt.cx, windowExt.cy, windowExtAfter.cx, windowExtAfter.cy);
453
454 GetWindowOrgEx(hdc, &windowOrgAfter);
455 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
456 "Window origin changed from (%d,%d) to (%d,%d)\n",
457 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
458
459 GetViewportOrgEx(hdc, &viewportOrgAfter);
460 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
461 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
462 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
463 }
464
465 static void test_isotropic_mapping(void)
466 {
467 SIZE win, vp;
468 HDC hdc = GetDC(0);
469
470 SetMapMode(hdc, MM_ISOTROPIC);
471
472 /* MM_ISOTROPIC is set up like MM_LOMETRIC.
473 Initial values after SetMapMode():
474 (1 inch = 25.4 mm)
475
476 Windows 9x: Windows NT:
477 Window Ext: 254 x -254 HORZSIZE*10 x VERTSIZE*10
478 Viewport Ext: LOGPIXELSX x LOGPIXELSY HORZRES x -VERTRES
479
480 To test without rounding errors, we have to use multiples of
481 these values!
482 */
483
484 GetWindowExtEx(hdc, &win);
485 GetViewportExtEx(hdc, &vp);
486
487 test_SetViewportExt(hdc, 10 * vp.cx, 10 * vp.cy, 10 * vp.cx, 10 * vp.cy);
488 test_SetWindowExt(hdc, win.cx, win.cy, 10 * vp.cx, 10 * vp.cy);
489 test_SetWindowExt(hdc, 2 * win.cx, win.cy, 10 * vp.cx, 5 * vp.cy);
490 test_SetWindowExt(hdc, win.cx, win.cy, 5 * vp.cx, 5 * vp.cy);
491 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
492 test_SetViewportExt(hdc, vp.cx, 2 * vp.cy, vp.cx, vp.cy);
493 test_SetViewportExt(hdc, 2 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
494 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
495 test_SetWindowExt(hdc, 4 * win.cx, 2 * win.cy, 2 * vp.cx, vp.cy);
496 test_SetViewportExt(hdc, -2 * vp.cx, -4 * vp.cy, -2 * vp.cx, -vp.cy);
497 test_SetViewportExt(hdc, -2 * vp.cx, -1 * vp.cy, -2 * vp.cx, -vp.cy);
498 test_SetWindowExt(hdc, -4 * win.cx, -2 * win.cy, -2 * vp.cx, -vp.cy);
499 test_SetWindowExt(hdc, 4 * win.cx, -4 * win.cy, -vp.cx, -vp.cy);
500
501 ReleaseDC(0, hdc);
502 }
503
504 static void test_setvirtualresolution(void)
505 {
506 HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
507 BOOL r;
508 INT horz_res = GetDeviceCaps(hdc, HORZRES);
509 INT horz_size = GetDeviceCaps(hdc, HORZSIZE);
510 INT log_pixels_x = GetDeviceCaps(hdc, LOGPIXELSX);
511 SIZE orig_lometric_vp, orig_lometric_wnd;
512
513 if(!pSetVirtualResolution)
514 {
515 win_skip("Don't have SetVirtualResolution\n");
516 return;
517 }
518
519 /* Get the true resolution limits */
520 SetMapMode(hdc, MM_LOMETRIC);
521 GetViewportExtEx(hdc, &orig_lometric_vp);
522 GetWindowExtEx(hdc, &orig_lometric_wnd);
523 SetMapMode(hdc, MM_TEXT);
524
525 r = pSetVirtualResolution(hdc, 4000, 1000, 400, 200); /* 10 pix/mm x 5 pix/mm */
526 ok(r == TRUE, "got %d\n", r);
527 expect_LPtoDP(hdc, 1000, 1000);
528 expect_viewport_ext(hdc, 1, 1);
529 expect_window_ext(hdc, 1, 1);
530
531 SetMapMode(hdc, MM_LOMETRIC);
532 expect_LPtoDP(hdc, 1000, -500);
533 expect_viewport_ext(hdc, 4000, -1000);
534 expect_window_ext(hdc, 4000, 2000);
535
536 /* Doesn't change the device caps */
537 ok(horz_res == GetDeviceCaps(hdc, HORZRES), "horz_res changed\n");
538 ok(horz_size == GetDeviceCaps(hdc, HORZSIZE), "horz_size changed\n");
539 ok(log_pixels_x == GetDeviceCaps(hdc, LOGPIXELSX), "log_pixels_x changed\n");
540
541 r = pSetVirtualResolution(hdc, 8000, 1000, 400, 200); /* 20 pix/mm x 5 pix/mm */
542 ok(r == TRUE, "got %d\n", r);
543 expect_LPtoDP(hdc, 1000, -500); /* No change, need to re-set the mapping mode */
544 SetMapMode(hdc, MM_TEXT);
545 SetMapMode(hdc, MM_LOMETRIC);
546 expect_LPtoDP(hdc, 2000, -500);
547 expect_viewport_ext(hdc, 8000, -1000);
548 expect_window_ext(hdc, 4000, 2000);
549
550 r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
551 ok(r == TRUE, "got %d\n", r);
552 SetMapMode(hdc, MM_TEXT);
553 SetMapMode(hdc, MM_LOMETRIC);
554 expect_LPtoDP(hdc, 4000, -500);
555 expect_viewport_ext(hdc, 8000, -1000);
556 expect_window_ext(hdc, 2000, 2000);
557
558 r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
559 ok(r == TRUE, "got %d\n", r);
560 SetMapMode(hdc, MM_TEXT);
561 SetMapMode(hdc, MM_LOMETRIC);
562 expect_LPtoDP(hdc, 4000, -500);
563 expect_viewport_ext(hdc, 8000, -1000);
564 expect_window_ext(hdc, 2000, 2000);
565
566 r = pSetVirtualResolution(hdc, 8000, 2000, 200, 200); /* 40 pix/mm x 10 pix/mm */
567 ok(r == TRUE, "got %d\n", r);
568 SetMapMode(hdc, MM_TEXT);
569 SetMapMode(hdc, MM_LOMETRIC);
570 expect_LPtoDP(hdc, 4000, -1000);
571 expect_viewport_ext(hdc, 8000, -2000);
572 expect_window_ext(hdc, 2000, 2000);
573
574 r = pSetVirtualResolution(hdc, 0, 0, 10, 0); /* Error */
575 ok(r == FALSE, "got %d\n", r);
576 SetMapMode(hdc, MM_TEXT);
577 SetMapMode(hdc, MM_LOMETRIC);
578 expect_LPtoDP(hdc, 4000, -1000);
579 expect_viewport_ext(hdc, 8000, -2000);
580 expect_window_ext(hdc, 2000, 2000);
581
582 r = pSetVirtualResolution(hdc, 0, 0, 0, 0); /* Reset to true resolution */
583 ok(r == TRUE, "got %d\n", r);
584 SetMapMode(hdc, MM_TEXT);
585 SetMapMode(hdc, MM_LOMETRIC);
586 expect_viewport_ext(hdc, orig_lometric_vp.cx, orig_lometric_vp.cy);
587 expect_window_ext(hdc, orig_lometric_wnd.cx, orig_lometric_wnd.cy);
588
589 DeleteDC(hdc);
590 }
591
592
593 static inline void expect_identity(int line, XFORM *xf)
594 {
595 ok(xf->eM11 == 1.0, "%d: got %f\n", line, xf->eM11);
596 ok(xf->eM12 == 0.0, "%d: got %f\n", line, xf->eM12);
597 ok(xf->eM21 == 0.0, "%d: got %f\n", line, xf->eM21);
598 ok(xf->eM22 == 1.0, "%d: got %f\n", line, xf->eM22);
599 ok(xf->eDx == 0.0, "%d: got %f\n", line, xf->eDx);
600 ok(xf->eDy == 0.0, "%d: got %f\n", line, xf->eDy);
601 }
602
603 static inline void xform_near_match(int line, XFORM *got, XFORM *expect)
604 {
605 ok(fabs(got->eM11 - expect->eM11) < 0.001, "%d: got %f expect %f\n", line, got->eM11, expect->eM11);
606 ok(fabs(got->eM12 - expect->eM12) < 0.001, "%d: got %f expect %f\n", line, got->eM12, expect->eM12);
607 ok(fabs(got->eM21 - expect->eM21) < 0.001, "%d: got %f expect %f\n", line, got->eM21, expect->eM21);
608 ok(fabs(got->eM22 - expect->eM22) < 0.001, "%d: got %f expect %f\n", line, got->eM22, expect->eM22);
609 ok(fabs(got->eDx - expect->eDx) < 0.001, "%d: got %f expect %f\n", line, got->eDx, expect->eDx);
610 ok(fabs(got->eDy - expect->eDy) < 0.001, "%d: got %f expect %f\n", line, got->eDy, expect->eDy);
611 }
612
613
614 static void test_gettransform(void)
615 {
616 HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
617 XFORM xform, expect;
618 BOOL r;
619 SIZE lometric_vp, lometric_wnd;
620
621 if(!pGetTransform)
622 {
623 win_skip("Don't have GetTransform\n");
624 return;
625 }
626
627 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
628 ok(r == TRUE, "got %d\n", r);
629 expect_identity(__LINE__, &xform);
630 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
631 ok(r == TRUE, "got %d\n", r);
632 expect_identity(__LINE__, &xform);
633 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
634 ok(r == TRUE, "got %d\n", r);
635 expect_identity(__LINE__, &xform);
636 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
637 ok(r == TRUE, "got %d\n", r);
638 expect_identity(__LINE__, &xform);
639
640 SetMapMode(hdc, MM_LOMETRIC);
641 GetViewportExtEx(hdc, &lometric_vp);
642 GetWindowExtEx(hdc, &lometric_wnd);
643
644 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
645 ok(r == TRUE, "got %d\n", r);
646 expect_identity(__LINE__, &xform);
647
648 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
649 ok(r == TRUE, "got %d\n", r);
650 expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
651 expect.eM12 = expect.eM21 = 0.0;
652 expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
653 expect.eDx = expect.eDy = 0.0;
654 xform_near_match(__LINE__, &xform, &expect);
655
656 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
657 ok(r == TRUE, "got %d\n", r);
658 xform_near_match(__LINE__, &xform, &expect);
659
660 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
661 ok(r == TRUE, "got %d\n", r);
662 expect.eM11 = (FLOAT) lometric_wnd.cx / lometric_vp.cx;
663 expect.eM22 = (FLOAT) lometric_wnd.cy / lometric_vp.cy;
664 xform_near_match(__LINE__, &xform, &expect);
665
666
667 SetGraphicsMode(hdc, GM_ADVANCED);
668
669 expect.eM11 = 10.0;
670 expect.eM22 = 20.0;
671 SetWorldTransform(hdc, &expect);
672 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
673 ok(r == TRUE, "got %d\n", r);
674 xform_near_match(__LINE__, &xform, &expect);
675
676 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
677 ok(r == TRUE, "got %d\n", r);
678 expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
679 expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
680 xform_near_match(__LINE__, &xform, &expect);
681
682 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
683 ok(r == TRUE, "got %d\n", r);
684 expect.eM11 *= 10.0;
685 expect.eM22 *= 20.0;
686 xform_near_match(__LINE__, &xform, &expect);
687
688 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
689 ok(r == TRUE, "got %d\n", r);
690 expect.eM11 = 1 / expect.eM11;
691 expect.eM22 = 1 / expect.eM22;
692 xform_near_match(__LINE__, &xform, &expect);
693
694 r = pGetTransform(hdc, 0x102, &xform);
695 ok(r == FALSE, "got %d\n", r);
696 r = pGetTransform(hdc, 0x103, &xform);
697 ok(r == FALSE, "got %d\n", r);
698 r = pGetTransform(hdc, 0x104, &xform);
699 ok(r == FALSE, "got %d\n", r);
700 r = pGetTransform(hdc, 0x202, &xform);
701 ok(r == FALSE, "got %d\n", r);
702 r = pGetTransform(hdc, 0x302, &xform);
703 ok(r == FALSE, "got %d\n", r);
704 r = pGetTransform(hdc, 0x303, &xform);
705 ok(r == FALSE, "got %d\n", r);
706 r = pGetTransform(hdc, 0x403, &xform);
707 ok(r == FALSE, "got %d\n", r);
708 r = pGetTransform(hdc, 0x404, &xform);
709 ok(r == FALSE, "got %d\n", r);
710 r = pGetTransform(hdc, 0xffff, &xform);
711 ok(r == FALSE, "got %d\n", r);
712 }
713
714 START_TEST(mapping)
715 {
716 HMODULE mod = GetModuleHandleA("gdi32.dll");
717 pGetLayout = (void *)GetProcAddress( mod, "GetLayout" );
718 pSetLayout = (void *)GetProcAddress( mod, "SetLayout" );
719 pGetRandomRgn = (void *)GetProcAddress( mod, "GetRandomRgn" );
720 pGetTransform = (void *)GetProcAddress( mod, "GetTransform" );
721 pSetVirtualResolution = (void *)GetProcAddress( mod, "SetVirtualResolution" );
722
723 test_modify_world_transform();
724 test_world_transform();
725 test_dc_layout();
726 test_isotropic_mapping();
727 test_setvirtualresolution();
728 test_gettransform();
729 }