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 /***********************************************************************
145 INT16 WINAPI
SetMapMode16( HDC16 hdc
, INT16 mode
)
147 return SetMapMode( hdc
, mode
);
151 /***********************************************************************
152 * SetMapMode (GDI32.@)
154 INT WINAPI
SetMapMode( HDC hdc
, INT mode
)
157 INT horzSize
, vertSize
, horzRes
, vertRes
;
159 DC
* dc
= DC_GetDCPtr( hdc
);
161 if (dc
->funcs
->pSetMapMode
)
163 prevMode
= dc
->funcs
->pSetMapMode( dc
->physDev
, mode
);
167 TRACE("%04x %d\n", hdc
, mode
);
169 prevMode
= dc
->MapMode
;
170 horzSize
= GetDeviceCaps( hdc
, HORZSIZE
);
171 vertSize
= GetDeviceCaps( hdc
, VERTSIZE
);
172 horzRes
= GetDeviceCaps( hdc
, HORZRES
);
173 vertRes
= GetDeviceCaps( hdc
, VERTRES
);
184 dc
->wndExtX
= horzSize
;
185 dc
->wndExtY
= vertSize
;
186 dc
->vportExtX
= horzRes
/ 10;
187 dc
->vportExtY
= vertRes
/ -10;
190 dc
->wndExtX
= horzSize
* 10;
191 dc
->wndExtY
= vertSize
* 10;
192 dc
->vportExtX
= horzRes
/ 10;
193 dc
->vportExtY
= vertRes
/ -10;
196 dc
->wndExtX
= horzSize
;
197 dc
->wndExtY
= vertSize
;
198 dc
->vportExtX
= 254L * horzRes
/ 1000;
199 dc
->vportExtY
= -254L * vertRes
/ 1000;
202 dc
->wndExtX
= horzSize
* 10;
203 dc
->wndExtY
= vertSize
* 10;
204 dc
->vportExtX
= 254L * horzRes
/ 1000;
205 dc
->vportExtY
= -254L * vertRes
/ 1000;
208 dc
->wndExtX
= 144L * horzSize
/ 10;
209 dc
->wndExtY
= 144L * vertSize
/ 10;
210 dc
->vportExtX
= 254L * horzRes
/ 1000;
211 dc
->vportExtY
= -254L * vertRes
/ 1000;
219 DC_UpdateXforms( dc
);
221 GDI_ReleaseObj( hdc
);
226 /***********************************************************************
227 * SetViewportExt (GDI.14)
229 DWORD WINAPI
SetViewportExt16( HDC16 hdc
, INT16 x
, INT16 y
)
232 if (!SetViewportExtEx( hdc
, x
, y
, &size
)) return 0;
233 return MAKELONG( size
.cx
, size
.cy
);
237 /***********************************************************************
238 * SetViewportExtEx (GDI.479)
240 BOOL16 WINAPI
SetViewportExtEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPSIZE16 size
)
243 BOOL16 ret
= SetViewportExtEx( hdc
, x
, y
, &size32
);
244 if (size
) { size
->cx
= size32
.cx
; size
->cy
= size32
.cy
; }
249 /***********************************************************************
250 * SetViewportExtEx (GDI32.@)
252 BOOL WINAPI
SetViewportExtEx( HDC hdc
, INT x
, INT y
, LPSIZE size
)
255 DC
* dc
= DC_GetDCPtr( hdc
);
256 if (!dc
) return FALSE
;
257 if (dc
->funcs
->pSetViewportExt
)
259 ret
= dc
->funcs
->pSetViewportExt( dc
->physDev
, x
, y
);
264 size
->cx
= dc
->vportExtX
;
265 size
->cy
= dc
->vportExtY
;
267 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
276 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
277 DC_UpdateXforms( dc
);
279 GDI_ReleaseObj( hdc
);
284 /***********************************************************************
285 * SetViewportOrg (GDI.13)
287 DWORD WINAPI
SetViewportOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
290 if (!SetViewportOrgEx( hdc
, x
, y
, &pt
)) return 0;
291 return MAKELONG( pt
.x
, pt
.y
);
295 /***********************************************************************
296 * SetViewportOrgEx (GDI.480)
298 BOOL16 WINAPI
SetViewportOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
301 BOOL16 ret
= SetViewportOrgEx( hdc
, x
, y
, &pt32
);
302 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
307 /***********************************************************************
308 * SetViewportOrgEx (GDI32.@)
310 BOOL WINAPI
SetViewportOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
313 DC
* dc
= DC_GetDCPtr( hdc
);
314 if (!dc
) return FALSE
;
315 if (dc
->funcs
->pSetViewportOrg
)
316 ret
= dc
->funcs
->pSetViewportOrg( dc
->physDev
, x
, y
);
321 pt
->x
= dc
->vportOrgX
;
322 pt
->y
= dc
->vportOrgY
;
326 DC_UpdateXforms( dc
);
328 GDI_ReleaseObj( hdc
);
333 /***********************************************************************
334 * SetWindowExt (GDI.12)
336 DWORD WINAPI
SetWindowExt16( HDC16 hdc
, INT16 x
, INT16 y
)
339 if (!SetWindowExtEx( hdc
, x
, y
, &size
)) return 0;
340 return MAKELONG( size
.cx
, size
.cy
);
344 /***********************************************************************
345 * SetWindowExtEx (GDI.481)
347 BOOL16 WINAPI
SetWindowExtEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPSIZE16 size
)
350 BOOL16 ret
= SetWindowExtEx( hdc
, x
, y
, &size32
);
351 if (size
) { size
->cx
= size32
.cx
; size
->cy
= size32
.cy
; }
356 /***********************************************************************
357 * SetWindowExtEx (GDI32.@)
359 BOOL WINAPI
SetWindowExtEx( HDC hdc
, INT x
, INT y
, LPSIZE size
)
362 DC
* dc
= DC_GetDCPtr( hdc
);
363 if (!dc
) return FALSE
;
364 if (dc
->funcs
->pSetWindowExt
)
366 ret
= dc
->funcs
->pSetWindowExt( dc
->physDev
, x
, y
);
371 size
->cx
= dc
->wndExtX
;
372 size
->cy
= dc
->wndExtY
;
374 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
383 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
384 DC_UpdateXforms( dc
);
386 GDI_ReleaseObj( hdc
);
391 /***********************************************************************
392 * SetWindowOrg (GDI.11)
394 DWORD WINAPI
SetWindowOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
397 if (!SetWindowOrgEx( hdc
, x
, y
, &pt
)) return 0;
398 return MAKELONG( pt
.x
, pt
.y
);
402 /***********************************************************************
403 * SetWindowOrgEx (GDI.482)
405 BOOL16 WINAPI
SetWindowOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
408 BOOL16 ret
= SetWindowOrgEx( hdc
, x
, y
, &pt32
);
409 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
414 /***********************************************************************
415 * SetWindowOrgEx (GDI32.@)
417 BOOL WINAPI
SetWindowOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
420 DC
* dc
= DC_GetDCPtr( hdc
);
421 if (!dc
) return FALSE
;
422 if (dc
->funcs
->pSetWindowOrg
) ret
= dc
->funcs
->pSetWindowOrg( dc
->physDev
, x
, y
);
432 DC_UpdateXforms( dc
);
434 GDI_ReleaseObj( hdc
);
439 /***********************************************************************
440 * OffsetViewportOrg (GDI.17)
442 DWORD WINAPI
OffsetViewportOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
445 if (!OffsetViewportOrgEx( hdc
, x
, y
, &pt
)) return 0;
446 return MAKELONG( pt
.x
, pt
.y
);
450 /***********************************************************************
451 * OffsetViewportOrgEx (GDI.476)
453 BOOL16 WINAPI
OffsetViewportOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
456 BOOL16 ret
= OffsetViewportOrgEx( hdc
, x
, y
, &pt32
);
457 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
462 /***********************************************************************
463 * OffsetViewportOrgEx (GDI32.@)
465 BOOL WINAPI
OffsetViewportOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
468 DC
* dc
= DC_GetDCPtr( hdc
);
469 if (!dc
) return FALSE
;
470 if (dc
->funcs
->pOffsetViewportOrg
)
471 ret
= dc
->funcs
->pOffsetViewportOrg( dc
->physDev
, x
, y
);
476 pt
->x
= dc
->vportOrgX
;
477 pt
->y
= dc
->vportOrgY
;
481 DC_UpdateXforms( dc
);
483 GDI_ReleaseObj( hdc
);
488 /***********************************************************************
489 * OffsetWindowOrg (GDI.15)
491 DWORD WINAPI
OffsetWindowOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
494 if (!OffsetWindowOrgEx( hdc
, x
, y
, &pt
)) return 0;
495 return MAKELONG( pt
.x
, pt
.y
);
499 /***********************************************************************
500 * OffsetWindowOrgEx (GDI.477)
502 BOOL16 WINAPI
OffsetWindowOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
505 BOOL16 ret
= OffsetWindowOrgEx( hdc
, x
, y
, &pt32
);
506 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
511 /***********************************************************************
512 * OffsetWindowOrgEx (GDI32.@)
514 BOOL WINAPI
OffsetWindowOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
517 DC
* dc
= DC_GetDCPtr( hdc
);
518 if (!dc
) return FALSE
;
519 if (dc
->funcs
->pOffsetWindowOrg
)
520 ret
= dc
->funcs
->pOffsetWindowOrg( dc
->physDev
, x
, y
);
530 DC_UpdateXforms( dc
);
532 GDI_ReleaseObj( hdc
);
537 /***********************************************************************
538 * ScaleViewportExt (GDI.18)
540 DWORD WINAPI
ScaleViewportExt16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
541 INT16 yNum
, INT16 yDenom
)
544 if (!ScaleViewportExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
, &size
))
546 return MAKELONG( size
.cx
, size
.cy
);
550 /***********************************************************************
551 * ScaleViewportExtEx (GDI.484)
553 BOOL16 WINAPI
ScaleViewportExtEx16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
554 INT16 yNum
, INT16 yDenom
, LPSIZE16 size
)
557 BOOL16 ret
= ScaleViewportExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
,
559 if (size
) { size
->cx
= size32
.cx
; size
->cy
= size32
.cy
; }
564 /***********************************************************************
565 * ScaleViewportExtEx (GDI32.@)
567 BOOL WINAPI
ScaleViewportExtEx( HDC hdc
, INT xNum
, INT xDenom
,
568 INT yNum
, INT yDenom
, LPSIZE size
)
571 DC
* dc
= DC_GetDCPtr( hdc
);
572 if (!dc
) return FALSE
;
573 if (dc
->funcs
->pScaleViewportExt
)
575 ret
= dc
->funcs
->pScaleViewportExt( dc
->physDev
, xNum
, xDenom
, yNum
, yDenom
);
580 size
->cx
= dc
->vportExtX
;
581 size
->cy
= dc
->vportExtY
;
583 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
585 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
)
590 dc
->vportExtX
= (dc
->vportExtX
* xNum
) / xDenom
;
591 dc
->vportExtY
= (dc
->vportExtY
* yNum
) / yDenom
;
592 if (dc
->vportExtX
== 0) dc
->vportExtX
= 1;
593 if (dc
->vportExtY
== 0) dc
->vportExtY
= 1;
594 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
595 DC_UpdateXforms( dc
);
597 GDI_ReleaseObj( hdc
);
602 /***********************************************************************
603 * ScaleWindowExt (GDI.16)
605 DWORD WINAPI
ScaleWindowExt16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
606 INT16 yNum
, INT16 yDenom
)
609 if (!ScaleWindowExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
, &size
))
611 return MAKELONG( size
.cx
, size
.cy
);
615 /***********************************************************************
616 * ScaleWindowExtEx (GDI.485)
618 BOOL16 WINAPI
ScaleWindowExtEx16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
619 INT16 yNum
, INT16 yDenom
, LPSIZE16 size
)
622 BOOL16 ret
= ScaleWindowExtEx( hdc
, xNum
, xDenom
, yNum
, yDenom
,
624 if (size
) { size
->cx
= size32
.cx
; size
->cy
= size32
.cy
; }
629 /***********************************************************************
630 * ScaleWindowExtEx (GDI32.@)
632 BOOL WINAPI
ScaleWindowExtEx( HDC hdc
, INT xNum
, INT xDenom
,
633 INT yNum
, INT yDenom
, LPSIZE size
)
636 DC
* dc
= DC_GetDCPtr( hdc
);
637 if (!dc
) return FALSE
;
638 if (dc
->funcs
->pScaleWindowExt
)
640 ret
= dc
->funcs
->pScaleWindowExt( dc
->physDev
, xNum
, xDenom
, yNum
, yDenom
);
645 size
->cx
= dc
->wndExtX
;
646 size
->cy
= dc
->wndExtY
;
648 if ((dc
->MapMode
!= MM_ISOTROPIC
) && (dc
->MapMode
!= MM_ANISOTROPIC
))
650 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
)
655 dc
->wndExtX
= (dc
->wndExtX
* xNum
) / xDenom
;
656 dc
->wndExtY
= (dc
->wndExtY
* yNum
) / yDenom
;
657 if (dc
->wndExtX
== 0) dc
->wndExtX
= 1;
658 if (dc
->wndExtY
== 0) dc
->wndExtY
= 1;
659 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
660 DC_UpdateXforms( dc
);
662 GDI_ReleaseObj( hdc
);