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 "gdi_private.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
29 /***********************************************************************
30 * MAPPING_FixIsotropic
32 * Fix viewport extensions for isotropic mode.
34 void MAPPING_FixIsotropic( DC
* dc
)
36 double xdim
= fabs((double)dc
->vportExtX
* GetDeviceCaps( dc
->hSelf
, HORZSIZE
) /
37 (GetDeviceCaps( dc
->hSelf
, HORZRES
) * dc
->wndExtX
));
38 double ydim
= fabs((double)dc
->vportExtY
* GetDeviceCaps( dc
->hSelf
, VERTSIZE
) /
39 (GetDeviceCaps( dc
->hSelf
, VERTRES
) * dc
->wndExtY
));
43 INT mincx
= (dc
->vportExtX
>= 0) ? 1 : -1;
44 dc
->vportExtX
= floor(dc
->vportExtX
* ydim
/ xdim
+ 0.5);
45 if (!dc
->vportExtX
) dc
->vportExtX
= mincx
;
49 INT mincy
= (dc
->vportExtY
>= 0) ? 1 : -1;
50 dc
->vportExtY
= floor(dc
->vportExtY
* xdim
/ ydim
+ 0.5);
51 if (!dc
->vportExtY
) dc
->vportExtY
= mincy
;
56 /***********************************************************************
59 BOOL16 WINAPI
DPtoLP16( HDC16 hdc
, LPPOINT16 points
, INT16 count
)
61 DC
* dc
= DC_GetDCPtr( HDC_32(hdc
) );
62 if (!dc
) return FALSE
;
66 points
->x
= MulDiv( points
->x
- dc
->vportOrgX
, dc
->wndExtX
, dc
->vportExtX
) + dc
->wndOrgX
;
67 points
->y
= MulDiv( points
->y
- dc
->vportOrgY
, dc
->wndExtY
, dc
->vportExtY
) + dc
->wndOrgY
;
70 GDI_ReleaseObj( HDC_32(hdc
) );
75 /***********************************************************************
78 BOOL WINAPI
DPtoLP( HDC hdc
, LPPOINT points
, INT count
)
80 DC
* dc
= DC_GetDCPtr( hdc
);
81 if (!dc
) return FALSE
;
83 if (dc
->vport2WorldValid
)
89 points
->x
= floor( x
* dc
->xformVport2World
.eM11
+
90 y
* dc
->xformVport2World
.eM21
+
91 dc
->xformVport2World
.eDx
+ 0.5 );
92 points
->y
= floor( x
* dc
->xformVport2World
.eM12
+
93 y
* dc
->xformVport2World
.eM22
+
94 dc
->xformVport2World
.eDy
+ 0.5 );
98 GDI_ReleaseObj( hdc
);
103 /***********************************************************************
106 BOOL16 WINAPI
LPtoDP16( HDC16 hdc
, LPPOINT16 points
, INT16 count
)
108 DC
* dc
= DC_GetDCPtr( HDC_32(hdc
) );
109 if (!dc
) return FALSE
;
113 points
->x
= MulDiv( points
->x
- dc
->wndOrgX
, dc
->vportExtX
, dc
->wndExtX
) + dc
->vportOrgX
;
114 points
->y
= MulDiv( points
->y
- dc
->wndOrgY
, dc
->vportExtY
, dc
->wndExtY
) + dc
->vportOrgY
;
117 GDI_ReleaseObj( HDC_32(hdc
) );
122 /***********************************************************************
125 BOOL WINAPI
LPtoDP( HDC hdc
, LPPOINT points
, INT count
)
127 DC
* dc
= DC_GetDCPtr( hdc
);
128 if (!dc
) return FALSE
;
134 points
->x
= floor( x
* dc
->xformWorld2Vport
.eM11
+
135 y
* dc
->xformWorld2Vport
.eM21
+
136 dc
->xformWorld2Vport
.eDx
+ 0.5 );
137 points
->y
= floor( x
* dc
->xformWorld2Vport
.eM12
+
138 y
* dc
->xformWorld2Vport
.eM22
+
139 dc
->xformWorld2Vport
.eDy
+ 0.5 );
142 GDI_ReleaseObj( hdc
);
147 /***********************************************************************
148 * SetMapMode (GDI32.@)
150 INT WINAPI
SetMapMode( HDC hdc
, INT mode
)
153 INT horzSize
, vertSize
, horzRes
, vertRes
;
155 DC
* dc
= DC_GetDCPtr( hdc
);
157 if (dc
->funcs
->pSetMapMode
)
159 if((ret
= dc
->funcs
->pSetMapMode( dc
->physDev
, mode
)) != TRUE
)
161 if(ret
== GDI_NO_MORE_WORK
)
167 TRACE("%p %d\n", hdc
, mode
);
171 if (mode
== dc
->MapMode
&& (mode
== MM_ISOTROPIC
|| mode
== MM_ANISOTROPIC
))
174 horzSize
= GetDeviceCaps( hdc
, HORZSIZE
);
175 vertSize
= GetDeviceCaps( hdc
, VERTSIZE
);
176 horzRes
= GetDeviceCaps( hdc
, HORZRES
);
177 vertRes
= GetDeviceCaps( hdc
, VERTRES
);
188 dc
->wndExtX
= horzSize
* 10;
189 dc
->wndExtY
= vertSize
* 10;
190 dc
->vportExtX
= horzRes
;
191 dc
->vportExtY
= -vertRes
;
194 dc
->wndExtX
= horzSize
* 100;
195 dc
->wndExtY
= vertSize
* 100;
196 dc
->vportExtX
= horzRes
;
197 dc
->vportExtY
= -vertRes
;
200 dc
->wndExtX
= MulDiv(1000, horzSize
, 254);
201 dc
->wndExtY
= MulDiv(1000, vertSize
, 254);
202 dc
->vportExtX
= horzRes
;
203 dc
->vportExtY
= -vertRes
;
206 dc
->wndExtX
= MulDiv(10000, horzSize
, 254);
207 dc
->wndExtY
= MulDiv(10000, vertSize
, 254);
208 dc
->vportExtX
= horzRes
;
209 dc
->vportExtY
= -vertRes
;
212 dc
->wndExtX
= MulDiv(14400, horzSize
, 254);
213 dc
->wndExtY
= MulDiv(14400, vertSize
, 254);
214 dc
->vportExtX
= horzRes
;
215 dc
->vportExtY
= -vertRes
;
223 DC_UpdateXforms( dc
);
225 GDI_ReleaseObj( hdc
);
230 /***********************************************************************
231 * SetViewportExtEx (GDI32.@)
233 BOOL WINAPI
SetViewportExtEx( HDC hdc
, INT x
, INT y
, LPSIZE size
)
236 DC
* dc
= DC_GetDCPtr( hdc
);
237 if (!dc
) return FALSE
;
238 if (dc
->funcs
->pSetViewportExt
)
240 if((ret
= dc
->funcs
->pSetViewportExt( dc
->physDev
, x
, y
)) != TRUE
)
242 if(ret
== GDI_NO_MORE_WORK
)
249 size
->cx
= dc
->vportExtX
;
250 size
->cy
= dc
->vportExtY
;
252 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
261 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
262 DC_UpdateXforms( dc
);
264 GDI_ReleaseObj( hdc
);
269 /***********************************************************************
270 * SetViewportOrgEx (GDI32.@)
272 BOOL WINAPI
SetViewportOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
275 DC
* dc
= DC_GetDCPtr( hdc
);
276 if (!dc
) return FALSE
;
277 if (dc
->funcs
->pSetViewportOrg
)
279 if((ret
= dc
->funcs
->pSetViewportOrg( dc
->physDev
, x
, y
)) != TRUE
)
281 if(ret
== GDI_NO_MORE_WORK
)
288 pt
->x
= dc
->vportOrgX
;
289 pt
->y
= dc
->vportOrgY
;
293 DC_UpdateXforms( dc
);
296 GDI_ReleaseObj( hdc
);
301 /***********************************************************************
302 * SetWindowExtEx (GDI32.@)
304 BOOL WINAPI
SetWindowExtEx( HDC hdc
, INT x
, INT y
, LPSIZE size
)
307 DC
* dc
= DC_GetDCPtr( hdc
);
308 if (!dc
) return FALSE
;
309 if (dc
->funcs
->pSetWindowExt
)
311 if((ret
= dc
->funcs
->pSetWindowExt( dc
->physDev
, x
, y
)) != TRUE
)
313 if(ret
== GDI_NO_MORE_WORK
)
320 size
->cx
= dc
->wndExtX
;
321 size
->cy
= dc
->wndExtY
;
323 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
332 /* The API docs say that you should call SetWindowExtEx before
333 SetViewportExtEx. This advice does not imply that Windows
334 doesn't ensure the isotropic mapping after SetWindowExtEx! */
335 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
336 DC_UpdateXforms( dc
);
338 GDI_ReleaseObj( hdc
);
343 /***********************************************************************
344 * SetWindowOrgEx (GDI32.@)
346 BOOL WINAPI
SetWindowOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
349 DC
* dc
= DC_GetDCPtr( hdc
);
350 if (!dc
) return FALSE
;
351 if (dc
->funcs
->pSetWindowOrg
)
353 if((ret
= dc
->funcs
->pSetWindowOrg( dc
->physDev
, x
, y
)) != TRUE
)
355 if(ret
== GDI_NO_MORE_WORK
)
367 DC_UpdateXforms( dc
);
369 GDI_ReleaseObj( hdc
);
374 /***********************************************************************
375 * OffsetViewportOrgEx (GDI32.@)
377 BOOL WINAPI
OffsetViewportOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
380 DC
* dc
= DC_GetDCPtr( hdc
);
381 if (!dc
) return FALSE
;
382 if (dc
->funcs
->pOffsetViewportOrg
)
384 if((ret
= dc
->funcs
->pOffsetViewportOrg( dc
->physDev
, x
, y
)) != TRUE
)
386 if(ret
== GDI_NO_MORE_WORK
)
393 pt
->x
= dc
->vportOrgX
;
394 pt
->y
= dc
->vportOrgY
;
398 DC_UpdateXforms( dc
);
400 GDI_ReleaseObj( hdc
);
405 /***********************************************************************
406 * OffsetWindowOrgEx (GDI32.@)
408 BOOL WINAPI
OffsetWindowOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
411 DC
* dc
= DC_GetDCPtr( hdc
);
412 if (!dc
) return FALSE
;
413 if (dc
->funcs
->pOffsetWindowOrg
)
415 if((ret
= dc
->funcs
->pOffsetWindowOrg( dc
->physDev
, x
, y
)) != TRUE
)
417 if(ret
== GDI_NO_MORE_WORK
)
429 DC_UpdateXforms( dc
);
431 GDI_ReleaseObj( hdc
);
436 /***********************************************************************
437 * ScaleViewportExtEx (GDI32.@)
439 BOOL WINAPI
ScaleViewportExtEx( HDC hdc
, INT xNum
, INT xDenom
,
440 INT yNum
, INT yDenom
, LPSIZE size
)
443 DC
* dc
= DC_GetDCPtr( hdc
);
444 if (!dc
) return FALSE
;
445 if (dc
->funcs
->pScaleViewportExt
)
447 if((ret
= dc
->funcs
->pScaleViewportExt( dc
->physDev
, xNum
, xDenom
, yNum
, yDenom
)) != TRUE
)
449 if(ret
== GDI_NO_MORE_WORK
)
456 size
->cx
= dc
->vportExtX
;
457 size
->cy
= dc
->vportExtY
;
459 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
461 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
)
466 dc
->vportExtX
= (dc
->vportExtX
* xNum
) / xDenom
;
467 dc
->vportExtY
= (dc
->vportExtY
* yNum
) / yDenom
;
468 if (dc
->vportExtX
== 0) dc
->vportExtX
= 1;
469 if (dc
->vportExtY
== 0) dc
->vportExtY
= 1;
470 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
471 DC_UpdateXforms( dc
);
473 GDI_ReleaseObj( hdc
);
478 /***********************************************************************
479 * ScaleWindowExtEx (GDI32.@)
481 BOOL WINAPI
ScaleWindowExtEx( HDC hdc
, INT xNum
, INT xDenom
,
482 INT yNum
, INT yDenom
, LPSIZE size
)
485 DC
* dc
= DC_GetDCPtr( hdc
);
486 if (!dc
) return FALSE
;
487 if (dc
->funcs
->pScaleWindowExt
)
489 if((ret
= dc
->funcs
->pScaleWindowExt( dc
->physDev
, xNum
, xDenom
, yNum
, yDenom
)) != TRUE
)
491 if(ret
== GDI_NO_MORE_WORK
)
498 size
->cx
= dc
->wndExtX
;
499 size
->cy
= dc
->wndExtY
;
501 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
503 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
)
508 dc
->wndExtX
= (dc
->wndExtX
* xNum
) / xDenom
;
509 dc
->wndExtY
= (dc
->wndExtY
* yNum
) / yDenom
;
510 if (dc
->wndExtX
== 0) dc
->wndExtX
= 1;
511 if (dc
->wndExtY
== 0) dc
->wndExtY
= 1;
512 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
513 DC_UpdateXforms( dc
);
515 GDI_ReleaseObj( hdc
);