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 #define rough_match(got, expected) (abs( MulDiv( (got) - (expected), 1000, (expected) )) <= 5)
34 #define expect_LPtoDP(_hdc, _x, _y) \
36 POINT _pt = { 1000, 1000 }; \
37 LPtoDP(_hdc, &_pt, 1); \
38 ok(rough_match(_pt.x, _x), "expected x %d, got %d\n", (_x), _pt.x); \
39 ok(rough_match(_pt.y, _y), "expected y %d, got %d\n", (_y), _pt.y); \
42 #define expect_world_transform(_hdc, _em11, _em22) \
46 SetLastError(0xdeadbeef); \
47 _ret = GetWorldTransform(_hdc, &_xform); \
48 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) \
50 ok(_ret, "GetWorldTransform error %u\n", GetLastError()); \
51 ok(_xform.eM11 == (_em11), "expected %f, got %f\n", (_em11), _xform.eM11); \
52 ok(_xform.eM12 == 0.0, "expected 0.0, got %f\n", _xform.eM12); \
53 ok(_xform.eM21 == 0.0, "expected 0.0, got %f\n", _xform.eM21); \
54 ok(_xform.eM22 == (_em22), "expected %f, got %f\n", (_em22), _xform.eM22); \
55 ok(_xform.eDx == 0.0, "expected 0.0, got %f\n", _xform.eDx); \
56 ok(_xform.eDy == 0.0, "expected 0.0, got %f\n", _xform.eDy); \
60 #define expect_dc_ext(_func, _hdc, _cx, _cy) \
64 SetLastError(0xdeadbeef); \
65 _ret = _func(_hdc, &_size); \
66 ok(_ret, #_func " error %u\n", GetLastError()); \
67 ok(_size.cx == (_cx), "expected cx %d, got %d\n", (_cx), _size.cx); \
68 ok(_size.cy == (_cy), "expected cy %d, got %d\n", (_cy), _size.cy); \
71 #define expect_viewport_ext(_hdc, _cx, _cy) expect_dc_ext(GetViewportExtEx, _hdc, _cx, _cy)
72 #define expect_window_ext(_hdc, _cx, _cy) expect_dc_ext(GetWindowExtEx, _hdc, _cx, _cy)
74 static void test_world_transform(void)
78 INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
82 SetLastError(0xdeadbeef);
83 GetWorldTransform(0, NULL);
84 is_win9x = GetLastError() == ERROR_CALL_NOT_IMPLEMENTED;
86 hdc = CreateCompatibleDC(0);
94 ret = SetWorldTransform(hdc, &xform);
95 ok(!ret, "SetWorldTransform should fail in GM_COMPATIBLE mode\n");
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 );
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);
111 SetLastError(0xdeadbeef);
112 ret = SetMapMode(hdc, MM_LOMETRIC);
113 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
117 expect_viewport_ext(hdc, dpi_x, dpi_y);
118 expect_window_ext(hdc, 254, -254);
122 expect_viewport_ext(hdc, res_x, -res_y);
123 ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
124 ok( rough_match( size.cx, size_cx * 10 ) ||
125 rough_match( size.cx, MulDiv( res_x, 254, dpi_x )), /* Vista uses a more precise method */
126 "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
127 ok( rough_match( size.cy, size_cy * 10 ) ||
128 rough_match( size.cy, MulDiv( res_y, 254, dpi_y )), /* Vista uses a more precise method */
129 "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
131 expect_world_transform(hdc, 1.0, 1.0);
132 expect_LPtoDP(hdc, MulDiv(1000 / 10, res_x, size_cx), -MulDiv(1000 / 10, res_y, size_cy));
134 SetLastError(0xdeadbeef);
135 ret = SetMapMode(hdc, MM_TEXT);
136 ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
138 expect_viewport_ext(hdc, 1, 1);
139 expect_window_ext(hdc, 1, 1);
140 expect_world_transform(hdc, 1.0, 1.0);
141 expect_LPtoDP(hdc, 1000, 1000);
143 ret = SetGraphicsMode(hdc, GM_ADVANCED);
147 skip("GM_ADVANCED is not supported on this platform\n");
151 expect_viewport_ext(hdc, 1, 1);
152 expect_window_ext(hdc, 1, 1);
153 expect_world_transform(hdc, 1.0, 1.0);
154 expect_LPtoDP(hdc, 1000, 1000);
156 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
163 ret = SetWorldTransform(hdc, &xform);
165 broken(ret), /* NT4 */
166 "SetWorldTransform should fail with an invalid xform\n");
174 SetLastError(0xdeadbeef);
175 ret = SetWorldTransform(hdc, &xform);
176 ok(ret, "SetWorldTransform error %u\n", GetLastError());
178 expect_viewport_ext(hdc, 1, 1);
179 expect_window_ext(hdc, 1, 1);
180 expect_world_transform(hdc, 20.0, 20.0);
181 expect_LPtoDP(hdc, 20000, 20000);
183 SetLastError(0xdeadbeef);
184 ret = SetMapMode(hdc, MM_LOMETRIC);
185 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
187 expect_viewport_ext(hdc, res_x, -res_y);
188 ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
189 ok( rough_match( size.cx, size_cx * 10 ) ||
190 rough_match( size.cx, MulDiv( res_x, 254, dpi_x )), /* Vista uses a more precise method */
191 "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
192 ok( rough_match( size.cy, size_cy * 10 ) ||
193 rough_match( size.cy, MulDiv( res_y, 254, dpi_y )), /* Vista uses a more precise method */
194 "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
195 expect_world_transform(hdc, 20.0, 20.0);
196 expect_LPtoDP(hdc, MulDiv(20000, res_x, size.cx), -MulDiv(20000, res_y, size.cy));
198 SetLastError(0xdeadbeef);
199 ret = SetMapMode(hdc, MM_TEXT);
200 ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);
202 expect_viewport_ext(hdc, 1, 1);
203 expect_window_ext(hdc, 1, 1);
204 expect_world_transform(hdc, 20.0, 20.0);
205 expect_LPtoDP(hdc, 20000, 20000);
207 ret = SetGraphicsMode(hdc, GM_COMPATIBLE);
208 ok(ret, "SetGraphicsMode(GM_COMPATIBLE) should not fail if DC has't an identity transform\n");
209 ret = GetGraphicsMode(hdc);
210 ok(ret == GM_COMPATIBLE, "expected GM_COMPATIBLE, got %d\n", ret);
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);
220 static void test_dc_layout(void)
222 INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
224 DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);
225 DWORD (WINAPI *pGetLayout)(HDC hdc);
228 pGetLayout = (void *)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GetLayout");
229 pSetLayout = (void *)GetProcAddress(GetModuleHandleA("gdi32.dll"), "SetLayout");
230 if (!pGetLayout || !pSetLayout)
232 win_skip( "Don't have SetLayout\n" );
236 hdc = CreateCompatibleDC(0);
238 size_cx = GetDeviceCaps(hdc, HORZSIZE);
239 size_cy = GetDeviceCaps(hdc, VERTSIZE);
240 res_x = GetDeviceCaps(hdc, HORZRES);
241 res_y = GetDeviceCaps(hdc, VERTRES);
242 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
243 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
245 ret = GetMapMode( hdc );
246 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
247 expect_viewport_ext(hdc, 1, 1);
248 expect_window_ext(hdc, 1, 1);
249 expect_world_transform(hdc, 1.0, 1.0);
250 expect_LPtoDP(hdc, 1000, 1000);
252 pSetLayout( hdc, LAYOUT_RTL );
253 if (!pGetLayout( hdc ))
255 win_skip( "SetLayout not supported\n" );
260 ret = GetMapMode( hdc );
261 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
262 expect_viewport_ext(hdc, 1, 1);
263 expect_window_ext(hdc, 1, 1);
264 expect_world_transform(hdc, 1.0, 1.0);
265 expect_LPtoDP(hdc, -1000, 1000);
267 SetMapMode(hdc, MM_LOMETRIC);
268 ret = GetMapMode( hdc );
269 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
271 expect_viewport_ext(hdc, res_x, -res_y);
272 ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
273 ok( rough_match( size.cx, size_cx * 10 ) ||
274 rough_match( size.cx, MulDiv( res_x, 254, dpi_x )), /* Vista uses a more precise method */
275 "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
276 ok( rough_match( size.cy, size_cy * 10 ) ||
277 rough_match( size.cy, MulDiv( res_y, 254, dpi_y )), /* Vista uses a more precise method */
278 "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
279 expect_world_transform(hdc, 1.0, 1.0);
280 expect_LPtoDP(hdc, -MulDiv(1000 / 10, res_x, size_cx), -MulDiv(1000 / 10, res_y, size_cy));
282 SetMapMode(hdc, MM_TEXT);
283 ret = GetMapMode( hdc );
284 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
285 pSetLayout( hdc, LAYOUT_LTR );
286 ret = GetMapMode( hdc );
287 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
288 SetMapMode(hdc, MM_TEXT);
289 ret = GetMapMode( hdc );
290 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
295 static void test_modify_world_transform(void)
300 ret = SetGraphicsMode(hdc, GM_ADVANCED);
301 if(!ret) /* running in win9x so quit */
304 skip("GM_ADVANCED is not supported on this platform\n");
308 ret = ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
309 ok(ret, "ret = %d\n", ret);
311 ret = ModifyWorldTransform(hdc, NULL, MWT_LEFTMULTIPLY);
312 ok(!ret, "ret = %d\n", ret);
314 ret = ModifyWorldTransform(hdc, NULL, MWT_RIGHTMULTIPLY);
315 ok(!ret, "ret = %d\n", ret);
320 static void test_SetWindowExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
322 SIZE windowExt, viewportExt;
323 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
325 GetWindowOrgEx(hdc, &windowOrg);
326 GetViewportOrgEx(hdc, &viewportOrg);
328 SetWindowExtEx(hdc, cx, cy, NULL);
329 GetWindowExtEx(hdc, &windowExt);
330 ok(windowExt.cx == cx && windowExt.cy == cy,
331 "Window extension: Expected %dx%d, got %dx%d\n",
332 cx, cy, windowExt.cx, windowExt.cy);
334 GetViewportExtEx(hdc, &viewportExt);
335 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
336 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
337 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
339 GetWindowOrgEx(hdc, &windowOrgAfter);
340 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
341 "Window origin changed from (%d,%d) to (%d,%d)\n",
342 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
344 GetViewportOrgEx(hdc, &viewportOrgAfter);
345 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
346 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
347 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
350 static void test_SetViewportExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
352 SIZE windowExt, windowExtAfter, viewportExt;
353 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
355 GetWindowOrgEx(hdc, &windowOrg);
356 GetViewportOrgEx(hdc, &viewportOrg);
357 GetWindowExtEx(hdc, &windowExt);
359 SetViewportExtEx(hdc, cx, cy, NULL);
360 GetViewportExtEx(hdc, &viewportExt);
361 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
362 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
363 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
365 GetWindowExtEx(hdc, &windowExtAfter);
366 ok(windowExt.cx == windowExtAfter.cx && windowExt.cy == windowExtAfter.cy,
367 "Window extension changed from %dx%d to %dx%d\n",
368 windowExt.cx, windowExt.cy, windowExtAfter.cx, windowExtAfter.cy);
370 GetWindowOrgEx(hdc, &windowOrgAfter);
371 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
372 "Window origin changed from (%d,%d) to (%d,%d)\n",
373 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
375 GetViewportOrgEx(hdc, &viewportOrgAfter);
376 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
377 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
378 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
381 static void test_isotropic_mapping(void)
386 SetMapMode(hdc, MM_ISOTROPIC);
388 /* MM_ISOTROPIC is set up like MM_LOMETRIC.
389 Initial values after SetMapMode():
392 Windows 9x: Windows NT:
393 Window Ext: 254 x -254 HORZSIZE*10 x VERTSIZE*10
394 Viewport Ext: LOGPIXELSX x LOGPIXELSY HORZRES x -VERTRES
396 To test without rounding errors, we have to use multiples of
400 GetWindowExtEx(hdc, &win);
401 GetViewportExtEx(hdc, &vp);
403 test_SetViewportExt(hdc, 10 * vp.cx, 10 * vp.cy, 10 * vp.cx, 10 * vp.cy);
404 test_SetWindowExt(hdc, win.cx, win.cy, 10 * vp.cx, 10 * vp.cy);
405 test_SetWindowExt(hdc, 2 * win.cx, win.cy, 10 * vp.cx, 5 * vp.cy);
406 test_SetWindowExt(hdc, win.cx, win.cy, 5 * vp.cx, 5 * vp.cy);
407 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
408 test_SetViewportExt(hdc, vp.cx, 2 * vp.cy, vp.cx, vp.cy);
409 test_SetViewportExt(hdc, 2 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
410 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
411 test_SetWindowExt(hdc, 4 * win.cx, 2 * win.cy, 2 * vp.cx, vp.cy);
412 test_SetViewportExt(hdc, -2 * vp.cx, -4 * vp.cy, -2 * vp.cx, -vp.cy);
413 test_SetViewportExt(hdc, -2 * vp.cx, -1 * vp.cy, -2 * vp.cx, -vp.cy);
414 test_SetWindowExt(hdc, -4 * win.cx, -2 * win.cy, -2 * vp.cx, -vp.cy);
415 test_SetWindowExt(hdc, 4 * win.cx, -4 * win.cy, -vp.cx, -vp.cy);
420 static void test_setvirtualresolution(void)
422 HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
424 DWORD (WINAPI *pSetVirtualResolution)(HDC, DWORD, DWORD, DWORD, DWORD);
425 INT horz_res = GetDeviceCaps(hdc, HORZRES);
426 INT horz_size = GetDeviceCaps(hdc, HORZSIZE);
427 INT log_pixels_x = GetDeviceCaps(hdc, LOGPIXELSX);
428 SIZE orig_lometric_vp, orig_lometric_wnd;
430 pSetVirtualResolution = (void *)GetProcAddress(GetModuleHandleA("gdi32.dll"), "SetVirtualResolution");
432 if(!pSetVirtualResolution)
434 win_skip("Don't have SetVirtualResolution\n");
438 /* Get the true resolution limits */
439 SetMapMode(hdc, MM_LOMETRIC);
440 GetViewportExtEx(hdc, &orig_lometric_vp);
441 GetWindowExtEx(hdc, &orig_lometric_wnd);
442 SetMapMode(hdc, MM_TEXT);
444 r = pSetVirtualResolution(hdc, 4000, 1000, 400, 200); /* 10 pix/mm x 5 pix/mm */
445 ok(r == TRUE, "got %d\n", r);
446 expect_LPtoDP(hdc, 1000, 1000);
447 expect_viewport_ext(hdc, 1, 1);
448 expect_window_ext(hdc, 1, 1);
450 SetMapMode(hdc, MM_LOMETRIC);
451 expect_LPtoDP(hdc, 1000, -500);
452 expect_viewport_ext(hdc, 4000, -1000);
453 expect_window_ext(hdc, 4000, 2000);
455 /* Doesn't change the device caps */
456 ok(horz_res == GetDeviceCaps(hdc, HORZRES), "horz_res changed\n");
457 ok(horz_size == GetDeviceCaps(hdc, HORZSIZE), "horz_size changed\n");
458 ok(log_pixels_x == GetDeviceCaps(hdc, LOGPIXELSX), "log_pixels_x changed\n");
460 r = pSetVirtualResolution(hdc, 8000, 1000, 400, 200); /* 20 pix/mm x 5 pix/mm */
461 ok(r == TRUE, "got %d\n", r);
462 expect_LPtoDP(hdc, 1000, -500); /* No change, need to re-set the mapping mode */
463 SetMapMode(hdc, MM_TEXT);
464 SetMapMode(hdc, MM_LOMETRIC);
465 expect_LPtoDP(hdc, 2000, -500);
466 expect_viewport_ext(hdc, 8000, -1000);
467 expect_window_ext(hdc, 4000, 2000);
469 r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
470 ok(r == TRUE, "got %d\n", r);
471 SetMapMode(hdc, MM_TEXT);
472 SetMapMode(hdc, MM_LOMETRIC);
473 expect_LPtoDP(hdc, 4000, -500);
474 expect_viewport_ext(hdc, 8000, -1000);
475 expect_window_ext(hdc, 2000, 2000);
477 r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
478 ok(r == TRUE, "got %d\n", r);
479 SetMapMode(hdc, MM_TEXT);
480 SetMapMode(hdc, MM_LOMETRIC);
481 expect_LPtoDP(hdc, 4000, -500);
482 expect_viewport_ext(hdc, 8000, -1000);
483 expect_window_ext(hdc, 2000, 2000);
485 r = pSetVirtualResolution(hdc, 8000, 2000, 200, 200); /* 40 pix/mm x 10 pix/mm */
486 ok(r == TRUE, "got %d\n", r);
487 SetMapMode(hdc, MM_TEXT);
488 SetMapMode(hdc, MM_LOMETRIC);
489 expect_LPtoDP(hdc, 4000, -1000);
490 expect_viewport_ext(hdc, 8000, -2000);
491 expect_window_ext(hdc, 2000, 2000);
493 r = pSetVirtualResolution(hdc, 0, 0, 10, 0); /* Error */
494 ok(r == FALSE, "got %d\n", r);
495 SetMapMode(hdc, MM_TEXT);
496 SetMapMode(hdc, MM_LOMETRIC);
497 expect_LPtoDP(hdc, 4000, -1000);
498 expect_viewport_ext(hdc, 8000, -2000);
499 expect_window_ext(hdc, 2000, 2000);
501 r = pSetVirtualResolution(hdc, 0, 0, 0, 0); /* Reset to true resolution */
502 ok(r == TRUE, "got %d\n", r);
503 SetMapMode(hdc, MM_TEXT);
504 SetMapMode(hdc, MM_LOMETRIC);
505 expect_viewport_ext(hdc, orig_lometric_vp.cx, orig_lometric_vp.cy);
506 expect_window_ext(hdc, orig_lometric_wnd.cx, orig_lometric_wnd.cy);
512 static inline void expect_identity(int line, XFORM *xf)
514 ok(xf->eM11 == 1.0, "%d: got %f\n", line, xf->eM11);
515 ok(xf->eM12 == 0.0, "%d: got %f\n", line, xf->eM12);
516 ok(xf->eM21 == 0.0, "%d: got %f\n", line, xf->eM21);
517 ok(xf->eM22 == 1.0, "%d: got %f\n", line, xf->eM22);
518 ok(xf->eDx == 0.0, "%d: got %f\n", line, xf->eDx);
519 ok(xf->eDy == 0.0, "%d: got %f\n", line, xf->eDy);
522 static inline void xform_near_match(int line, XFORM *got, XFORM *expect)
524 ok(fabs(got->eM11 - expect->eM11) < 0.001, "%d: got %f expect %f\n", line, got->eM11, expect->eM11);
525 ok(fabs(got->eM12 - expect->eM12) < 0.001, "%d: got %f expect %f\n", line, got->eM12, expect->eM12);
526 ok(fabs(got->eM21 - expect->eM21) < 0.001, "%d: got %f expect %f\n", line, got->eM21, expect->eM21);
527 ok(fabs(got->eM22 - expect->eM22) < 0.001, "%d: got %f expect %f\n", line, got->eM22, expect->eM22);
528 ok(fabs(got->eDx - expect->eDx) < 0.001, "%d: got %f expect %f\n", line, got->eDx, expect->eDx);
529 ok(fabs(got->eDy - expect->eDy) < 0.001, "%d: got %f expect %f\n", line, got->eDy, expect->eDy);
533 static void test_gettransform(void)
535 HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
536 BOOL (WINAPI *pGetTransform)(HDC, DWORD, XFORM *);
539 SIZE lometric_vp, lometric_wnd;
541 pGetTransform = (void *)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GetTransform");
545 win_skip("Don't have GetTransform\n");
549 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
550 ok(r == TRUE, "got %d\n", r);
551 expect_identity(__LINE__, &xform);
552 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
553 ok(r == TRUE, "got %d\n", r);
554 expect_identity(__LINE__, &xform);
555 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
556 ok(r == TRUE, "got %d\n", r);
557 expect_identity(__LINE__, &xform);
558 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
559 ok(r == TRUE, "got %d\n", r);
560 expect_identity(__LINE__, &xform);
562 SetMapMode(hdc, MM_LOMETRIC);
563 GetViewportExtEx(hdc, &lometric_vp);
564 GetWindowExtEx(hdc, &lometric_wnd);
566 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
567 ok(r == TRUE, "got %d\n", r);
568 expect_identity(__LINE__, &xform);
570 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
571 ok(r == TRUE, "got %d\n", r);
572 expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
573 expect.eM12 = expect.eM21 = 0.0;
574 expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
575 expect.eDx = expect.eDy = 0.0;
576 xform_near_match(__LINE__, &xform, &expect);
578 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
579 ok(r == TRUE, "got %d\n", r);
580 xform_near_match(__LINE__, &xform, &expect);
582 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
583 ok(r == TRUE, "got %d\n", r);
584 expect.eM11 = (FLOAT) lometric_wnd.cx / lometric_vp.cx;
585 expect.eM22 = (FLOAT) lometric_wnd.cy / lometric_vp.cy;
586 xform_near_match(__LINE__, &xform, &expect);
589 SetGraphicsMode(hdc, GM_ADVANCED);
593 SetWorldTransform(hdc, &expect);
594 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
595 ok(r == TRUE, "got %d\n", r);
596 xform_near_match(__LINE__, &xform, &expect);
598 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
599 ok(r == TRUE, "got %d\n", r);
600 expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
601 expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
602 xform_near_match(__LINE__, &xform, &expect);
604 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
605 ok(r == TRUE, "got %d\n", r);
608 xform_near_match(__LINE__, &xform, &expect);
610 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
611 ok(r == TRUE, "got %d\n", r);
612 expect.eM11 = 1 / expect.eM11;
613 expect.eM22 = 1 / expect.eM22;
614 xform_near_match(__LINE__, &xform, &expect);
616 r = pGetTransform(hdc, 0x102, &xform);
617 ok(r == FALSE, "got %d\n", r);
618 r = pGetTransform(hdc, 0x103, &xform);
619 ok(r == FALSE, "got %d\n", r);
620 r = pGetTransform(hdc, 0x104, &xform);
621 ok(r == FALSE, "got %d\n", r);
622 r = pGetTransform(hdc, 0x202, &xform);
623 ok(r == FALSE, "got %d\n", r);
624 r = pGetTransform(hdc, 0x302, &xform);
625 ok(r == FALSE, "got %d\n", r);
626 r = pGetTransform(hdc, 0x303, &xform);
627 ok(r == FALSE, "got %d\n", r);
628 r = pGetTransform(hdc, 0x403, &xform);
629 ok(r == FALSE, "got %d\n", r);
630 r = pGetTransform(hdc, 0x404, &xform);
631 ok(r == FALSE, "got %d\n", r);
632 r = pGetTransform(hdc, 0xffff, &xform);
633 ok(r == FALSE, "got %d\n", r);
638 test_modify_world_transform();
639 test_world_transform();
641 test_isotropic_mapping();
642 test_setvirtualresolution();