2 * GDI mapping mode functions
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "gdi_private.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(dc);
32 /***********************************************************************
33 * MAPPING_FixIsotropic
35 * Fix viewport extensions for isotropic mode.
37 static void MAPPING_FixIsotropic( DC * dc )
39 double xdim = fabs((double)dc->vportExtX * dc->virtual_size.cx /
40 (dc->virtual_res.cx * dc->wndExtX));
41 double ydim = fabs((double)dc->vportExtY * dc->virtual_size.cy /
42 (dc->virtual_res.cy * dc->wndExtY));
46 INT mincx = (dc->vportExtX >= 0) ? 1 : -1;
47 dc->vportExtX = floor(dc->vportExtX * ydim / xdim + 0.5);
48 if (!dc->vportExtX) dc->vportExtX = mincx;
52 INT mincy = (dc->vportExtY >= 0) ? 1 : -1;
53 dc->vportExtY = floor(dc->vportExtY * xdim / ydim + 0.5);
54 if (!dc->vportExtY) dc->vportExtY = mincy;
59 /***********************************************************************
60 * null driver fallback implementations
63 BOOL CDECL nulldrv_OffsetViewportOrgEx( PHYSDEV dev, INT x, INT y, POINT *pt )
65 DC *dc = get_nulldrv_dc( dev );
69 pt->x = dc->vportOrgX;
70 pt->y = dc->vportOrgY;
74 DC_UpdateXforms( dc );
78 BOOL CDECL nulldrv_OffsetWindowOrgEx( PHYSDEV dev, INT x, INT y, POINT *pt )
80 DC *dc = get_nulldrv_dc( dev );
89 DC_UpdateXforms( dc );
93 BOOL CDECL nulldrv_ScaleViewportExtEx( PHYSDEV dev, INT x_num, INT x_denom, INT y_num, INT y_denom,
96 DC *dc = get_nulldrv_dc( dev );
100 size->cx = dc->vportExtX;
101 size->cy = dc->vportExtY;
103 if (dc->MapMode != MM_ISOTROPIC && dc->MapMode != MM_ANISOTROPIC) return TRUE;
104 if (!x_num || !x_denom || !y_num || !y_denom) return FALSE;
106 dc->vportExtX = (dc->vportExtX * x_num) / x_denom;
107 dc->vportExtY = (dc->vportExtY * y_num) / y_denom;
108 if (dc->vportExtX == 0) dc->vportExtX = 1;
109 if (dc->vportExtY == 0) dc->vportExtY = 1;
110 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
111 DC_UpdateXforms( dc );
115 BOOL CDECL nulldrv_ScaleWindowExtEx( PHYSDEV dev, INT x_num, INT x_denom, INT y_num, INT y_denom,
118 DC *dc = get_nulldrv_dc( dev );
122 size->cx = dc->wndExtX;
123 size->cy = dc->wndExtY;
125 if (dc->MapMode != MM_ISOTROPIC && dc->MapMode != MM_ANISOTROPIC) return TRUE;
126 if (!x_num || !x_denom || !y_num || !y_denom) return FALSE;
128 dc->wndExtX = (dc->wndExtX * x_num) / x_denom;
129 dc->wndExtY = (dc->wndExtY * y_num) / y_denom;
130 if (dc->wndExtX == 0) dc->wndExtX = 1;
131 if (dc->wndExtY == 0) dc->wndExtY = 1;
132 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
133 DC_UpdateXforms( dc );
137 INT CDECL nulldrv_SetMapMode( PHYSDEV dev, INT mode )
139 DC *dc = get_nulldrv_dc( dev );
140 INT ret = dc->MapMode;
141 INT horzSize, vertSize, horzRes, vertRes;
143 if (mode == dc->MapMode && (mode == MM_ISOTROPIC || mode == MM_ANISOTROPIC)) return ret;
145 horzSize = dc->virtual_size.cx;
146 vertSize = dc->virtual_size.cy;
147 horzRes = dc->virtual_res.cx;
148 vertRes = dc->virtual_res.cy;
159 dc->wndExtX = horzSize * 10;
160 dc->wndExtY = vertSize * 10;
161 dc->vportExtX = horzRes;
162 dc->vportExtY = -vertRes;
165 dc->wndExtX = horzSize * 100;
166 dc->wndExtY = vertSize * 100;
167 dc->vportExtX = horzRes;
168 dc->vportExtY = -vertRes;
171 dc->wndExtX = MulDiv(1000, horzSize, 254);
172 dc->wndExtY = MulDiv(1000, vertSize, 254);
173 dc->vportExtX = horzRes;
174 dc->vportExtY = -vertRes;
177 dc->wndExtX = MulDiv(10000, horzSize, 254);
178 dc->wndExtY = MulDiv(10000, vertSize, 254);
179 dc->vportExtX = horzRes;
180 dc->vportExtY = -vertRes;
183 dc->wndExtX = MulDiv(14400, horzSize, 254);
184 dc->wndExtY = MulDiv(14400, vertSize, 254);
185 dc->vportExtX = horzRes;
186 dc->vportExtY = -vertRes;
193 /* RTL layout is always MM_ANISOTROPIC */
194 if (!(dc->layout & LAYOUT_RTL)) dc->MapMode = mode;
195 DC_UpdateXforms( dc );
199 BOOL CDECL nulldrv_SetViewportExtEx( PHYSDEV dev, INT cx, INT cy, SIZE *size )
201 DC *dc = get_nulldrv_dc( dev );
205 size->cx = dc->vportExtX;
206 size->cy = dc->vportExtY;
208 if (dc->MapMode != MM_ISOTROPIC && dc->MapMode != MM_ANISOTROPIC) return TRUE;
209 if (!cx || !cy) return FALSE;
212 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
213 DC_UpdateXforms( dc );
217 BOOL CDECL nulldrv_SetViewportOrgEx( PHYSDEV dev, INT x, INT y, POINT *pt )
219 DC *dc = get_nulldrv_dc( dev );
223 pt->x = dc->vportOrgX;
224 pt->y = dc->vportOrgY;
228 DC_UpdateXforms( dc );
232 BOOL CDECL nulldrv_SetWindowExtEx( PHYSDEV dev, INT cx, INT cy, SIZE *size )
234 DC *dc = get_nulldrv_dc( dev );
238 size->cx = dc->wndExtX;
239 size->cy = dc->wndExtY;
241 if (dc->MapMode != MM_ISOTROPIC && dc->MapMode != MM_ANISOTROPIC) return TRUE;
242 if (!cx || !cy) return FALSE;
245 /* The API docs say that you should call SetWindowExtEx before
246 SetViewportExtEx. This advice does not imply that Windows
247 doesn't ensure the isotropic mapping after SetWindowExtEx! */
248 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
249 DC_UpdateXforms( dc );
253 BOOL CDECL nulldrv_SetWindowOrgEx( PHYSDEV dev, INT x, INT y, POINT *pt )
255 DC *dc = get_nulldrv_dc( dev );
264 DC_UpdateXforms( dc );
268 /***********************************************************************
271 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
273 DC * dc = get_dc_ptr( hdc );
274 if (!dc) return FALSE;
276 if (dc->vport2WorldValid)
280 double x = points->x;
281 double y = points->y;
282 points->x = floor( x * dc->xformVport2World.eM11 +
283 y * dc->xformVport2World.eM21 +
284 dc->xformVport2World.eDx + 0.5 );
285 points->y = floor( x * dc->xformVport2World.eM12 +
286 y * dc->xformVport2World.eM22 +
287 dc->xformVport2World.eDy + 0.5 );
291 release_dc_ptr( dc );
296 /***********************************************************************
299 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
301 DC * dc = get_dc_ptr( hdc );
302 if (!dc) return FALSE;
306 double x = points->x;
307 double y = points->y;
308 points->x = floor( x * dc->xformWorld2Vport.eM11 +
309 y * dc->xformWorld2Vport.eM21 +
310 dc->xformWorld2Vport.eDx + 0.5 );
311 points->y = floor( x * dc->xformWorld2Vport.eM12 +
312 y * dc->xformWorld2Vport.eM22 +
313 dc->xformWorld2Vport.eDy + 0.5 );
316 release_dc_ptr( dc );
321 /***********************************************************************
322 * SetMapMode (GDI32.@)
324 INT WINAPI SetMapMode( HDC hdc, INT mode )
327 DC * dc = get_dc_ptr( hdc );
329 TRACE("%p %d\n", hdc, mode );
333 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetMapMode );
334 ret = physdev->funcs->pSetMapMode( physdev, mode );
335 release_dc_ptr( dc );
341 /***********************************************************************
342 * SetViewportExtEx (GDI32.@)
344 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
347 DC * dc = get_dc_ptr( hdc );
351 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetViewportExtEx );
352 ret = physdev->funcs->pSetViewportExtEx( physdev, x, y, size );
353 release_dc_ptr( dc );
359 /***********************************************************************
360 * SetViewportOrgEx (GDI32.@)
362 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
365 DC * dc = get_dc_ptr( hdc );
369 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetViewportOrgEx );
370 ret = physdev->funcs->pSetViewportOrgEx( physdev, x, y, pt );
371 release_dc_ptr( dc );
377 /***********************************************************************
378 * SetWindowExtEx (GDI32.@)
380 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
383 DC * dc = get_dc_ptr( hdc );
387 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetWindowExtEx );
388 ret = physdev->funcs->pSetWindowExtEx( physdev, x, y, size );
389 release_dc_ptr( dc );
395 /***********************************************************************
396 * SetWindowOrgEx (GDI32.@)
398 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
401 DC * dc = get_dc_ptr( hdc );
405 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetWindowOrgEx );
406 ret = physdev->funcs->pSetWindowOrgEx( physdev, x, y, pt );
407 release_dc_ptr( dc );
413 /***********************************************************************
414 * OffsetViewportOrgEx (GDI32.@)
416 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
419 DC * dc = get_dc_ptr( hdc );
423 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pOffsetViewportOrgEx );
424 ret = physdev->funcs->pOffsetViewportOrgEx( physdev, x, y, pt );
425 release_dc_ptr( dc );
431 /***********************************************************************
432 * OffsetWindowOrgEx (GDI32.@)
434 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
437 DC * dc = get_dc_ptr( hdc );
441 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pOffsetWindowOrgEx );
442 ret = physdev->funcs->pOffsetWindowOrgEx( physdev, x, y, pt );
443 release_dc_ptr( dc );
449 /***********************************************************************
450 * ScaleViewportExtEx (GDI32.@)
452 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
453 INT yNum, INT yDenom, LPSIZE size )
456 DC * dc = get_dc_ptr( hdc );
460 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pScaleViewportExtEx );
461 ret = physdev->funcs->pScaleViewportExtEx( physdev, xNum, xDenom, yNum, yDenom, size );
462 release_dc_ptr( dc );
468 /***********************************************************************
469 * ScaleWindowExtEx (GDI32.@)
471 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
472 INT yNum, INT yDenom, LPSIZE size )
475 DC * dc = get_dc_ptr( hdc );
479 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pScaleWindowExtEx );
480 ret = physdev->funcs->pScaleWindowExtEx( physdev, xNum, xDenom, yNum, yDenom, size );
481 release_dc_ptr( dc );
486 /***********************************************************************
487 * SetVirtualResolution (GDI32.@)
489 * Undocumented on msdn.
491 * Changes the values of screen size in pixels and millimeters used by
492 * the mapping mode functions.
495 * hdc [I] Device context
496 * horz_res [I] Width in pixels (equivalent to HORZRES device cap).
497 * vert_res [I] Height in pixels (equivalent to VERTRES device cap).
498 * horz_size [I] Width in mm (equivalent to HORZSIZE device cap).
499 * vert_size [I] Height in mm (equivalent to VERTSIZE device cap).
502 * TRUE if successful.
503 * FALSE if any (but not all) of the last four params are zero.
506 * This doesn't change the values returned by GetDeviceCaps, just the
507 * scaling of the mapping modes.
509 * Calling with the last four params equal to zero sets the values
510 * back to their defaults obtained by calls to GetDeviceCaps.
512 BOOL WINAPI SetVirtualResolution(HDC hdc, DWORD horz_res, DWORD vert_res,
513 DWORD horz_size, DWORD vert_size)
516 TRACE("(%p %d %d %d %d)\n", hdc, horz_res, vert_res, horz_size, vert_size);
518 if(horz_res == 0 && vert_res == 0 && horz_size == 0 && vert_size == 0)
520 horz_res = GetDeviceCaps(hdc, HORZRES);
521 vert_res = GetDeviceCaps(hdc, VERTRES);
522 horz_size = GetDeviceCaps(hdc, HORZSIZE);
523 vert_size = GetDeviceCaps(hdc, VERTSIZE);
525 else if(horz_res == 0 || vert_res == 0 || horz_size == 0 || vert_size == 0)
528 dc = get_dc_ptr( hdc );
529 if (!dc) return FALSE;
531 dc->virtual_res.cx = horz_res;
532 dc->virtual_res.cy = vert_res;
533 dc->virtual_size.cx = horz_size;
534 dc->virtual_size.cy = vert_size;
536 release_dc_ptr( dc );