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
25 #include "wine/test.h"
31 static DWORD (WINAPI
*pGetLayout
)(HDC hdc
);
32 static INT (WINAPI
*pGetRandomRgn
)(HDC hDC
, HRGN hRgn
, INT iCode
);
33 static BOOL (WINAPI
*pGetTransform
)(HDC
, DWORD
, XFORM
*);
34 static BOOL (WINAPI
*pSetVirtualResolution
)(HDC
, DWORD
, DWORD
, DWORD
, DWORD
);
36 #define rough_match(got, expected) (abs( MulDiv( (got) - (expected), 1000, (expected) )) <= 5)
38 #define expect_LPtoDP(_hdc, _x, _y) \
40 POINT _pt = { 1000, 1000 }; \
41 LPtoDP(_hdc, &_pt, 1); \
42 ok(rough_match(_pt.x, _x), "expected x %d, got %d\n", (_x), _pt.x); \
43 ok(rough_match(_pt.y, _y), "expected y %d, got %d\n", (_y), _pt.y); \
46 #define expect_world_transform(_hdc, _em11, _em22) \
50 SetLastError(0xdeadbeef); \
51 _ret = GetWorldTransform(_hdc, &_xform); \
52 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) \
54 ok(_ret, "GetWorldTransform error %u\n", GetLastError()); \
55 ok(_xform.eM11 == (_em11), "expected %f, got %f\n", (_em11), _xform.eM11); \
56 ok(_xform.eM12 == 0.0, "expected 0.0, got %f\n", _xform.eM12); \
57 ok(_xform.eM21 == 0.0, "expected 0.0, got %f\n", _xform.eM21); \
58 ok(_xform.eM22 == (_em22), "expected %f, got %f\n", (_em22), _xform.eM22); \
59 ok(_xform.eDx == 0.0, "expected 0.0, got %f\n", _xform.eDx); \
60 ok(_xform.eDy == 0.0, "expected 0.0, got %f\n", _xform.eDy); \
64 #define expect_dc_ext(_func, _hdc, _cx, _cy) \
68 SetLastError(0xdeadbeef); \
69 _ret = _func(_hdc, &_size); \
70 ok(_ret, #_func " error %u\n", GetLastError()); \
71 ok(_size.cx == (_cx), "expected cx %d, got %d\n", (_cx), _size.cx); \
72 ok(_size.cy == (_cy), "expected cy %d, got %d\n", (_cy), _size.cy); \
75 #define expect_viewport_ext(_hdc, _cx, _cy) expect_dc_ext(GetViewportExtEx, _hdc, _cx, _cy)
76 #define expect_window_ext(_hdc, _cx, _cy) expect_dc_ext(GetWindowExtEx, _hdc, _cx, _cy)
78 static void test_world_transform(void)
81 INT ret
, size_cx
, size_cy
, res_x
, res_y
, dpi_x
, dpi_y
;
85 hdc
= CreateCompatibleDC(0);
93 ret
= SetWorldTransform(hdc
, &xform
);
94 ok(!ret
, "SetWorldTransform should fail in GM_COMPATIBLE mode\n");
96 size_cx
= GetDeviceCaps(hdc
, HORZSIZE
);
97 size_cy
= GetDeviceCaps(hdc
, VERTSIZE
);
98 res_x
= GetDeviceCaps(hdc
, HORZRES
);
99 res_y
= GetDeviceCaps(hdc
, VERTRES
);
100 dpi_x
= GetDeviceCaps(hdc
, LOGPIXELSX
);
101 dpi_y
= GetDeviceCaps(hdc
, LOGPIXELSY
);
102 trace("dc size %d x %d, resolution %d x %d dpi %d x %d\n",
103 size_cx
, size_cy
, res_x
, res_y
, dpi_x
, dpi_y
);
105 expect_viewport_ext(hdc
, 1, 1);
106 expect_window_ext(hdc
, 1, 1);
107 expect_world_transform(hdc
, 1.0, 1.0);
108 expect_LPtoDP(hdc
, 1000, 1000);
110 SetLastError(0xdeadbeef);
111 ret
= SetMapMode(hdc
, MM_LOMETRIC
);
112 ok(ret
== MM_TEXT
, "expected MM_TEXT, got %d\n", ret
);
114 expect_viewport_ext(hdc
, res_x
, -res_y
);
115 ok( GetWindowExtEx( hdc
, &size
), "GetWindowExtEx failed\n" );
116 ok( rough_match( size
.cx
, size_cx
* 10 ) ||
117 rough_match( size
.cx
, MulDiv( res_x
, 254, dpi_x
)), /* Vista uses a more precise method */
118 "expected cx %d or %d, got %d\n", size_cx
* 10, MulDiv( res_x
, 254, dpi_x
), size
.cx
);
119 ok( rough_match( size
.cy
, size_cy
* 10 ) ||
120 rough_match( size
.cy
, MulDiv( res_y
, 254, dpi_y
)), /* Vista uses a more precise method */
121 "expected cy %d or %d, got %d\n", size_cy
* 10, MulDiv( res_y
, 254, dpi_y
), size
.cy
);
122 expect_world_transform(hdc
, 1.0, 1.0);
123 expect_LPtoDP(hdc
, MulDiv(1000 / 10, res_x
, size_cx
), -MulDiv(1000 / 10, res_y
, size_cy
));
125 SetLastError(0xdeadbeef);
126 ret
= SetMapMode(hdc
, MM_TEXT
);
127 ok(ret
== MM_LOMETRIC
, "expected MM_LOMETRIC, got %d\n", ret
);
129 expect_viewport_ext(hdc
, 1, 1);
130 expect_window_ext(hdc
, 1, 1);
131 expect_world_transform(hdc
, 1.0, 1.0);
132 expect_LPtoDP(hdc
, 1000, 1000);
134 ret
= SetGraphicsMode(hdc
, GM_ADVANCED
);
138 skip("GM_ADVANCED is not supported on this platform\n");
142 expect_viewport_ext(hdc
, 1, 1);
143 expect_window_ext(hdc
, 1, 1);
144 expect_world_transform(hdc
, 1.0, 1.0);
145 expect_LPtoDP(hdc
, 1000, 1000);
147 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
154 ret
= SetWorldTransform(hdc
, &xform
);
156 broken(ret
), /* NT4 */
157 "SetWorldTransform should fail with an invalid xform\n");
165 SetLastError(0xdeadbeef);
166 ret
= SetWorldTransform(hdc
, &xform
);
167 ok(ret
, "SetWorldTransform error %u\n", GetLastError());
169 expect_viewport_ext(hdc
, 1, 1);
170 expect_window_ext(hdc
, 1, 1);
171 expect_world_transform(hdc
, 20.0, 20.0);
172 expect_LPtoDP(hdc
, 20000, 20000);
174 SetLastError(0xdeadbeef);
175 ret
= SetMapMode(hdc
, MM_LOMETRIC
);
176 ok(ret
== MM_TEXT
, "expected MM_TEXT, got %d\n", ret
);
178 expect_viewport_ext(hdc
, res_x
, -res_y
);
179 ok( GetWindowExtEx( hdc
, &size
), "GetWindowExtEx failed\n" );
180 ok( rough_match( size
.cx
, size_cx
* 10 ) ||
181 rough_match( size
.cx
, MulDiv( res_x
, 254, dpi_x
)), /* Vista uses a more precise method */
182 "expected cx %d or %d, got %d\n", size_cx
* 10, MulDiv( res_x
, 254, dpi_x
), size
.cx
);
183 ok( rough_match( size
.cy
, size_cy
* 10 ) ||
184 rough_match( size
.cy
, MulDiv( res_y
, 254, dpi_y
)), /* Vista uses a more precise method */
185 "expected cy %d or %d, got %d\n", size_cy
* 10, MulDiv( res_y
, 254, dpi_y
), size
.cy
);
186 expect_world_transform(hdc
, 20.0, 20.0);
187 expect_LPtoDP(hdc
, MulDiv(20000, res_x
, size
.cx
), -MulDiv(20000, res_y
, size
.cy
));
189 SetLastError(0xdeadbeef);
190 ret
= SetMapMode(hdc
, MM_TEXT
);
191 ok(ret
== MM_LOMETRIC
, "expected MM_LOMETRIC, got %d\n", ret
);
193 expect_viewport_ext(hdc
, 1, 1);
194 expect_window_ext(hdc
, 1, 1);
195 expect_world_transform(hdc
, 20.0, 20.0);
196 expect_LPtoDP(hdc
, 20000, 20000);
198 size
.cx
= 0xdeadbeef;
199 size
.cy
= 0xdeadbeef;
200 ret
= SetViewportExtEx(hdc
, -1, -1, &size
);
201 ok(ret
, "SetViewportExtEx(-1, -1) failed\n");
202 ok(size
.cx
== 1 && size
.cy
== 1, "expected 1,1 got %d,%d\n", size
.cx
, size
.cy
);
203 expect_viewport_ext(hdc
, 1, 1);
204 expect_window_ext(hdc
, 1, 1);
205 expect_world_transform(hdc
, 20.0, 20.0);
206 expect_LPtoDP(hdc
, 20000, 20000);
208 ret
= SetMapMode(hdc
, MM_ANISOTROPIC
);
209 ok(ret
== MM_TEXT
, "expected MM_TEXT, got %d\n", ret
);
211 expect_viewport_ext(hdc
, 1, 1);
212 expect_window_ext(hdc
, 1, 1);
213 expect_world_transform(hdc
, 20.0, 20.0);
214 expect_LPtoDP(hdc
, 20000, 20000);
216 size
.cx
= 0xdeadbeef;
217 size
.cy
= 0xdeadbeef;
218 ret
= SetViewportExtEx(hdc
, -1, -1, &size
);
219 ok(ret
, "SetViewportExtEx(-1, -1) failed\n");
220 ok(size
.cx
== 1 && size
.cy
== 1, "expected 1,1 got %d,%d\n", size
.cx
, size
.cy
);
221 expect_viewport_ext(hdc
, -1, -1);
222 expect_window_ext(hdc
, 1, 1);
223 expect_world_transform(hdc
, 20.0, 20.0);
224 expect_LPtoDP(hdc
, -20000, -20000);
226 ret
= SetGraphicsMode(hdc
, GM_COMPATIBLE
);
227 ok(ret
, "SetGraphicsMode(GM_COMPATIBLE) should not fail if DC has't an identity transform\n");
228 ret
= GetGraphicsMode(hdc
);
229 ok(ret
== GM_COMPATIBLE
, "expected GM_COMPATIBLE, got %d\n", ret
);
231 expect_viewport_ext(hdc
, -1, -1);
232 expect_window_ext(hdc
, 1, 1);
233 expect_world_transform(hdc
, 20.0, 20.0);
234 expect_LPtoDP(hdc
, -20000, -20000);
239 static void test_dc_layout(void)
241 INT ret
, size_cx
, size_cy
, res_x
, res_y
, dpi_x
, dpi_y
;
251 win_skip( "Don't have GetLayout\n" );
255 hdc
= CreateCompatibleDC(0);
256 bitmap
= CreateCompatibleBitmap( hdc
, 100, 100 );
257 SelectObject( hdc
, bitmap
);
259 size_cx
= GetDeviceCaps(hdc
, HORZSIZE
);
260 size_cy
= GetDeviceCaps(hdc
, VERTSIZE
);
261 res_x
= GetDeviceCaps(hdc
, HORZRES
);
262 res_y
= GetDeviceCaps(hdc
, VERTRES
);
263 dpi_x
= GetDeviceCaps(hdc
, LOGPIXELSX
);
264 dpi_y
= GetDeviceCaps(hdc
, LOGPIXELSY
);
266 ret
= GetMapMode( hdc
);
267 ok(ret
== MM_TEXT
, "expected MM_TEXT, got %d\n", ret
);
268 expect_viewport_ext(hdc
, 1, 1);
269 expect_window_ext(hdc
, 1, 1);
270 expect_world_transform(hdc
, 1.0, 1.0);
271 expect_LPtoDP(hdc
, 1000, 1000);
273 SetLayout( hdc
, LAYOUT_RTL
);
274 if (!pGetLayout( hdc
))
276 win_skip( "SetLayout not supported\n" );
281 ret
= GetMapMode( hdc
);
282 ok(ret
== MM_ANISOTROPIC
, "expected MM_ANISOTROPIC, got %d\n", ret
);
283 ret
= pGetLayout( hdc
);
284 ok(ret
== LAYOUT_RTL
, "got %x\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 %s\n", wine_dbgstr_rect( &ret_rc
));
314 SetLayout( hdc
, LAYOUT_LTR
);
315 SetRect( &rc
, 80, 10, 90, 20 );
316 GetClipRgn( hdc
, hrgn
);
317 GetRgnBox( hrgn
, &ret_rc
);
318 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc
));
319 GetClipBox( hdc
, &ret_rc
);
320 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc
));
321 IntersectClipRect( hdc
, 80, 10, 85, 20 );
322 SetLayout( hdc
, LAYOUT_RTL
);
323 SetRect( &rc
, 15, 10, 20, 20 );
324 GetClipRgn( hdc
, hrgn
);
325 GetRgnBox( hrgn
, &ret_rc
);
326 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc
));
327 GetClipBox( hdc
, &ret_rc
);
328 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc
));
329 SetRectRgn( hrgn
, 60, 10, 80, 20 );
330 SetLayout( hdc
, LAYOUT_LTR
);
331 ExtSelectClipRgn( hdc
, hrgn
, RGN_OR
);
332 SetLayout( hdc
, LAYOUT_RTL
);
333 SetRect( &rc
, 15, 10, 40, 20 );
334 GetClipRgn( hdc
, hrgn
);
335 GetRgnBox( hrgn
, &ret_rc
);
336 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc
));
337 GetClipBox( hdc
, &ret_rc
);
338 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc
));
340 /* OffsetClipRgn mirrors too */
341 OffsetClipRgn( hdc
, 5, 5 );
342 OffsetRect( &rc
, 5, 5 );
343 GetClipRgn( hdc
, hrgn
);
344 GetRgnBox( hrgn
, &ret_rc
);
345 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc
));
347 /* GetRandomRgn returns the raw region */
350 SetRect( &rc
, 55, 15, 80, 25 );
351 pGetRandomRgn( hdc
, hrgn
, 1 );
352 GetRgnBox( hrgn
, &ret_rc
);
353 ok( EqualRect( &rc
, &ret_rc
), "wrong clip box %s\n", wine_dbgstr_rect( &ret_rc
));
356 SetMapMode(hdc
, MM_LOMETRIC
);
357 ret
= GetMapMode( hdc
);
358 ok(ret
== MM_ANISOTROPIC
, "expected MM_ANISOTROPIC, got %d\n", ret
);
360 expect_viewport_ext(hdc
, res_x
, -res_y
);
361 ok( GetWindowExtEx( hdc
, &size
), "GetWindowExtEx failed\n" );
362 ok( rough_match( size
.cx
, size_cx
* 10 ) ||
363 rough_match( size
.cx
, MulDiv( res_x
, 254, dpi_x
)), /* Vista uses a more precise method */
364 "expected cx %d or %d, got %d\n", size_cx
* 10, MulDiv( res_x
, 254, dpi_x
), size
.cx
);
365 ok( rough_match( size
.cy
, size_cy
* 10 ) ||
366 rough_match( size
.cy
, MulDiv( res_y
, 254, dpi_y
)), /* Vista uses a more precise method */
367 "expected cy %d or %d, got %d\n", size_cy
* 10, MulDiv( res_y
, 254, dpi_y
), size
.cy
);
368 expect_world_transform(hdc
, 1.0, 1.0);
369 expect_LPtoDP(hdc
, -MulDiv(1000 / 10, res_x
, size_cx
) + 99, -MulDiv(1000 / 10, res_y
, size_cy
));
371 SetMapMode(hdc
, MM_TEXT
);
372 ret
= GetMapMode( hdc
);
373 ok(ret
== MM_ANISOTROPIC
, "expected MM_ANISOTROPIC, got %d\n", ret
);
374 SetLayout( hdc
, LAYOUT_LTR
);
375 ret
= GetMapMode( hdc
);
376 ok(ret
== MM_ANISOTROPIC
, "expected MM_ANISOTROPIC, got %d\n", ret
);
377 SetMapMode(hdc
, MM_TEXT
);
378 ret
= GetMapMode( hdc
);
379 ok(ret
== MM_TEXT
, "expected MM_TEXT, got %d\n", ret
);
382 DeleteObject( bitmap
);
385 static void test_modify_world_transform(void)
390 ret
= SetGraphicsMode(hdc
, GM_ADVANCED
);
391 ok(ret
, "ret = %d\n", ret
);
393 ret
= ModifyWorldTransform(hdc
, NULL
, MWT_IDENTITY
);
394 ok(ret
, "ret = %d\n", ret
);
396 ret
= ModifyWorldTransform(hdc
, NULL
, MWT_LEFTMULTIPLY
);
397 ok(!ret
, "ret = %d\n", ret
);
399 ret
= ModifyWorldTransform(hdc
, NULL
, MWT_RIGHTMULTIPLY
);
400 ok(!ret
, "ret = %d\n", ret
);
405 static void test_SetWindowExt(HDC hdc
, LONG cx
, LONG cy
, LONG expected_vp_cx
, LONG expected_vp_cy
)
407 SIZE windowExt
, viewportExt
;
408 POINT windowOrg
, windowOrgAfter
, viewportOrg
, viewportOrgAfter
;
410 GetWindowOrgEx(hdc
, &windowOrg
);
411 GetViewportOrgEx(hdc
, &viewportOrg
);
413 SetWindowExtEx(hdc
, cx
, cy
, NULL
);
414 GetWindowExtEx(hdc
, &windowExt
);
415 ok(windowExt
.cx
== cx
&& windowExt
.cy
== cy
,
416 "Window extension: Expected %dx%d, got %dx%d\n",
417 cx
, cy
, windowExt
.cx
, windowExt
.cy
);
419 GetViewportExtEx(hdc
, &viewportExt
);
420 ok(rough_match(viewportExt
.cx
, expected_vp_cx
) && rough_match(viewportExt
.cy
, expected_vp_cy
),
421 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
422 expected_vp_cx
, expected_vp_cy
, viewportExt
.cx
, viewportExt
.cy
);
424 GetWindowOrgEx(hdc
, &windowOrgAfter
);
425 ok(windowOrg
.x
== windowOrgAfter
.x
&& windowOrg
.y
== windowOrgAfter
.y
,
426 "Window origin changed from (%d,%d) to (%d,%d)\n",
427 windowOrg
.x
, windowOrg
.y
, windowOrgAfter
.x
, windowOrgAfter
.y
);
429 GetViewportOrgEx(hdc
, &viewportOrgAfter
);
430 ok(viewportOrg
.x
== viewportOrgAfter
.x
&& viewportOrg
.y
== viewportOrgAfter
.y
,
431 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
432 viewportOrg
.x
, viewportOrg
.y
, viewportOrgAfter
.x
, viewportOrgAfter
.y
);
435 static void test_SetViewportExt(HDC hdc
, LONG cx
, LONG cy
, LONG expected_vp_cx
, LONG expected_vp_cy
)
437 SIZE windowExt
, windowExtAfter
, viewportExt
;
438 POINT windowOrg
, windowOrgAfter
, viewportOrg
, viewportOrgAfter
;
440 GetWindowOrgEx(hdc
, &windowOrg
);
441 GetViewportOrgEx(hdc
, &viewportOrg
);
442 GetWindowExtEx(hdc
, &windowExt
);
444 SetViewportExtEx(hdc
, cx
, cy
, NULL
);
445 GetViewportExtEx(hdc
, &viewportExt
);
446 ok(rough_match(viewportExt
.cx
, expected_vp_cx
) && rough_match(viewportExt
.cy
, expected_vp_cy
),
447 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
448 expected_vp_cx
, expected_vp_cy
, viewportExt
.cx
, viewportExt
.cy
);
450 GetWindowExtEx(hdc
, &windowExtAfter
);
451 ok(windowExt
.cx
== windowExtAfter
.cx
&& windowExt
.cy
== windowExtAfter
.cy
,
452 "Window extension changed from %dx%d to %dx%d\n",
453 windowExt
.cx
, windowExt
.cy
, windowExtAfter
.cx
, windowExtAfter
.cy
);
455 GetWindowOrgEx(hdc
, &windowOrgAfter
);
456 ok(windowOrg
.x
== windowOrgAfter
.x
&& windowOrg
.y
== windowOrgAfter
.y
,
457 "Window origin changed from (%d,%d) to (%d,%d)\n",
458 windowOrg
.x
, windowOrg
.y
, windowOrgAfter
.x
, windowOrgAfter
.y
);
460 GetViewportOrgEx(hdc
, &viewportOrgAfter
);
461 ok(viewportOrg
.x
== viewportOrgAfter
.x
&& viewportOrg
.y
== viewportOrgAfter
.y
,
462 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
463 viewportOrg
.x
, viewportOrg
.y
, viewportOrgAfter
.x
, viewportOrgAfter
.y
);
466 static void test_isotropic_mapping(void)
471 SetMapMode(hdc
, MM_ISOTROPIC
);
473 /* MM_ISOTROPIC is set up like MM_LOMETRIC.
474 Initial values after SetMapMode():
477 Windows 9x: Windows NT:
478 Window Ext: 254 x -254 HORZSIZE*10 x VERTSIZE*10
479 Viewport Ext: LOGPIXELSX x LOGPIXELSY HORZRES x -VERTRES
481 To test without rounding errors, we have to use multiples of
485 GetWindowExtEx(hdc
, &win
);
486 GetViewportExtEx(hdc
, &vp
);
488 test_SetViewportExt(hdc
, 10 * vp
.cx
, 10 * vp
.cy
, 10 * vp
.cx
, 10 * vp
.cy
);
489 test_SetWindowExt(hdc
, win
.cx
, win
.cy
, 10 * vp
.cx
, 10 * vp
.cy
);
490 test_SetWindowExt(hdc
, 2 * win
.cx
, win
.cy
, 10 * vp
.cx
, 5 * vp
.cy
);
491 test_SetWindowExt(hdc
, win
.cx
, win
.cy
, 5 * vp
.cx
, 5 * vp
.cy
);
492 test_SetViewportExt(hdc
, 4 * vp
.cx
, 2 * vp
.cy
, 2 * vp
.cx
, 2 * vp
.cy
);
493 test_SetViewportExt(hdc
, vp
.cx
, 2 * vp
.cy
, vp
.cx
, vp
.cy
);
494 test_SetViewportExt(hdc
, 2 * vp
.cx
, 2 * vp
.cy
, 2 * vp
.cx
, 2 * vp
.cy
);
495 test_SetViewportExt(hdc
, 4 * vp
.cx
, 2 * vp
.cy
, 2 * vp
.cx
, 2 * vp
.cy
);
496 test_SetWindowExt(hdc
, 4 * win
.cx
, 2 * win
.cy
, 2 * vp
.cx
, vp
.cy
);
497 test_SetViewportExt(hdc
, -2 * vp
.cx
, -4 * vp
.cy
, -2 * vp
.cx
, -vp
.cy
);
498 test_SetViewportExt(hdc
, -2 * vp
.cx
, -1 * vp
.cy
, -2 * vp
.cx
, -vp
.cy
);
499 test_SetWindowExt(hdc
, -4 * win
.cx
, -2 * win
.cy
, -2 * vp
.cx
, -vp
.cy
);
500 test_SetWindowExt(hdc
, 4 * win
.cx
, -4 * win
.cy
, -vp
.cx
, -vp
.cy
);
505 static void test_setvirtualresolution(void)
507 HDC hdc
= CreateICA("DISPLAY", NULL
, NULL
, NULL
);
509 INT horz_res
= GetDeviceCaps(hdc
, HORZRES
);
510 INT horz_size
= GetDeviceCaps(hdc
, HORZSIZE
);
511 INT log_pixels_x
= GetDeviceCaps(hdc
, LOGPIXELSX
);
512 SIZE orig_lometric_vp
, orig_lometric_wnd
;
514 if(!pSetVirtualResolution
)
516 win_skip("Don't have SetVirtualResolution\n");
520 /* Get the true resolution limits */
521 SetMapMode(hdc
, MM_LOMETRIC
);
522 GetViewportExtEx(hdc
, &orig_lometric_vp
);
523 GetWindowExtEx(hdc
, &orig_lometric_wnd
);
524 SetMapMode(hdc
, MM_TEXT
);
526 r
= pSetVirtualResolution(hdc
, 4000, 1000, 400, 200); /* 10 pix/mm x 5 pix/mm */
527 ok(r
== TRUE
, "got %d\n", r
);
528 expect_LPtoDP(hdc
, 1000, 1000);
529 expect_viewport_ext(hdc
, 1, 1);
530 expect_window_ext(hdc
, 1, 1);
532 SetMapMode(hdc
, MM_LOMETRIC
);
533 expect_LPtoDP(hdc
, 1000, -500);
534 expect_viewport_ext(hdc
, 4000, -1000);
535 expect_window_ext(hdc
, 4000, 2000);
537 /* Doesn't change the device caps */
538 ok(horz_res
== GetDeviceCaps(hdc
, HORZRES
), "horz_res changed\n");
539 ok(horz_size
== GetDeviceCaps(hdc
, HORZSIZE
), "horz_size changed\n");
540 ok(log_pixels_x
== GetDeviceCaps(hdc
, LOGPIXELSX
), "log_pixels_x changed\n");
542 r
= pSetVirtualResolution(hdc
, 8000, 1000, 400, 200); /* 20 pix/mm x 5 pix/mm */
543 ok(r
== TRUE
, "got %d\n", r
);
544 expect_LPtoDP(hdc
, 1000, -500); /* No change, need to re-set the mapping mode */
545 SetMapMode(hdc
, MM_TEXT
);
546 SetMapMode(hdc
, MM_LOMETRIC
);
547 expect_LPtoDP(hdc
, 2000, -500);
548 expect_viewport_ext(hdc
, 8000, -1000);
549 expect_window_ext(hdc
, 4000, 2000);
551 r
= pSetVirtualResolution(hdc
, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
552 ok(r
== TRUE
, "got %d\n", r
);
553 SetMapMode(hdc
, MM_TEXT
);
554 SetMapMode(hdc
, MM_LOMETRIC
);
555 expect_LPtoDP(hdc
, 4000, -500);
556 expect_viewport_ext(hdc
, 8000, -1000);
557 expect_window_ext(hdc
, 2000, 2000);
559 r
= pSetVirtualResolution(hdc
, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
560 ok(r
== TRUE
, "got %d\n", r
);
561 SetMapMode(hdc
, MM_TEXT
);
562 SetMapMode(hdc
, MM_LOMETRIC
);
563 expect_LPtoDP(hdc
, 4000, -500);
564 expect_viewport_ext(hdc
, 8000, -1000);
565 expect_window_ext(hdc
, 2000, 2000);
567 r
= pSetVirtualResolution(hdc
, 8000, 2000, 200, 200); /* 40 pix/mm x 10 pix/mm */
568 ok(r
== TRUE
, "got %d\n", r
);
569 SetMapMode(hdc
, MM_TEXT
);
570 SetMapMode(hdc
, MM_LOMETRIC
);
571 expect_LPtoDP(hdc
, 4000, -1000);
572 expect_viewport_ext(hdc
, 8000, -2000);
573 expect_window_ext(hdc
, 2000, 2000);
575 r
= pSetVirtualResolution(hdc
, 0, 0, 10, 0); /* Error */
576 ok(r
== FALSE
, "got %d\n", r
);
577 SetMapMode(hdc
, MM_TEXT
);
578 SetMapMode(hdc
, MM_LOMETRIC
);
579 expect_LPtoDP(hdc
, 4000, -1000);
580 expect_viewport_ext(hdc
, 8000, -2000);
581 expect_window_ext(hdc
, 2000, 2000);
583 r
= pSetVirtualResolution(hdc
, 0, 0, 0, 0); /* Reset to true resolution */
584 ok(r
== TRUE
, "got %d\n", r
);
585 SetMapMode(hdc
, MM_TEXT
);
586 SetMapMode(hdc
, MM_LOMETRIC
);
587 expect_viewport_ext(hdc
, orig_lometric_vp
.cx
, orig_lometric_vp
.cy
);
588 expect_window_ext(hdc
, orig_lometric_wnd
.cx
, orig_lometric_wnd
.cy
);
594 static inline void expect_identity(int line
, XFORM
*xf
)
596 ok(xf
->eM11
== 1.0, "%d: got %f\n", line
, xf
->eM11
);
597 ok(xf
->eM12
== 0.0, "%d: got %f\n", line
, xf
->eM12
);
598 ok(xf
->eM21
== 0.0, "%d: got %f\n", line
, xf
->eM21
);
599 ok(xf
->eM22
== 1.0, "%d: got %f\n", line
, xf
->eM22
);
600 ok(xf
->eDx
== 0.0, "%d: got %f\n", line
, xf
->eDx
);
601 ok(xf
->eDy
== 0.0, "%d: got %f\n", line
, xf
->eDy
);
604 static inline void xform_near_match(int line
, XFORM
*got
, XFORM
*expect
)
606 ok(fabs(got
->eM11
- expect
->eM11
) < 0.001, "%d: got %f expect %f\n", line
, got
->eM11
, expect
->eM11
);
607 ok(fabs(got
->eM12
- expect
->eM12
) < 0.001, "%d: got %f expect %f\n", line
, got
->eM12
, expect
->eM12
);
608 ok(fabs(got
->eM21
- expect
->eM21
) < 0.001, "%d: got %f expect %f\n", line
, got
->eM21
, expect
->eM21
);
609 ok(fabs(got
->eM22
- expect
->eM22
) < 0.001, "%d: got %f expect %f\n", line
, got
->eM22
, expect
->eM22
);
610 ok(fabs(got
->eDx
- expect
->eDx
) < 0.001, "%d: got %f expect %f\n", line
, got
->eDx
, expect
->eDx
);
611 ok(fabs(got
->eDy
- expect
->eDy
) < 0.001, "%d: got %f expect %f\n", line
, got
->eDy
, expect
->eDy
);
615 static void test_gettransform(void)
617 HDC hdc
= CreateICA("DISPLAY", NULL
, NULL
, NULL
);
620 SIZE lometric_vp
, lometric_wnd
;
624 win_skip("Don't have GetTransform\n");
628 r
= pGetTransform(hdc
, 0x203, &xform
); /* World -> Page */
629 ok(r
== TRUE
, "got %d\n", r
);
630 expect_identity(__LINE__
, &xform
);
631 r
= pGetTransform(hdc
, 0x304, &xform
); /* Page -> Device */
632 ok(r
== TRUE
, "got %d\n", r
);
633 expect_identity(__LINE__
, &xform
);
634 r
= pGetTransform(hdc
, 0x204, &xform
); /* World -> Device */
635 ok(r
== TRUE
, "got %d\n", r
);
636 expect_identity(__LINE__
, &xform
);
637 r
= pGetTransform(hdc
, 0x402, &xform
); /* Device -> World */
638 ok(r
== TRUE
, "got %d\n", r
);
639 expect_identity(__LINE__
, &xform
);
641 SetMapMode(hdc
, MM_LOMETRIC
);
642 GetViewportExtEx(hdc
, &lometric_vp
);
643 GetWindowExtEx(hdc
, &lometric_wnd
);
645 r
= pGetTransform(hdc
, 0x203, &xform
); /* World -> Page */
646 ok(r
== TRUE
, "got %d\n", r
);
647 expect_identity(__LINE__
, &xform
);
649 r
= pGetTransform(hdc
, 0x304, &xform
); /* Page -> Device */
650 ok(r
== TRUE
, "got %d\n", r
);
651 expect
.eM11
= (FLOAT
) lometric_vp
.cx
/ lometric_wnd
.cx
;
652 expect
.eM12
= expect
.eM21
= 0.0;
653 expect
.eM22
= (FLOAT
) lometric_vp
.cy
/ lometric_wnd
.cy
;
654 expect
.eDx
= expect
.eDy
= 0.0;
655 xform_near_match(__LINE__
, &xform
, &expect
);
657 r
= pGetTransform(hdc
, 0x204, &xform
); /* World -> Device */
658 ok(r
== TRUE
, "got %d\n", r
);
659 xform_near_match(__LINE__
, &xform
, &expect
);
661 r
= pGetTransform(hdc
, 0x402, &xform
); /* Device -> World */
662 ok(r
== TRUE
, "got %d\n", r
);
663 expect
.eM11
= (FLOAT
) lometric_wnd
.cx
/ lometric_vp
.cx
;
664 expect
.eM22
= (FLOAT
) lometric_wnd
.cy
/ lometric_vp
.cy
;
665 xform_near_match(__LINE__
, &xform
, &expect
);
668 SetGraphicsMode(hdc
, GM_ADVANCED
);
672 SetWorldTransform(hdc
, &expect
);
673 r
= pGetTransform(hdc
, 0x203, &xform
); /* World -> Page */
674 ok(r
== TRUE
, "got %d\n", r
);
675 xform_near_match(__LINE__
, &xform
, &expect
);
677 r
= pGetTransform(hdc
, 0x304, &xform
); /* Page -> Device */
678 ok(r
== TRUE
, "got %d\n", r
);
679 expect
.eM11
= (FLOAT
) lometric_vp
.cx
/ lometric_wnd
.cx
;
680 expect
.eM22
= (FLOAT
) lometric_vp
.cy
/ lometric_wnd
.cy
;
681 xform_near_match(__LINE__
, &xform
, &expect
);
683 r
= pGetTransform(hdc
, 0x204, &xform
); /* World -> Device */
684 ok(r
== TRUE
, "got %d\n", r
);
687 xform_near_match(__LINE__
, &xform
, &expect
);
689 r
= pGetTransform(hdc
, 0x402, &xform
); /* Device -> World */
690 ok(r
== TRUE
, "got %d\n", r
);
691 expect
.eM11
= 1 / expect
.eM11
;
692 expect
.eM22
= 1 / expect
.eM22
;
693 xform_near_match(__LINE__
, &xform
, &expect
);
695 r
= pGetTransform(hdc
, 0x102, &xform
);
696 ok(r
== FALSE
, "got %d\n", r
);
697 r
= pGetTransform(hdc
, 0x103, &xform
);
698 ok(r
== FALSE
, "got %d\n", r
);
699 r
= pGetTransform(hdc
, 0x104, &xform
);
700 ok(r
== FALSE
, "got %d\n", r
);
701 r
= pGetTransform(hdc
, 0x202, &xform
);
702 ok(r
== FALSE
, "got %d\n", r
);
703 r
= pGetTransform(hdc
, 0x302, &xform
);
704 ok(r
== FALSE
, "got %d\n", r
);
705 r
= pGetTransform(hdc
, 0x303, &xform
);
706 ok(r
== FALSE
, "got %d\n", r
);
707 r
= pGetTransform(hdc
, 0x403, &xform
);
708 ok(r
== FALSE
, "got %d\n", r
);
709 r
= pGetTransform(hdc
, 0x404, &xform
);
710 ok(r
== FALSE
, "got %d\n", r
);
711 r
= pGetTransform(hdc
, 0xffff, &xform
);
712 ok(r
== FALSE
, "got %d\n", r
);
717 HMODULE mod
= GetModuleHandleA("gdi32.dll");
718 pGetLayout
= (void *)GetProcAddress( mod
, "GetLayout" );
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();