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
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
27 /***********************************************************************
28 * MAPPING_FixIsotropic
30 * Fix viewport extensions for isotropic mode.
32 void MAPPING_FixIsotropic( DC * dc )
34 double xdim = (double)dc->vportExtX * GetDeviceCaps( dc->hSelf, HORZSIZE ) /
35 (GetDeviceCaps( dc->hSelf, HORZRES ) * dc->wndExtX);
36 double ydim = (double)dc->vportExtY * GetDeviceCaps( dc->hSelf, VERTSIZE ) /
37 (GetDeviceCaps( dc->hSelf, VERTRES ) * dc->wndExtY);
40 dc->vportExtX = dc->vportExtX * fabs( ydim / xdim );
41 if (!dc->vportExtX) dc->vportExtX = 1;
45 dc->vportExtY = dc->vportExtY * fabs( xdim / ydim );
46 if (!dc->vportExtY) dc->vportExtY = 1;
51 /***********************************************************************
54 BOOL16 WINAPI DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
56 DC * dc = DC_GetDCPtr( hdc );
57 if (!dc) return FALSE;
61 points->x = MulDiv( points->x - dc->vportOrgX, dc->wndExtX, dc->vportExtX ) + dc->wndOrgX;
62 points->y = MulDiv( points->y - dc->vportOrgY, dc->wndExtY, dc->vportExtY ) + dc->wndOrgY;
65 GDI_ReleaseObj( hdc );
70 /***********************************************************************
73 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
75 DC * dc = DC_GetDCPtr( hdc );
76 if (!dc) return FALSE;
78 if (dc->vport2WorldValid)
84 points->x = floor( x * dc->xformVport2World.eM11 +
85 y * dc->xformVport2World.eM21 +
86 dc->xformVport2World.eDx + 0.5 );
87 points->y = floor( x * dc->xformVport2World.eM12 +
88 y * dc->xformVport2World.eM22 +
89 dc->xformVport2World.eDy + 0.5 );
93 GDI_ReleaseObj( hdc );
98 /***********************************************************************
101 BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
103 DC * dc = DC_GetDCPtr( hdc );
104 if (!dc) return FALSE;
108 points->x = MulDiv( points->x - dc->wndOrgX, dc->vportExtX, dc->wndExtX ) + dc->vportOrgX;
109 points->y = MulDiv( points->y - dc->wndOrgY, dc->vportExtY, dc->wndExtY ) + dc->vportOrgY;
112 GDI_ReleaseObj( hdc );
117 /***********************************************************************
120 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
122 DC * dc = DC_GetDCPtr( hdc );
123 if (!dc) return FALSE;
129 points->x = floor( x * dc->xformWorld2Vport.eM11 +
130 y * dc->xformWorld2Vport.eM21 +
131 dc->xformWorld2Vport.eDx + 0.5 );
132 points->y = floor( x * dc->xformWorld2Vport.eM12 +
133 y * dc->xformWorld2Vport.eM22 +
134 dc->xformWorld2Vport.eDy + 0.5 );
137 GDI_ReleaseObj( hdc );
142 /***********************************************************************
143 * SetMapMode (GDI32.@)
145 INT WINAPI SetMapMode( HDC hdc, INT mode )
148 INT horzSize, vertSize, horzRes, vertRes;
150 DC * dc = DC_GetDCPtr( hdc );
152 if (dc->funcs->pSetMapMode)
154 if((ret = dc->funcs->pSetMapMode( dc->physDev, mode )) != TRUE)
156 if(ret == GDI_NO_MORE_WORK)
162 TRACE("%04x %d\n", hdc, mode );
165 horzSize = GetDeviceCaps( hdc, HORZSIZE );
166 vertSize = GetDeviceCaps( hdc, VERTSIZE );
167 horzRes = GetDeviceCaps( hdc, HORZRES );
168 vertRes = GetDeviceCaps( hdc, VERTRES );
179 dc->wndExtX = horzSize;
180 dc->wndExtY = vertSize;
181 dc->vportExtX = horzRes / 10;
182 dc->vportExtY = vertRes / -10;
185 dc->wndExtX = horzSize * 10;
186 dc->wndExtY = vertSize * 10;
187 dc->vportExtX = horzRes / 10;
188 dc->vportExtY = vertRes / -10;
191 dc->wndExtX = horzSize;
192 dc->wndExtY = vertSize;
193 dc->vportExtX = 254L * horzRes / 1000;
194 dc->vportExtY = -254L * vertRes / 1000;
197 dc->wndExtX = horzSize * 10;
198 dc->wndExtY = vertSize * 10;
199 dc->vportExtX = 254L * horzRes / 1000;
200 dc->vportExtY = -254L * vertRes / 1000;
203 dc->wndExtX = 144L * horzSize / 10;
204 dc->wndExtY = 144L * vertSize / 10;
205 dc->vportExtX = 254L * horzRes / 1000;
206 dc->vportExtY = -254L * vertRes / 1000;
214 DC_UpdateXforms( dc );
216 GDI_ReleaseObj( hdc );
221 /***********************************************************************
222 * SetViewportExtEx (GDI32.@)
224 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
227 DC * dc = DC_GetDCPtr( hdc );
228 if (!dc) return FALSE;
229 if (dc->funcs->pSetViewportExt)
231 if((ret = dc->funcs->pSetViewportExt( dc->physDev, x, y )) != TRUE)
233 if(ret == GDI_NO_MORE_WORK)
240 size->cx = dc->vportExtX;
241 size->cy = dc->vportExtY;
243 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
252 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
253 DC_UpdateXforms( dc );
255 GDI_ReleaseObj( hdc );
260 /***********************************************************************
261 * SetViewportOrgEx (GDI32.@)
263 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
266 DC * dc = DC_GetDCPtr( hdc );
267 if (!dc) return FALSE;
268 if (dc->funcs->pSetViewportOrg)
270 if((ret = dc->funcs->pSetViewportOrg( dc->physDev, x, y )) != TRUE)
272 if(ret == GDI_NO_MORE_WORK)
279 pt->x = dc->vportOrgX;
280 pt->y = dc->vportOrgY;
284 DC_UpdateXforms( dc );
287 GDI_ReleaseObj( hdc );
292 /***********************************************************************
293 * SetWindowExtEx (GDI32.@)
295 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
298 DC * dc = DC_GetDCPtr( hdc );
299 if (!dc) return FALSE;
300 if (dc->funcs->pSetWindowExt)
302 if((ret = dc->funcs->pSetWindowExt( dc->physDev, x, y )) != TRUE)
304 if(ret == GDI_NO_MORE_WORK)
311 size->cx = dc->wndExtX;
312 size->cy = dc->wndExtY;
314 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
323 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
324 DC_UpdateXforms( dc );
326 GDI_ReleaseObj( hdc );
331 /***********************************************************************
332 * SetWindowOrgEx (GDI32.@)
334 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
337 DC * dc = DC_GetDCPtr( hdc );
338 if (!dc) return FALSE;
339 if (dc->funcs->pSetWindowOrg)
341 if((ret = dc->funcs->pSetWindowOrg( dc->physDev, x, y )) != TRUE)
343 if(ret == GDI_NO_MORE_WORK)
355 DC_UpdateXforms( dc );
357 GDI_ReleaseObj( hdc );
362 /***********************************************************************
363 * OffsetViewportOrgEx (GDI32.@)
365 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
368 DC * dc = DC_GetDCPtr( hdc );
369 if (!dc) return FALSE;
370 if (dc->funcs->pOffsetViewportOrg)
372 if((ret = dc->funcs->pOffsetViewportOrg( dc->physDev, x, y )) != TRUE)
374 if(ret == GDI_NO_MORE_WORK)
381 pt->x = dc->vportOrgX;
382 pt->y = dc->vportOrgY;
386 DC_UpdateXforms( dc );
388 GDI_ReleaseObj( hdc );
393 /***********************************************************************
394 * OffsetWindowOrgEx (GDI32.@)
396 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
399 DC * dc = DC_GetDCPtr( hdc );
400 if (!dc) return FALSE;
401 if (dc->funcs->pOffsetWindowOrg)
403 if((ret = dc->funcs->pOffsetWindowOrg( dc->physDev, x, y )) != TRUE)
405 if(ret == GDI_NO_MORE_WORK)
417 DC_UpdateXforms( dc );
419 GDI_ReleaseObj( hdc );
424 /***********************************************************************
425 * ScaleViewportExtEx (GDI32.@)
427 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
428 INT yNum, INT yDenom, LPSIZE size )
431 DC * dc = DC_GetDCPtr( hdc );
432 if (!dc) return FALSE;
433 if (dc->funcs->pScaleViewportExt)
435 if((ret = dc->funcs->pScaleViewportExt( dc->physDev, xNum, xDenom, yNum, yDenom )) != TRUE)
437 if(ret == GDI_NO_MORE_WORK)
444 size->cx = dc->vportExtX;
445 size->cy = dc->vportExtY;
447 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
449 if (!xNum || !xDenom || !xNum || !yDenom)
454 dc->vportExtX = (dc->vportExtX * xNum) / xDenom;
455 dc->vportExtY = (dc->vportExtY * yNum) / yDenom;
456 if (dc->vportExtX == 0) dc->vportExtX = 1;
457 if (dc->vportExtY == 0) dc->vportExtY = 1;
458 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
459 DC_UpdateXforms( dc );
461 GDI_ReleaseObj( hdc );
466 /***********************************************************************
467 * ScaleWindowExtEx (GDI32.@)
469 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
470 INT yNum, INT yDenom, LPSIZE size )
473 DC * dc = DC_GetDCPtr( hdc );
474 if (!dc) return FALSE;
475 if (dc->funcs->pScaleWindowExt)
477 if((ret = dc->funcs->pScaleWindowExt( dc->physDev, xNum, xDenom, yNum, yDenom )) != TRUE)
479 if(ret == GDI_NO_MORE_WORK)
486 size->cx = dc->wndExtX;
487 size->cy = dc->wndExtY;
489 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
491 if (!xNum || !xDenom || !xNum || !yDenom)
496 dc->wndExtX = (dc->wndExtX * xNum) / xDenom;
497 dc->wndExtY = (dc->wndExtY * yNum) / yDenom;
498 if (dc->wndExtX == 0) dc->wndExtX = 1;
499 if (dc->wndExtY == 0) dc->wndExtY = 1;
500 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
501 DC_UpdateXforms( dc );
503 GDI_ReleaseObj( hdc );