gdi32: Mirror the clip region when the DC is mirrored, with tests.
[wine/multimedia.git] / dlls / gdi32 / tests / mapping.c
blobc4a97acb5ddd35009446a4e95d027b89e264f637
1 /*
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
22 #include <assert.h>
23 #include <stdio.h>
24 #include <math.h>
26 #include "wine/test.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winerror.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) \
41 { \
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) \
49 { \
50 BOOL _ret; \
51 XFORM _xform; \
52 SetLastError(0xdeadbeef); \
53 _ret = GetWorldTransform(_hdc, &_xform); \
54 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) \
55 { \
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); \
63 } \
66 #define expect_dc_ext(_func, _hdc, _cx, _cy) \
67 { \
68 BOOL _ret; \
69 SIZE _size; \
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)
82 BOOL is_win9x;
83 HDC hdc;
84 INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
85 XFORM xform;
86 SIZE size;
88 SetLastError(0xdeadbeef);
89 GetWorldTransform(0, NULL);
90 is_win9x = GetLastError() == ERROR_CALL_NOT_IMPLEMENTED;
92 hdc = CreateCompatibleDC(0);
94 xform.eM11 = 1.0f;
95 xform.eM12 = 0.0f;
96 xform.eM21 = 0.0f;
97 xform.eM22 = 1.0f;
98 xform.eDx = 0.0f;
99 xform.eDy = 0.0f;
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);
121 if (is_win9x)
123 expect_viewport_ext(hdc, dpi_x, dpi_y);
124 expect_window_ext(hdc, 254, -254);
126 else
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);
150 if (!ret)
152 DeleteDC(hdc);
153 skip("GM_ADVANCED is not supported on this platform\n");
154 return;
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 */
163 xform.eM11 = 1.0f;
164 xform.eM12 = 2.0f;
165 xform.eM21 = 1.0f;
166 xform.eM22 = 2.0f;
167 xform.eDx = 0.0f;
168 xform.eDy = 0.0f;
169 ret = SetWorldTransform(hdc, &xform);
170 ok(!ret ||
171 broken(ret), /* NT4 */
172 "SetWorldTransform should fail with an invalid xform\n");
174 xform.eM11 = 20.0f;
175 xform.eM12 = 0.0f;
176 xform.eM21 = 0.0f;
177 xform.eM22 = 20.0f;
178 xform.eDx = 0.0f;
179 xform.eDy = 0.0f;
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);
223 DeleteDC(hdc);
226 static void test_dc_layout(void)
228 INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
229 SIZE size;
230 POINT pt;
231 HBITMAP bitmap;
232 RECT rc, ret_rc;
233 HDC hdc;
234 HRGN hrgn;
236 if (!pGetLayout || !pSetLayout)
238 win_skip( "Don't have SetLayout\n" );
239 return;
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" );
264 DeleteDC(hdc);
265 return;
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 );
280 if (pGetTransform)
282 XFORM xform;
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 SetRectRgn( hrgn, 60, 10, 80, 20 );
317 pSetLayout( hdc, LAYOUT_LTR );
318 ExtSelectClipRgn( hdc, hrgn, RGN_OR );
319 pSetLayout( hdc, LAYOUT_RTL );
320 SetRect( &rc, 15, 10, 40, 20 );
321 GetClipRgn( hdc, hrgn );
322 GetRgnBox( hrgn, &ret_rc );
323 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
324 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
326 /* OffsetClipRgn mirrors too */
327 OffsetClipRgn( hdc, 5, 5 );
328 OffsetRect( &rc, 5, 5 );
329 GetClipRgn( hdc, hrgn );
330 GetRgnBox( hrgn, &ret_rc );
331 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
332 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
334 /* GetRandomRgn returns the raw region */
335 if (pGetRandomRgn)
337 SetRect( &rc, 55, 15, 80, 25 );
338 pGetRandomRgn( hdc, hrgn, 1 );
339 GetRgnBox( hrgn, &ret_rc );
340 ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
341 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
344 SetMapMode(hdc, MM_LOMETRIC);
345 ret = GetMapMode( hdc );
346 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
348 expect_viewport_ext(hdc, res_x, -res_y);
349 ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
350 ok( rough_match( size.cx, size_cx * 10 ) ||
351 rough_match( size.cx, MulDiv( res_x, 254, dpi_x )), /* Vista uses a more precise method */
352 "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
353 ok( rough_match( size.cy, size_cy * 10 ) ||
354 rough_match( size.cy, MulDiv( res_y, 254, dpi_y )), /* Vista uses a more precise method */
355 "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
356 expect_world_transform(hdc, 1.0, 1.0);
357 expect_LPtoDP(hdc, -MulDiv(1000 / 10, res_x, size_cx) + 99, -MulDiv(1000 / 10, res_y, size_cy));
359 SetMapMode(hdc, MM_TEXT);
360 ret = GetMapMode( hdc );
361 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
362 pSetLayout( hdc, LAYOUT_LTR );
363 ret = GetMapMode( hdc );
364 ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
365 SetMapMode(hdc, MM_TEXT);
366 ret = GetMapMode( hdc );
367 ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
369 DeleteDC(hdc);
370 DeleteObject( bitmap );
373 static void test_modify_world_transform(void)
375 HDC hdc = GetDC(0);
376 int ret;
378 ret = SetGraphicsMode(hdc, GM_ADVANCED);
379 if(!ret) /* running in win9x so quit */
381 ReleaseDC(0, hdc);
382 skip("GM_ADVANCED is not supported on this platform\n");
383 return;
386 ret = ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
387 ok(ret, "ret = %d\n", ret);
389 ret = ModifyWorldTransform(hdc, NULL, MWT_LEFTMULTIPLY);
390 ok(!ret, "ret = %d\n", ret);
392 ret = ModifyWorldTransform(hdc, NULL, MWT_RIGHTMULTIPLY);
393 ok(!ret, "ret = %d\n", ret);
395 ReleaseDC(0, hdc);
398 static void test_SetWindowExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
400 SIZE windowExt, viewportExt;
401 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
403 GetWindowOrgEx(hdc, &windowOrg);
404 GetViewportOrgEx(hdc, &viewportOrg);
406 SetWindowExtEx(hdc, cx, cy, NULL);
407 GetWindowExtEx(hdc, &windowExt);
408 ok(windowExt.cx == cx && windowExt.cy == cy,
409 "Window extension: Expected %dx%d, got %dx%d\n",
410 cx, cy, windowExt.cx, windowExt.cy);
412 GetViewportExtEx(hdc, &viewportExt);
413 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
414 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
415 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
417 GetWindowOrgEx(hdc, &windowOrgAfter);
418 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
419 "Window origin changed from (%d,%d) to (%d,%d)\n",
420 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
422 GetViewportOrgEx(hdc, &viewportOrgAfter);
423 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
424 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
425 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
428 static void test_SetViewportExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
430 SIZE windowExt, windowExtAfter, viewportExt;
431 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
433 GetWindowOrgEx(hdc, &windowOrg);
434 GetViewportOrgEx(hdc, &viewportOrg);
435 GetWindowExtEx(hdc, &windowExt);
437 SetViewportExtEx(hdc, cx, cy, NULL);
438 GetViewportExtEx(hdc, &viewportExt);
439 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
440 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
441 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
443 GetWindowExtEx(hdc, &windowExtAfter);
444 ok(windowExt.cx == windowExtAfter.cx && windowExt.cy == windowExtAfter.cy,
445 "Window extension changed from %dx%d to %dx%d\n",
446 windowExt.cx, windowExt.cy, windowExtAfter.cx, windowExtAfter.cy);
448 GetWindowOrgEx(hdc, &windowOrgAfter);
449 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
450 "Window origin changed from (%d,%d) to (%d,%d)\n",
451 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
453 GetViewportOrgEx(hdc, &viewportOrgAfter);
454 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
455 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
456 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
459 static void test_isotropic_mapping(void)
461 SIZE win, vp;
462 HDC hdc = GetDC(0);
464 SetMapMode(hdc, MM_ISOTROPIC);
466 /* MM_ISOTROPIC is set up like MM_LOMETRIC.
467 Initial values after SetMapMode():
468 (1 inch = 25.4 mm)
470 Windows 9x: Windows NT:
471 Window Ext: 254 x -254 HORZSIZE*10 x VERTSIZE*10
472 Viewport Ext: LOGPIXELSX x LOGPIXELSY HORZRES x -VERTRES
474 To test without rounding errors, we have to use multiples of
475 these values!
478 GetWindowExtEx(hdc, &win);
479 GetViewportExtEx(hdc, &vp);
481 test_SetViewportExt(hdc, 10 * vp.cx, 10 * vp.cy, 10 * vp.cx, 10 * vp.cy);
482 test_SetWindowExt(hdc, win.cx, win.cy, 10 * vp.cx, 10 * vp.cy);
483 test_SetWindowExt(hdc, 2 * win.cx, win.cy, 10 * vp.cx, 5 * vp.cy);
484 test_SetWindowExt(hdc, win.cx, win.cy, 5 * vp.cx, 5 * vp.cy);
485 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
486 test_SetViewportExt(hdc, vp.cx, 2 * vp.cy, vp.cx, vp.cy);
487 test_SetViewportExt(hdc, 2 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
488 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
489 test_SetWindowExt(hdc, 4 * win.cx, 2 * win.cy, 2 * vp.cx, vp.cy);
490 test_SetViewportExt(hdc, -2 * vp.cx, -4 * vp.cy, -2 * vp.cx, -vp.cy);
491 test_SetViewportExt(hdc, -2 * vp.cx, -1 * vp.cy, -2 * vp.cx, -vp.cy);
492 test_SetWindowExt(hdc, -4 * win.cx, -2 * win.cy, -2 * vp.cx, -vp.cy);
493 test_SetWindowExt(hdc, 4 * win.cx, -4 * win.cy, -vp.cx, -vp.cy);
495 ReleaseDC(0, hdc);
498 static void test_setvirtualresolution(void)
500 HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
501 DWORD r;
502 INT horz_res = GetDeviceCaps(hdc, HORZRES);
503 INT horz_size = GetDeviceCaps(hdc, HORZSIZE);
504 INT log_pixels_x = GetDeviceCaps(hdc, LOGPIXELSX);
505 SIZE orig_lometric_vp, orig_lometric_wnd;
507 if(!pSetVirtualResolution)
509 win_skip("Don't have SetVirtualResolution\n");
510 return;
513 /* Get the true resolution limits */
514 SetMapMode(hdc, MM_LOMETRIC);
515 GetViewportExtEx(hdc, &orig_lometric_vp);
516 GetWindowExtEx(hdc, &orig_lometric_wnd);
517 SetMapMode(hdc, MM_TEXT);
519 r = pSetVirtualResolution(hdc, 4000, 1000, 400, 200); /* 10 pix/mm x 5 pix/mm */
520 ok(r == TRUE, "got %d\n", r);
521 expect_LPtoDP(hdc, 1000, 1000);
522 expect_viewport_ext(hdc, 1, 1);
523 expect_window_ext(hdc, 1, 1);
525 SetMapMode(hdc, MM_LOMETRIC);
526 expect_LPtoDP(hdc, 1000, -500);
527 expect_viewport_ext(hdc, 4000, -1000);
528 expect_window_ext(hdc, 4000, 2000);
530 /* Doesn't change the device caps */
531 ok(horz_res == GetDeviceCaps(hdc, HORZRES), "horz_res changed\n");
532 ok(horz_size == GetDeviceCaps(hdc, HORZSIZE), "horz_size changed\n");
533 ok(log_pixels_x == GetDeviceCaps(hdc, LOGPIXELSX), "log_pixels_x changed\n");
535 r = pSetVirtualResolution(hdc, 8000, 1000, 400, 200); /* 20 pix/mm x 5 pix/mm */
536 ok(r == TRUE, "got %d\n", r);
537 expect_LPtoDP(hdc, 1000, -500); /* No change, need to re-set the mapping mode */
538 SetMapMode(hdc, MM_TEXT);
539 SetMapMode(hdc, MM_LOMETRIC);
540 expect_LPtoDP(hdc, 2000, -500);
541 expect_viewport_ext(hdc, 8000, -1000);
542 expect_window_ext(hdc, 4000, 2000);
544 r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
545 ok(r == TRUE, "got %d\n", r);
546 SetMapMode(hdc, MM_TEXT);
547 SetMapMode(hdc, MM_LOMETRIC);
548 expect_LPtoDP(hdc, 4000, -500);
549 expect_viewport_ext(hdc, 8000, -1000);
550 expect_window_ext(hdc, 2000, 2000);
552 r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
553 ok(r == TRUE, "got %d\n", r);
554 SetMapMode(hdc, MM_TEXT);
555 SetMapMode(hdc, MM_LOMETRIC);
556 expect_LPtoDP(hdc, 4000, -500);
557 expect_viewport_ext(hdc, 8000, -1000);
558 expect_window_ext(hdc, 2000, 2000);
560 r = pSetVirtualResolution(hdc, 8000, 2000, 200, 200); /* 40 pix/mm x 10 pix/mm */
561 ok(r == TRUE, "got %d\n", r);
562 SetMapMode(hdc, MM_TEXT);
563 SetMapMode(hdc, MM_LOMETRIC);
564 expect_LPtoDP(hdc, 4000, -1000);
565 expect_viewport_ext(hdc, 8000, -2000);
566 expect_window_ext(hdc, 2000, 2000);
568 r = pSetVirtualResolution(hdc, 0, 0, 10, 0); /* Error */
569 ok(r == FALSE, "got %d\n", r);
570 SetMapMode(hdc, MM_TEXT);
571 SetMapMode(hdc, MM_LOMETRIC);
572 expect_LPtoDP(hdc, 4000, -1000);
573 expect_viewport_ext(hdc, 8000, -2000);
574 expect_window_ext(hdc, 2000, 2000);
576 r = pSetVirtualResolution(hdc, 0, 0, 0, 0); /* Reset to true resolution */
577 ok(r == TRUE, "got %d\n", r);
578 SetMapMode(hdc, MM_TEXT);
579 SetMapMode(hdc, MM_LOMETRIC);
580 expect_viewport_ext(hdc, orig_lometric_vp.cx, orig_lometric_vp.cy);
581 expect_window_ext(hdc, orig_lometric_wnd.cx, orig_lometric_wnd.cy);
583 DeleteDC(hdc);
587 static inline void expect_identity(int line, XFORM *xf)
589 ok(xf->eM11 == 1.0, "%d: got %f\n", line, xf->eM11);
590 ok(xf->eM12 == 0.0, "%d: got %f\n", line, xf->eM12);
591 ok(xf->eM21 == 0.0, "%d: got %f\n", line, xf->eM21);
592 ok(xf->eM22 == 1.0, "%d: got %f\n", line, xf->eM22);
593 ok(xf->eDx == 0.0, "%d: got %f\n", line, xf->eDx);
594 ok(xf->eDy == 0.0, "%d: got %f\n", line, xf->eDy);
597 static inline void xform_near_match(int line, XFORM *got, XFORM *expect)
599 ok(fabs(got->eM11 - expect->eM11) < 0.001, "%d: got %f expect %f\n", line, got->eM11, expect->eM11);
600 ok(fabs(got->eM12 - expect->eM12) < 0.001, "%d: got %f expect %f\n", line, got->eM12, expect->eM12);
601 ok(fabs(got->eM21 - expect->eM21) < 0.001, "%d: got %f expect %f\n", line, got->eM21, expect->eM21);
602 ok(fabs(got->eM22 - expect->eM22) < 0.001, "%d: got %f expect %f\n", line, got->eM22, expect->eM22);
603 ok(fabs(got->eDx - expect->eDx) < 0.001, "%d: got %f expect %f\n", line, got->eDx, expect->eDx);
604 ok(fabs(got->eDy - expect->eDy) < 0.001, "%d: got %f expect %f\n", line, got->eDy, expect->eDy);
608 static void test_gettransform(void)
610 HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
611 XFORM xform, expect;
612 BOOL r;
613 SIZE lometric_vp, lometric_wnd;
615 if(!pGetTransform)
617 win_skip("Don't have GetTransform\n");
618 return;
621 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
622 ok(r == TRUE, "got %d\n", r);
623 expect_identity(__LINE__, &xform);
624 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
625 ok(r == TRUE, "got %d\n", r);
626 expect_identity(__LINE__, &xform);
627 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
628 ok(r == TRUE, "got %d\n", r);
629 expect_identity(__LINE__, &xform);
630 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
631 ok(r == TRUE, "got %d\n", r);
632 expect_identity(__LINE__, &xform);
634 SetMapMode(hdc, MM_LOMETRIC);
635 GetViewportExtEx(hdc, &lometric_vp);
636 GetWindowExtEx(hdc, &lometric_wnd);
638 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
639 ok(r == TRUE, "got %d\n", r);
640 expect_identity(__LINE__, &xform);
642 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
643 ok(r == TRUE, "got %d\n", r);
644 expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
645 expect.eM12 = expect.eM21 = 0.0;
646 expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
647 expect.eDx = expect.eDy = 0.0;
648 xform_near_match(__LINE__, &xform, &expect);
650 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
651 ok(r == TRUE, "got %d\n", r);
652 xform_near_match(__LINE__, &xform, &expect);
654 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
655 ok(r == TRUE, "got %d\n", r);
656 expect.eM11 = (FLOAT) lometric_wnd.cx / lometric_vp.cx;
657 expect.eM22 = (FLOAT) lometric_wnd.cy / lometric_vp.cy;
658 xform_near_match(__LINE__, &xform, &expect);
661 SetGraphicsMode(hdc, GM_ADVANCED);
663 expect.eM11 = 10.0;
664 expect.eM22 = 20.0;
665 SetWorldTransform(hdc, &expect);
666 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
667 ok(r == TRUE, "got %d\n", r);
668 xform_near_match(__LINE__, &xform, &expect);
670 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
671 ok(r == TRUE, "got %d\n", r);
672 expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
673 expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
674 xform_near_match(__LINE__, &xform, &expect);
676 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
677 ok(r == TRUE, "got %d\n", r);
678 expect.eM11 *= 10.0;
679 expect.eM22 *= 20.0;
680 xform_near_match(__LINE__, &xform, &expect);
682 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
683 ok(r == TRUE, "got %d\n", r);
684 expect.eM11 = 1 / expect.eM11;
685 expect.eM22 = 1 / expect.eM22;
686 xform_near_match(__LINE__, &xform, &expect);
688 r = pGetTransform(hdc, 0x102, &xform);
689 ok(r == FALSE, "got %d\n", r);
690 r = pGetTransform(hdc, 0x103, &xform);
691 ok(r == FALSE, "got %d\n", r);
692 r = pGetTransform(hdc, 0x104, &xform);
693 ok(r == FALSE, "got %d\n", r);
694 r = pGetTransform(hdc, 0x202, &xform);
695 ok(r == FALSE, "got %d\n", r);
696 r = pGetTransform(hdc, 0x302, &xform);
697 ok(r == FALSE, "got %d\n", r);
698 r = pGetTransform(hdc, 0x303, &xform);
699 ok(r == FALSE, "got %d\n", r);
700 r = pGetTransform(hdc, 0x403, &xform);
701 ok(r == FALSE, "got %d\n", r);
702 r = pGetTransform(hdc, 0x404, &xform);
703 ok(r == FALSE, "got %d\n", r);
704 r = pGetTransform(hdc, 0xffff, &xform);
705 ok(r == FALSE, "got %d\n", r);
708 START_TEST(mapping)
710 HMODULE mod = GetModuleHandleA("gdi32.dll");
711 pGetLayout = (void *)GetProcAddress( mod, "GetLayout" );
712 pSetLayout = (void *)GetProcAddress( mod, "SetLayout" );
713 pGetRandomRgn = (void *)GetProcAddress( mod, "GetRandomRgn" );
714 pGetTransform = (void *)GetProcAddress( mod, "GetTransform" );
715 pSetVirtualResolution = (void *)GetProcAddress( mod, "SetVirtualResolution" );
717 test_modify_world_transform();
718 test_world_transform();
719 test_dc_layout();
720 test_isotropic_mapping();
721 test_setvirtualresolution();
722 test_gettransform();