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 *) GDI_GetObjPtr( hdc, DC_MAGIC );
57 if (!dc) return FALSE;
61 points->x = XDPTOLP( dc, points->x );
62 points->y = YDPTOLP( dc, points->y );
65 GDI_ReleaseObj( hdc );
70 /***********************************************************************
73 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
75 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
76 if (!dc) return FALSE;
80 if (!INTERNAL_DPTOLP( dc, points ))
84 GDI_ReleaseObj( hdc );
89 /***********************************************************************
92 BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
94 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
95 if (!dc) return FALSE;
99 points->x = XLPTODP( dc, points->x );
100 points->y = YLPTODP( dc, points->y );
103 GDI_ReleaseObj( hdc );
108 /***********************************************************************
111 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
113 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
114 if (!dc) return FALSE;
118 INTERNAL_LPTODP( dc, points );
121 GDI_ReleaseObj( hdc );
126 /***********************************************************************
129 INT16 WINAPI SetMapMode16( HDC16 hdc, INT16 mode )
131 return SetMapMode( hdc, mode );
135 /***********************************************************************
136 * SetMapMode (GDI32.@)
138 INT WINAPI SetMapMode( HDC hdc, INT mode )
141 INT horzSize, vertSize, horzRes, vertRes;
143 DC * dc = DC_GetDCPtr( hdc );
145 if (dc->funcs->pSetMapMode)
147 prevMode = dc->funcs->pSetMapMode( dc->physDev, mode );
151 TRACE("%04x %d\n", hdc, mode );
153 prevMode = dc->MapMode;
154 horzSize = GetDeviceCaps( hdc, HORZSIZE );
155 vertSize = GetDeviceCaps( hdc, VERTSIZE );
156 horzRes = GetDeviceCaps( hdc, HORZRES );
157 vertRes = GetDeviceCaps( hdc, VERTRES );
168 dc->wndExtX = horzSize;
169 dc->wndExtY = vertSize;
170 dc->vportExtX = horzRes / 10;
171 dc->vportExtY = vertRes / -10;
174 dc->wndExtX = horzSize * 10;
175 dc->wndExtY = vertSize * 10;
176 dc->vportExtX = horzRes / 10;
177 dc->vportExtY = vertRes / -10;
180 dc->wndExtX = horzSize;
181 dc->wndExtY = vertSize;
182 dc->vportExtX = 254L * horzRes / 1000;
183 dc->vportExtY = -254L * vertRes / 1000;
186 dc->wndExtX = horzSize * 10;
187 dc->wndExtY = vertSize * 10;
188 dc->vportExtX = 254L * horzRes / 1000;
189 dc->vportExtY = -254L * vertRes / 1000;
192 dc->wndExtX = 144L * horzSize / 10;
193 dc->wndExtY = 144L * vertSize / 10;
194 dc->vportExtX = 254L * horzRes / 1000;
195 dc->vportExtY = -254L * vertRes / 1000;
203 DC_UpdateXforms( dc );
205 GDI_ReleaseObj( hdc );
210 /***********************************************************************
211 * SetViewportExt (GDI.14)
213 DWORD WINAPI SetViewportExt16( HDC16 hdc, INT16 x, INT16 y )
216 if (!SetViewportExtEx( hdc, x, y, &size )) return 0;
217 return MAKELONG( size.cx, size.cy );
221 /***********************************************************************
222 * SetViewportExtEx (GDI.479)
224 BOOL16 WINAPI SetViewportExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
227 BOOL16 ret = SetViewportExtEx( hdc, x, y, &size32 );
228 if (size) { size->cx = size32.cx; size->cy = size32.cy; }
233 /***********************************************************************
234 * SetViewportExtEx (GDI32.@)
236 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
239 DC * dc = DC_GetDCPtr( hdc );
240 if (!dc) return FALSE;
241 if (dc->funcs->pSetViewportExt)
243 ret = dc->funcs->pSetViewportExt( dc->physDev, x, y );
248 size->cx = dc->vportExtX;
249 size->cy = dc->vportExtY;
251 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
260 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
261 DC_UpdateXforms( dc );
263 GDI_ReleaseObj( hdc );
268 /***********************************************************************
269 * SetViewportOrg (GDI.13)
271 DWORD WINAPI SetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
274 if (!SetViewportOrgEx( hdc, x, y, &pt )) return 0;
275 return MAKELONG( pt.x, pt.y );
279 /***********************************************************************
280 * SetViewportOrgEx (GDI.480)
282 BOOL16 WINAPI SetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
285 BOOL16 ret = SetViewportOrgEx( hdc, x, y, &pt32 );
286 if (pt) CONV_POINT32TO16( &pt32, pt );
291 /***********************************************************************
292 * SetViewportOrgEx (GDI32.@)
294 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
297 DC * dc = DC_GetDCPtr( hdc );
298 if (!dc) return FALSE;
299 if (dc->funcs->pSetViewportOrg)
300 ret = dc->funcs->pSetViewportOrg( dc->physDev, x, y );
305 pt->x = dc->vportOrgX;
306 pt->y = dc->vportOrgY;
310 DC_UpdateXforms( dc );
312 GDI_ReleaseObj( hdc );
317 /***********************************************************************
318 * SetWindowExt (GDI.12)
320 DWORD WINAPI SetWindowExt16( HDC16 hdc, INT16 x, INT16 y )
323 if (!SetWindowExtEx( hdc, x, y, &size )) return 0;
324 return MAKELONG( size.cx, size.cy );
328 /***********************************************************************
329 * SetWindowExtEx (GDI.481)
331 BOOL16 WINAPI SetWindowExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
334 BOOL16 ret = SetWindowExtEx( hdc, x, y, &size32 );
335 if (size) { size->cx = size32.cx; size->cy = size32.cy; }
340 /***********************************************************************
341 * SetWindowExtEx (GDI32.@)
343 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
346 DC * dc = DC_GetDCPtr( hdc );
347 if (!dc) return FALSE;
348 if (dc->funcs->pSetWindowExt)
350 ret = dc->funcs->pSetWindowExt( dc->physDev, x, y );
355 size->cx = dc->wndExtX;
356 size->cy = dc->wndExtY;
358 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
367 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
368 DC_UpdateXforms( dc );
370 GDI_ReleaseObj( hdc );
375 /***********************************************************************
376 * SetWindowOrg (GDI.11)
378 DWORD WINAPI SetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
381 if (!SetWindowOrgEx( hdc, x, y, &pt )) return 0;
382 return MAKELONG( pt.x, pt.y );
386 /***********************************************************************
387 * SetWindowOrgEx (GDI.482)
389 BOOL16 WINAPI SetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
392 BOOL16 ret = SetWindowOrgEx( hdc, x, y, &pt32 );
393 if (pt) CONV_POINT32TO16( &pt32, pt );
398 /***********************************************************************
399 * SetWindowOrgEx (GDI32.@)
401 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
404 DC * dc = DC_GetDCPtr( hdc );
405 if (!dc) return FALSE;
406 if (dc->funcs->pSetWindowOrg) ret = dc->funcs->pSetWindowOrg( dc->physDev, x, y );
416 DC_UpdateXforms( dc );
418 GDI_ReleaseObj( hdc );
423 /***********************************************************************
424 * OffsetViewportOrg (GDI.17)
426 DWORD WINAPI OffsetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
429 if (!OffsetViewportOrgEx( hdc, x, y, &pt )) return 0;
430 return MAKELONG( pt.x, pt.y );
434 /***********************************************************************
435 * OffsetViewportOrgEx (GDI.476)
437 BOOL16 WINAPI OffsetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt)
440 BOOL16 ret = OffsetViewportOrgEx( hdc, x, y, &pt32 );
441 if (pt) CONV_POINT32TO16( &pt32, pt );
446 /***********************************************************************
447 * OffsetViewportOrgEx (GDI32.@)
449 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
452 DC * dc = DC_GetDCPtr( hdc );
453 if (!dc) return FALSE;
454 if (dc->funcs->pOffsetViewportOrg)
455 ret = dc->funcs->pOffsetViewportOrg( dc->physDev, x, y );
460 pt->x = dc->vportOrgX;
461 pt->y = dc->vportOrgY;
465 DC_UpdateXforms( dc );
467 GDI_ReleaseObj( hdc );
472 /***********************************************************************
473 * OffsetWindowOrg (GDI.15)
475 DWORD WINAPI OffsetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
478 if (!OffsetWindowOrgEx( hdc, x, y, &pt )) return 0;
479 return MAKELONG( pt.x, pt.y );
483 /***********************************************************************
484 * OffsetWindowOrgEx (GDI.477)
486 BOOL16 WINAPI OffsetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
489 BOOL16 ret = OffsetWindowOrgEx( hdc, x, y, &pt32 );
490 if (pt) CONV_POINT32TO16( &pt32, pt );
495 /***********************************************************************
496 * OffsetWindowOrgEx (GDI32.@)
498 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
501 DC * dc = DC_GetDCPtr( hdc );
502 if (!dc) return FALSE;
503 if (dc->funcs->pOffsetWindowOrg)
504 ret = dc->funcs->pOffsetWindowOrg( dc->physDev, x, y );
514 DC_UpdateXforms( dc );
516 GDI_ReleaseObj( hdc );
521 /***********************************************************************
522 * ScaleViewportExt (GDI.18)
524 DWORD WINAPI ScaleViewportExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
525 INT16 yNum, INT16 yDenom )
528 if (!ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
530 return MAKELONG( size.cx, size.cy );
534 /***********************************************************************
535 * ScaleViewportExtEx (GDI.484)
537 BOOL16 WINAPI ScaleViewportExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
538 INT16 yNum, INT16 yDenom, LPSIZE16 size )
541 BOOL16 ret = ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom,
543 if (size) { size->cx = size32.cx; size->cy = size32.cy; }
548 /***********************************************************************
549 * ScaleViewportExtEx (GDI32.@)
551 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
552 INT yNum, INT yDenom, LPSIZE size )
555 DC * dc = DC_GetDCPtr( hdc );
556 if (!dc) return FALSE;
557 if (dc->funcs->pScaleViewportExt)
559 ret = dc->funcs->pScaleViewportExt( dc->physDev, xNum, xDenom, yNum, yDenom );
564 size->cx = dc->vportExtX;
565 size->cy = dc->vportExtY;
567 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
569 if (!xNum || !xDenom || !xNum || !yDenom)
574 dc->vportExtX = (dc->vportExtX * xNum) / xDenom;
575 dc->vportExtY = (dc->vportExtY * yNum) / yDenom;
576 if (dc->vportExtX == 0) dc->vportExtX = 1;
577 if (dc->vportExtY == 0) dc->vportExtY = 1;
578 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
579 DC_UpdateXforms( dc );
581 GDI_ReleaseObj( hdc );
586 /***********************************************************************
587 * ScaleWindowExt (GDI.16)
589 DWORD WINAPI ScaleWindowExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
590 INT16 yNum, INT16 yDenom )
593 if (!ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
595 return MAKELONG( size.cx, size.cy );
599 /***********************************************************************
600 * ScaleWindowExtEx (GDI.485)
602 BOOL16 WINAPI ScaleWindowExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
603 INT16 yNum, INT16 yDenom, LPSIZE16 size )
606 BOOL16 ret = ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom,
608 if (size) { size->cx = size32.cx; size->cy = size32.cy; }
613 /***********************************************************************
614 * ScaleWindowExtEx (GDI32.@)
616 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
617 INT yNum, INT yDenom, LPSIZE size )
620 DC * dc = DC_GetDCPtr( hdc );
621 if (!dc) return FALSE;
622 if (dc->funcs->pScaleWindowExt)
624 ret = dc->funcs->pScaleWindowExt( dc->physDev, xNum, xDenom, yNum, yDenom );
629 size->cx = dc->wndExtX;
630 size->cy = dc->wndExtY;
632 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
634 if (!xNum || !xDenom || !xNum || !yDenom)
639 dc->wndExtX = (dc->wndExtX * xNum) / xDenom;
640 dc->wndExtY = (dc->wndExtY * yNum) / yDenom;
641 if (dc->wndExtX == 0) dc->wndExtX = 1;
642 if (dc->wndExtY == 0) dc->wndExtY = 1;
643 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
644 DC_UpdateXforms( dc );
646 GDI_ReleaseObj( hdc );