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 prevMode = dc->funcs->pSetMapMode( dc->physDev, mode );
158 TRACE("%04x %d\n", hdc, mode );
160 prevMode = dc->MapMode;
161 horzSize = GetDeviceCaps( hdc, HORZSIZE );
162 vertSize = GetDeviceCaps( hdc, VERTSIZE );
163 horzRes = GetDeviceCaps( hdc, HORZRES );
164 vertRes = GetDeviceCaps( hdc, VERTRES );
175 dc->wndExtX = horzSize;
176 dc->wndExtY = vertSize;
177 dc->vportExtX = horzRes / 10;
178 dc->vportExtY = vertRes / -10;
181 dc->wndExtX = horzSize * 10;
182 dc->wndExtY = vertSize * 10;
183 dc->vportExtX = horzRes / 10;
184 dc->vportExtY = vertRes / -10;
187 dc->wndExtX = horzSize;
188 dc->wndExtY = vertSize;
189 dc->vportExtX = 254L * horzRes / 1000;
190 dc->vportExtY = -254L * vertRes / 1000;
193 dc->wndExtX = horzSize * 10;
194 dc->wndExtY = vertSize * 10;
195 dc->vportExtX = 254L * horzRes / 1000;
196 dc->vportExtY = -254L * vertRes / 1000;
199 dc->wndExtX = 144L * horzSize / 10;
200 dc->wndExtY = 144L * vertSize / 10;
201 dc->vportExtX = 254L * horzRes / 1000;
202 dc->vportExtY = -254L * vertRes / 1000;
210 DC_UpdateXforms( dc );
212 GDI_ReleaseObj( hdc );
217 /***********************************************************************
218 * SetViewportExtEx (GDI32.@)
220 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
223 DC * dc = DC_GetDCPtr( hdc );
224 if (!dc) return FALSE;
225 if (dc->funcs->pSetViewportExt)
227 ret = dc->funcs->pSetViewportExt( dc->physDev, x, y );
232 size->cx = dc->vportExtX;
233 size->cy = dc->vportExtY;
235 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
244 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
245 DC_UpdateXforms( dc );
247 GDI_ReleaseObj( hdc );
252 /***********************************************************************
253 * SetViewportOrgEx (GDI32.@)
255 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
258 DC * dc = DC_GetDCPtr( hdc );
259 if (!dc) return FALSE;
260 if (dc->funcs->pSetViewportOrg)
261 ret = dc->funcs->pSetViewportOrg( dc->physDev, x, y );
266 pt->x = dc->vportOrgX;
267 pt->y = dc->vportOrgY;
271 DC_UpdateXforms( dc );
273 GDI_ReleaseObj( hdc );
278 /***********************************************************************
279 * SetWindowExtEx (GDI32.@)
281 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
284 DC * dc = DC_GetDCPtr( hdc );
285 if (!dc) return FALSE;
286 if (dc->funcs->pSetWindowExt)
288 ret = dc->funcs->pSetWindowExt( dc->physDev, x, y );
293 size->cx = dc->wndExtX;
294 size->cy = dc->wndExtY;
296 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
305 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
306 DC_UpdateXforms( dc );
308 GDI_ReleaseObj( hdc );
313 /***********************************************************************
314 * SetWindowOrgEx (GDI32.@)
316 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
319 DC * dc = DC_GetDCPtr( hdc );
320 if (!dc) return FALSE;
321 if (dc->funcs->pSetWindowOrg) ret = dc->funcs->pSetWindowOrg( dc->physDev, x, y );
331 DC_UpdateXforms( dc );
333 GDI_ReleaseObj( hdc );
338 /***********************************************************************
339 * OffsetViewportOrgEx (GDI32.@)
341 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
344 DC * dc = DC_GetDCPtr( hdc );
345 if (!dc) return FALSE;
346 if (dc->funcs->pOffsetViewportOrg)
347 ret = dc->funcs->pOffsetViewportOrg( dc->physDev, x, y );
352 pt->x = dc->vportOrgX;
353 pt->y = dc->vportOrgY;
357 DC_UpdateXforms( dc );
359 GDI_ReleaseObj( hdc );
364 /***********************************************************************
365 * OffsetWindowOrgEx (GDI32.@)
367 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
370 DC * dc = DC_GetDCPtr( hdc );
371 if (!dc) return FALSE;
372 if (dc->funcs->pOffsetWindowOrg)
373 ret = dc->funcs->pOffsetWindowOrg( dc->physDev, x, y );
383 DC_UpdateXforms( dc );
385 GDI_ReleaseObj( hdc );
390 /***********************************************************************
391 * ScaleViewportExtEx (GDI32.@)
393 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
394 INT yNum, INT yDenom, LPSIZE size )
397 DC * dc = DC_GetDCPtr( hdc );
398 if (!dc) return FALSE;
399 if (dc->funcs->pScaleViewportExt)
401 ret = dc->funcs->pScaleViewportExt( dc->physDev, xNum, xDenom, yNum, yDenom );
406 size->cx = dc->vportExtX;
407 size->cy = dc->vportExtY;
409 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
411 if (!xNum || !xDenom || !xNum || !yDenom)
416 dc->vportExtX = (dc->vportExtX * xNum) / xDenom;
417 dc->vportExtY = (dc->vportExtY * yNum) / yDenom;
418 if (dc->vportExtX == 0) dc->vportExtX = 1;
419 if (dc->vportExtY == 0) dc->vportExtY = 1;
420 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
421 DC_UpdateXforms( dc );
423 GDI_ReleaseObj( hdc );
428 /***********************************************************************
429 * ScaleWindowExtEx (GDI32.@)
431 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
432 INT yNum, INT yDenom, LPSIZE size )
435 DC * dc = DC_GetDCPtr( hdc );
436 if (!dc) return FALSE;
437 if (dc->funcs->pScaleWindowExt)
439 ret = dc->funcs->pScaleWindowExt( dc->physDev, xNum, xDenom, yNum, yDenom );
444 size->cx = dc->wndExtX;
445 size->cy = dc->wndExtY;
447 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
449 if (!xNum || !xDenom || !xNum || !yDenom)
454 dc->wndExtX = (dc->wndExtX * xNum) / xDenom;
455 dc->wndExtY = (dc->wndExtY * yNum) / yDenom;
456 if (dc->wndExtX == 0) dc->wndExtX = 1;
457 if (dc->wndExtY == 0) dc->wndExtY = 1;
458 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
459 DC_UpdateXforms( dc );
461 GDI_ReleaseObj( hdc );