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 "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
28 /***********************************************************************
29 * MAPPING_FixIsotropic
31 * Fix viewport extensions for isotropic mode.
33 void MAPPING_FixIsotropic( DC * dc )
35 double xdim = (double)dc->vportExtX * GetDeviceCaps( dc->hSelf, HORZSIZE ) /
36 (GetDeviceCaps( dc->hSelf, HORZRES ) * dc->wndExtX);
37 double ydim = (double)dc->vportExtY * GetDeviceCaps( dc->hSelf, VERTSIZE ) /
38 (GetDeviceCaps( dc->hSelf, VERTRES ) * dc->wndExtY);
41 dc->vportExtX = dc->vportExtX * fabs( ydim / xdim );
42 if (!dc->vportExtX) dc->vportExtX = 1;
46 dc->vportExtY = dc->vportExtY * fabs( xdim / ydim );
47 if (!dc->vportExtY) dc->vportExtY = 1;
52 /***********************************************************************
55 BOOL16 WINAPI DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
57 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
58 if (!dc) return FALSE;
62 points->x = MulDiv( points->x - dc->vportOrgX, dc->wndExtX, dc->vportExtX ) + dc->wndOrgX;
63 points->y = MulDiv( points->y - dc->vportOrgY, dc->wndExtY, dc->vportExtY ) + dc->wndOrgY;
66 GDI_ReleaseObj( HDC_32(hdc) );
71 /***********************************************************************
74 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
76 DC * dc = DC_GetDCPtr( hdc );
77 if (!dc) return FALSE;
79 if (dc->vport2WorldValid)
85 points->x = floor( x * dc->xformVport2World.eM11 +
86 y * dc->xformVport2World.eM21 +
87 dc->xformVport2World.eDx + 0.5 );
88 points->y = floor( x * dc->xformVport2World.eM12 +
89 y * dc->xformVport2World.eM22 +
90 dc->xformVport2World.eDy + 0.5 );
94 GDI_ReleaseObj( hdc );
99 /***********************************************************************
102 BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
104 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
105 if (!dc) return FALSE;
109 points->x = MulDiv( points->x - dc->wndOrgX, dc->vportExtX, dc->wndExtX ) + dc->vportOrgX;
110 points->y = MulDiv( points->y - dc->wndOrgY, dc->vportExtY, dc->wndExtY ) + dc->vportOrgY;
113 GDI_ReleaseObj( HDC_32(hdc) );
118 /***********************************************************************
121 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
123 DC * dc = DC_GetDCPtr( hdc );
124 if (!dc) return FALSE;
130 points->x = floor( x * dc->xformWorld2Vport.eM11 +
131 y * dc->xformWorld2Vport.eM21 +
132 dc->xformWorld2Vport.eDx + 0.5 );
133 points->y = floor( x * dc->xformWorld2Vport.eM12 +
134 y * dc->xformWorld2Vport.eM22 +
135 dc->xformWorld2Vport.eDy + 0.5 );
138 GDI_ReleaseObj( hdc );
143 /***********************************************************************
144 * SetMapMode (GDI32.@)
146 INT WINAPI SetMapMode( HDC hdc, INT mode )
149 INT horzSize, vertSize, horzRes, vertRes;
151 DC * dc = DC_GetDCPtr( hdc );
153 if (dc->funcs->pSetMapMode)
155 if((ret = dc->funcs->pSetMapMode( dc->physDev, mode )) != TRUE)
157 if(ret == GDI_NO_MORE_WORK)
163 TRACE("%p %d\n", hdc, mode );
166 horzSize = GetDeviceCaps( hdc, HORZSIZE );
167 vertSize = GetDeviceCaps( hdc, VERTSIZE );
168 horzRes = GetDeviceCaps( hdc, HORZRES );
169 vertRes = GetDeviceCaps( hdc, VERTRES );
180 dc->wndExtX = horzSize;
181 dc->wndExtY = vertSize;
182 dc->vportExtX = horzRes / 10;
183 dc->vportExtY = vertRes / -10;
186 dc->wndExtX = horzSize * 10;
187 dc->wndExtY = vertSize * 10;
188 dc->vportExtX = horzRes / 10;
189 dc->vportExtY = vertRes / -10;
192 dc->wndExtX = horzSize;
193 dc->wndExtY = vertSize;
194 dc->vportExtX = 254L * horzRes / 1000;
195 dc->vportExtY = -254L * vertRes / 1000;
198 dc->wndExtX = horzSize * 10;
199 dc->wndExtY = vertSize * 10;
200 dc->vportExtX = 254L * horzRes / 1000;
201 dc->vportExtY = -254L * vertRes / 1000;
204 dc->wndExtX = 144L * horzSize / 10;
205 dc->wndExtY = 144L * vertSize / 10;
206 dc->vportExtX = 254L * horzRes / 1000;
207 dc->vportExtY = -254L * vertRes / 1000;
215 DC_UpdateXforms( dc );
217 GDI_ReleaseObj( hdc );
222 /***********************************************************************
223 * SetViewportExtEx (GDI32.@)
225 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
228 DC * dc = DC_GetDCPtr( hdc );
229 if (!dc) return FALSE;
230 if (dc->funcs->pSetViewportExt)
232 if((ret = dc->funcs->pSetViewportExt( dc->physDev, x, y )) != TRUE)
234 if(ret == GDI_NO_MORE_WORK)
241 size->cx = dc->vportExtX;
242 size->cy = dc->vportExtY;
244 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
253 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
254 DC_UpdateXforms( dc );
256 GDI_ReleaseObj( hdc );
261 /***********************************************************************
262 * SetViewportOrgEx (GDI32.@)
264 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
267 DC * dc = DC_GetDCPtr( hdc );
268 if (!dc) return FALSE;
269 if (dc->funcs->pSetViewportOrg)
271 if((ret = dc->funcs->pSetViewportOrg( dc->physDev, x, y )) != TRUE)
273 if(ret == GDI_NO_MORE_WORK)
280 pt->x = dc->vportOrgX;
281 pt->y = dc->vportOrgY;
285 DC_UpdateXforms( dc );
288 GDI_ReleaseObj( hdc );
293 /***********************************************************************
294 * SetWindowExtEx (GDI32.@)
296 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
299 DC * dc = DC_GetDCPtr( hdc );
300 if (!dc) return FALSE;
301 if (dc->funcs->pSetWindowExt)
303 if((ret = dc->funcs->pSetWindowExt( dc->physDev, x, y )) != TRUE)
305 if(ret == GDI_NO_MORE_WORK)
312 size->cx = dc->wndExtX;
313 size->cy = dc->wndExtY;
315 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
324 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
325 DC_UpdateXforms( dc );
327 GDI_ReleaseObj( hdc );
332 /***********************************************************************
333 * SetWindowOrgEx (GDI32.@)
335 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
338 DC * dc = DC_GetDCPtr( hdc );
339 if (!dc) return FALSE;
340 if (dc->funcs->pSetWindowOrg)
342 if((ret = dc->funcs->pSetWindowOrg( dc->physDev, x, y )) != TRUE)
344 if(ret == GDI_NO_MORE_WORK)
356 DC_UpdateXforms( dc );
358 GDI_ReleaseObj( hdc );
363 /***********************************************************************
364 * OffsetViewportOrgEx (GDI32.@)
366 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
369 DC * dc = DC_GetDCPtr( hdc );
370 if (!dc) return FALSE;
371 if (dc->funcs->pOffsetViewportOrg)
373 if((ret = dc->funcs->pOffsetViewportOrg( dc->physDev, x, y )) != TRUE)
375 if(ret == GDI_NO_MORE_WORK)
382 pt->x = dc->vportOrgX;
383 pt->y = dc->vportOrgY;
387 DC_UpdateXforms( dc );
389 GDI_ReleaseObj( hdc );
394 /***********************************************************************
395 * OffsetWindowOrgEx (GDI32.@)
397 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
400 DC * dc = DC_GetDCPtr( hdc );
401 if (!dc) return FALSE;
402 if (dc->funcs->pOffsetWindowOrg)
404 if((ret = dc->funcs->pOffsetWindowOrg( dc->physDev, x, y )) != TRUE)
406 if(ret == GDI_NO_MORE_WORK)
418 DC_UpdateXforms( dc );
420 GDI_ReleaseObj( hdc );
425 /***********************************************************************
426 * ScaleViewportExtEx (GDI32.@)
428 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
429 INT yNum, INT yDenom, LPSIZE size )
432 DC * dc = DC_GetDCPtr( hdc );
433 if (!dc) return FALSE;
434 if (dc->funcs->pScaleViewportExt)
436 if((ret = dc->funcs->pScaleViewportExt( dc->physDev, xNum, xDenom, yNum, yDenom )) != TRUE)
438 if(ret == GDI_NO_MORE_WORK)
445 size->cx = dc->vportExtX;
446 size->cy = dc->vportExtY;
448 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
450 if (!xNum || !xDenom || !xNum || !yDenom)
455 dc->vportExtX = (dc->vportExtX * xNum) / xDenom;
456 dc->vportExtY = (dc->vportExtY * yNum) / yDenom;
457 if (dc->vportExtX == 0) dc->vportExtX = 1;
458 if (dc->vportExtY == 0) dc->vportExtY = 1;
459 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
460 DC_UpdateXforms( dc );
462 GDI_ReleaseObj( hdc );
467 /***********************************************************************
468 * ScaleWindowExtEx (GDI32.@)
470 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
471 INT yNum, INT yDenom, LPSIZE size )
474 DC * dc = DC_GetDCPtr( hdc );
475 if (!dc) return FALSE;
476 if (dc->funcs->pScaleWindowExt)
478 if((ret = dc->funcs->pScaleWindowExt( dc->physDev, xNum, xDenom, yNum, yDenom )) != TRUE)
480 if(ret == GDI_NO_MORE_WORK)
487 size->cx = dc->wndExtX;
488 size->cy = dc->wndExtY;
490 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
492 if (!xNum || !xDenom || !xNum || !yDenom)
497 dc->wndExtX = (dc->wndExtX * xNum) / xDenom;
498 dc->wndExtY = (dc->wndExtY * yNum) / yDenom;
499 if (dc->wndExtX == 0) dc->wndExtX = 1;
500 if (dc->wndExtY == 0) dc->wndExtY = 1;
501 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
502 DC_UpdateXforms( dc );
504 GDI_ReleaseObj( hdc );