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
27 #include "gdi_private.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(dc);
33 /***********************************************************************
34 * MAPPING_FixIsotropic
36 * Fix viewport extensions for isotropic mode.
38 static void MAPPING_FixIsotropic( DC * dc )
40 double xdim = fabs((double)dc->vportExtX * GetDeviceCaps( dc->hSelf, HORZSIZE ) /
41 (GetDeviceCaps( dc->hSelf, HORZRES ) * dc->wndExtX));
42 double ydim = fabs((double)dc->vportExtY * GetDeviceCaps( dc->hSelf, VERTSIZE ) /
43 (GetDeviceCaps( dc->hSelf, VERTRES ) * dc->wndExtY));
47 INT mincx = (dc->vportExtX >= 0) ? 1 : -1;
48 dc->vportExtX = floor(dc->vportExtX * ydim / xdim + 0.5);
49 if (!dc->vportExtX) dc->vportExtX = mincx;
53 INT mincy = (dc->vportExtY >= 0) ? 1 : -1;
54 dc->vportExtY = floor(dc->vportExtY * xdim / ydim + 0.5);
55 if (!dc->vportExtY) dc->vportExtY = mincy;
60 /***********************************************************************
63 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
65 DC * dc = get_dc_ptr( hdc );
66 if (!dc) return FALSE;
68 if (dc->vport2WorldValid)
74 points->x = floor( x * dc->xformVport2World.eM11 +
75 y * dc->xformVport2World.eM21 +
76 dc->xformVport2World.eDx + 0.5 );
77 points->y = floor( x * dc->xformVport2World.eM12 +
78 y * dc->xformVport2World.eM22 +
79 dc->xformVport2World.eDy + 0.5 );
88 /***********************************************************************
91 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
93 DC * dc = get_dc_ptr( hdc );
94 if (!dc) return FALSE;
100 points->x = floor( x * dc->xformWorld2Vport.eM11 +
101 y * dc->xformWorld2Vport.eM21 +
102 dc->xformWorld2Vport.eDx + 0.5 );
103 points->y = floor( x * dc->xformWorld2Vport.eM12 +
104 y * dc->xformWorld2Vport.eM22 +
105 dc->xformWorld2Vport.eDy + 0.5 );
108 release_dc_ptr( dc );
113 /***********************************************************************
114 * SetMapMode (GDI32.@)
116 INT WINAPI SetMapMode( HDC hdc, INT mode )
119 INT horzSize, vertSize, horzRes, vertRes;
121 DC * dc = get_dc_ptr( hdc );
123 if (dc->funcs->pSetMapMode)
125 if((ret = dc->funcs->pSetMapMode( dc->physDev, mode )) != TRUE)
127 if(ret == GDI_NO_MORE_WORK)
133 TRACE("%p %d\n", hdc, mode );
137 if (mode == dc->MapMode && (mode == MM_ISOTROPIC || mode == MM_ANISOTROPIC))
140 horzSize = GetDeviceCaps( hdc, HORZSIZE );
141 vertSize = GetDeviceCaps( hdc, VERTSIZE );
142 horzRes = GetDeviceCaps( hdc, HORZRES );
143 vertRes = GetDeviceCaps( hdc, VERTRES );
154 dc->wndExtX = horzSize * 10;
155 dc->wndExtY = vertSize * 10;
156 dc->vportExtX = horzRes;
157 dc->vportExtY = -vertRes;
160 dc->wndExtX = horzSize * 100;
161 dc->wndExtY = vertSize * 100;
162 dc->vportExtX = horzRes;
163 dc->vportExtY = -vertRes;
166 dc->wndExtX = MulDiv(1000, horzSize, 254);
167 dc->wndExtY = MulDiv(1000, vertSize, 254);
168 dc->vportExtX = horzRes;
169 dc->vportExtY = -vertRes;
172 dc->wndExtX = MulDiv(10000, horzSize, 254);
173 dc->wndExtY = MulDiv(10000, vertSize, 254);
174 dc->vportExtX = horzRes;
175 dc->vportExtY = -vertRes;
178 dc->wndExtX = MulDiv(14400, horzSize, 254);
179 dc->wndExtY = MulDiv(14400, vertSize, 254);
180 dc->vportExtX = horzRes;
181 dc->vportExtY = -vertRes;
189 DC_UpdateXforms( dc );
191 release_dc_ptr( dc );
196 /***********************************************************************
197 * SetViewportExtEx (GDI32.@)
199 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
202 DC * dc = get_dc_ptr( hdc );
203 if (!dc) return FALSE;
204 if (dc->funcs->pSetViewportExt)
206 if((ret = dc->funcs->pSetViewportExt( dc->physDev, x, y )) != TRUE)
208 if(ret == GDI_NO_MORE_WORK)
215 size->cx = dc->vportExtX;
216 size->cy = dc->vportExtY;
218 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
227 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
228 DC_UpdateXforms( dc );
230 release_dc_ptr( dc );
235 /***********************************************************************
236 * SetViewportOrgEx (GDI32.@)
238 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
241 DC * dc = get_dc_ptr( hdc );
242 if (!dc) return FALSE;
243 if (dc->funcs->pSetViewportOrg)
245 if((ret = dc->funcs->pSetViewportOrg( dc->physDev, x, y )) != TRUE)
247 if(ret == GDI_NO_MORE_WORK)
254 pt->x = dc->vportOrgX;
255 pt->y = dc->vportOrgY;
259 DC_UpdateXforms( dc );
262 release_dc_ptr( dc );
267 /***********************************************************************
268 * SetWindowExtEx (GDI32.@)
270 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
273 DC * dc = get_dc_ptr( hdc );
274 if (!dc) return FALSE;
275 if (dc->funcs->pSetWindowExt)
277 if((ret = dc->funcs->pSetWindowExt( dc->physDev, x, y )) != TRUE)
279 if(ret == GDI_NO_MORE_WORK)
286 size->cx = dc->wndExtX;
287 size->cy = dc->wndExtY;
289 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
298 /* The API docs say that you should call SetWindowExtEx before
299 SetViewportExtEx. This advice does not imply that Windows
300 doesn't ensure the isotropic mapping after SetWindowExtEx! */
301 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
302 DC_UpdateXforms( dc );
304 release_dc_ptr( dc );
309 /***********************************************************************
310 * SetWindowOrgEx (GDI32.@)
312 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
315 DC * dc = get_dc_ptr( hdc );
316 if (!dc) return FALSE;
317 if (dc->funcs->pSetWindowOrg)
319 if((ret = dc->funcs->pSetWindowOrg( dc->physDev, x, y )) != TRUE)
321 if(ret == GDI_NO_MORE_WORK)
333 DC_UpdateXforms( dc );
335 release_dc_ptr( dc );
340 /***********************************************************************
341 * OffsetViewportOrgEx (GDI32.@)
343 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
346 DC * dc = get_dc_ptr( hdc );
347 if (!dc) return FALSE;
348 if (dc->funcs->pOffsetViewportOrg)
350 if((ret = dc->funcs->pOffsetViewportOrg( dc->physDev, x, y )) != TRUE)
352 if(ret == GDI_NO_MORE_WORK)
359 pt->x = dc->vportOrgX;
360 pt->y = dc->vportOrgY;
364 DC_UpdateXforms( dc );
366 release_dc_ptr( dc );
371 /***********************************************************************
372 * OffsetWindowOrgEx (GDI32.@)
374 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
377 DC * dc = get_dc_ptr( hdc );
378 if (!dc) return FALSE;
379 if (dc->funcs->pOffsetWindowOrg)
381 if((ret = dc->funcs->pOffsetWindowOrg( dc->physDev, x, y )) != TRUE)
383 if(ret == GDI_NO_MORE_WORK)
395 DC_UpdateXforms( dc );
397 release_dc_ptr( dc );
402 /***********************************************************************
403 * ScaleViewportExtEx (GDI32.@)
405 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
406 INT yNum, INT yDenom, LPSIZE size )
409 DC * dc = get_dc_ptr( hdc );
410 if (!dc) return FALSE;
411 if (dc->funcs->pScaleViewportExt)
413 if((ret = dc->funcs->pScaleViewportExt( dc->physDev, xNum, xDenom, yNum, yDenom )) != TRUE)
415 if(ret == GDI_NO_MORE_WORK)
422 size->cx = dc->vportExtX;
423 size->cy = dc->vportExtY;
425 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
427 if (!xNum || !xDenom || !xNum || !yDenom)
432 dc->vportExtX = (dc->vportExtX * xNum) / xDenom;
433 dc->vportExtY = (dc->vportExtY * yNum) / yDenom;
434 if (dc->vportExtX == 0) dc->vportExtX = 1;
435 if (dc->vportExtY == 0) dc->vportExtY = 1;
436 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
437 DC_UpdateXforms( dc );
439 release_dc_ptr( dc );
444 /***********************************************************************
445 * ScaleWindowExtEx (GDI32.@)
447 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
448 INT yNum, INT yDenom, LPSIZE size )
451 DC * dc = get_dc_ptr( hdc );
452 if (!dc) return FALSE;
453 if (dc->funcs->pScaleWindowExt)
455 if((ret = dc->funcs->pScaleWindowExt( dc->physDev, xNum, xDenom, yNum, yDenom )) != TRUE)
457 if(ret == GDI_NO_MORE_WORK)
464 size->cx = dc->wndExtX;
465 size->cy = dc->wndExtY;
467 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
469 if (!xNum || !xDenom || !xNum || !yDenom)
474 dc->wndExtX = (dc->wndExtX * xNum) / xDenom;
475 dc->wndExtY = (dc->wndExtY * yNum) / yDenom;
476 if (dc->wndExtX == 0) dc->wndExtX = 1;
477 if (dc->wndExtY == 0) dc->wndExtY = 1;
478 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
479 DC_UpdateXforms( dc );
481 release_dc_ptr( dc );