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
= floor(dc
->vportExtX
* fabs( ydim
/ xdim
) + 0.5);
42 if (!dc
->vportExtX
) dc
->vportExtX
= 1;
46 dc
->vportExtY
= floor(dc
->vportExtY
* fabs( xdim
/ ydim
) + 0.5);
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
);
167 if (mode
== dc
->MapMode
&& (mode
== MM_ISOTROPIC
|| mode
== MM_ANISOTROPIC
))
170 horzSize
= GetDeviceCaps( hdc
, HORZSIZE
);
171 vertSize
= GetDeviceCaps( hdc
, VERTSIZE
);
172 horzRes
= GetDeviceCaps( hdc
, HORZRES
);
173 vertRes
= GetDeviceCaps( hdc
, VERTRES
);
184 dc
->wndExtX
= horzSize
* 10;
185 dc
->wndExtY
= vertSize
* 10;
186 dc
->vportExtX
= horzRes
;
187 dc
->vportExtY
= -vertRes
;
190 dc
->wndExtX
= horzSize
* 100;
191 dc
->wndExtY
= vertSize
* 100;
192 dc
->vportExtX
= horzRes
;
193 dc
->vportExtY
= -vertRes
;
196 dc
->wndExtX
= MulDiv(1000, horzSize
, 254);
197 dc
->wndExtY
= MulDiv(1000, vertSize
, 254);
198 dc
->vportExtX
= horzRes
;
199 dc
->vportExtY
= -vertRes
;
202 dc
->wndExtX
= MulDiv(10000, horzSize
, 254);
203 dc
->wndExtY
= MulDiv(10000, vertSize
, 254);
204 dc
->vportExtX
= horzRes
;
205 dc
->vportExtY
= -vertRes
;
208 dc
->wndExtX
= MulDiv(14400, horzSize
, 254);
209 dc
->wndExtY
= MulDiv(14400, vertSize
, 254);
210 dc
->vportExtX
= horzRes
;
211 dc
->vportExtY
= -vertRes
;
219 DC_UpdateXforms( dc
);
221 GDI_ReleaseObj( hdc
);
226 /***********************************************************************
227 * SetViewportExtEx (GDI32.@)
229 BOOL WINAPI
SetViewportExtEx( HDC hdc
, INT x
, INT y
, LPSIZE size
)
232 DC
* dc
= DC_GetDCPtr( hdc
);
233 if (!dc
) return FALSE
;
234 if (dc
->funcs
->pSetViewportExt
)
236 if((ret
= dc
->funcs
->pSetViewportExt( dc
->physDev
, x
, y
)) != TRUE
)
238 if(ret
== GDI_NO_MORE_WORK
)
245 size
->cx
= dc
->vportExtX
;
246 size
->cy
= dc
->vportExtY
;
248 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
257 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
258 DC_UpdateXforms( dc
);
260 GDI_ReleaseObj( hdc
);
265 /***********************************************************************
266 * SetViewportOrgEx (GDI32.@)
268 BOOL WINAPI
SetViewportOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
271 DC
* dc
= DC_GetDCPtr( hdc
);
272 if (!dc
) return FALSE
;
273 if (dc
->funcs
->pSetViewportOrg
)
275 if((ret
= dc
->funcs
->pSetViewportOrg( dc
->physDev
, x
, y
)) != TRUE
)
277 if(ret
== GDI_NO_MORE_WORK
)
284 pt
->x
= dc
->vportOrgX
;
285 pt
->y
= dc
->vportOrgY
;
289 DC_UpdateXforms( dc
);
292 GDI_ReleaseObj( hdc
);
297 /***********************************************************************
298 * SetWindowExtEx (GDI32.@)
300 BOOL WINAPI
SetWindowExtEx( HDC hdc
, INT x
, INT y
, LPSIZE size
)
303 DC
* dc
= DC_GetDCPtr( hdc
);
304 if (!dc
) return FALSE
;
305 if (dc
->funcs
->pSetWindowExt
)
307 if((ret
= dc
->funcs
->pSetWindowExt( dc
->physDev
, x
, y
)) != TRUE
)
309 if(ret
== GDI_NO_MORE_WORK
)
316 size
->cx
= dc
->wndExtX
;
317 size
->cy
= dc
->wndExtY
;
319 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
328 /* Windows fixes MM_ISOTROPIC mode only in SetViewportExtEx() */
329 DC_UpdateXforms( dc
);
331 GDI_ReleaseObj( hdc
);
336 /***********************************************************************
337 * SetWindowOrgEx (GDI32.@)
339 BOOL WINAPI
SetWindowOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
342 DC
* dc
= DC_GetDCPtr( hdc
);
343 if (!dc
) return FALSE
;
344 if (dc
->funcs
->pSetWindowOrg
)
346 if((ret
= dc
->funcs
->pSetWindowOrg( dc
->physDev
, x
, y
)) != TRUE
)
348 if(ret
== GDI_NO_MORE_WORK
)
360 DC_UpdateXforms( dc
);
362 GDI_ReleaseObj( hdc
);
367 /***********************************************************************
368 * OffsetViewportOrgEx (GDI32.@)
370 BOOL WINAPI
OffsetViewportOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
373 DC
* dc
= DC_GetDCPtr( hdc
);
374 if (!dc
) return FALSE
;
375 if (dc
->funcs
->pOffsetViewportOrg
)
377 if((ret
= dc
->funcs
->pOffsetViewportOrg( dc
->physDev
, x
, y
)) != TRUE
)
379 if(ret
== GDI_NO_MORE_WORK
)
386 pt
->x
= dc
->vportOrgX
;
387 pt
->y
= dc
->vportOrgY
;
391 DC_UpdateXforms( dc
);
393 GDI_ReleaseObj( hdc
);
398 /***********************************************************************
399 * OffsetWindowOrgEx (GDI32.@)
401 BOOL WINAPI
OffsetWindowOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
404 DC
* dc
= DC_GetDCPtr( hdc
);
405 if (!dc
) return FALSE
;
406 if (dc
->funcs
->pOffsetWindowOrg
)
408 if((ret
= dc
->funcs
->pOffsetWindowOrg( dc
->physDev
, x
, y
)) != TRUE
)
410 if(ret
== GDI_NO_MORE_WORK
)
422 DC_UpdateXforms( dc
);
424 GDI_ReleaseObj( hdc
);
429 /***********************************************************************
430 * ScaleViewportExtEx (GDI32.@)
432 BOOL WINAPI
ScaleViewportExtEx( HDC hdc
, INT xNum
, INT xDenom
,
433 INT yNum
, INT yDenom
, LPSIZE size
)
436 DC
* dc
= DC_GetDCPtr( hdc
);
437 if (!dc
) return FALSE
;
438 if (dc
->funcs
->pScaleViewportExt
)
440 if((ret
= dc
->funcs
->pScaleViewportExt( dc
->physDev
, xNum
, xDenom
, yNum
, yDenom
)) != TRUE
)
442 if(ret
== GDI_NO_MORE_WORK
)
449 size
->cx
= dc
->vportExtX
;
450 size
->cy
= dc
->vportExtY
;
452 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
454 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
)
459 dc
->vportExtX
= (dc
->vportExtX
* xNum
) / xDenom
;
460 dc
->vportExtY
= (dc
->vportExtY
* yNum
) / yDenom
;
461 if (dc
->vportExtX
== 0) dc
->vportExtX
= 1;
462 if (dc
->vportExtY
== 0) dc
->vportExtY
= 1;
463 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
464 DC_UpdateXforms( dc
);
466 GDI_ReleaseObj( hdc
);
471 /***********************************************************************
472 * ScaleWindowExtEx (GDI32.@)
474 BOOL WINAPI
ScaleWindowExtEx( HDC hdc
, INT xNum
, INT xDenom
,
475 INT yNum
, INT yDenom
, LPSIZE size
)
478 DC
* dc
= DC_GetDCPtr( hdc
);
479 if (!dc
) return FALSE
;
480 if (dc
->funcs
->pScaleWindowExt
)
482 if((ret
= dc
->funcs
->pScaleWindowExt( dc
->physDev
, xNum
, xDenom
, yNum
, yDenom
)) != TRUE
)
484 if(ret
== GDI_NO_MORE_WORK
)
491 size
->cx
= dc
->wndExtX
;
492 size
->cy
= dc
->wndExtY
;
494 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
496 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
)
501 dc
->wndExtX
= (dc
->wndExtX
* xNum
) / xDenom
;
502 dc
->wndExtY
= (dc
->wndExtY
* yNum
) / yDenom
;
503 if (dc
->wndExtX
== 0) dc
->wndExtX
= 1;
504 if (dc
->wndExtY
== 0) dc
->wndExtY
= 1;
505 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
506 DC_UpdateXforms( dc
);
508 GDI_ReleaseObj( hdc
);