2 * GDI mapping mode functions
4 * Copyright 1993 Alexandre Julliard
12 /***********************************************************************
13 * MAPPING_FixIsotropic
15 * Fix viewport extensions for isotropic mode.
17 void MAPPING_FixIsotropic( DC
* dc
)
19 double xdim
= (double)dc
->vportExtX
* dc
->w
.devCaps
->horzSize
/
20 (dc
->w
.devCaps
->horzRes
* dc
->wndExtX
);
21 double ydim
= (double)dc
->vportExtY
* dc
->w
.devCaps
->vertSize
/
22 (dc
->w
.devCaps
->vertRes
* dc
->wndExtY
);
25 dc
->vportExtX
= dc
->vportExtX
* fabs( ydim
/ xdim
);
26 if (!dc
->vportExtX
) dc
->vportExtX
= 1;
30 dc
->vportExtY
= dc
->vportExtY
* fabs( xdim
/ ydim
);
31 if (!dc
->vportExtY
) dc
->vportExtY
= 1;
36 /***********************************************************************
39 BOOL16 WINAPI
DPtoLP16( HDC16 hdc
, LPPOINT16 points
, INT16 count
)
41 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
42 if (!dc
) return FALSE
;
46 points
->x
= XDPTOLP( dc
, points
->x
);
47 points
->y
= YDPTOLP( dc
, points
->y
);
54 /***********************************************************************
57 BOOL32 WINAPI
DPtoLP32( HDC32 hdc
, LPPOINT32 points
, INT32 count
)
59 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
60 if (!dc
) return FALSE
;
64 if (!INTERNAL_DPTOLP( dc
, points
))
72 /***********************************************************************
75 BOOL16 WINAPI
LPtoDP16( HDC16 hdc
, LPPOINT16 points
, INT16 count
)
77 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
78 if (!dc
) return FALSE
;
82 points
->x
= XLPTODP( dc
, points
->x
);
83 points
->y
= YLPTODP( dc
, points
->y
);
90 /***********************************************************************
91 * LPtoDP32 (GDI32.247)
93 BOOL32 WINAPI
LPtoDP32( HDC32 hdc
, LPPOINT32 points
, INT32 count
)
95 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
96 if (!dc
) return FALSE
;
100 INTERNAL_LPTODP( dc
, points
);
107 /***********************************************************************
108 * SetMapMode16 (GDI.3)
110 INT16 WINAPI
SetMapMode16( HDC16 hdc
, INT16 mode
)
112 return SetMapMode32( hdc
, mode
);
116 /***********************************************************************
117 * SetMapMode32 (GDI32.321)
119 INT32 WINAPI
SetMapMode32( HDC32 hdc
, INT32 mode
)
122 DC
* dc
= DC_GetDCPtr( hdc
);
124 if (dc
->funcs
->pSetMapMode
) return dc
->funcs
->pSetMapMode( dc
, mode
);
126 TRACE(gdi
, "%04x %d\n", hdc
, mode
);
128 prevMode
= dc
->w
.MapMode
;
132 dc
->wndOrgX
= dc
->wndOrgY
= 0;
133 dc
->vportOrgX
= dc
->vportOrgY
= 0;
142 dc
->wndOrgX
= dc
->wndOrgY
= 0;
143 dc
->vportOrgX
= dc
->vportOrgY
= 0;
144 dc
->wndExtX
= dc
->w
.devCaps
->horzSize
;
145 dc
->wndExtY
= dc
->w
.devCaps
->vertSize
;
146 dc
->vportExtX
= dc
->w
.devCaps
->horzRes
/ 10;
147 dc
->vportExtY
= dc
->w
.devCaps
->vertRes
/ -10;
151 dc
->wndOrgX
= dc
->wndOrgY
= 0;
152 dc
->vportOrgX
= dc
->vportOrgY
= 0;
153 dc
->wndExtX
= dc
->w
.devCaps
->horzSize
* 10;
154 dc
->wndExtY
= dc
->w
.devCaps
->vertSize
* 10;
155 dc
->vportExtX
= dc
->w
.devCaps
->horzRes
/ 10;
156 dc
->vportExtY
= dc
->w
.devCaps
->vertRes
/ -10;
160 dc
->wndOrgX
= dc
->wndOrgY
= 0;
161 dc
->vportOrgX
= dc
->vportOrgY
= 0;
162 dc
->wndExtX
= dc
->w
.devCaps
->horzSize
;
163 dc
->wndExtY
= dc
->w
.devCaps
->vertSize
;
164 dc
->vportExtX
= 254L * dc
->w
.devCaps
->horzRes
/ 1000;
165 dc
->vportExtY
= -254L * dc
->w
.devCaps
->vertRes
/ 1000;
169 dc
->wndOrgX
= dc
->wndOrgY
= 0;
170 dc
->vportOrgX
= dc
->vportOrgY
= 0;
171 dc
->wndExtX
= dc
->w
.devCaps
->horzSize
* 10;
172 dc
->wndExtY
= dc
->w
.devCaps
->vertSize
* 10;
173 dc
->vportExtX
= 254L * dc
->w
.devCaps
->horzRes
/ 1000;
174 dc
->vportExtY
= -254L * dc
->w
.devCaps
->vertRes
/ 1000;
178 dc
->wndOrgX
= dc
->wndOrgY
= 0;
179 dc
->vportOrgX
= dc
->vportOrgY
= 0;
180 dc
->wndExtX
= 144L * dc
->w
.devCaps
->horzSize
/ 10;
181 dc
->wndExtY
= 144L * dc
->w
.devCaps
->vertSize
/ 10;
182 dc
->vportExtX
= 254L * dc
->w
.devCaps
->horzRes
/ 1000;
183 dc
->vportExtY
= -254L * dc
->w
.devCaps
->vertRes
/ 1000;
192 dc
->w
.MapMode
= mode
;
193 DC_UpdateXforms( dc
);
198 /***********************************************************************
199 * SetViewportExt (GDI.14)
201 DWORD WINAPI
SetViewportExt( HDC16 hdc
, INT16 x
, INT16 y
)
204 if (!SetViewportExtEx32( hdc
, x
, y
, &size
)) return 0;
205 return MAKELONG( size
.cx
, size
.cy
);
209 /***********************************************************************
210 * SetViewportExtEx16 (GDI.479)
212 BOOL16 WINAPI
SetViewportExtEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPSIZE16 size
)
215 BOOL16 ret
= SetViewportExtEx32( hdc
, x
, y
, &size32
);
216 if (size
) CONV_SIZE32TO16( &size32
, size
);
221 /***********************************************************************
222 * SetViewportExtEx32 (GDI32.340)
224 BOOL32 WINAPI
SetViewportExtEx32( HDC32 hdc
, INT32 x
, INT32 y
, LPSIZE32 size
)
226 DC
* dc
= DC_GetDCPtr( hdc
);
227 if (!dc
) return FALSE
;
228 if (dc
->funcs
->pSetViewportExt
)
229 return dc
->funcs
->pSetViewportExt( dc
, x
, y
);
232 size
->cx
= dc
->vportExtX
;
233 size
->cy
= dc
->vportExtY
;
235 if ((dc
->w
.MapMode
!= MM_ISOTROPIC
) && (dc
->w
.MapMode
!= MM_ANISOTROPIC
))
237 if (!x
|| !y
) return FALSE
;
240 if (dc
->w
.MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
241 DC_UpdateXforms( dc
);
246 /***********************************************************************
247 * SetViewportOrg (GDI.13)
249 DWORD WINAPI
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 WINAPI
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 WINAPI
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
;
285 DC_UpdateXforms( dc
);
290 /***********************************************************************
291 * SetWindowExt (GDI.12)
293 DWORD WINAPI
SetWindowExt( HDC16 hdc
, INT16 x
, INT16 y
)
296 if (!SetWindowExtEx32( hdc
, x
, y
, &size
)) return 0;
297 return MAKELONG( size
.cx
, size
.cy
);
301 /***********************************************************************
302 * SetWindowExtEx16 (GDI.481)
304 BOOL16 WINAPI
SetWindowExtEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPSIZE16 size
)
307 BOOL16 ret
= SetWindowExtEx32( hdc
, x
, y
, &size32
);
308 if (size
) CONV_SIZE32TO16( &size32
, size
);
313 /***********************************************************************
314 * SetWindowExtEx32 (GDI32.344)
316 BOOL32 WINAPI
SetWindowExtEx32( HDC32 hdc
, INT32 x
, INT32 y
, LPSIZE32 size
)
318 DC
* dc
= DC_GetDCPtr( hdc
);
319 if (!dc
) return FALSE
;
320 if (dc
->funcs
->pSetWindowExt
) return dc
->funcs
->pSetWindowExt( dc
, x
, y
);
323 size
->cx
= dc
->wndExtX
;
324 size
->cy
= dc
->wndExtY
;
326 if ((dc
->w
.MapMode
!= MM_ISOTROPIC
) && (dc
->w
.MapMode
!= MM_ANISOTROPIC
))
328 if (!x
|| !y
) return FALSE
;
331 if (dc
->w
.MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
332 DC_UpdateXforms( dc
);
337 /***********************************************************************
338 * SetWindowOrg (GDI.11)
340 DWORD WINAPI
SetWindowOrg( HDC16 hdc
, INT16 x
, INT16 y
)
343 if (!SetWindowOrgEx32( hdc
, x
, y
, &pt
)) return 0;
344 return MAKELONG( pt
.x
, pt
.y
);
348 /***********************************************************************
349 * SetWindowOrgEx16 (GDI.482)
351 BOOL16 WINAPI
SetWindowOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
354 BOOL16 ret
= SetWindowOrgEx32( hdc
, x
, y
, &pt32
);
355 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
360 /***********************************************************************
361 * SetWindowOrgEx32 (GDI32.345)
363 BOOL32 WINAPI
SetWindowOrgEx32( HDC32 hdc
, INT32 x
, INT32 y
, LPPOINT32 pt
)
365 DC
* dc
= DC_GetDCPtr( hdc
);
366 if (!dc
) return FALSE
;
367 if (dc
->funcs
->pSetWindowOrg
) return dc
->funcs
->pSetWindowOrg( dc
, x
, y
);
375 DC_UpdateXforms( dc
);
380 /***********************************************************************
381 * OffsetViewportOrg (GDI.17)
383 DWORD WINAPI
OffsetViewportOrg( HDC16 hdc
, INT16 x
, INT16 y
)
386 if (!OffsetViewportOrgEx32( hdc
, x
, y
, &pt
)) return 0;
387 return MAKELONG( pt
.x
, pt
.y
);
391 /***********************************************************************
392 * OffsetViewportOrgEx16 (GDI.476)
394 BOOL16 WINAPI
OffsetViewportOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
397 BOOL16 ret
= OffsetViewportOrgEx32( hdc
, x
, y
, &pt32
);
398 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
403 /***********************************************************************
404 * OffsetViewportOrgEx32 (GDI32.257)
406 BOOL32 WINAPI
OffsetViewportOrgEx32( HDC32 hdc
, INT32 x
, INT32 y
, LPPOINT32 pt
)
408 DC
* dc
= DC_GetDCPtr( hdc
);
409 if (!dc
) return FALSE
;
410 if (dc
->funcs
->pOffsetViewportOrg
)
411 return dc
->funcs
->pOffsetViewportOrg( dc
, x
, y
);
414 pt
->x
= dc
->vportOrgX
;
415 pt
->y
= dc
->vportOrgY
;
419 DC_UpdateXforms( dc
);
424 /***********************************************************************
425 * OffsetWindowOrg (GDI.15)
427 DWORD WINAPI
OffsetWindowOrg( HDC16 hdc
, INT16 x
, INT16 y
)
430 if (!OffsetWindowOrgEx32( hdc
, x
, y
, &pt
)) return 0;
431 return MAKELONG( pt
.x
, pt
.y
);
435 /***********************************************************************
436 * OffsetWindowOrgEx16 (GDI.477)
438 BOOL16 WINAPI
OffsetWindowOrgEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
441 BOOL16 ret
= OffsetWindowOrgEx32( hdc
, x
, y
, &pt32
);
442 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
447 /***********************************************************************
448 * OffsetWindowOrgEx32 (GDI32.258)
450 BOOL32 WINAPI
OffsetWindowOrgEx32( HDC32 hdc
, INT32 x
, INT32 y
, LPPOINT32 pt
)
452 DC
* dc
= DC_GetDCPtr( hdc
);
453 if (!dc
) return FALSE
;
454 if (dc
->funcs
->pOffsetWindowOrg
)
455 return dc
->funcs
->pOffsetWindowOrg( dc
, x
, y
);
463 DC_UpdateXforms( dc
);
468 /***********************************************************************
469 * ScaleViewportExt (GDI.18)
471 DWORD WINAPI
ScaleViewportExt( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
472 INT16 yNum
, INT16 yDenom
)
475 if (!ScaleViewportExtEx32( hdc
, xNum
, xDenom
, yNum
, yDenom
, &size
))
477 return MAKELONG( size
.cx
, size
.cy
);
481 /***********************************************************************
482 * ScaleViewportExtEx16 (GDI.484)
484 BOOL16 WINAPI
ScaleViewportExtEx16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
485 INT16 yNum
, INT16 yDenom
, LPSIZE16 size
)
488 BOOL16 ret
= ScaleViewportExtEx32( hdc
, xNum
, xDenom
, yNum
, yDenom
,
490 if (size
) CONV_SIZE32TO16( &size32
, size
);
495 /***********************************************************************
496 * ScaleViewportExtEx32 (GDI32.293)
498 BOOL32 WINAPI
ScaleViewportExtEx32( HDC32 hdc
, INT32 xNum
, INT32 xDenom
,
499 INT32 yNum
, INT32 yDenom
, LPSIZE32 size
)
501 DC
* dc
= DC_GetDCPtr( hdc
);
502 if (!dc
) return FALSE
;
503 if (dc
->funcs
->pScaleViewportExt
)
504 return dc
->funcs
->pScaleViewportExt( dc
, xNum
, xDenom
, yNum
, yDenom
);
507 size
->cx
= dc
->vportExtX
;
508 size
->cy
= dc
->vportExtY
;
510 if ((dc
->w
.MapMode
!= MM_ISOTROPIC
) && (dc
->w
.MapMode
!= MM_ANISOTROPIC
))
512 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
) return FALSE
;
513 dc
->vportExtX
= (dc
->vportExtX
* xNum
) / xDenom
;
514 dc
->vportExtY
= (dc
->vportExtY
* yNum
) / yDenom
;
515 if (dc
->vportExtX
== 0) dc
->vportExtX
= 1;
516 if (dc
->vportExtY
== 0) dc
->vportExtY
= 1;
517 if (dc
->w
.MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
518 DC_UpdateXforms( dc
);
523 /***********************************************************************
524 * ScaleWindowExt (GDI.16)
526 DWORD WINAPI
ScaleWindowExt( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
527 INT16 yNum
, INT16 yDenom
)
530 if (!ScaleWindowExtEx32( hdc
, xNum
, xDenom
, yNum
, yDenom
, &size
))
532 return MAKELONG( size
.cx
, size
.cy
);
536 /***********************************************************************
537 * ScaleWindowExtEx16 (GDI.485)
539 BOOL16 WINAPI
ScaleWindowExtEx16( HDC16 hdc
, INT16 xNum
, INT16 xDenom
,
540 INT16 yNum
, INT16 yDenom
, LPSIZE16 size
)
543 BOOL16 ret
= ScaleWindowExtEx32( hdc
, xNum
, xDenom
, yNum
, yDenom
,
545 if (size
) CONV_SIZE32TO16( &size32
, size
);
550 /***********************************************************************
551 * ScaleWindowExtEx32 (GDI32.294)
553 BOOL32 WINAPI
ScaleWindowExtEx32( HDC32 hdc
, INT32 xNum
, INT32 xDenom
,
554 INT32 yNum
, INT32 yDenom
, LPSIZE32 size
)
556 DC
* dc
= DC_GetDCPtr( hdc
);
557 if (!dc
) return FALSE
;
558 if (dc
->funcs
->pScaleWindowExt
)
559 return dc
->funcs
->pScaleWindowExt( dc
, xNum
, xDenom
, yNum
, yDenom
);
562 size
->cx
= dc
->wndExtX
;
563 size
->cy
= dc
->wndExtY
;
565 if ((dc
->w
.MapMode
!= MM_ISOTROPIC
) && (dc
->w
.MapMode
!= MM_ANISOTROPIC
))
567 if (!xNum
|| !xDenom
|| !xNum
|| !yDenom
) return FALSE
;
568 dc
->wndExtX
= (dc
->wndExtX
* xNum
) / xDenom
;
569 dc
->wndExtY
= (dc
->wndExtY
* yNum
) / yDenom
;
570 if (dc
->wndExtX
== 0) dc
->wndExtX
= 1;
571 if (dc
->wndExtY
== 0) dc
->wndExtY
= 1;
572 if (dc
->w
.MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
573 DC_UpdateXforms( dc
);