2 * GDI mapping mode functions
4 * Copyright 1993 Alexandre Julliard
13 /***********************************************************************
14 * MAPPING_FixIsotropic
16 * Fix viewport extensions for isotropic mode.
18 void MAPPING_FixIsotropic( DC
* dc
)
20 double xdim
= (double)dc
->vportExtX
* dc
->w
.devCaps
->horzSize
/
21 (dc
->w
.devCaps
->horzRes
* dc
->wndExtX
);
22 double ydim
= (double)dc
->vportExtY
* dc
->w
.devCaps
->vertSize
/
23 (dc
->w
.devCaps
->vertRes
* dc
->wndExtY
);
26 dc
->vportExtX
= dc
->vportExtX
* fabs( ydim
/ xdim
);
27 if (!dc
->vportExtX
) dc
->vportExtX
= 1;
31 dc
->vportExtY
= dc
->vportExtY
* fabs( xdim
/ ydim
);
32 if (!dc
->vportExtY
) dc
->vportExtY
= 1;
37 /***********************************************************************
40 BOOL16
DPtoLP16( HDC16 hdc
, LPPOINT16 points
, INT16 count
)
42 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
43 if (!dc
) return FALSE
;
47 points
->x
= XDPTOLP( dc
, points
->x
);
48 points
->y
= YDPTOLP( dc
, points
->y
);
55 /***********************************************************************
58 BOOL32
DPtoLP32( HDC32 hdc
, LPPOINT32 points
, INT32 count
)
60 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
61 if (!dc
) return FALSE
;
65 points
->x
= XDPTOLP( dc
, points
->x
);
66 points
->y
= YDPTOLP( dc
, points
->y
);
73 /***********************************************************************
76 BOOL16
LPtoDP16( HDC16 hdc
, LPPOINT16 points
, INT16 count
)
78 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
79 if (!dc
) return FALSE
;
83 points
->x
= XLPTODP( dc
, points
->x
);
84 points
->y
= YLPTODP( dc
, points
->y
);
91 /***********************************************************************
92 * LPtoDP32 (GDI32.247)
94 BOOL32
LPtoDP32( HDC32 hdc
, LPPOINT32 points
, INT32 count
)
96 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
97 if (!dc
) return FALSE
;
101 points
->x
= XLPTODP( dc
, points
->x
);
102 points
->y
= YLPTODP( dc
, points
->y
);
109 /***********************************************************************
110 * SetMapMode16 (GDI.3)
112 INT16
SetMapMode16( HDC16 hdc
, INT16 mode
)
114 return SetMapMode32( hdc
, mode
);
118 /***********************************************************************
119 * SetMapMode32 (GDI32.321)
121 INT32
SetMapMode32( HDC32 hdc
, INT32 mode
)
124 DC
* dc
= DC_GetDCPtr( hdc
);
126 if (dc
->funcs
->pSetMapMode
) return dc
->funcs
->pSetMapMode( dc
, mode
);
128 dprintf_gdi(stddeb
, "SetMapMode: %04x %d\n", hdc
, mode
);
130 prevMode
= dc
->w
.MapMode
;
134 dc
->wndOrgX
= dc
->wndOrgY
= 0;
135 dc
->vportOrgX
= dc
->vportOrgY
= 0;
144 dc
->wndOrgX
= dc
->wndOrgY
= 0;
145 dc
->vportOrgX
= dc
->vportOrgY
= 0;
146 dc
->wndExtX
= dc
->w
.devCaps
->horzSize
;
147 dc
->wndExtY
= dc
->w
.devCaps
->vertSize
;
148 dc
->vportExtX
= dc
->w
.devCaps
->horzRes
/ 10;
149 dc
->vportExtY
= dc
->w
.devCaps
->vertRes
/ -10;
153 dc
->wndOrgX
= dc
->wndOrgY
= 0;
154 dc
->vportOrgX
= dc
->vportOrgY
= 0;
155 dc
->wndExtX
= dc
->w
.devCaps
->horzSize
* 10;
156 dc
->wndExtY
= dc
->w
.devCaps
->vertSize
* 10;
157 dc
->vportExtX
= dc
->w
.devCaps
->horzRes
/ 10;
158 dc
->vportExtY
= dc
->w
.devCaps
->vertRes
/ -10;
162 dc
->wndOrgX
= dc
->wndOrgY
= 0;
163 dc
->vportOrgX
= dc
->vportOrgY
= 0;
164 dc
->wndExtX
= dc
->w
.devCaps
->horzSize
;
165 dc
->wndExtY
= dc
->w
.devCaps
->vertSize
;
166 dc
->vportExtX
= 254L * dc
->w
.devCaps
->horzRes
/ 1000;
167 dc
->vportExtY
= -254L * dc
->w
.devCaps
->vertRes
/ 1000;
171 dc
->wndOrgX
= dc
->wndOrgY
= 0;
172 dc
->vportOrgX
= dc
->vportOrgY
= 0;
173 dc
->wndExtX
= dc
->w
.devCaps
->horzSize
* 10;
174 dc
->wndExtY
= dc
->w
.devCaps
->vertSize
* 10;
175 dc
->vportExtX
= 254L * dc
->w
.devCaps
->horzRes
/ 1000;
176 dc
->vportExtY
= -254L * dc
->w
.devCaps
->vertRes
/ 1000;
180 dc
->wndOrgX
= dc
->wndOrgY
= 0;
181 dc
->vportOrgX
= dc
->vportOrgY
= 0;
182 dc
->wndExtX
= 144L * dc
->w
.devCaps
->horzSize
/ 10;
183 dc
->wndExtY
= 144L * dc
->w
.devCaps
->vertSize
/ 10;
184 dc
->vportExtX
= 254L * dc
->w
.devCaps
->horzRes
/ 1000;
185 dc
->vportExtY
= -254L * dc
->w
.devCaps
->vertRes
/ 1000;
194 dc
->w
.MapMode
= mode
;
199 /***********************************************************************
200 * SetViewportExt (GDI.14)
202 DWORD
SetViewportExt( HDC16 hdc
, INT16 x
, INT16 y
)
205 if (!SetViewportExtEx32( hdc
, x
, y
, &size
)) return 0;
206 return MAKELONG( size
.cx
, size
.cy
);
210 /***********************************************************************
211 * SetViewportExtEx16 (GDI.479)
213 BOOL16
SetViewportExtEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPSIZE16 size
)
216 BOOL16 ret
= SetViewportExtEx32( hdc
, x
, y
, &size32
);
217 if (size
) CONV_SIZE32TO16( &size32
, size
);
222 /***********************************************************************
223 * SetViewportExtEx32 (GDI32.340)
225 BOOL32
SetViewportExtEx32( HDC32 hdc
, INT32 x
, INT32 y
, LPSIZE32 size
)
227 DC
* dc
= DC_GetDCPtr( hdc
);
228 if (!dc
) return FALSE
;
229 if (dc
->funcs
->pSetViewportExt
)
230 return dc
->funcs
->pSetViewportExt( dc
, x
, y
);
233 size
->cx
= dc
->vportExtX
;
234 size
->cy
= dc
->vportExtY
;
236 if ((dc
->w
.MapMode
!= MM_ISOTROPIC
) && (dc
->w
.MapMode
!= MM_ANISOTROPIC
))
238 if (!x
|| !y
) return FALSE
;
241 if (dc
->w
.MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
246 /***********************************************************************
247 * SetViewportOrg (GDI.13)
249 DWORD
SetViewportOrg( HDC16 hdc
, INT16 x
, INT16 y
)
252 if (!SetViewportOrgEx32( hdc
, x
, y
, &pt
)) return 0;
253 return MAKELONG( pt
.x
, pt
.y
);
257 /***********************************************************************
258 * SetViewportOrgEx16 (GDI.480)
260 BOOL16
SetViewportOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
263 BOOL16 ret
= SetViewportOrgEx32( hdc
, x
, y
, &pt32
);
264 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
269 /***********************************************************************
270 * SetViewportOrgEx32 (GDI32.341)
272 BOOL32
SetViewportOrgEx32( HDC32 hdc
, INT32 x
, INT32 y
, LPPOINT32 pt
)
274 DC
* dc
= DC_GetDCPtr( hdc
);
275 if (!dc
) return FALSE
;
276 if (dc
->funcs
->pSetViewportOrg
)
277 return dc
->funcs
->pSetViewportOrg( dc
, x
, y
);
280 pt
->x
= dc
->vportOrgX
;
281 pt
->y
= dc
->vportOrgY
;
289 /***********************************************************************
290 * SetWindowExt (GDI.12)
292 DWORD
SetWindowExt( HDC16 hdc
, INT16 x
, INT16 y
)
295 if (!SetWindowExtEx32( hdc
, x
, y
, &size
)) return 0;
296 return MAKELONG( size
.cx
, size
.cy
);
300 /***********************************************************************
301 * SetWindowExtEx16 (GDI.481)
303 BOOL16
SetWindowExtEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPSIZE16 size
)
306 BOOL16 ret
= SetWindowExtEx32( hdc
, x
, y
, &size32
);
307 if (size
) CONV_SIZE32TO16( &size32
, size
);
312 /***********************************************************************
313 * SetWindowExtEx32 (GDI32.344)
315 BOOL32
SetWindowExtEx32( HDC32 hdc
, INT32 x
, INT32 y
, LPSIZE32 size
)
317 DC
* dc
= DC_GetDCPtr( hdc
);
318 if (!dc
) return FALSE
;
319 if (dc
->funcs
->pSetWindowExt
) return dc
->funcs
->pSetWindowExt( dc
, x
, y
);
322 size
->cx
= dc
->wndExtX
;
323 size
->cy
= dc
->wndExtY
;
325 if ((dc
->w
.MapMode
!= MM_ISOTROPIC
) && (dc
->w
.MapMode
!= MM_ANISOTROPIC
))
327 if (!x
|| !y
) return FALSE
;
330 if (dc
->w
.MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
335 /***********************************************************************
336 * SetWindowOrg (GDI.11)
338 DWORD
SetWindowOrg( HDC16 hdc
, INT16 x
, INT16 y
)
341 if (!SetWindowOrgEx32( hdc
, x
, y
, &pt
)) return 0;
342 return MAKELONG( pt
.x
, pt
.y
);
346 /***********************************************************************
347 * SetWindowOrgEx16 (GDI.482)
349 BOOL16
SetWindowOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
352 BOOL16 ret
= SetWindowOrgEx32( hdc
, x
, y
, &pt32
);
353 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
358 /***********************************************************************
359 * SetWindowOrgEx32 (GDI32.345)
361 BOOL32
SetWindowOrgEx32( HDC32 hdc
, INT32 x
, INT32 y
, LPPOINT32 pt
)
363 DC
* dc
= DC_GetDCPtr( hdc
);
364 if (!dc
) return FALSE
;
365 if (dc
->funcs
->pSetWindowOrg
) return dc
->funcs
->pSetWindowOrg( dc
, x
, y
);
377 /***********************************************************************
378 * OffsetViewportOrg (GDI.17)
380 DWORD
OffsetViewportOrg( HDC16 hdc
, INT16 x
, INT16 y
)
383 if (!OffsetViewportOrgEx32( hdc
, x
, y
, &pt
)) return 0;
384 return MAKELONG( pt
.x
, pt
.y
);
388 /***********************************************************************
389 * OffsetViewportOrgEx16 (GDI.476)
391 BOOL16
OffsetViewportOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
394 BOOL16 ret
= OffsetViewportOrgEx32( hdc
, x
, y
, &pt32
);
395 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
400 /***********************************************************************
401 * OffsetViewportOrgEx32 (GDI32.257)
403 BOOL32
OffsetViewportOrgEx32( HDC32 hdc
, INT32 x
, INT32 y
, LPPOINT32 pt
)
405 DC
* dc
= DC_GetDCPtr( hdc
);
406 if (!dc
) return FALSE
;
407 if (dc
->funcs
->pOffsetViewportOrg
)
408 return dc
->funcs
->pOffsetViewportOrg( dc
, x
, y
);
411 pt
->x
= dc
->vportOrgX
;
412 pt
->y
= dc
->vportOrgY
;
420 /***********************************************************************
421 * OffsetWindowOrg (GDI.15)
423 DWORD
OffsetWindowOrg( HDC16 hdc
, INT16 x
, INT16 y
)
426 if (!OffsetWindowOrgEx32( hdc
, x
, y
, &pt
)) return 0;
427 return MAKELONG( pt
.x
, pt
.y
);
431 /***********************************************************************
432 * OffsetWindowOrgEx16 (GDI.477)
434 BOOL16
OffsetWindowOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
437 BOOL16 ret
= OffsetWindowOrgEx32( hdc
, x
, y
, &pt32
);
438 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
443 /***********************************************************************
444 * OffsetWindowOrgEx32 (GDI32.258)
446 BOOL32
OffsetWindowOrgEx32( HDC32 hdc
, INT32 x
, INT32 y
, LPPOINT32 pt
)
448 DC
* dc
= DC_GetDCPtr( hdc
);
449 if (!dc
) return FALSE
;
450 if (dc
->funcs
->pOffsetWindowOrg
)
451 return dc
->funcs
->pOffsetWindowOrg( dc
, x
, y
);
463 /***********************************************************************
464 * ScaleViewportExt (GDI.18)
466 DWORD
ScaleViewportExt( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
467 INT16 yNum
, INT16 yDenom
)
470 if (!ScaleViewportExtEx32( hdc
, xNum
, xDenom
, yNum
, yDenom
, &size
))
472 return MAKELONG( size
.cx
, size
.cy
);
476 /***********************************************************************
477 * ScaleViewportExtEx16 (GDI.484)
479 BOOL16
ScaleViewportExtEx16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
480 INT16 yNum
, INT16 yDenom
, LPSIZE16 size
)
483 BOOL16 ret
= ScaleViewportExtEx32( hdc
, xNum
, xDenom
, yNum
, yDenom
,
485 if (size
) CONV_SIZE32TO16( &size32
, size
);
490 /***********************************************************************
491 * ScaleViewportExtEx32 (GDI32.293)
493 BOOL32
ScaleViewportExtEx32( HDC32 hdc
, INT32 xNum
, INT32 xDenom
,
494 INT32 yNum
, INT32 yDenom
, LPSIZE32 size
)
496 DC
* dc
= DC_GetDCPtr( hdc
);
497 if (!dc
) return FALSE
;
498 if (dc
->funcs
->pScaleViewportExt
)
499 return dc
->funcs
->pScaleViewportExt( dc
, xNum
, xDenom
, yNum
, yDenom
);
502 size
->cx
= dc
->vportExtX
;
503 size
->cy
= dc
->vportExtY
;
505 if ((dc
->w
.MapMode
!= MM_ISOTROPIC
) && (dc
->w
.MapMode
!= MM_ANISOTROPIC
))
507 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
) return FALSE
;
508 dc
->vportExtX
= (dc
->vportExtX
* xNum
) / xDenom
;
509 dc
->vportExtY
= (dc
->vportExtY
* yNum
) / yDenom
;
510 if (dc
->vportExtX
== 0) dc
->vportExtX
= 1;
511 if (dc
->vportExtY
== 0) dc
->vportExtY
= 1;
512 if (dc
->w
.MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
517 /***********************************************************************
518 * ScaleWindowExt (GDI.16)
520 DWORD
ScaleWindowExt( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
521 INT16 yNum
, INT16 yDenom
)
524 if (!ScaleWindowExtEx32( hdc
, xNum
, xDenom
, yNum
, yDenom
, &size
))
526 return MAKELONG( size
.cx
, size
.cy
);
530 /***********************************************************************
531 * ScaleWindowExtEx16 (GDI.485)
533 BOOL16
ScaleWindowExtEx16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
534 INT16 yNum
, INT16 yDenom
, LPSIZE16 size
)
537 BOOL16 ret
= ScaleWindowExtEx32( hdc
, xNum
, xDenom
, yNum
, yDenom
,
539 if (size
) CONV_SIZE32TO16( &size32
, size
);
544 /***********************************************************************
545 * ScaleWindowExtEx32 (GDI32.294)
547 BOOL32
ScaleWindowExtEx32( HDC32 hdc
, INT32 xNum
, INT32 xDenom
,
548 INT32 yNum
, INT32 yDenom
, LPSIZE32 size
)
550 DC
* dc
= DC_GetDCPtr( hdc
);
551 if (!dc
) return FALSE
;
552 if (dc
->funcs
->pScaleWindowExt
)
553 return dc
->funcs
->pScaleWindowExt( dc
, xNum
, xDenom
, yNum
, yDenom
);
556 size
->cx
= dc
->wndExtX
;
557 size
->cy
= dc
->wndExtY
;
559 if ((dc
->w
.MapMode
!= MM_ISOTROPIC
) && (dc
->w
.MapMode
!= MM_ANISOTROPIC
))
561 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
) return FALSE
;
562 dc
->wndExtX
= (dc
->wndExtX
* xNum
) / xDenom
;
563 dc
->wndExtY
= (dc
->wndExtY
* yNum
) / yDenom
;
564 if (dc
->wndExtX
== 0) dc
->wndExtX
= 1;
565 if (dc
->wndExtY
== 0) dc
->wndExtY
= 1;
566 if (dc
->w
.MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);