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)
84 INT ret
, size_cx
, size_cy
, res_x
, res_y
, dpi_x
, dpi_y
;
88 SetLastError(0xdeadbeef);
89 GetWorldTransform(0, NULL
);
90 is_win9x
= GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
;
92 hdc
= CreateCompatibleDC(0);
100 ret
= SetWorldTransform(hdc
, &xform
);
101 ok(!ret
, "SetWorldTransform should fail in GM_COMPATIBLE mode\n");
103 size_cx
= GetDeviceCaps(hdc
, HORZSIZE
);
104 size_cy
= GetDeviceCaps(hdc
, VERTSIZE
);
105 res_x
= GetDeviceCaps(hdc
, HORZRES
);
106 res_y
= GetDeviceCaps(hdc
, VERTRES
);
107 dpi_x
= GetDeviceCaps(hdc
, LOGPIXELSX
);
108 dpi_y
= GetDeviceCaps(hdc
, LOGPIXELSY
);
109 trace("dc size %d x %d, resolution %d x %d dpi %d x %d\n",
110 size_cx
, size_cy
, res_x
, res_y
, dpi_x
, dpi_y
);
112 expect_viewport_ext(hdc
, 1, 1);
113 expect_window_ext(hdc
, 1, 1);
114 expect_world_transform(hdc
, 1.0, 1.0);
115 expect_LPtoDP(hdc
, 1000, 1000);
117 SetLastError(0xdeadbeef);
118 ret
= SetMapMode(hdc
, MM_LOMETRIC
);
119 ok(ret
== MM_TEXT
, "expected MM_TEXT, got %d\n", ret
);
123 expect_viewport_ext(hdc
, dpi_x
, dpi_y
);
124 expect_window_ext(hdc
, 254, -254);
128 expect_viewport_ext(hdc
, res_x
, -res_y
);
129 ok( GetWindowExtEx( hdc
, &size
), "GetWindowExtEx failed\n" );
130 ok( rough_match( size
.cx
, size_cx
* 10 ) ||
131 rough_match( size
.cx
, MulDiv( res_x
, 254, dpi_x
)), /* Vista uses a more precise method */
132 "expected cx %d or %d, got %d\n", size_cx
* 10, MulDiv( res_x
, 254, dpi_x
), size
.cx
);
133 ok( rough_match( size
.cy
, size_cy
* 10 ) ||
134 rough_match( size
.cy
, MulDiv( res_y
, 254, dpi_y
)), /* Vista uses a more precise method */
135 "expected cy %d or %d, got %d\n", size_cy
* 10, MulDiv( res_y
, 254, dpi_y
), size
.cy
);
137 expect_world_transform(hdc
, 1.0, 1.0);
138 expect_LPtoDP(hdc
, MulDiv(1000 / 10, res_x
, size_cx
), -MulDiv(1000 / 10, res_y
, size_cy
));
140 SetLastError(0xdeadbeef);
141 ret
= SetMapMode(hdc
, MM_TEXT
);
142 ok(ret
== MM_LOMETRIC
, "expected MM_LOMETRIC, got %d\n", ret
);
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 ret
= SetGraphicsMode(hdc
, GM_ADVANCED
);
153 skip("GM_ADVANCED is not supported on this platform\n");
157 expect_viewport_ext(hdc
, 1, 1);
158 expect_window_ext(hdc
, 1, 1);
159 expect_world_transform(hdc
, 1.0, 1.0);
160 expect_LPtoDP(hdc
, 1000, 1000);
162 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
169 ret
= SetWorldTransform(hdc
, &xform
);
171 broken(ret
), /* NT4 */
172 "SetWorldTransform should fail with an invalid xform\n");
180 SetLastError(0xdeadbeef);
181 ret
= SetWorldTransform(hdc
, &xform
);
182 ok(ret
, "SetWorldTransform error %u\n", GetLastError());
184 expect_viewport_ext(hdc
, 1, 1);
185 expect_window_ext(hdc
, 1, 1);
186 expect_world_transform(hdc
, 20.0, 20.0);
187 expect_LPtoDP(hdc
, 20000, 20000);
189 SetLastError(0xdeadbeef);
190 ret
= SetMapMode(hdc
, MM_LOMETRIC
);
191 ok(ret
== MM_TEXT
, "expected MM_TEXT, got %d\n", ret
);
193 expect_viewport_ext(hdc
, res_x
, -res_y
);
194 ok( GetWindowExtEx( hdc
, &size
), "GetWindowExtEx failed\n" );
195 ok( rough_match( size
.cx
, size_cx
* 10 ) ||
196 rough_match( size
.cx
, MulDiv( res_x
, 254, dpi_x
)), /* Vista uses a more precise method */
197 "expected cx %d or %d, got %d\n", size_cx
* 10, MulDiv( res_x
, 254, dpi_x
), size
.cx
);
198 ok( rough_match( size
.cy
, size_cy
* 10 ) ||
199 rough_match( size
.cy
, MulDiv( res_y
, 254, dpi_y
)), /* Vista uses a more precise method */
200 "expected cy %d or %d, got %d\n", size_cy
* 10, MulDiv( res_y
, 254, dpi_y
), size
.cy
);
201 expect_world_transform(hdc
, 20.0, 20.0);
202 expect_LPtoDP(hdc
, MulDiv(20000, res_x
, size
.cx
), -MulDiv(20000, res_y
, size
.cy
));
204 SetLastError(0xdeadbeef);
205 ret
= SetMapMode(hdc
, MM_TEXT
);
206 ok(ret
== MM_LOMETRIC
, "expected MM_LOMETRIC, got %d\n", ret
);
208 expect_viewport_ext(hdc
, 1, 1);
209 expect_window_ext(hdc
, 1, 1);
210 expect_world_transform(hdc
, 20.0, 20.0);
211 expect_LPtoDP(hdc
, 20000, 20000);
213 ret
= SetGraphicsMode(hdc
, GM_COMPATIBLE
);
214 ok(ret
, "SetGraphicsMode(GM_COMPATIBLE) should not fail if DC has't an identity transform\n");
215 ret
= GetGraphicsMode(hdc
);
216 ok(ret
== GM_COMPATIBLE
, "expected GM_COMPATIBLE, got %d\n", ret
);
218 expect_viewport_ext(hdc
, 1, 1);
219 expect_window_ext(hdc
, 1, 1);
220 expect_world_transform(hdc
, 20.0, 20.0);
221 expect_LPtoDP(hdc
, 20000, 20000);
226 static void test_dc_layout(void)
228 INT ret
, size_cx
, size_cy
, res_x
, res_y
, dpi_x
, dpi_y
;
236 if (!pGetLayout
|| !pSetLayout
)
238 win_skip( "Don't have SetLayout\n" );
242 hdc
= CreateCompatibleDC(0);
243 bitmap
= CreateCompatibleBitmap( hdc
, 100, 100 );
244 SelectObject( hdc
, bitmap
);
246 size_cx
= GetDeviceCaps(hdc
, HORZSIZE
);
247 size_cy
= GetDeviceCaps(hdc
, VERTSIZE
);
248 res_x
= GetDeviceCaps(hdc
, HORZRES
);
249 res_y
= GetDeviceCaps(hdc
, VERTRES
);
250 dpi_x
= GetDeviceCaps(hdc
, LOGPIXELSX
);
251 dpi_y
= GetDeviceCaps(hdc
, LOGPIXELSY
);
253 ret
= GetMapMode( hdc
);
254 ok(ret
== MM_TEXT
, "expected MM_TEXT, got %d\n", ret
);
255 expect_viewport_ext(hdc
, 1, 1);
256 expect_window_ext(hdc
, 1, 1);
257 expect_world_transform(hdc
, 1.0, 1.0);
258 expect_LPtoDP(hdc
, 1000, 1000);
260 pSetLayout( hdc
, LAYOUT_RTL
);
261 if (!pGetLayout( hdc
))
263 win_skip( "SetLayout not supported\n" );
268 ret
= GetMapMode( hdc
);
269 ok(ret
== MM_ANISOTROPIC
, "expected MM_ANISOTROPIC, 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 + 99, 1000);
274 GetViewportOrgEx( hdc
, &pt
);
275 ok( pt
.x
== 0 && pt
.y
== 0, "wrong origin %d,%d\n", pt
.x
, pt
.y
);
276 GetWindowOrgEx( hdc
, &pt
);
277 ok( pt
.x
== 0 && pt
.y
== 0, "wrong origin %d,%d\n", pt
.x
, pt
.y
);
278 GetDCOrgEx( hdc
, &pt
);
279 ok( pt
.x
== 0 && pt
.y
== 0, "wrong origin %d,%d\n", pt
.x
, pt
.y
);
283 BOOL ret
= pGetTransform( hdc
, 0x204, &xform
); /* World -> Device */
284 ok( ret
, "got %d\n", ret
);
285 ok( xform
.eM11
== -1.0, "got %f\n", xform
.eM11
);
286 ok( xform
.eM12
== 0.0, "got %f\n", xform
.eM12
);
287 ok( xform
.eM21
== 0.0, "got %f\n", xform
.eM21
);
288 ok( xform
.eM22
== 1.0, "got %f\n", xform
.eM22
);
289 ok( xform
.eDx
== 99.0, "got %f\n", xform
.eDx
);
290 ok( xform
.eDy
== 0.0, "got %f\n", xform
.eDy
);
293 SetRect( &rc
, 10, 10, 20, 20 );
294 IntersectClipRect( hdc
, 10, 10, 20, 20 );
295 hrgn
= CreateRectRgn( 0, 0, 0, 0 );
296 GetClipRgn( hdc
, hrgn
);
297 GetRgnBox( hrgn
, &ret_rc
);
298 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %d,%d - %d,%d\n",
299 ret_rc
.left
, ret_rc
.top
, ret_rc
.right
, ret_rc
.bottom
);
300 pSetLayout( hdc
, LAYOUT_LTR
);
301 SetRect( &rc
, 80, 10, 90, 20 );
302 GetClipRgn( hdc
, hrgn
);
303 GetRgnBox( hrgn
, &ret_rc
);
304 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %d,%d - %d,%d\n",
305 ret_rc
.left
, ret_rc
.top
, ret_rc
.right
, ret_rc
.bottom
);
306 GetClipBox( hdc
, &ret_rc
);
307 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %d,%d - %d,%d\n",
308 ret_rc
.left
, ret_rc
.top
, ret_rc
.right
, ret_rc
.bottom
);
309 IntersectClipRect( hdc
, 80, 10, 85, 20 );
310 pSetLayout( hdc
, LAYOUT_RTL
);
311 SetRect( &rc
, 15, 10, 20, 20 );
312 GetClipRgn( hdc
, hrgn
);
313 GetRgnBox( hrgn
, &ret_rc
);
314 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %d,%d - %d,%d\n",
315 ret_rc
.left
, ret_rc
.top
, ret_rc
.right
, ret_rc
.bottom
);
316 GetClipBox( hdc
, &ret_rc
);
317 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %d,%d - %d,%d\n",
318 ret_rc
.left
, ret_rc
.top
, ret_rc
.right
, ret_rc
.bottom
);
319 SetRectRgn( hrgn
, 60, 10, 80, 20 );
320 pSetLayout( hdc
, LAYOUT_LTR
);
321 ExtSelectClipRgn( hdc
, hrgn
, RGN_OR
);
322 pSetLayout( hdc
, LAYOUT_RTL
);
323 SetRect( &rc
, 15, 10, 40, 20 );
324 GetClipRgn( hdc
, hrgn
);
325 GetRgnBox( hrgn
, &ret_rc
);
326 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %d,%d - %d,%d\n",
327 ret_rc
.left
, ret_rc
.top
, ret_rc
.right
, ret_rc
.bottom
);
328 GetClipBox( hdc
, &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
);
332 /* OffsetClipRgn mirrors too */
333 OffsetClipRgn( hdc
, 5, 5 );
334 OffsetRect( &rc
, 5, 5 );
335 GetClipRgn( hdc
, hrgn
);
336 GetRgnBox( hrgn
, &ret_rc
);
337 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %d,%d - %d,%d\n",
338 ret_rc
.left
, ret_rc
.top
, ret_rc
.right
, ret_rc
.bottom
);
340 /* GetRandomRgn returns the raw region */
343 SetRect( &rc
, 55, 15, 80, 25 );
344 pGetRandomRgn( hdc
, hrgn
, 1 );
345 GetRgnBox( hrgn
, &ret_rc
);
346 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %d,%d - %d,%d\n",
347 ret_rc
.left
, ret_rc
.top
, ret_rc
.right
, ret_rc
.bottom
);
350 SetMapMode(hdc
, MM_LOMETRIC
);
351 ret
= GetMapMode( hdc
);
352 ok(ret
== MM_ANISOTROPIC
, "expected MM_ANISOTROPIC, got %d\n", ret
);
354 expect_viewport_ext(hdc
, res_x
, -res_y
);
355 ok( GetWindowExtEx( hdc
, &size
), "GetWindowExtEx failed\n" );
356 ok( rough_match( size
.cx
, size_cx
* 10 ) ||
357 rough_match( size
.cx
, MulDiv( res_x
, 254, dpi_x
)), /* Vista uses a more precise method */
358 "expected cx %d or %d, got %d\n", size_cx
* 10, MulDiv( res_x
, 254, dpi_x
), size
.cx
);
359 ok( rough_match( size
.cy
, size_cy
* 10 ) ||
360 rough_match( size
.cy
, MulDiv( res_y
, 254, dpi_y
)), /* Vista uses a more precise method */
361 "expected cy %d or %d, got %d\n", size_cy
* 10, MulDiv( res_y
, 254, dpi_y
), size
.cy
);
362 expect_world_transform(hdc
, 1.0, 1.0);
363 expect_LPtoDP(hdc
, -MulDiv(1000 / 10, res_x
, size_cx
) + 99, -MulDiv(1000 / 10, res_y
, size_cy
));
365 SetMapMode(hdc
, MM_TEXT
);
366 ret
= GetMapMode( hdc
);
367 ok(ret
== MM_ANISOTROPIC
, "expected MM_ANISOTROPIC, got %d\n", ret
);
368 pSetLayout( hdc
, LAYOUT_LTR
);
369 ret
= GetMapMode( hdc
);
370 ok(ret
== MM_ANISOTROPIC
, "expected MM_ANISOTROPIC, got %d\n", ret
);
371 SetMapMode(hdc
, MM_TEXT
);
372 ret
= GetMapMode( hdc
);
373 ok(ret
== MM_TEXT
, "expected MM_TEXT, got %d\n", ret
);
376 DeleteObject( bitmap
);
379 static void test_modify_world_transform(void)
384 ret
= SetGraphicsMode(hdc
, GM_ADVANCED
);
385 if(!ret
) /* running in win9x so quit */
388 skip("GM_ADVANCED is not supported on this platform\n");
392 ret
= ModifyWorldTransform(hdc
, NULL
, MWT_IDENTITY
);
393 ok(ret
, "ret = %d\n", ret
);
395 ret
= ModifyWorldTransform(hdc
, NULL
, MWT_LEFTMULTIPLY
);
396 ok(!ret
, "ret = %d\n", ret
);
398 ret
= ModifyWorldTransform(hdc
, NULL
, MWT_RIGHTMULTIPLY
);
399 ok(!ret
, "ret = %d\n", ret
);
404 static void test_SetWindowExt(HDC hdc
, LONG cx
, LONG cy
, LONG expected_vp_cx
, LONG expected_vp_cy
)
406 SIZE windowExt
, viewportExt
;
407 POINT windowOrg
, windowOrgAfter
, viewportOrg
, viewportOrgAfter
;
409 GetWindowOrgEx(hdc
, &windowOrg
);
410 GetViewportOrgEx(hdc
, &viewportOrg
);
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
);
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
);
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
);
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
);
434 static void test_SetViewportExt(HDC hdc
, LONG cx
, LONG cy
, LONG expected_vp_cx
, LONG expected_vp_cy
)
436 SIZE windowExt
, windowExtAfter
, viewportExt
;
437 POINT windowOrg
, windowOrgAfter
, viewportOrg
, viewportOrgAfter
;
439 GetWindowOrgEx(hdc
, &windowOrg
);
440 GetViewportOrgEx(hdc
, &viewportOrg
);
441 GetWindowExtEx(hdc
, &windowExt
);
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
);
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
);
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
);
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
);
465 static void test_isotropic_mapping(void)
470 SetMapMode(hdc
, MM_ISOTROPIC
);
472 /* MM_ISOTROPIC is set up like MM_LOMETRIC.
473 Initial values after SetMapMode():
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
480 To test without rounding errors, we have to use multiples of
484 GetWindowExtEx(hdc
, &win
);
485 GetViewportExtEx(hdc
, &vp
);
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
);
504 static void test_setvirtualresolution(void)
506 HDC hdc
= CreateICA("DISPLAY", NULL
, NULL
, NULL
);
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
;
513 if(!pSetVirtualResolution
)
515 win_skip("Don't have SetVirtualResolution\n");
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
);
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);
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);
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");
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);
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);
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);
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);
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);
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
);
593 static inline void expect_identity(int line
, XFORM
*xf
)
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
);
603 static inline void xform_near_match(int line
, XFORM
*got
, XFORM
*expect
)
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
);
614 static void test_gettransform(void)
616 HDC hdc
= CreateICA("DISPLAY", NULL
, NULL
, NULL
);
619 SIZE lometric_vp
, lometric_wnd
;
623 win_skip("Don't have GetTransform\n");
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
);
640 SetMapMode(hdc
, MM_LOMETRIC
);
641 GetViewportExtEx(hdc
, &lometric_vp
);
642 GetWindowExtEx(hdc
, &lometric_wnd
);
644 r
= pGetTransform(hdc
, 0x203, &xform
); /* World -> Page */
645 ok(r
== TRUE
, "got %d\n", r
);
646 expect_identity(__LINE__
, &xform
);
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
);
656 r
= pGetTransform(hdc
, 0x204, &xform
); /* World -> Device */
657 ok(r
== TRUE
, "got %d\n", r
);
658 xform_near_match(__LINE__
, &xform
, &expect
);
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
);
667 SetGraphicsMode(hdc
, GM_ADVANCED
);
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
);
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
);
682 r
= pGetTransform(hdc
, 0x204, &xform
); /* World -> Device */
683 ok(r
== TRUE
, "got %d\n", r
);
686 xform_near_match(__LINE__
, &xform
, &expect
);
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
);
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
);
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" );
723 test_modify_world_transform();
724 test_world_transform();
726 test_isotropic_mapping();
727 test_setvirtualresolution();