static void test_setvirtualresolution(void) { HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL); DWORD r; DWORD (WINAPI *pSetVirtualResolution)(HDC, DWORD, DWORD, DWORD, DWORD); INT horz_res = GetDeviceCaps(hdc, HORZRES); INT horz_size = GetDeviceCaps(hdc, HORZSIZE); INT log_pixels_x = GetDeviceCaps(hdc, LOGPIXELSX); SIZE orig_lometric_vp, orig_lometric_wnd; pSetVirtualResolution = (void *)GetProcAddress(GetModuleHandleA("gdi32.dll"), "SetVirtualResolution"); if(!pSetVirtualResolution) { win_skip("Don't have SetVirtualResolution\n"); return; } /* Get the true resolution limits */ SetMapMode(hdc, MM_LOMETRIC); GetViewportExtEx(hdc, &orig_lometric_vp); GetWindowExtEx(hdc, &orig_lometric_wnd); SetMapMode(hdc, MM_TEXT); r = pSetVirtualResolution(hdc, 4000, 1000, 400, 200); /* 10 pix/mm x 5 pix/mm */ ok(r == TRUE, "got %d\n", r); expect_LPtoDP(hdc, 1000, 1000); expect_viewport_ext(hdc, 1, 1); expect_window_ext(hdc, 1, 1); SetMapMode(hdc, MM_LOMETRIC); expect_LPtoDP(hdc, 1000, -500); expect_viewport_ext(hdc, 4000, -1000); expect_window_ext(hdc, 4000, 2000); /* Doesn't change the device caps */ ok(horz_res == GetDeviceCaps(hdc, HORZRES), "horz_res changed\n"); ok(horz_size == GetDeviceCaps(hdc, HORZSIZE), "horz_size changed\n"); ok(log_pixels_x == GetDeviceCaps(hdc, LOGPIXELSX), "log_pixels_x changed\n"); r = pSetVirtualResolution(hdc, 8000, 1000, 400, 200); /* 20 pix/mm x 5 pix/mm */ ok(r == TRUE, "got %d\n", r); expect_LPtoDP(hdc, 1000, -500); /* No change, need to re-set the mapping mode */ SetMapMode(hdc, MM_TEXT); SetMapMode(hdc, MM_LOMETRIC); expect_LPtoDP(hdc, 2000, -500); expect_viewport_ext(hdc, 8000, -1000); expect_window_ext(hdc, 4000, 2000); r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */ ok(r == TRUE, "got %d\n", r); SetMapMode(hdc, MM_TEXT); SetMapMode(hdc, MM_LOMETRIC); expect_LPtoDP(hdc, 4000, -500); expect_viewport_ext(hdc, 8000, -1000); expect_window_ext(hdc, 2000, 2000); r = pSetVirtualResolution(hdc, 8000, 1000, 200, 200); /* 40 pix/mm x 5 pix/mm */ ok(r == TRUE, "got %d\n", r); SetMapMode(hdc, MM_TEXT); SetMapMode(hdc, MM_LOMETRIC); expect_LPtoDP(hdc, 4000, -500); expect_viewport_ext(hdc, 8000, -1000); expect_window_ext(hdc, 2000, 2000); r = pSetVirtualResolution(hdc, 8000, 2000, 200, 200); /* 40 pix/mm x 10 pix/mm */ ok(r == TRUE, "got %d\n", r); SetMapMode(hdc, MM_TEXT); SetMapMode(hdc, MM_LOMETRIC); expect_LPtoDP(hdc, 4000, -1000); expect_viewport_ext(hdc, 8000, -2000); expect_window_ext(hdc, 2000, 2000); r = pSetVirtualResolution(hdc, 0, 0, 10, 0); /* Error */ ok(r == FALSE, "got %d\n", r); SetMapMode(hdc, MM_TEXT); SetMapMode(hdc, MM_LOMETRIC); expect_LPtoDP(hdc, 4000, -1000); expect_viewport_ext(hdc, 8000, -2000); expect_window_ext(hdc, 2000, 2000); r = pSetVirtualResolution(hdc, 0, 0, 0, 0); /* Reset to true resolution */ ok(r == TRUE, "got %d\n", r); SetMapMode(hdc, MM_TEXT); SetMapMode(hdc, MM_LOMETRIC); expect_viewport_ext(hdc, orig_lometric_vp.cx, orig_lometric_vp.cy); expect_window_ext(hdc, orig_lometric_wnd.cx, orig_lometric_wnd.cy); DeleteDC(hdc); }
static void test_world_transform(void) { BOOL is_win9x; HDC hdc; INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y; XFORM xform; SIZE size; SetLastError(0xdeadbeef); GetWorldTransform(0, NULL); is_win9x = GetLastError() == ERROR_CALL_NOT_IMPLEMENTED; hdc = CreateCompatibleDC(0); xform.eM11 = 1.0f; xform.eM12 = 0.0f; xform.eM21 = 0.0f; xform.eM22 = 1.0f; xform.eDx = 0.0f; xform.eDy = 0.0f; ret = SetWorldTransform(hdc, &xform); ok(!ret, "SetWorldTransform should fail in GM_COMPATIBLE mode\n"); size_cx = GetDeviceCaps(hdc, HORZSIZE); size_cy = GetDeviceCaps(hdc, VERTSIZE); res_x = GetDeviceCaps(hdc, HORZRES); res_y = GetDeviceCaps(hdc, VERTRES); dpi_x = GetDeviceCaps(hdc, LOGPIXELSX); dpi_y = GetDeviceCaps(hdc, LOGPIXELSY); trace("dc size %d x %d, resolution %d x %d dpi %d x %d\n", size_cx, size_cy, res_x, res_y, dpi_x, dpi_y ); expect_viewport_ext(hdc, 1, 1); expect_window_ext(hdc, 1, 1); expect_world_trasform(hdc, 1.0, 1.0); expect_LPtoDP(hdc, 1000, 1000); SetLastError(0xdeadbeef); ret = SetMapMode(hdc, MM_LOMETRIC); ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret); if (is_win9x) { expect_viewport_ext(hdc, dpi_x, dpi_y); expect_window_ext(hdc, 254, -254); } else { expect_viewport_ext(hdc, res_x, -res_y); ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" ); ok( size.cx == size_cx * 10 || size.cx == MulDiv( res_x, 254, dpi_x ), /* Vista uses a more precise method */ "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx ); ok( size.cy == size_cy * 10 || size.cy == MulDiv( res_y, 254, dpi_y ), /* Vista uses a more precise method */ "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy ); } expect_world_trasform(hdc, 1.0, 1.0); expect_LPtoDP(hdc, MulDiv(1000 / 10, res_x, size_cx), -MulDiv(1000 / 10, res_y, size_cy)); SetLastError(0xdeadbeef); ret = SetMapMode(hdc, MM_TEXT); ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret); expect_viewport_ext(hdc, 1, 1); expect_window_ext(hdc, 1, 1); expect_world_trasform(hdc, 1.0, 1.0); expect_LPtoDP(hdc, 1000, 1000); ret = SetGraphicsMode(hdc, GM_ADVANCED); if (!ret) { DeleteDC(hdc); skip("GM_ADVANCED is not supported on this platform\n"); return; } expect_viewport_ext(hdc, 1, 1); expect_window_ext(hdc, 1, 1); expect_world_trasform(hdc, 1.0, 1.0); expect_LPtoDP(hdc, 1000, 1000); /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */ xform.eM11 = 1.0f; xform.eM12 = 2.0f; xform.eM21 = 1.0f; xform.eM22 = 2.0f; xform.eDx = 0.0f; xform.eDy = 0.0f; ret = SetWorldTransform(hdc, &xform); ok(!ret || broken(ret), /* NT4 */ "SetWorldTransform should fail with an invalid xform\n"); xform.eM11 = 20.0f; xform.eM12 = 0.0f; xform.eM21 = 0.0f; xform.eM22 = 20.0f; xform.eDx = 0.0f; xform.eDy = 0.0f; SetLastError(0xdeadbeef); ret = SetWorldTransform(hdc, &xform); ok(ret, "SetWorldTransform error %u\n", GetLastError()); expect_viewport_ext(hdc, 1, 1); expect_window_ext(hdc, 1, 1); expect_world_trasform(hdc, 20.0, 20.0); expect_LPtoDP(hdc, 20000, 20000); SetLastError(0xdeadbeef); ret = SetMapMode(hdc, MM_LOMETRIC); ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret); expect_viewport_ext(hdc, res_x, -res_y); ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" ); ok( size.cx == size_cx * 10 || size.cx == MulDiv( res_x, 254, dpi_x ), /* Vista uses a more precise method */ "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx ); ok( size.cy == size_cy * 10 || size.cy == MulDiv( res_y, 254, dpi_y ), /* Vista uses a more precise method */ "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy ); expect_world_trasform(hdc, 20.0, 20.0); expect_LPtoDP(hdc, MulDiv(20000, res_x, size.cx), -MulDiv(20000, res_y, size.cy)); SetLastError(0xdeadbeef); ret = SetMapMode(hdc, MM_TEXT); ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret); expect_viewport_ext(hdc, 1, 1); expect_window_ext(hdc, 1, 1); expect_world_trasform(hdc, 20.0, 20.0); expect_LPtoDP(hdc, 20000, 20000); ret = SetGraphicsMode(hdc, GM_COMPATIBLE); ok(ret, "SetGraphicsMode(GM_COMPATIBLE) should not fail if DC has't an identity transform\n"); ret = GetGraphicsMode(hdc); ok(ret == GM_COMPATIBLE, "expected GM_COMPATIBLE, got %d\n", ret); expect_viewport_ext(hdc, 1, 1); expect_window_ext(hdc, 1, 1); expect_world_trasform(hdc, 20.0, 20.0); expect_LPtoDP(hdc, 20000, 20000); DeleteDC(hdc); }
static void test_dc_layout(void) { INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y; SIZE size; POINT pt; HBITMAP bitmap; RECT rc, ret_rc; HDC hdc; HRGN hrgn; if (!pGetLayout || !pSetLayout) { win_skip( "Don't have SetLayout\n" ); return; } hdc = CreateCompatibleDC(0); bitmap = CreateCompatibleBitmap( hdc, 100, 100 ); SelectObject( hdc, bitmap ); size_cx = GetDeviceCaps(hdc, HORZSIZE); size_cy = GetDeviceCaps(hdc, VERTSIZE); res_x = GetDeviceCaps(hdc, HORZRES); res_y = GetDeviceCaps(hdc, VERTRES); dpi_x = GetDeviceCaps(hdc, LOGPIXELSX); dpi_y = GetDeviceCaps(hdc, LOGPIXELSY); ret = GetMapMode( hdc ); ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret); expect_viewport_ext(hdc, 1, 1); expect_window_ext(hdc, 1, 1); expect_world_transform(hdc, 1.0, 1.0); expect_LPtoDP(hdc, 1000, 1000); pSetLayout( hdc, LAYOUT_RTL ); if (!pGetLayout( hdc )) { win_skip( "SetLayout not supported\n" ); DeleteDC(hdc); return; } ret = GetMapMode( hdc ); ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret); expect_viewport_ext(hdc, 1, 1); expect_window_ext(hdc, 1, 1); expect_world_transform(hdc, 1.0, 1.0); expect_LPtoDP(hdc, -1000 + 99, 1000); GetViewportOrgEx( hdc, &pt ); ok( pt.x == 0 && pt.y == 0, "wrong origin %d,%d\n", pt.x, pt.y ); GetWindowOrgEx( hdc, &pt ); ok( pt.x == 0 && pt.y == 0, "wrong origin %d,%d\n", pt.x, pt.y ); GetDCOrgEx( hdc, &pt ); ok( pt.x == 0 && pt.y == 0, "wrong origin %d,%d\n", pt.x, pt.y ); if (pGetTransform) { XFORM xform; BOOL ret = pGetTransform( hdc, 0x204, &xform ); /* World -> Device */ ok( ret, "got %d\n", ret ); ok( xform.eM11 == -1.0, "got %f\n", xform.eM11 ); ok( xform.eM12 == 0.0, "got %f\n", xform.eM12 ); ok( xform.eM21 == 0.0, "got %f\n", xform.eM21 ); ok( xform.eM22 == 1.0, "got %f\n", xform.eM22 ); ok( xform.eDx == 99.0, "got %f\n", xform.eDx ); ok( xform.eDy == 0.0, "got %f\n", xform.eDy ); } SetRect( &rc, 10, 10, 20, 20 ); IntersectClipRect( hdc, 10, 10, 20, 20 ); hrgn = CreateRectRgn( 0, 0, 0, 0 ); GetClipRgn( hdc, hrgn ); GetRgnBox( hrgn, &ret_rc ); ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n", ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom ); pSetLayout( hdc, LAYOUT_LTR ); SetRect( &rc, 80, 10, 90, 20 ); GetClipRgn( hdc, hrgn ); GetRgnBox( hrgn, &ret_rc ); ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n", ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom ); GetClipBox( hdc, &ret_rc ); ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n", ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom ); IntersectClipRect( hdc, 80, 10, 85, 20 ); pSetLayout( hdc, LAYOUT_RTL ); SetRect( &rc, 15, 10, 20, 20 ); GetClipRgn( hdc, hrgn ); GetRgnBox( hrgn, &ret_rc ); ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n", ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom ); GetClipBox( hdc, &ret_rc ); ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n", ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom ); SetRectRgn( hrgn, 60, 10, 80, 20 ); pSetLayout( hdc, LAYOUT_LTR ); ExtSelectClipRgn( hdc, hrgn, RGN_OR ); pSetLayout( hdc, LAYOUT_RTL ); SetRect( &rc, 15, 10, 40, 20 ); GetClipRgn( hdc, hrgn ); GetRgnBox( hrgn, &ret_rc ); ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n", ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom ); GetClipBox( hdc, &ret_rc ); ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n", ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom ); /* OffsetClipRgn mirrors too */ OffsetClipRgn( hdc, 5, 5 ); OffsetRect( &rc, 5, 5 ); GetClipRgn( hdc, hrgn ); GetRgnBox( hrgn, &ret_rc ); ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n", ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom ); /* GetRandomRgn returns the raw region */ if (pGetRandomRgn) { SetRect( &rc, 55, 15, 80, 25 ); pGetRandomRgn( hdc, hrgn, 1 ); GetRgnBox( hrgn, &ret_rc ); ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n", ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom ); } SetMapMode(hdc, MM_LOMETRIC); ret = GetMapMode( hdc ); ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret); expect_viewport_ext(hdc, res_x, -res_y); ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" ); ok( rough_match( size.cx, size_cx * 10 ) || rough_match( size.cx, MulDiv( res_x, 254, dpi_x )), /* Vista uses a more precise method */ "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx ); ok( rough_match( size.cy, size_cy * 10 ) || rough_match( size.cy, MulDiv( res_y, 254, dpi_y )), /* Vista uses a more precise method */ "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy ); expect_world_transform(hdc, 1.0, 1.0); expect_LPtoDP(hdc, -MulDiv(1000 / 10, res_x, size_cx) + 99, -MulDiv(1000 / 10, res_y, size_cy)); SetMapMode(hdc, MM_TEXT); ret = GetMapMode( hdc ); ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret); pSetLayout( hdc, LAYOUT_LTR ); ret = GetMapMode( hdc ); ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret); SetMapMode(hdc, MM_TEXT); ret = GetMapMode( hdc ); ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret); DeleteDC(hdc); DeleteObject( bitmap ); }