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 BOOL (WINAPI
*pGetTransform
)(HDC
, DWORD
, XFORM
*);
35 static DWORD (WINAPI
*pSetVirtualResolution
)(HDC
, DWORD
, DWORD
, DWORD
, DWORD
);
37 #define rough_match(got, expected) (abs( MulDiv( (got) - (expected), 1000, (expected) )) <= 5)
39 #define expect_LPtoDP(_hdc, _x, _y) \
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); \
47 #define expect_world_transform(_hdc, _em11, _em22) \
51 SetLastError(0xdeadbeef); \
52 _ret = GetWorldTransform(_hdc, &_xform); \
53 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) \
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); \
65 #define expect_dc_ext(_func, _hdc, _cx, _cy) \
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); \
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)
79 static void test_world_transform(void)
83 INT ret
, size_cx
, size_cy
, res_x
, res_y
, dpi_x
, dpi_y
;
87 SetLastError(0xdeadbeef);
88 GetWorldTransform(0, NULL
);
89 is_win9x
= GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
;
91 hdc
= CreateCompatibleDC(0);
99 ret
= SetWorldTransform(hdc
, &xform
);
100 ok(!ret
, "SetWorldTransform should fail in GM_COMPATIBLE mode\n");
102 size_cx
= GetDeviceCaps(hdc
, HORZSIZE
);
103 size_cy
= GetDeviceCaps(hdc
, VERTSIZE
);
104 res_x
= GetDeviceCaps(hdc
, HORZRES
);
105 res_y
= GetDeviceCaps(hdc
, VERTRES
);
106 dpi_x
= GetDeviceCaps(hdc
, LOGPIXELSX
);
107 dpi_y
= GetDeviceCaps(hdc
, LOGPIXELSY
);
108 trace("dc size %d x %d, resolution %d x %d dpi %d x %d\n",
109 size_cx
, size_cy
, res_x
, res_y
, dpi_x
, dpi_y
);
111 expect_viewport_ext(hdc
, 1, 1);
112 expect_window_ext(hdc
, 1, 1);
113 expect_world_transform(hdc
, 1.0, 1.0);
114 expect_LPtoDP(hdc
, 1000, 1000);
116 SetLastError(0xdeadbeef);
117 ret
= SetMapMode(hdc
, MM_LOMETRIC
);
118 ok(ret
== MM_TEXT
, "expected MM_TEXT, got %d\n", ret
);
122 expect_viewport_ext(hdc
, dpi_x
, dpi_y
);
123 expect_window_ext(hdc
, 254, -254);
127 expect_viewport_ext(hdc
, res_x
, -res_y
);
128 ok( GetWindowExtEx( hdc
, &size
), "GetWindowExtEx failed\n" );
129 ok( rough_match( size
.cx
, size_cx
* 10 ) ||
130 rough_match( size
.cx
, MulDiv( res_x
, 254, dpi_x
)), /* Vista uses a more precise method */
131 "expected cx %d or %d, got %d\n", size_cx
* 10, MulDiv( res_x
, 254, dpi_x
), size
.cx
);
132 ok( rough_match( size
.cy
, size_cy
* 10 ) ||
133 rough_match( size
.cy
, MulDiv( res_y
, 254, dpi_y
)), /* Vista uses a more precise method */
134 "expected cy %d or %d, got %d\n", size_cy
* 10, MulDiv( res_y
, 254, dpi_y
), size
.cy
);
136 expect_world_transform(hdc
, 1.0, 1.0);
137 expect_LPtoDP(hdc
, MulDiv(1000 / 10, res_x
, size_cx
), -MulDiv(1000 / 10, res_y
, size_cy
));
139 SetLastError(0xdeadbeef);
140 ret
= SetMapMode(hdc
, MM_TEXT
);
141 ok(ret
== MM_LOMETRIC
, "expected MM_LOMETRIC, got %d\n", ret
);
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);
148 ret
= SetGraphicsMode(hdc
, GM_ADVANCED
);
152 skip("GM_ADVANCED is not supported on this platform\n");
156 expect_viewport_ext(hdc
, 1, 1);
157 expect_window_ext(hdc
, 1, 1);
158 expect_world_transform(hdc
, 1.0, 1.0);
159 expect_LPtoDP(hdc
, 1000, 1000);
161 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
168 ret
= SetWorldTransform(hdc
, &xform
);
170 broken(ret
), /* NT4 */
171 "SetWorldTransform should fail with an invalid xform\n");
179 SetLastError(0xdeadbeef);
180 ret
= SetWorldTransform(hdc
, &xform
);
181 ok(ret
, "SetWorldTransform error %u\n", GetLastError());
183 expect_viewport_ext(hdc
, 1, 1);
184 expect_window_ext(hdc
, 1, 1);
185 expect_world_transform(hdc
, 20.0, 20.0);
186 expect_LPtoDP(hdc
, 20000, 20000);
188 SetLastError(0xdeadbeef);
189 ret
= SetMapMode(hdc
, MM_LOMETRIC
);
190 ok(ret
== MM_TEXT
, "expected MM_TEXT, got %d\n", ret
);
192 expect_viewport_ext(hdc
, res_x
, -res_y
);
193 ok( GetWindowExtEx( hdc
, &size
), "GetWindowExtEx failed\n" );
194 ok( rough_match( size
.cx
, size_cx
* 10 ) ||
195 rough_match( size
.cx
, MulDiv( res_x
, 254, dpi_x
)), /* Vista uses a more precise method */
196 "expected cx %d or %d, got %d\n", size_cx
* 10, MulDiv( res_x
, 254, dpi_x
), size
.cx
);
197 ok( rough_match( size
.cy
, size_cy
* 10 ) ||
198 rough_match( size
.cy
, MulDiv( res_y
, 254, dpi_y
)), /* Vista uses a more precise method */
199 "expected cy %d or %d, got %d\n", size_cy
* 10, MulDiv( res_y
, 254, dpi_y
), size
.cy
);
200 expect_world_transform(hdc
, 20.0, 20.0);
201 expect_LPtoDP(hdc
, MulDiv(20000, res_x
, size
.cx
), -MulDiv(20000, res_y
, size
.cy
));
203 SetLastError(0xdeadbeef);
204 ret
= SetMapMode(hdc
, MM_TEXT
);
205 ok(ret
== MM_LOMETRIC
, "expected MM_LOMETRIC, got %d\n", ret
);
207 expect_viewport_ext(hdc
, 1, 1);
208 expect_window_ext(hdc
, 1, 1);
209 expect_world_transform(hdc
, 20.0, 20.0);
210 expect_LPtoDP(hdc
, 20000, 20000);
212 ret
= SetGraphicsMode(hdc
, GM_COMPATIBLE
);
213 ok(ret
, "SetGraphicsMode(GM_COMPATIBLE) should not fail if DC has't an identity transform\n");
214 ret
= GetGraphicsMode(hdc
);
215 ok(ret
== GM_COMPATIBLE
, "expected GM_COMPATIBLE, got %d\n", ret
);
217 expect_viewport_ext(hdc
, 1, 1);
218 expect_window_ext(hdc
, 1, 1);
219 expect_world_transform(hdc
, 20.0, 20.0);
220 expect_LPtoDP(hdc
, 20000, 20000);
225 static void test_dc_layout(void)
227 INT ret
, size_cx
, size_cy
, res_x
, res_y
, dpi_x
, dpi_y
;
231 if (!pGetLayout
|| !pSetLayout
)
233 win_skip( "Don't have SetLayout\n" );
237 hdc
= CreateCompatibleDC(0);
239 size_cx
= GetDeviceCaps(hdc
, HORZSIZE
);
240 size_cy
= GetDeviceCaps(hdc
, VERTSIZE
);
241 res_x
= GetDeviceCaps(hdc
, HORZRES
);
242 res_y
= GetDeviceCaps(hdc
, VERTRES
);
243 dpi_x
= GetDeviceCaps(hdc
, LOGPIXELSX
);
244 dpi_y
= GetDeviceCaps(hdc
, LOGPIXELSY
);
246 ret
= GetMapMode( hdc
);
247 ok(ret
== MM_TEXT
, "expected MM_TEXT, got %d\n", ret
);
248 expect_viewport_ext(hdc
, 1, 1);
249 expect_window_ext(hdc
, 1, 1);
250 expect_world_transform(hdc
, 1.0, 1.0);
251 expect_LPtoDP(hdc
, 1000, 1000);
253 pSetLayout( hdc
, LAYOUT_RTL
);
254 if (!pGetLayout( hdc
))
256 win_skip( "SetLayout not supported\n" );
261 ret
= GetMapMode( hdc
);
262 ok(ret
== MM_ANISOTROPIC
, "expected MM_ANISOTROPIC, got %d\n", ret
);
263 expect_viewport_ext(hdc
, 1, 1);
264 expect_window_ext(hdc
, 1, 1);
265 expect_world_transform(hdc
, 1.0, 1.0);
266 expect_LPtoDP(hdc
, -1000, 1000);
268 SetMapMode(hdc
, MM_LOMETRIC
);
269 ret
= GetMapMode( hdc
);
270 ok(ret
== MM_ANISOTROPIC
, "expected MM_ANISOTROPIC, got %d\n", ret
);
272 expect_viewport_ext(hdc
, res_x
, -res_y
);
273 ok( GetWindowExtEx( hdc
, &size
), "GetWindowExtEx failed\n" );
274 ok( rough_match( size
.cx
, size_cx
* 10 ) ||
275 rough_match( size
.cx
, MulDiv( res_x
, 254, dpi_x
)), /* Vista uses a more precise method */
276 "expected cx %d or %d, got %d\n", size_cx
* 10, MulDiv( res_x
, 254, dpi_x
), size
.cx
);
277 ok( rough_match( size
.cy
, size_cy
* 10 ) ||
278 rough_match( size
.cy
, MulDiv( res_y
, 254, dpi_y
)), /* Vista uses a more precise method */
279 "expected cy %d or %d, got %d\n", size_cy
* 10, MulDiv( res_y
, 254, dpi_y
), size
.cy
);
280 expect_world_transform(hdc
, 1.0, 1.0);
281 expect_LPtoDP(hdc
, -MulDiv(1000 / 10, res_x
, size_cx
), -MulDiv(1000 / 10, res_y
, size_cy
));
283 SetMapMode(hdc
, MM_TEXT
);
284 ret
= GetMapMode( hdc
);
285 ok(ret
== MM_ANISOTROPIC
, "expected MM_ANISOTROPIC, got %d\n", ret
);
286 pSetLayout( hdc
, LAYOUT_LTR
);
287 ret
= GetMapMode( hdc
);
288 ok(ret
== MM_ANISOTROPIC
, "expected MM_ANISOTROPIC, got %d\n", ret
);
289 SetMapMode(hdc
, MM_TEXT
);
290 ret
= GetMapMode( hdc
);
291 ok(ret
== MM_TEXT
, "expected MM_TEXT, got %d\n", ret
);
296 static void test_modify_world_transform(void)
301 ret
= SetGraphicsMode(hdc
, GM_ADVANCED
);
302 if(!ret
) /* running in win9x so quit */
305 skip("GM_ADVANCED is not supported on this platform\n");
309 ret
= ModifyWorldTransform(hdc
, NULL
, MWT_IDENTITY
);
310 ok(ret
, "ret = %d\n", ret
);
312 ret
= ModifyWorldTransform(hdc
, NULL
, MWT_LEFTMULTIPLY
);
313 ok(!ret
, "ret = %d\n", ret
);
315 ret
= ModifyWorldTransform(hdc
, NULL
, MWT_RIGHTMULTIPLY
);
316 ok(!ret
, "ret = %d\n", ret
);
321 static void test_SetWindowExt(HDC hdc
, LONG cx
, LONG cy
, LONG expected_vp_cx
, LONG expected_vp_cy
)
323 SIZE windowExt
, viewportExt
;
324 POINT windowOrg
, windowOrgAfter
, viewportOrg
, viewportOrgAfter
;
326 GetWindowOrgEx(hdc
, &windowOrg
);
327 GetViewportOrgEx(hdc
, &viewportOrg
);
329 SetWindowExtEx(hdc
, cx
, cy
, NULL
);
330 GetWindowExtEx(hdc
, &windowExt
);
331 ok(windowExt
.cx
== cx
&& windowExt
.cy
== cy
,
332 "Window extension: Expected %dx%d, got %dx%d\n",
333 cx
, cy
, windowExt
.cx
, windowExt
.cy
);
335 GetViewportExtEx(hdc
, &viewportExt
);
336 ok(rough_match(viewportExt
.cx
, expected_vp_cx
) && rough_match(viewportExt
.cy
, expected_vp_cy
),
337 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
338 expected_vp_cx
, expected_vp_cy
, viewportExt
.cx
, viewportExt
.cy
);
340 GetWindowOrgEx(hdc
, &windowOrgAfter
);
341 ok(windowOrg
.x
== windowOrgAfter
.x
&& windowOrg
.y
== windowOrgAfter
.y
,
342 "Window origin changed from (%d,%d) to (%d,%d)\n",
343 windowOrg
.x
, windowOrg
.y
, windowOrgAfter
.x
, windowOrgAfter
.y
);
345 GetViewportOrgEx(hdc
, &viewportOrgAfter
);
346 ok(viewportOrg
.x
== viewportOrgAfter
.x
&& viewportOrg
.y
== viewportOrgAfter
.y
,
347 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
348 viewportOrg
.x
, viewportOrg
.y
, viewportOrgAfter
.x
, viewportOrgAfter
.y
);
351 static void test_SetViewportExt(HDC hdc
, LONG cx
, LONG cy
, LONG expected_vp_cx
, LONG expected_vp_cy
)
353 SIZE windowExt
, windowExtAfter
, viewportExt
;
354 POINT windowOrg
, windowOrgAfter
, viewportOrg
, viewportOrgAfter
;
356 GetWindowOrgEx(hdc
, &windowOrg
);
357 GetViewportOrgEx(hdc
, &viewportOrg
);
358 GetWindowExtEx(hdc
, &windowExt
);
360 SetViewportExtEx(hdc
, cx
, cy
, NULL
);
361 GetViewportExtEx(hdc
, &viewportExt
);
362 ok(rough_match(viewportExt
.cx
, expected_vp_cx
) && rough_match(viewportExt
.cy
, expected_vp_cy
),
363 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
364 expected_vp_cx
, expected_vp_cy
, viewportExt
.cx
, viewportExt
.cy
);
366 GetWindowExtEx(hdc
, &windowExtAfter
);
367 ok(windowExt
.cx
== windowExtAfter
.cx
&& windowExt
.cy
== windowExtAfter
.cy
,
368 "Window extension changed from %dx%d to %dx%d\n",
369 windowExt
.cx
, windowExt
.cy
, windowExtAfter
.cx
, windowExtAfter
.cy
);
371 GetWindowOrgEx(hdc
, &windowOrgAfter
);
372 ok(windowOrg
.x
== windowOrgAfter
.x
&& windowOrg
.y
== windowOrgAfter
.y
,
373 "Window origin changed from (%d,%d) to (%d,%d)\n",
374 windowOrg
.x
, windowOrg
.y
, windowOrgAfter
.x
, windowOrgAfter
.y
);
376 GetViewportOrgEx(hdc
, &viewportOrgAfter
);
377 ok(viewportOrg
.x
== viewportOrgAfter
.x
&& viewportOrg
.y
== viewportOrgAfter
.y
,
378 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
379 viewportOrg
.x
, viewportOrg
.y
, viewportOrgAfter
.x
, viewportOrgAfter
.y
);
382 static void test_isotropic_mapping(void)
387 SetMapMode(hdc
, MM_ISOTROPIC
);
389 /* MM_ISOTROPIC is set up like MM_LOMETRIC.
390 Initial values after SetMapMode():
393 Windows 9x: Windows NT:
394 Window Ext: 254 x -254 HORZSIZE*10 x VERTSIZE*10
395 Viewport Ext: LOGPIXELSX x LOGPIXELSY HORZRES x -VERTRES
397 To test without rounding errors, we have to use multiples of
401 GetWindowExtEx(hdc
, &win
);
402 GetViewportExtEx(hdc
, &vp
);
404 test_SetViewportExt(hdc
, 10 * vp
.cx
, 10 * vp
.cy
, 10 * vp
.cx
, 10 * vp
.cy
);
405 test_SetWindowExt(hdc
, win
.cx
, win
.cy
, 10 * vp
.cx
, 10 * vp
.cy
);
406 test_SetWindowExt(hdc
, 2 * win
.cx
, win
.cy
, 10 * vp
.cx
, 5 * vp
.cy
);
407 test_SetWindowExt(hdc
, win
.cx
, win
.cy
, 5 * vp
.cx
, 5 * vp
.cy
);
408 test_SetViewportExt(hdc
, 4 * vp
.cx
, 2 * vp
.cy
, 2 * vp
.cx
, 2 * vp
.cy
);
409 test_SetViewportExt(hdc
, vp
.cx
, 2 * vp
.cy
, vp
.cx
, vp
.cy
);
410 test_SetViewportExt(hdc
, 2 * vp
.cx
, 2 * vp
.cy
, 2 * vp
.cx
, 2 * vp
.cy
);
411 test_SetViewportExt(hdc
, 4 * vp
.cx
, 2 * vp
.cy
, 2 * vp
.cx
, 2 * vp
.cy
);
412 test_SetWindowExt(hdc
, 4 * win
.cx
, 2 * win
.cy
, 2 * vp
.cx
, vp
.cy
);
413 test_SetViewportExt(hdc
, -2 * vp
.cx
, -4 * vp
.cy
, -2 * vp
.cx
, -vp
.cy
);
414 test_SetViewportExt(hdc
, -2 * vp
.cx
, -1 * vp
.cy
, -2 * vp
.cx
, -vp
.cy
);
415 test_SetWindowExt(hdc
, -4 * win
.cx
, -2 * win
.cy
, -2 * vp
.cx
, -vp
.cy
);
416 test_SetWindowExt(hdc
, 4 * win
.cx
, -4 * win
.cy
, -vp
.cx
, -vp
.cy
);
421 static void test_setvirtualresolution(void)
423 HDC hdc
= CreateICA("DISPLAY", NULL
, NULL
, NULL
);
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 if(!pSetVirtualResolution
)
432 win_skip("Don't have SetVirtualResolution\n");
436 /* Get the true resolution limits */
437 SetMapMode(hdc
, MM_LOMETRIC
);
438 GetViewportExtEx(hdc
, &orig_lometric_vp
);
439 GetWindowExtEx(hdc
, &orig_lometric_wnd
);
440 SetMapMode(hdc
, MM_TEXT
);
442 r
= pSetVirtualResolution(hdc
, 4000, 1000, 400, 200); /* 10 pix/mm x 5 pix/mm */
443 ok(r
== TRUE
, "got %d\n", r
);
444 expect_LPtoDP(hdc
, 1000, 1000);
445 expect_viewport_ext(hdc
, 1, 1);
446 expect_window_ext(hdc
, 1, 1);
448 SetMapMode(hdc
, MM_LOMETRIC
);
449 expect_LPtoDP(hdc
, 1000, -500);
450 expect_viewport_ext(hdc
, 4000, -1000);
451 expect_window_ext(hdc
, 4000, 2000);
453 /* Doesn't change the device caps */
454 ok(horz_res
== GetDeviceCaps(hdc
, HORZRES
), "horz_res changed\n");
455 ok(horz_size
== GetDeviceCaps(hdc
, HORZSIZE
), "horz_size changed\n");
456 ok(log_pixels_x
== GetDeviceCaps(hdc
, LOGPIXELSX
), "log_pixels_x changed\n");
458 r
= pSetVirtualResolution(hdc
, 8000, 1000, 400, 200); /* 20 pix/mm x 5 pix/mm */
459 ok(r
== TRUE
, "got %d\n", r
);
460 expect_LPtoDP(hdc
, 1000, -500); /* No change, need to re-set the mapping mode */
461 SetMapMode(hdc
, MM_TEXT
);
462 SetMapMode(hdc
, MM_LOMETRIC
);
463 expect_LPtoDP(hdc
, 2000, -500);
464 expect_viewport_ext(hdc
, 8000, -1000);
465 expect_window_ext(hdc
, 4000, 2000);
467 r
= pSetVirtualResolution(hdc
, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
468 ok(r
== TRUE
, "got %d\n", r
);
469 SetMapMode(hdc
, MM_TEXT
);
470 SetMapMode(hdc
, MM_LOMETRIC
);
471 expect_LPtoDP(hdc
, 4000, -500);
472 expect_viewport_ext(hdc
, 8000, -1000);
473 expect_window_ext(hdc
, 2000, 2000);
475 r
= pSetVirtualResolution(hdc
, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
476 ok(r
== TRUE
, "got %d\n", r
);
477 SetMapMode(hdc
, MM_TEXT
);
478 SetMapMode(hdc
, MM_LOMETRIC
);
479 expect_LPtoDP(hdc
, 4000, -500);
480 expect_viewport_ext(hdc
, 8000, -1000);
481 expect_window_ext(hdc
, 2000, 2000);
483 r
= pSetVirtualResolution(hdc
, 8000, 2000, 200, 200); /* 40 pix/mm x 10 pix/mm */
484 ok(r
== TRUE
, "got %d\n", r
);
485 SetMapMode(hdc
, MM_TEXT
);
486 SetMapMode(hdc
, MM_LOMETRIC
);
487 expect_LPtoDP(hdc
, 4000, -1000);
488 expect_viewport_ext(hdc
, 8000, -2000);
489 expect_window_ext(hdc
, 2000, 2000);
491 r
= pSetVirtualResolution(hdc
, 0, 0, 10, 0); /* Error */
492 ok(r
== FALSE
, "got %d\n", r
);
493 SetMapMode(hdc
, MM_TEXT
);
494 SetMapMode(hdc
, MM_LOMETRIC
);
495 expect_LPtoDP(hdc
, 4000, -1000);
496 expect_viewport_ext(hdc
, 8000, -2000);
497 expect_window_ext(hdc
, 2000, 2000);
499 r
= pSetVirtualResolution(hdc
, 0, 0, 0, 0); /* Reset to true resolution */
500 ok(r
== TRUE
, "got %d\n", r
);
501 SetMapMode(hdc
, MM_TEXT
);
502 SetMapMode(hdc
, MM_LOMETRIC
);
503 expect_viewport_ext(hdc
, orig_lometric_vp
.cx
, orig_lometric_vp
.cy
);
504 expect_window_ext(hdc
, orig_lometric_wnd
.cx
, orig_lometric_wnd
.cy
);
510 static inline void expect_identity(int line
, XFORM
*xf
)
512 ok(xf
->eM11
== 1.0, "%d: got %f\n", line
, xf
->eM11
);
513 ok(xf
->eM12
== 0.0, "%d: got %f\n", line
, xf
->eM12
);
514 ok(xf
->eM21
== 0.0, "%d: got %f\n", line
, xf
->eM21
);
515 ok(xf
->eM22
== 1.0, "%d: got %f\n", line
, xf
->eM22
);
516 ok(xf
->eDx
== 0.0, "%d: got %f\n", line
, xf
->eDx
);
517 ok(xf
->eDy
== 0.0, "%d: got %f\n", line
, xf
->eDy
);
520 static inline void xform_near_match(int line
, XFORM
*got
, XFORM
*expect
)
522 ok(fabs(got
->eM11
- expect
->eM11
) < 0.001, "%d: got %f expect %f\n", line
, got
->eM11
, expect
->eM11
);
523 ok(fabs(got
->eM12
- expect
->eM12
) < 0.001, "%d: got %f expect %f\n", line
, got
->eM12
, expect
->eM12
);
524 ok(fabs(got
->eM21
- expect
->eM21
) < 0.001, "%d: got %f expect %f\n", line
, got
->eM21
, expect
->eM21
);
525 ok(fabs(got
->eM22
- expect
->eM22
) < 0.001, "%d: got %f expect %f\n", line
, got
->eM22
, expect
->eM22
);
526 ok(fabs(got
->eDx
- expect
->eDx
) < 0.001, "%d: got %f expect %f\n", line
, got
->eDx
, expect
->eDx
);
527 ok(fabs(got
->eDy
- expect
->eDy
) < 0.001, "%d: got %f expect %f\n", line
, got
->eDy
, expect
->eDy
);
531 static void test_gettransform(void)
533 HDC hdc
= CreateICA("DISPLAY", NULL
, NULL
, NULL
);
536 SIZE lometric_vp
, lometric_wnd
;
540 win_skip("Don't have GetTransform\n");
544 r
= pGetTransform(hdc
, 0x203, &xform
); /* World -> Page */
545 ok(r
== TRUE
, "got %d\n", r
);
546 expect_identity(__LINE__
, &xform
);
547 r
= pGetTransform(hdc
, 0x304, &xform
); /* Page -> Device */
548 ok(r
== TRUE
, "got %d\n", r
);
549 expect_identity(__LINE__
, &xform
);
550 r
= pGetTransform(hdc
, 0x204, &xform
); /* World -> Device */
551 ok(r
== TRUE
, "got %d\n", r
);
552 expect_identity(__LINE__
, &xform
);
553 r
= pGetTransform(hdc
, 0x402, &xform
); /* Device -> World */
554 ok(r
== TRUE
, "got %d\n", r
);
555 expect_identity(__LINE__
, &xform
);
557 SetMapMode(hdc
, MM_LOMETRIC
);
558 GetViewportExtEx(hdc
, &lometric_vp
);
559 GetWindowExtEx(hdc
, &lometric_wnd
);
561 r
= pGetTransform(hdc
, 0x203, &xform
); /* World -> Page */
562 ok(r
== TRUE
, "got %d\n", r
);
563 expect_identity(__LINE__
, &xform
);
565 r
= pGetTransform(hdc
, 0x304, &xform
); /* Page -> Device */
566 ok(r
== TRUE
, "got %d\n", r
);
567 expect
.eM11
= (FLOAT
) lometric_vp
.cx
/ lometric_wnd
.cx
;
568 expect
.eM12
= expect
.eM21
= 0.0;
569 expect
.eM22
= (FLOAT
) lometric_vp
.cy
/ lometric_wnd
.cy
;
570 expect
.eDx
= expect
.eDy
= 0.0;
571 xform_near_match(__LINE__
, &xform
, &expect
);
573 r
= pGetTransform(hdc
, 0x204, &xform
); /* World -> Device */
574 ok(r
== TRUE
, "got %d\n", r
);
575 xform_near_match(__LINE__
, &xform
, &expect
);
577 r
= pGetTransform(hdc
, 0x402, &xform
); /* Device -> World */
578 ok(r
== TRUE
, "got %d\n", r
);
579 expect
.eM11
= (FLOAT
) lometric_wnd
.cx
/ lometric_vp
.cx
;
580 expect
.eM22
= (FLOAT
) lometric_wnd
.cy
/ lometric_vp
.cy
;
581 xform_near_match(__LINE__
, &xform
, &expect
);
584 SetGraphicsMode(hdc
, GM_ADVANCED
);
588 SetWorldTransform(hdc
, &expect
);
589 r
= pGetTransform(hdc
, 0x203, &xform
); /* World -> Page */
590 ok(r
== TRUE
, "got %d\n", r
);
591 xform_near_match(__LINE__
, &xform
, &expect
);
593 r
= pGetTransform(hdc
, 0x304, &xform
); /* Page -> Device */
594 ok(r
== TRUE
, "got %d\n", r
);
595 expect
.eM11
= (FLOAT
) lometric_vp
.cx
/ lometric_wnd
.cx
;
596 expect
.eM22
= (FLOAT
) lometric_vp
.cy
/ lometric_wnd
.cy
;
597 xform_near_match(__LINE__
, &xform
, &expect
);
599 r
= pGetTransform(hdc
, 0x204, &xform
); /* World -> Device */
600 ok(r
== TRUE
, "got %d\n", r
);
603 xform_near_match(__LINE__
, &xform
, &expect
);
605 r
= pGetTransform(hdc
, 0x402, &xform
); /* Device -> World */
606 ok(r
== TRUE
, "got %d\n", r
);
607 expect
.eM11
= 1 / expect
.eM11
;
608 expect
.eM22
= 1 / expect
.eM22
;
609 xform_near_match(__LINE__
, &xform
, &expect
);
611 r
= pGetTransform(hdc
, 0x102, &xform
);
612 ok(r
== FALSE
, "got %d\n", r
);
613 r
= pGetTransform(hdc
, 0x103, &xform
);
614 ok(r
== FALSE
, "got %d\n", r
);
615 r
= pGetTransform(hdc
, 0x104, &xform
);
616 ok(r
== FALSE
, "got %d\n", r
);
617 r
= pGetTransform(hdc
, 0x202, &xform
);
618 ok(r
== FALSE
, "got %d\n", r
);
619 r
= pGetTransform(hdc
, 0x302, &xform
);
620 ok(r
== FALSE
, "got %d\n", r
);
621 r
= pGetTransform(hdc
, 0x303, &xform
);
622 ok(r
== FALSE
, "got %d\n", r
);
623 r
= pGetTransform(hdc
, 0x403, &xform
);
624 ok(r
== FALSE
, "got %d\n", r
);
625 r
= pGetTransform(hdc
, 0x404, &xform
);
626 ok(r
== FALSE
, "got %d\n", r
);
627 r
= pGetTransform(hdc
, 0xffff, &xform
);
628 ok(r
== FALSE
, "got %d\n", r
);
633 HMODULE mod
= GetModuleHandleA("gdi32.dll");
634 pGetLayout
= (void *)GetProcAddress( mod
, "GetLayout" );
635 pSetLayout
= (void *)GetProcAddress( mod
, "SetLayout" );
636 pGetTransform
= (void *)GetProcAddress( mod
, "GetTransform" );
637 pSetVirtualResolution
= (void *)GetProcAddress( mod
, "SetVirtualResolution" );
639 test_modify_world_transform();
640 test_world_transform();
642 test_isotropic_mapping();
643 test_setvirtualresolution();