gdi32: Support MWT_SET in NtGdiModifyWorldTransform.
[wine.git] / dlls / gdi32 / tests / mapping.c
blob90c9d5a6617d4a6854cfe76e9af9363ab66153d5
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 <stdio.h>
23 #include <math.h>
25 #include "wine/test.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winerror.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) \
39 { \
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) \
47 { \
48 BOOL _ret; \
49 XFORM _xform; \
50 SetLastError(0xdeadbeef); \
51 _ret = GetWorldTransform(_hdc, &_xform); \
52 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) \
53 { \
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); \
61 } \
64 #define expect_dc_ext(_func, _hdc, _cx, _cy) \
65 { \
66 BOOL _ret; \
67 SIZE _size; \
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)
80 HDC hdc;
81 INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
82 XFORM xform;
83 SIZE size;
85 hdc = CreateCompatibleDC(0);
87 xform.eM11 = 1.0f;
88 xform.eM12 = 0.0f;
89 xform.eM21 = 0.0f;
90 xform.eM22 = 1.0f;
91 xform.eDx = 0.0f;
92 xform.eDy = 0.0f;
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);
135 if (!ret)
137 DeleteDC(hdc);
138 skip("GM_ADVANCED is not supported on this platform\n");
139 return;
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 */
148 xform.eM11 = 1.0f;
149 xform.eM12 = 2.0f;
150 xform.eM21 = 1.0f;
151 xform.eM22 = 2.0f;
152 xform.eDx = 0.0f;
153 xform.eDy = 0.0f;
154 ret = SetWorldTransform(hdc, &xform);
155 ok(!ret ||
156 broken(ret), /* NT4 */
157 "SetWorldTransform should fail with an invalid xform\n");
159 xform.eM11 = 20.0f;
160 xform.eM12 = 0.0f;
161 xform.eM21 = 0.0f;
162 xform.eM22 = 20.0f;
163 xform.eDx = 0.0f;
164 xform.eDy = 0.0f;
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);
236 DeleteDC(hdc);
239 static void test_dc_layout(void)
241 INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
242 SIZE size;
243 POINT pt;
244 HBITMAP bitmap;
245 RECT rc, ret_rc;
246 HDC hdc;
247 HRGN hrgn;
249 if (!pGetLayout)
251 win_skip( "Don't have GetLayout\n" );
252 return;
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" );
277 DeleteDC(hdc);
278 return;
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 );
295 if (pGetTransform)
297 XFORM xform;
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 */
348 if (pGetRandomRgn)
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);
381 DeleteDC(hdc);
382 DeleteObject( bitmap );
385 static void test_modify_world_transform(void)
387 HDC hdc = GetDC(0);
388 XFORM xform, xform2;
389 int ret;
391 ret = SetGraphicsMode(hdc, GM_ADVANCED);
392 ok(ret, "ret = %d\n", ret);
394 ret = ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
395 ok(ret, "ret = %d\n", ret);
397 ret = ModifyWorldTransform(hdc, NULL, MWT_LEFTMULTIPLY);
398 ok(!ret, "ret = %d\n", ret);
400 ret = ModifyWorldTransform(hdc, NULL, MWT_RIGHTMULTIPLY);
401 ok(!ret, "ret = %d\n", ret);
403 xform.eM11 = 2;
404 xform.eM12 = 0;
405 xform.eM21 = 0;
406 xform.eM22 = 1;
407 xform.eDx = xform.eDy = 0;
408 ret = ModifyWorldTransform(hdc, &xform, 4);
409 ok(ret, "ModifyWorldTransform failed\n");
411 memset(&xform2, 0xcc, sizeof(xform2));
412 ret = GetWorldTransform(hdc, &xform2);
413 ok(ret, "GetWorldTransform failed\n");
414 ok(!memcmp(&xform, &xform2, sizeof(xform)), "unexpected xform\n");
416 xform.eM11 = 1;
417 xform.eM12 = 1;
418 xform.eM21 = 1;
419 xform.eM22 = 1;
420 xform.eDx = xform.eDy = 0;
421 ret = ModifyWorldTransform(hdc, &xform, 4);
422 ok(!ret, "ModifyWorldTransform succeeded\n");
424 ReleaseDC(0, hdc);
427 static void test_SetWindowExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
429 SIZE windowExt, viewportExt;
430 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
432 GetWindowOrgEx(hdc, &windowOrg);
433 GetViewportOrgEx(hdc, &viewportOrg);
435 SetWindowExtEx(hdc, cx, cy, NULL);
436 GetWindowExtEx(hdc, &windowExt);
437 ok(windowExt.cx == cx && windowExt.cy == cy,
438 "Window extension: Expected %dx%d, got %dx%d\n",
439 cx, cy, windowExt.cx, windowExt.cy);
441 GetViewportExtEx(hdc, &viewportExt);
442 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
443 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
444 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
446 GetWindowOrgEx(hdc, &windowOrgAfter);
447 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
448 "Window origin changed from (%d,%d) to (%d,%d)\n",
449 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
451 GetViewportOrgEx(hdc, &viewportOrgAfter);
452 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
453 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
454 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
457 static void test_SetViewportExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy)
459 SIZE windowExt, windowExtAfter, viewportExt;
460 POINT windowOrg, windowOrgAfter, viewportOrg, viewportOrgAfter;
462 GetWindowOrgEx(hdc, &windowOrg);
463 GetViewportOrgEx(hdc, &viewportOrg);
464 GetWindowExtEx(hdc, &windowExt);
466 SetViewportExtEx(hdc, cx, cy, NULL);
467 GetViewportExtEx(hdc, &viewportExt);
468 ok(rough_match(viewportExt.cx, expected_vp_cx) && rough_match(viewportExt.cy, expected_vp_cy),
469 "Viewport extents have not been properly adjusted: Expected %dx%d, got %dx%d\n",
470 expected_vp_cx, expected_vp_cy, viewportExt.cx, viewportExt.cy);
472 GetWindowExtEx(hdc, &windowExtAfter);
473 ok(windowExt.cx == windowExtAfter.cx && windowExt.cy == windowExtAfter.cy,
474 "Window extension changed from %dx%d to %dx%d\n",
475 windowExt.cx, windowExt.cy, windowExtAfter.cx, windowExtAfter.cy);
477 GetWindowOrgEx(hdc, &windowOrgAfter);
478 ok(windowOrg.x == windowOrgAfter.x && windowOrg.y == windowOrgAfter.y,
479 "Window origin changed from (%d,%d) to (%d,%d)\n",
480 windowOrg.x, windowOrg.y, windowOrgAfter.x, windowOrgAfter.y);
482 GetViewportOrgEx(hdc, &viewportOrgAfter);
483 ok(viewportOrg.x == viewportOrgAfter.x && viewportOrg.y == viewportOrgAfter.y,
484 "Viewport origin changed from (%d,%d) to (%d,%d)\n",
485 viewportOrg.x, viewportOrg.y, viewportOrgAfter.x, viewportOrgAfter.y);
488 static void test_isotropic_mapping(void)
490 SIZE win, vp;
491 HDC hdc = GetDC(0);
493 SetMapMode(hdc, MM_ISOTROPIC);
495 /* MM_ISOTROPIC is set up like MM_LOMETRIC.
496 Initial values after SetMapMode():
497 (1 inch = 25.4 mm)
499 Windows 9x: Windows NT:
500 Window Ext: 254 x -254 HORZSIZE*10 x VERTSIZE*10
501 Viewport Ext: LOGPIXELSX x LOGPIXELSY HORZRES x -VERTRES
503 To test without rounding errors, we have to use multiples of
504 these values!
507 GetWindowExtEx(hdc, &win);
508 GetViewportExtEx(hdc, &vp);
510 test_SetViewportExt(hdc, 10 * vp.cx, 10 * vp.cy, 10 * vp.cx, 10 * vp.cy);
511 test_SetWindowExt(hdc, win.cx, win.cy, 10 * vp.cx, 10 * vp.cy);
512 test_SetWindowExt(hdc, 2 * win.cx, win.cy, 10 * vp.cx, 5 * vp.cy);
513 test_SetWindowExt(hdc, win.cx, win.cy, 5 * vp.cx, 5 * vp.cy);
514 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
515 test_SetViewportExt(hdc, vp.cx, 2 * vp.cy, vp.cx, vp.cy);
516 test_SetViewportExt(hdc, 2 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
517 test_SetViewportExt(hdc, 4 * vp.cx, 2 * vp.cy, 2 * vp.cx, 2 * vp.cy);
518 test_SetWindowExt(hdc, 4 * win.cx, 2 * win.cy, 2 * vp.cx, vp.cy);
519 test_SetViewportExt(hdc, -2 * vp.cx, -4 * vp.cy, -2 * vp.cx, -vp.cy);
520 test_SetViewportExt(hdc, -2 * vp.cx, -1 * vp.cy, -2 * vp.cx, -vp.cy);
521 test_SetWindowExt(hdc, -4 * win.cx, -2 * win.cy, -2 * vp.cx, -vp.cy);
522 test_SetWindowExt(hdc, 4 * win.cx, -4 * win.cy, -vp.cx, -vp.cy);
524 ReleaseDC(0, hdc);
527 static void test_setvirtualresolution(void)
529 HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
530 BOOL r;
531 INT horz_res = GetDeviceCaps(hdc, HORZRES);
532 INT horz_size = GetDeviceCaps(hdc, HORZSIZE);
533 INT log_pixels_x = GetDeviceCaps(hdc, LOGPIXELSX);
534 SIZE orig_lometric_vp, orig_lometric_wnd;
536 if(!pSetVirtualResolution)
538 win_skip("Don't have SetVirtualResolution\n");
539 return;
542 /* Get the true resolution limits */
543 SetMapMode(hdc, MM_LOMETRIC);
544 GetViewportExtEx(hdc, &orig_lometric_vp);
545 GetWindowExtEx(hdc, &orig_lometric_wnd);
546 SetMapMode(hdc, MM_TEXT);
548 r = pSetVirtualResolution(hdc, 4000, 1000, 400, 200); /* 10 pix/mm x 5 pix/mm */
549 ok(r == TRUE, "got %d\n", r);
550 expect_LPtoDP(hdc, 1000, 1000);
551 expect_viewport_ext(hdc, 1, 1);
552 expect_window_ext(hdc, 1, 1);
554 SetMapMode(hdc, MM_LOMETRIC);
555 expect_LPtoDP(hdc, 1000, -500);
556 expect_viewport_ext(hdc, 4000, -1000);
557 expect_window_ext(hdc, 4000, 2000);
559 /* Doesn't change the device caps */
560 ok(horz_res == GetDeviceCaps(hdc, HORZRES), "horz_res changed\n");
561 ok(horz_size == GetDeviceCaps(hdc, HORZSIZE), "horz_size changed\n");
562 ok(log_pixels_x == GetDeviceCaps(hdc, LOGPIXELSX), "log_pixels_x changed\n");
564 r = pSetVirtualResolution(hdc, 8000, 1000, 400, 200); /* 20 pix/mm x 5 pix/mm */
565 ok(r == TRUE, "got %d\n", r);
566 expect_LPtoDP(hdc, 1000, -500); /* No change, need to re-set the mapping mode */
567 SetMapMode(hdc, MM_TEXT);
568 SetMapMode(hdc, MM_LOMETRIC);
569 expect_LPtoDP(hdc, 2000, -500);
570 expect_viewport_ext(hdc, 8000, -1000);
571 expect_window_ext(hdc, 4000, 2000);
573 r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
574 ok(r == TRUE, "got %d\n", r);
575 SetMapMode(hdc, MM_TEXT);
576 SetMapMode(hdc, MM_LOMETRIC);
577 expect_LPtoDP(hdc, 4000, -500);
578 expect_viewport_ext(hdc, 8000, -1000);
579 expect_window_ext(hdc, 2000, 2000);
581 r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */
582 ok(r == TRUE, "got %d\n", r);
583 SetMapMode(hdc, MM_TEXT);
584 SetMapMode(hdc, MM_LOMETRIC);
585 expect_LPtoDP(hdc, 4000, -500);
586 expect_viewport_ext(hdc, 8000, -1000);
587 expect_window_ext(hdc, 2000, 2000);
589 r = pSetVirtualResolution(hdc, 8000, 2000, 200, 200); /* 40 pix/mm x 10 pix/mm */
590 ok(r == TRUE, "got %d\n", r);
591 SetMapMode(hdc, MM_TEXT);
592 SetMapMode(hdc, MM_LOMETRIC);
593 expect_LPtoDP(hdc, 4000, -1000);
594 expect_viewport_ext(hdc, 8000, -2000);
595 expect_window_ext(hdc, 2000, 2000);
597 r = pSetVirtualResolution(hdc, 0, 0, 10, 0); /* Error */
598 ok(r == FALSE, "got %d\n", r);
599 SetMapMode(hdc, MM_TEXT);
600 SetMapMode(hdc, MM_LOMETRIC);
601 expect_LPtoDP(hdc, 4000, -1000);
602 expect_viewport_ext(hdc, 8000, -2000);
603 expect_window_ext(hdc, 2000, 2000);
605 r = pSetVirtualResolution(hdc, 0, 0, 0, 0); /* Reset to true resolution */
606 ok(r == TRUE, "got %d\n", r);
607 SetMapMode(hdc, MM_TEXT);
608 SetMapMode(hdc, MM_LOMETRIC);
609 expect_viewport_ext(hdc, orig_lometric_vp.cx, orig_lometric_vp.cy);
610 expect_window_ext(hdc, orig_lometric_wnd.cx, orig_lometric_wnd.cy);
612 DeleteDC(hdc);
616 static inline void expect_identity(int line, XFORM *xf)
618 ok(xf->eM11 == 1.0, "%d: got %f\n", line, xf->eM11);
619 ok(xf->eM12 == 0.0, "%d: got %f\n", line, xf->eM12);
620 ok(xf->eM21 == 0.0, "%d: got %f\n", line, xf->eM21);
621 ok(xf->eM22 == 1.0, "%d: got %f\n", line, xf->eM22);
622 ok(xf->eDx == 0.0, "%d: got %f\n", line, xf->eDx);
623 ok(xf->eDy == 0.0, "%d: got %f\n", line, xf->eDy);
626 static inline void xform_near_match(int line, XFORM *got, XFORM *expect)
628 ok(fabs(got->eM11 - expect->eM11) < 0.001, "%d: got %f expect %f\n", line, got->eM11, expect->eM11);
629 ok(fabs(got->eM12 - expect->eM12) < 0.001, "%d: got %f expect %f\n", line, got->eM12, expect->eM12);
630 ok(fabs(got->eM21 - expect->eM21) < 0.001, "%d: got %f expect %f\n", line, got->eM21, expect->eM21);
631 ok(fabs(got->eM22 - expect->eM22) < 0.001, "%d: got %f expect %f\n", line, got->eM22, expect->eM22);
632 ok(fabs(got->eDx - expect->eDx) < 0.001, "%d: got %f expect %f\n", line, got->eDx, expect->eDx);
633 ok(fabs(got->eDy - expect->eDy) < 0.001, "%d: got %f expect %f\n", line, got->eDy, expect->eDy);
637 static void test_gettransform(void)
639 HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
640 XFORM xform, expect;
641 BOOL r;
642 SIZE lometric_vp, lometric_wnd;
644 if(!pGetTransform)
646 win_skip("Don't have GetTransform\n");
647 return;
650 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
651 ok(r == TRUE, "got %d\n", r);
652 expect_identity(__LINE__, &xform);
653 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
654 ok(r == TRUE, "got %d\n", r);
655 expect_identity(__LINE__, &xform);
656 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
657 ok(r == TRUE, "got %d\n", r);
658 expect_identity(__LINE__, &xform);
659 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
660 ok(r == TRUE, "got %d\n", r);
661 expect_identity(__LINE__, &xform);
663 SetMapMode(hdc, MM_LOMETRIC);
664 GetViewportExtEx(hdc, &lometric_vp);
665 GetWindowExtEx(hdc, &lometric_wnd);
667 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
668 ok(r == TRUE, "got %d\n", r);
669 expect_identity(__LINE__, &xform);
671 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
672 ok(r == TRUE, "got %d\n", r);
673 expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
674 expect.eM12 = expect.eM21 = 0.0;
675 expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
676 expect.eDx = expect.eDy = 0.0;
677 xform_near_match(__LINE__, &xform, &expect);
679 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
680 ok(r == TRUE, "got %d\n", r);
681 xform_near_match(__LINE__, &xform, &expect);
683 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
684 ok(r == TRUE, "got %d\n", r);
685 expect.eM11 = (FLOAT) lometric_wnd.cx / lometric_vp.cx;
686 expect.eM22 = (FLOAT) lometric_wnd.cy / lometric_vp.cy;
687 xform_near_match(__LINE__, &xform, &expect);
690 SetGraphicsMode(hdc, GM_ADVANCED);
692 expect.eM11 = 10.0;
693 expect.eM22 = 20.0;
694 SetWorldTransform(hdc, &expect);
695 r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
696 ok(r == TRUE, "got %d\n", r);
697 xform_near_match(__LINE__, &xform, &expect);
699 r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
700 ok(r == TRUE, "got %d\n", r);
701 expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
702 expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
703 xform_near_match(__LINE__, &xform, &expect);
705 r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
706 ok(r == TRUE, "got %d\n", r);
707 expect.eM11 *= 10.0;
708 expect.eM22 *= 20.0;
709 xform_near_match(__LINE__, &xform, &expect);
711 r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
712 ok(r == TRUE, "got %d\n", r);
713 expect.eM11 = 1 / expect.eM11;
714 expect.eM22 = 1 / expect.eM22;
715 xform_near_match(__LINE__, &xform, &expect);
717 r = pGetTransform(hdc, 0x102, &xform);
718 ok(r == FALSE, "got %d\n", r);
719 r = pGetTransform(hdc, 0x103, &xform);
720 ok(r == FALSE, "got %d\n", r);
721 r = pGetTransform(hdc, 0x104, &xform);
722 ok(r == FALSE, "got %d\n", r);
723 r = pGetTransform(hdc, 0x202, &xform);
724 ok(r == FALSE, "got %d\n", r);
725 r = pGetTransform(hdc, 0x302, &xform);
726 ok(r == FALSE, "got %d\n", r);
727 r = pGetTransform(hdc, 0x303, &xform);
728 ok(r == FALSE, "got %d\n", r);
729 r = pGetTransform(hdc, 0x403, &xform);
730 ok(r == FALSE, "got %d\n", r);
731 r = pGetTransform(hdc, 0x404, &xform);
732 ok(r == FALSE, "got %d\n", r);
733 r = pGetTransform(hdc, 0xffff, &xform);
734 ok(r == FALSE, "got %d\n", r);
737 START_TEST(mapping)
739 HMODULE mod = GetModuleHandleA("gdi32.dll");
740 pGetLayout = (void *)GetProcAddress( mod, "GetLayout" );
741 pGetRandomRgn = (void *)GetProcAddress( mod, "GetRandomRgn" );
742 pGetTransform = (void *)GetProcAddress( mod, "GetTransform" );
743 pSetVirtualResolution = (void *)GetProcAddress( mod, "SetVirtualResolution" );
745 test_modify_world_transform();
746 test_world_transform();
747 test_dc_layout();
748 test_isotropic_mapping();
749 test_setvirtualresolution();
750 test_gettransform();