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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "gdi_private.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
29 /***********************************************************************
30 * MAPPING_FixIsotropic
32 * Fix viewport extensions for isotropic mode.
34 void MAPPING_FixIsotropic( DC * dc )
36 double xdim = (double)dc->vportExtX * GetDeviceCaps( dc->hSelf, HORZSIZE ) /
37 (GetDeviceCaps( dc->hSelf, HORZRES ) * dc->wndExtX);
38 double ydim = (double)dc->vportExtY * GetDeviceCaps( dc->hSelf, VERTSIZE ) /
39 (GetDeviceCaps( dc->hSelf, VERTRES ) * dc->wndExtY);
42 dc->vportExtX = floor(dc->vportExtX * fabs( ydim / xdim ) + 0.5);
43 if (!dc->vportExtX) dc->vportExtX = 1;
47 dc->vportExtY = floor(dc->vportExtY * fabs( xdim / ydim ) + 0.5);
48 if (!dc->vportExtY) dc->vportExtY = 1;
53 /***********************************************************************
56 BOOL16 WINAPI DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
58 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
59 if (!dc) return FALSE;
63 points->x = MulDiv( points->x - dc->vportOrgX, dc->wndExtX, dc->vportExtX ) + dc->wndOrgX;
64 points->y = MulDiv( points->y - dc->vportOrgY, dc->wndExtY, dc->vportExtY ) + dc->wndOrgY;
67 GDI_ReleaseObj( HDC_32(hdc) );
72 /***********************************************************************
75 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
77 DC * dc = DC_GetDCPtr( hdc );
78 if (!dc) return FALSE;
80 if (dc->vport2WorldValid)
86 points->x = floor( x * dc->xformVport2World.eM11 +
87 y * dc->xformVport2World.eM21 +
88 dc->xformVport2World.eDx + 0.5 );
89 points->y = floor( x * dc->xformVport2World.eM12 +
90 y * dc->xformVport2World.eM22 +
91 dc->xformVport2World.eDy + 0.5 );
95 GDI_ReleaseObj( hdc );
100 /***********************************************************************
103 BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
105 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
106 if (!dc) return FALSE;
110 points->x = MulDiv( points->x - dc->wndOrgX, dc->vportExtX, dc->wndExtX ) + dc->vportOrgX;
111 points->y = MulDiv( points->y - dc->wndOrgY, dc->vportExtY, dc->wndExtY ) + dc->vportOrgY;
114 GDI_ReleaseObj( HDC_32(hdc) );
119 /***********************************************************************
122 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
124 DC * dc = DC_GetDCPtr( hdc );
125 if (!dc) return FALSE;
131 points->x = floor( x * dc->xformWorld2Vport.eM11 +
132 y * dc->xformWorld2Vport.eM21 +
133 dc->xformWorld2Vport.eDx + 0.5 );
134 points->y = floor( x * dc->xformWorld2Vport.eM12 +
135 y * dc->xformWorld2Vport.eM22 +
136 dc->xformWorld2Vport.eDy + 0.5 );
139 GDI_ReleaseObj( hdc );
144 /***********************************************************************
145 * SetMapMode (GDI32.@)
147 INT WINAPI SetMapMode( HDC hdc, INT mode )
150 INT horzSize, vertSize, horzRes, vertRes;
152 DC * dc = DC_GetDCPtr( hdc );
154 if (dc->funcs->pSetMapMode)
156 if((ret = dc->funcs->pSetMapMode( dc->physDev, mode )) != TRUE)
158 if(ret == GDI_NO_MORE_WORK)
164 TRACE("%p %d\n", hdc, mode );
168 if (mode == dc->MapMode && (mode == MM_ISOTROPIC || mode == MM_ANISOTROPIC))
171 horzSize = GetDeviceCaps( hdc, HORZSIZE );
172 vertSize = GetDeviceCaps( hdc, VERTSIZE );
173 horzRes = GetDeviceCaps( hdc, HORZRES );
174 vertRes = GetDeviceCaps( hdc, VERTRES );
185 dc->wndExtX = horzSize * 10;
186 dc->wndExtY = vertSize * 10;
187 dc->vportExtX = horzRes;
188 dc->vportExtY = -vertRes;
191 dc->wndExtX = horzSize * 100;
192 dc->wndExtY = vertSize * 100;
193 dc->vportExtX = horzRes;
194 dc->vportExtY = -vertRes;
197 dc->wndExtX = MulDiv(1000, horzSize, 254);
198 dc->wndExtY = MulDiv(1000, vertSize, 254);
199 dc->vportExtX = horzRes;
200 dc->vportExtY = -vertRes;
203 dc->wndExtX = MulDiv(10000, horzSize, 254);
204 dc->wndExtY = MulDiv(10000, vertSize, 254);
205 dc->vportExtX = horzRes;
206 dc->vportExtY = -vertRes;
209 dc->wndExtX = MulDiv(14400, horzSize, 254);
210 dc->wndExtY = MulDiv(14400, vertSize, 254);
211 dc->vportExtX = horzRes;
212 dc->vportExtY = -vertRes;
220 DC_UpdateXforms( dc );
222 GDI_ReleaseObj( hdc );
227 /***********************************************************************
228 * SetViewportExtEx (GDI32.@)
230 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
233 DC * dc = DC_GetDCPtr( hdc );
234 if (!dc) return FALSE;
235 if (dc->funcs->pSetViewportExt)
237 if((ret = dc->funcs->pSetViewportExt( dc->physDev, x, y )) != TRUE)
239 if(ret == GDI_NO_MORE_WORK)
246 size->cx = dc->vportExtX;
247 size->cy = dc->vportExtY;
249 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
258 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
259 DC_UpdateXforms( dc );
261 GDI_ReleaseObj( hdc );
266 /***********************************************************************
267 * SetViewportOrgEx (GDI32.@)
269 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
272 DC * dc = DC_GetDCPtr( hdc );
273 if (!dc) return FALSE;
274 if (dc->funcs->pSetViewportOrg)
276 if((ret = dc->funcs->pSetViewportOrg( dc->physDev, x, y )) != TRUE)
278 if(ret == GDI_NO_MORE_WORK)
285 pt->x = dc->vportOrgX;
286 pt->y = dc->vportOrgY;
290 DC_UpdateXforms( dc );
293 GDI_ReleaseObj( hdc );
298 /***********************************************************************
299 * SetWindowExtEx (GDI32.@)
301 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
304 DC * dc = DC_GetDCPtr( hdc );
305 if (!dc) return FALSE;
306 if (dc->funcs->pSetWindowExt)
308 if((ret = dc->funcs->pSetWindowExt( dc->physDev, x, y )) != TRUE)
310 if(ret == GDI_NO_MORE_WORK)
317 size->cx = dc->wndExtX;
318 size->cy = dc->wndExtY;
320 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
329 /* Windows fixes MM_ISOTROPIC mode only in SetViewportExtEx() */
330 DC_UpdateXforms( dc );
332 GDI_ReleaseObj( hdc );
337 /***********************************************************************
338 * SetWindowOrgEx (GDI32.@)
340 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
343 DC * dc = DC_GetDCPtr( hdc );
344 if (!dc) return FALSE;
345 if (dc->funcs->pSetWindowOrg)
347 if((ret = dc->funcs->pSetWindowOrg( dc->physDev, x, y )) != TRUE)
349 if(ret == GDI_NO_MORE_WORK)
361 DC_UpdateXforms( dc );
363 GDI_ReleaseObj( hdc );
368 /***********************************************************************
369 * OffsetViewportOrgEx (GDI32.@)
371 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
374 DC * dc = DC_GetDCPtr( hdc );
375 if (!dc) return FALSE;
376 if (dc->funcs->pOffsetViewportOrg)
378 if((ret = dc->funcs->pOffsetViewportOrg( dc->physDev, x, y )) != TRUE)
380 if(ret == GDI_NO_MORE_WORK)
387 pt->x = dc->vportOrgX;
388 pt->y = dc->vportOrgY;
392 DC_UpdateXforms( dc );
394 GDI_ReleaseObj( hdc );
399 /***********************************************************************
400 * OffsetWindowOrgEx (GDI32.@)
402 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
405 DC * dc = DC_GetDCPtr( hdc );
406 if (!dc) return FALSE;
407 if (dc->funcs->pOffsetWindowOrg)
409 if((ret = dc->funcs->pOffsetWindowOrg( dc->physDev, x, y )) != TRUE)
411 if(ret == GDI_NO_MORE_WORK)
423 DC_UpdateXforms( dc );
425 GDI_ReleaseObj( hdc );
430 /***********************************************************************
431 * ScaleViewportExtEx (GDI32.@)
433 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
434 INT yNum, INT yDenom, LPSIZE size )
437 DC * dc = DC_GetDCPtr( hdc );
438 if (!dc) return FALSE;
439 if (dc->funcs->pScaleViewportExt)
441 if((ret = dc->funcs->pScaleViewportExt( dc->physDev, xNum, xDenom, yNum, yDenom )) != TRUE)
443 if(ret == GDI_NO_MORE_WORK)
450 size->cx = dc->vportExtX;
451 size->cy = dc->vportExtY;
453 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
455 if (!xNum || !xDenom || !xNum || !yDenom)
460 dc->vportExtX = (dc->vportExtX * xNum) / xDenom;
461 dc->vportExtY = (dc->vportExtY * yNum) / yDenom;
462 if (dc->vportExtX == 0) dc->vportExtX = 1;
463 if (dc->vportExtY == 0) dc->vportExtY = 1;
464 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
465 DC_UpdateXforms( dc );
467 GDI_ReleaseObj( hdc );
472 /***********************************************************************
473 * ScaleWindowExtEx (GDI32.@)
475 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
476 INT yNum, INT yDenom, LPSIZE size )
479 DC * dc = DC_GetDCPtr( hdc );
480 if (!dc) return FALSE;
481 if (dc->funcs->pScaleWindowExt)
483 if((ret = dc->funcs->pScaleWindowExt( dc->physDev, xNum, xDenom, yNum, yDenom )) != TRUE)
485 if(ret == GDI_NO_MORE_WORK)
492 size->cx = dc->wndExtX;
493 size->cy = dc->wndExtY;
495 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
497 if (!xNum || !xDenom || !xNum || !yDenom)
502 dc->wndExtX = (dc->wndExtX * xNum) / xDenom;
503 dc->wndExtY = (dc->wndExtY * yNum) / yDenom;
504 if (dc->wndExtX == 0) dc->wndExtX = 1;
505 if (dc->wndExtY == 0) dc->wndExtY = 1;
506 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
507 DC_UpdateXforms( dc );
509 GDI_ReleaseObj( hdc );