2 * Unit tests for mapping functions
4 * Copyright (c) 2005 Huw Davies
5 * Copyright (c) 2008 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
26 #include "wine/test.h"
32 static DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);
33 static DWORD (WINAPI *pGetLayout)(HDC hdc);
34 static INT (WINAPI *pGetRandomRgn)(HDC hDC, HRGN hRgn, INT iCode);
35 static BOOL (WINAPI *pGetTransform)(HDC, DWORD, XFORM *);
36 static DWORD (WINAPI *pSetVirtualResolution)(HDC, DWORD, DWORD, DWORD, DWORD);
38 #define rough_match(got, expected) (abs( MulDiv( (got) - (expected), 1000, (expected) )) <= 5)
40 #define expect_LPtoDP(_hdc, _x, _y) \
42 POINT _pt = { 1000, 1000 }; \
43 LPtoDP(_hdc, &_pt, 1); \
44 ok(rough_match(_pt.x, _x), "expected x %d, got %d\n", (_x), _pt.x); \
45 ok(rough_match(_pt.y, _y), "expected y %d, got %d\n", (_y), _pt.y); \
48 #define expect_world_transform(_hdc, _em11, _em22) \
52 SetLastError(0xdeadbeef); \
53 _ret = GetWorldTransform(_hdc, &_xform); \
54 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) \
56 ok(_ret, "GetWorldTransform error %u\n", GetLastError()); \
57 ok(_xform.eM11 == (_em11), "expected %f, got %f\n", (_em11), _xform.eM11); \
58 ok(_xform.eM12 == 0.0, "expected 0.0, got %f\n", _xform.eM12); \
59 ok(_xform.eM21 == 0.0, "expected 0.0, got %f\n", _xform.eM21); \
60 ok(_xform.eM22 == (_em22), "expected %f, got %f\n", (_em22), _xform.eM22); \
61 ok(_xform.eDx == 0.0, "expected 0.0, got %f\n", _xform.eDx); \
62 ok(_xform.eDy == 0.0, "expected 0.0, got %f\n", _xform.eDy); \
66 #define expect_dc_ext(_func, _hdc, _cx, _cy) \
70 SetLastError(0xdeadbeef); \
71 _ret = _func(_hdc, &_size); \
72 ok(_ret, #_func " error %u\n", GetLastError()); \
73 ok(_size.cx == (_cx), "expected cx %d, got %d\n", (_cx), _size.cx); \
74 ok(_size.cy == (_cy), "expected cy %d, got %d\n", (_cy), _size.cy); \
77 #define expect_viewport_ext(_hdc, _cx, _cy) expect_dc_ext(GetViewportExtEx, _hdc, _cx, _cy)
78 #define expect_window_ext(_hdc, _cx, _cy) expect_dc_ext(GetWindowExtEx, _hdc, _cx, _cy)
80 static void test_world_transform(void)
83 INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
87 hdc = CreateCompatibleDC(0);
95 ret = SetWorldTransform(hdc, &xform);
96 ok(!ret, "SetWorldTransform should fail in GM_COMPATIBLE mode\n");
98 size_cx = GetDeviceCaps(hdc, HORZSIZE);
99 size_cy = GetDeviceCaps(hdc, VERTSIZE);
100 res_x = GetDeviceCaps(hdc, HORZRES);
101 res_y = GetDeviceCaps(hdc, VERTRES);
102 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
103 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
104 trace("dc size %d x %d, resolution %d x %d dpi %d x %d\n",
105 size_cx, size_cy, res_x, res_y, dpi_x, dpi_y );
107 expect_viewport_ext(hdc, 1, 1);
108 expect_window_ext(hdc, 1, 1);
109 expect_world_transform(hdc, 1.0, 1.0);
110 expect_LPtoDP(hdc, 1000, 1000);
112 SetLastError(0xdeadbeef);
113 ret = SetMapMode(hdc, MM_LOMETRIC);
114 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
116 expect_viewport_ext(hdc, res_x, -res_y);
117 ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
118 ok( rough_match( size.cx, size_cx * 10 ) ||
119 rough_match( size.cx, MulDiv( res_x, 254, dpi_x )), /* Vista uses a more precise method */
120 "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
121 ok( rough_match( size.cy, size_cy * 10 ) ||
122 rough_match( size.cy, MulDiv( res_y, 254, dpi_y )), /* Vista uses a more precise method */
123 "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
124 expect_world_transform(hdc, 1.0, 1.0);
125 expect_LPtoDP(hdc, MulDiv(1000 / 10, res_x, size_cx), -MulDiv(1000 / 10, res_y, size_cy));
127 SetLastError(0xdeadbeef);
128 ret = SetMapMode(hdc, MM_TEXT);
129 ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
131 expect_viewport_ext(hdc, 1, 1);
132 expect_window_ext(hdc, 1, 1);
133 expect_world_transform(hdc, 1.0, 1.0);
134 expect_LPtoDP(hdc, 1000, 1000);
136 ret = SetGraphicsMode(hdc, GM_ADVANCED);
140 skip("GM_ADVANCED is not supported on this platform\n");
144 expect_viewport_ext(hdc, 1, 1);
145 expect_window_ext(hdc, 1, 1);
146 expect_world_transform(hdc, 1.0, 1.0);
147 expect_LPtoDP(hdc, 1000, 1000);
149 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
156 ret = SetWorldTransform(hdc, &xform);
158 broken(ret), /* NT4 */
159 "SetWorldTransform should fail with an invalid xform\n");
167 SetLastError(0xdeadbeef);
168 ret = SetWorldTransform(hdc, &xform);
169 ok(ret, "SetWorldTransform error %u\n", GetLastError());
171 expect_viewport_ext(hdc, 1, 1);
172 expect_window_ext(hdc, 1, 1);
173 expect_world_transform(hdc, 20.0, 20.0);
174 expect_LPtoDP(hdc, 20000, 20000);
176 SetLastError(0xdeadbeef);
177 ret = SetMapMode(hdc, MM_LOMETRIC);
178 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
180 expect_viewport_ext(hdc, res_x, -res_y);
181 ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
182 ok( rough_match( size.cx, size_cx * 10 ) ||
183 rough_match( size.cx, MulDiv( res_x, 254, dpi_x )), /* Vista uses a more precise method */
184 "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
185 ok( rough_match( size.cy, size_cy * 10 ) ||
186 rough_match( size.cy, MulDiv( res_y, 254, dpi_y )), /* Vista uses a more precise method */
187 "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
188 expect_world_transform(hdc, 20.0, 20.0);
189 expect_LPtoDP(hdc, MulDiv(20000, res_x, size.cx), -MulDiv(20000, res_y, size.cy));
191 SetLastError(0xdeadbeef);
192 ret = SetMapMode(hdc, MM_TEXT);
193 ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
195 expect_viewport_ext(hdc, 1, 1);
196 expect_window_ext(hdc, 1, 1);
197 expect_world_transform(hdc, 20.0, 20.0);
198 expect_LPtoDP(hdc, 20000, 20000);
200 size.cx = 0xdeadbeef;
201 size.cy = 0xdeadbeef;
202 ret = SetViewportExtEx(hdc, -1, -1, &size);
203 ok(ret, "SetViewportExtEx(-1, -1) failed\n");
204 ok(size.cx == 1 && size.cy == 1, "expected 1,1 got %d,%d\n", size.cx, size.cy);
205 expect_viewport_ext(hdc, 1, 1);
206 expect_window_ext(hdc, 1, 1);
207 expect_world_transform(hdc, 20.0, 20.0);
208 expect_LPtoDP(hdc, 20000, 20000);
210 ret = SetMapMode(hdc, MM_ANISOTROPIC);
211 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
213 expect_viewport_ext(hdc, 1, 1);
214 expect_window_ext(hdc, 1, 1);
215 expect_world_transform(hdc, 20.0, 20.0);
216 expect_LPtoDP(hdc, 20000, 20000);
218 size.cx = 0xdeadbeef;
219 size.cy = 0xdeadbeef;
220 ret = SetViewportExtEx(hdc, -1, -1, &size);
221 ok(ret, "SetViewportExtEx(-1, -1) failed\n");
222 ok(size.cx == 1 && size.cy == 1, "expected 1,1 got %d,%d\n", size.cx, size.cy);
223 expect_viewport_ext(hdc, -1, -1);
224 expect_window_ext(hdc, 1, 1);
225 expect_world_transform(hdc, 20.0, 20.0);
226 expect_LPtoDP(hdc, -20000, -20000);
228 ret = SetGraphicsMode(hdc, GM_COMPATIBLE);
229 ok(ret, "SetGraphicsMode(GM_COMPATIBLE) should not fail if DC has't an identity transform\n");
230 ret = GetGraphicsMode(hdc);
231 ok(ret == GM_COMPATIBLE, "expected GM_COMPATIBLE, got %d\n", ret);
233 expect_viewport_ext(hdc, -1, -1);
234 expect_window_ext(hdc, 1, 1);
235 expect_world_transform(hdc, 20.0, 20.0);
236 expect_LPtoDP(hdc, -20000, -20000);
241 static void test_dc_layout(void)
243 INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
251 if (!pGetLayout || !pSetLayout)
253 win_skip( "Don't have SetLayout\n" );
257 hdc = CreateCompatibleDC(0);
258 bitmap = CreateCompatibleBitmap( hdc, 100, 100 );
259 SelectObject( hdc, bitmap );
261 size_cx = GetDeviceCaps(hdc, HORZSIZE);
262 size_cy = GetDeviceCaps(hdc, VERTSIZE);
263 res_x = GetDeviceCaps(hdc, HORZRES);
264 res_y = GetDeviceCaps(hdc, VERTRES);
265 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
266 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
268 ret = GetMapMode( hdc );
269 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
270 expect_viewport_ext(hdc, 1, 1);
271 expect_window_ext(hdc, 1, 1);
272 expect_world_transform(hdc, 1.0, 1.0);
273 expect_LPtoDP(hdc, 1000, 1000);
275 pSetLayout( hdc, LAYOUT_RTL );
276 if (!pGetLayout( hdc ))
278 win_skip( "SetLayout not supported\n" );
283 ret = GetMapMode( hdc );
284 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
285 expect_viewport_ext(hdc, 1, 1);
286 expect_window_ext(hdc, 1, 1);
287 expect_world_transform(hdc, 1.0, 1.0);
288 expect_LPtoDP(hdc, -1000 + 99, 1000);
289 GetViewportOrgEx( hdc, &pt );
290 ok( pt.x == 0 && pt.y == 0, "wrong origin %d,%d\n", pt.x, pt.y );
291 GetWindowOrgEx( hdc, &pt );
292 ok( pt.x == 0 && pt.y == 0, "wrong origin %d,%d\n", pt.x, pt.y );
293 GetDCOrgEx( hdc, &pt );
294 ok( pt.x == 0 && pt.y == 0, "wrong origin %d,%d\n", pt.x, pt.y );
298 BOOL ret = pGetTransform( hdc, 0x204, &xform ); /* World -> Device */
299 ok( ret, "got %d\n", ret );
300 ok( xform.eM11 == -1.0, "got %f\n", xform.eM11 );
301 ok( xform.eM12 == 0.0, "got %f\n", xform.eM12 );
302 ok( xform.eM21 == 0.0, "got %f\n", xform.eM21 );
303 ok( xform.eM22 == 1.0, "got %f\n", xform.eM22 );
304 ok( xform.eDx == 99.0, "got %f\n", xform.eDx );
305 ok( xform.eDy == 0.0, "got %f\n", xform.eDy );
308 SetRect( &rc, 10, 10, 20, 20 );
309 IntersectClipRect( hdc, 10, 10, 20, 20 );
310 hrgn = CreateRectRgn( 0, 0, 0, 0 );
311 GetClipRgn( hdc, hrgn );
312 GetRgnBox( hrgn, &ret_rc );
313 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
314 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
315 pSetLayout( hdc, LAYOUT_LTR );
316 SetRect( &rc, 80, 10, 90, 20 );
317 GetClipRgn( hdc, hrgn );
318 GetRgnBox( hrgn, &ret_rc );
319 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
320 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
321 GetClipBox( hdc, &ret_rc );
322 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
323 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
324 IntersectClipRect( hdc, 80, 10, 85, 20 );
325 pSetLayout( hdc, LAYOUT_RTL );
326 SetRect( &rc, 15, 10, 20, 20 );
327 GetClipRgn( hdc, hrgn );
328 GetRgnBox( hrgn, &ret_rc );
329 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
330 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
331 GetClipBox( hdc, &ret_rc );
332 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
333 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
334 SetRectRgn( hrgn, 60, 10, 80, 20 );
335 pSetLayout( hdc, LAYOUT_LTR );
336 ExtSelectClipRgn( hdc, hrgn, RGN_OR );
337 pSetLayout( hdc, LAYOUT_RTL );
338 SetRect( &rc, 15, 10, 40, 20 );
339 GetClipRgn( hdc, hrgn );
340 GetRgnBox( hrgn, &ret_rc );
341 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
342 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
343 GetClipBox( hdc, &ret_rc );
344 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
345 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
347 /* OffsetClipRgn mirrors too */
348 OffsetClipRgn( hdc, 5, 5 );
349 OffsetRect( &rc, 5, 5 );
350 GetClipRgn( hdc, hrgn );
351 GetRgnBox( hrgn, &ret_rc );
352 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
353 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
355 /* GetRandomRgn returns the raw region */
358 SetRect( &rc, 55, 15, 80, 25 );
359 pGetRandomRgn( hdc, hrgn, 1 );
360 GetRgnBox( hrgn, &ret_rc );
361 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
362 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
365 SetMapMode(hdc, MM_LOMETRIC);
366 ret = GetMapMode( hdc );
367 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
369 expect_viewport_ext(hdc, res_x, -res_y);
370 ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
371 ok( rough_match( size.cx, size_cx * 10 ) ||
372 rough_match( size.cx, MulDiv( res_x, 254, dpi_x )), /* Vista uses a more precise method */
373 "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
374 ok( rough_match( size.cy, size_cy * 10 ) ||
375 rough_match( size.cy, MulDiv( res_y, 254, dpi_y )), /* Vista uses a more precise method */
376 "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
377 expect_world_transform(hdc, 1.0, 1.0);
378 expect_LPtoDP(hdc, -MulDiv(1000 / 10, res_x, size_cx) + 99, -MulDiv(1000 / 10, res_y, size_cy));
380 SetMapMode(hdc, MM_TEXT);
381 ret = GetMapMode( hdc );
382 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
383 pSetLayout( hdc, LAYOUT_LTR );
384 ret = GetMapMode( hdc );
385 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
386 SetMapMode(hdc, MM_TEXT);
387 ret = GetMapMode( hdc );
388 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
391 DeleteObject( bitmap );
394 static void test_modify_world_transform(void)
399 ret = SetGraphicsMode(hdc, GM_ADVANCED);
400 ok(ret, "ret = %d\n", ret);
402 ret = ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
403 ok(ret, "ret = %d\n", ret);
405 ret = ModifyWorldTransform(hdc, NULL, MWT_LEFTMULTIPLY);
406 ok(!ret, "ret = %d\n", ret);
408 ret = ModifyWorldTransform(hdc, NULL, MWT_RIGHTMULTIPLY);
409 ok(!ret, "ret = %d\n", ret);
414 static void test_SetWindowExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
416 SIZE windowExt, viewportExt;
417 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
419 GetWindowOrgEx(hdc, &windowOrg);
420 GetViewportOrgEx(hdc, &viewportOrg);
422 SetWindowExtEx(hdc, cx, cy, NULL);
423 GetWindowExtEx(hdc, &windowExt);
424 ok(windowExt.cx == cx && windowExt.cy == cy,
425 "Window extension: Expected %dx%d, got %dx%d\n",
426 cx, cy, windowExt.cx, windowExt.cy);
428 GetViewportExtEx(hdc, &viewportExt);
429 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
430 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
431 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
433 GetWindowOrgEx(hdc, &windowOrgAfter);
434 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
435 "Window origin changed from (%d,%d) to (%d,%d)\n",
436 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
438 GetViewportOrgEx(hdc, &viewportOrgAfter);
439 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
440 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
441 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
444 static void test_SetViewportExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
446 SIZE windowExt, windowExtAfter, viewportExt;
447 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
449 GetWindowOrgEx(hdc, &windowOrg);
450 GetViewportOrgEx(hdc, &viewportOrg);
451 GetWindowExtEx(hdc, &windowExt);
453 SetViewportExtEx(hdc, cx, cy, NULL);
454 GetViewportExtEx(hdc, &viewportExt);
455 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
456 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
457 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
459 GetWindowExtEx(hdc, &windowExtAfter);
460 ok(windowExt.cx == windowExtAfter.cx && windowExt.cy == windowExtAfter.cy,
461 "Window extension changed from %dx%d to %dx%d\n",
462 windowExt.cx, windowExt.cy, windowExtAfter.cx, windowExtAfter.cy);
464 GetWindowOrgEx(hdc, &windowOrgAfter);
465 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
466 "Window origin changed from (%d,%d) to (%d,%d)\n",
467 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
469 GetViewportOrgEx(hdc, &viewportOrgAfter);
470 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
471 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
472 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
475 static void test_isotropic_mapping(void)
480 SetMapMode(hdc, MM_ISOTROPIC);
482 /* MM_ISOTROPIC is set up like MM_LOMETRIC.
483 Initial values after SetMapMode():
486 Windows 9x: Windows NT:
487 Window Ext: 254 x -254 HORZSIZE*10 x VERTSIZE*10
488 Viewport Ext: LOGPIXELSX x LOGPIXELSY HORZRES x -VERTRES
490 To test without rounding errors, we have to use multiples of
494 GetWindowExtEx(hdc, &win);
495 GetViewportExtEx(hdc, &vp);
497 test_SetViewportExt(hdc, 10 * vp.cx, 10 * vp.cy, 10 * vp.cx, 10 * vp.cy);
498 test_SetWindowExt(hdc, win.cx, win.cy, 10 * vp.cx, 10 * vp.cy);
499 test_SetWindowExt(hdc, 2 * win.cx, win.cy, 10 * vp.cx, 5 * vp.cy);
500 test_SetWindowExt(hdc, win.cx, win.cy, 5 * vp.cx, 5 * vp.cy);
501 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
502 test_SetViewportExt(hdc, vp.cx, 2 * vp.cy, vp.cx, vp.cy);
503 test_SetViewportExt(hdc, 2 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
504 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
505 test_SetWindowExt(hdc, 4 * win.cx, 2 * win.cy, 2 * vp.cx, vp.cy);
506 test_SetViewportExt(hdc, -2 * vp.cx, -4 * vp.cy, -2 * vp.cx, -vp.cy);
507 test_SetViewportExt(hdc, -2 * vp.cx, -1 * vp.cy, -2 * vp.cx, -vp.cy);
508 test_SetWindowExt(hdc, -4 * win.cx, -2 * win.cy, -2 * vp.cx, -vp.cy);
509 test_SetWindowExt(hdc, 4 * win.cx, -4 * win.cy, -vp.cx, -vp.cy);
514 static void test_setvirtualresolution(void)
516 HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
518 INT horz_res = GetDeviceCaps(hdc, HORZRES);
519 INT horz_size = GetDeviceCaps(hdc, HORZSIZE);
520 INT log_pixels_x = GetDeviceCaps(hdc, LOGPIXELSX);
521 SIZE orig_lometric_vp, orig_lometric_wnd;
523 if(!pSetVirtualResolution)
525 win_skip("Don't have SetVirtualResolution\n");
529 /* Get the true resolution limits */
530 SetMapMode(hdc, MM_LOMETRIC);
531 GetViewportExtEx(hdc, &orig_lometric_vp);
532 GetWindowExtEx(hdc, &orig_lometric_wnd);
533 SetMapMode(hdc, MM_TEXT);
535 r = pSetVirtualResolution(hdc, 4000, 1000, 400, 200); /* 10 pix/mm x 5 pix/mm */
536 ok(r == TRUE, "got %d\n", r);
537 expect_LPtoDP(hdc, 1000, 1000);
538 expect_viewport_ext(hdc, 1, 1);
539 expect_window_ext(hdc, 1, 1);
541 SetMapMode(hdc, MM_LOMETRIC);
542 expect_LPtoDP(hdc, 1000, -500);
543 expect_viewport_ext(hdc, 4000, -1000);
544 expect_window_ext(hdc, 4000, 2000);
546 /* Doesn't change the device caps */
547 ok(horz_res == GetDeviceCaps(hdc, HORZRES), "horz_res changed\n");
548 ok(horz_size == GetDeviceCaps(hdc, HORZSIZE), "horz_size changed\n");
549 ok(log_pixels_x == GetDeviceCaps(hdc, LOGPIXELSX), "log_pixels_x changed\n");
551 r = pSetVirtualResolution(hdc, 8000, 1000, 400, 200); /* 20 pix/mm x 5 pix/mm */
552 ok(r == TRUE, "got %d\n", r);
553 expect_LPtoDP(hdc, 1000, -500); /* No change, need to re-set the mapping mode */
554 SetMapMode(hdc, MM_TEXT);
555 SetMapMode(hdc, MM_LOMETRIC);
556 expect_LPtoDP(hdc, 2000, -500);
557 expect_viewport_ext(hdc, 8000, -1000);
558 expect_window_ext(hdc, 4000, 2000);
560 r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
561 ok(r == TRUE, "got %d\n", r);
562 SetMapMode(hdc, MM_TEXT);
563 SetMapMode(hdc, MM_LOMETRIC);
564 expect_LPtoDP(hdc, 4000, -500);
565 expect_viewport_ext(hdc, 8000, -1000);
566 expect_window_ext(hdc, 2000, 2000);
568 r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
569 ok(r == TRUE, "got %d\n", r);
570 SetMapMode(hdc, MM_TEXT);
571 SetMapMode(hdc, MM_LOMETRIC);
572 expect_LPtoDP(hdc, 4000, -500);
573 expect_viewport_ext(hdc, 8000, -1000);
574 expect_window_ext(hdc, 2000, 2000);
576 r = pSetVirtualResolution(hdc, 8000, 2000, 200, 200); /* 40 pix/mm x 10 pix/mm */
577 ok(r == TRUE, "got %d\n", r);
578 SetMapMode(hdc, MM_TEXT);
579 SetMapMode(hdc, MM_LOMETRIC);
580 expect_LPtoDP(hdc, 4000, -1000);
581 expect_viewport_ext(hdc, 8000, -2000);
582 expect_window_ext(hdc, 2000, 2000);
584 r = pSetVirtualResolution(hdc, 0, 0, 10, 0); /* Error */
585 ok(r == FALSE, "got %d\n", r);
586 SetMapMode(hdc, MM_TEXT);
587 SetMapMode(hdc, MM_LOMETRIC);
588 expect_LPtoDP(hdc, 4000, -1000);
589 expect_viewport_ext(hdc, 8000, -2000);
590 expect_window_ext(hdc, 2000, 2000);
592 r = pSetVirtualResolution(hdc, 0, 0, 0, 0); /* Reset to true resolution */
593 ok(r == TRUE, "got %d\n", r);
594 SetMapMode(hdc, MM_TEXT);
595 SetMapMode(hdc, MM_LOMETRIC);
596 expect_viewport_ext(hdc, orig_lometric_vp.cx, orig_lometric_vp.cy);
597 expect_window_ext(hdc, orig_lometric_wnd.cx, orig_lometric_wnd.cy);
603 static inline void expect_identity(int line, XFORM *xf)
605 ok(xf->eM11 == 1.0, "%d: got %f\n", line, xf->eM11);
606 ok(xf->eM12 == 0.0, "%d: got %f\n", line, xf->eM12);
607 ok(xf->eM21 == 0.0, "%d: got %f\n", line, xf->eM21);
608 ok(xf->eM22 == 1.0, "%d: got %f\n", line, xf->eM22);
609 ok(xf->eDx == 0.0, "%d: got %f\n", line, xf->eDx);
610 ok(xf->eDy == 0.0, "%d: got %f\n", line, xf->eDy);
613 static inline void xform_near_match(int line, XFORM *got, XFORM *expect)
615 ok(fabs(got->eM11 - expect->eM11) < 0.001, "%d: got %f expect %f\n", line, got->eM11, expect->eM11);
616 ok(fabs(got->eM12 - expect->eM12) < 0.001, "%d: got %f expect %f\n", line, got->eM12, expect->eM12);
617 ok(fabs(got->eM21 - expect->eM21) < 0.001, "%d: got %f expect %f\n", line, got->eM21, expect->eM21);
618 ok(fabs(got->eM22 - expect->eM22) < 0.001, "%d: got %f expect %f\n", line, got->eM22, expect->eM22);
619 ok(fabs(got->eDx - expect->eDx) < 0.001, "%d: got %f expect %f\n", line, got->eDx, expect->eDx);
620 ok(fabs(got->eDy - expect->eDy) < 0.001, "%d: got %f expect %f\n", line, got->eDy, expect->eDy);
624 static void test_gettransform(void)
626 HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
629 SIZE lometric_vp, lometric_wnd;
633 win_skip("Don't have GetTransform\n");
637 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
638 ok(r == TRUE, "got %d\n", r);
639 expect_identity(__LINE__, &xform);
640 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
641 ok(r == TRUE, "got %d\n", r);
642 expect_identity(__LINE__, &xform);
643 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
644 ok(r == TRUE, "got %d\n", r);
645 expect_identity(__LINE__, &xform);
646 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
647 ok(r == TRUE, "got %d\n", r);
648 expect_identity(__LINE__, &xform);
650 SetMapMode(hdc, MM_LOMETRIC);
651 GetViewportExtEx(hdc, &lometric_vp);
652 GetWindowExtEx(hdc, &lometric_wnd);
654 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
655 ok(r == TRUE, "got %d\n", r);
656 expect_identity(__LINE__, &xform);
658 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
659 ok(r == TRUE, "got %d\n", r);
660 expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
661 expect.eM12 = expect.eM21 = 0.0;
662 expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
663 expect.eDx = expect.eDy = 0.0;
664 xform_near_match(__LINE__, &xform, &expect);
666 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
667 ok(r == TRUE, "got %d\n", r);
668 xform_near_match(__LINE__, &xform, &expect);
670 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
671 ok(r == TRUE, "got %d\n", r);
672 expect.eM11 = (FLOAT) lometric_wnd.cx / lometric_vp.cx;
673 expect.eM22 = (FLOAT) lometric_wnd.cy / lometric_vp.cy;
674 xform_near_match(__LINE__, &xform, &expect);
677 SetGraphicsMode(hdc, GM_ADVANCED);
681 SetWorldTransform(hdc, &expect);
682 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
683 ok(r == TRUE, "got %d\n", r);
684 xform_near_match(__LINE__, &xform, &expect);
686 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
687 ok(r == TRUE, "got %d\n", r);
688 expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
689 expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
690 xform_near_match(__LINE__, &xform, &expect);
692 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
693 ok(r == TRUE, "got %d\n", r);
696 xform_near_match(__LINE__, &xform, &expect);
698 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
699 ok(r == TRUE, "got %d\n", r);
700 expect.eM11 = 1 / expect.eM11;
701 expect.eM22 = 1 / expect.eM22;
702 xform_near_match(__LINE__, &xform, &expect);
704 r = pGetTransform(hdc, 0x102, &xform);
705 ok(r == FALSE, "got %d\n", r);
706 r = pGetTransform(hdc, 0x103, &xform);
707 ok(r == FALSE, "got %d\n", r);
708 r = pGetTransform(hdc, 0x104, &xform);
709 ok(r == FALSE, "got %d\n", r);
710 r = pGetTransform(hdc, 0x202, &xform);
711 ok(r == FALSE, "got %d\n", r);
712 r = pGetTransform(hdc, 0x302, &xform);
713 ok(r == FALSE, "got %d\n", r);
714 r = pGetTransform(hdc, 0x303, &xform);
715 ok(r == FALSE, "got %d\n", r);
716 r = pGetTransform(hdc, 0x403, &xform);
717 ok(r == FALSE, "got %d\n", r);
718 r = pGetTransform(hdc, 0x404, &xform);
719 ok(r == FALSE, "got %d\n", r);
720 r = pGetTransform(hdc, 0xffff, &xform);
721 ok(r == FALSE, "got %d\n", r);
726 HMODULE mod = GetModuleHandleA("gdi32.dll");
727 pGetLayout = (void *)GetProcAddress( mod, "GetLayout" );
728 pSetLayout = (void *)GetProcAddress( mod, "SetLayout" );
729 pGetRandomRgn = (void *)GetProcAddress( mod, "GetRandomRgn" );
730 pGetTransform = (void *)GetProcAddress( mod, "GetTransform" );
731 pSetVirtualResolution = (void *)GetProcAddress( mod, "SetVirtualResolution" );
733 test_modify_world_transform();
734 test_world_transform();
736 test_isotropic_mapping();
737 test_setvirtualresolution();