2 * GDI mapping mode functions
4 * Copyright 1993 Alexandre Julliard
11 /* #define DEBUG_GDI */
15 /***********************************************************************
16 * MAPPING_FixIsotropic
18 * Fix viewport extensions for isotropic mode.
20 void MAPPING_FixIsotropic( DC * dc )
22 double xdim = (double)dc->w.VportExtX * dc->w.devCaps->horzSize /
23 (dc->w.devCaps->horzRes * dc->w.WndExtX);
24 double ydim = (double)dc->w.VportExtY * dc->w.devCaps->vertSize /
25 (dc->w.devCaps->vertRes * dc->w.WndExtY);
28 dc->w.VportExtX = dc->w.VportExtX * fabs( ydim / xdim );
29 if (!dc->w.VportExtX) dc->w.VportExtX = 1;
33 dc->w.VportExtY = dc->w.VportExtY * fabs( xdim / ydim );
34 if (!dc->w.VportExtY) dc->w.VportExtY = 1;
38 /***********************************************************************
41 BOOL DPtoLP( HDC hdc, LPPOINT points, int count )
44 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
45 if (!dc) return FALSE;
47 for (pt = points; count > 0; pt++, count--)
49 pt->x = XDPTOLP( dc, pt->x );
50 pt->y = YDPTOLP( dc, pt->y );
56 /***********************************************************************
59 BOOL LPtoDP( HDC hdc, LPPOINT points, int count )
62 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
63 if (!dc) return FALSE;
65 for (pt = points; count > 0; pt++, count--)
67 pt->x = XLPTODP( dc, pt->x );
68 pt->y = YLPTODP( dc, pt->y );
74 /***********************************************************************
77 WORD SetMapMode( HDC hdc, WORD mode )
80 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
83 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
85 MF_MetaParam1(dc, META_SETMAPMODE, mode);
89 dprintf_gdi(stddeb, "SetMapMode: %d %d\n", hdc, mode );
91 prevMode = dc->w.MapMode;
95 dc->w.WndOrgX = dc->w.WndOrgY = 0;
96 dc->w.VportOrgX = dc->w.VportOrgY = 0;
105 dc->w.WndOrgX = dc->w.WndOrgY = 0;
106 dc->w.VportOrgX = dc->w.VportOrgY = 0;
107 dc->w.WndExtX = dc->w.devCaps->horzSize;
108 dc->w.WndExtY = dc->w.devCaps->vertSize;
109 dc->w.VportExtX = dc->w.devCaps->horzRes / 10;
110 dc->w.VportExtY = dc->w.devCaps->vertRes / -10;
114 dc->w.WndOrgX = dc->w.WndOrgY = 0;
115 dc->w.VportOrgX = dc->w.VportOrgY = 0;
116 dc->w.WndExtX = dc->w.devCaps->horzSize * 10;
117 dc->w.WndExtY = dc->w.devCaps->vertSize * 10;
118 dc->w.VportExtX = dc->w.devCaps->horzRes / 10;
119 dc->w.VportExtY = dc->w.devCaps->vertRes / -10;
123 dc->w.WndOrgX = dc->w.WndOrgY = 0;
124 dc->w.VportOrgX = dc->w.VportOrgY = 0;
125 dc->w.WndExtX = dc->w.devCaps->horzSize;
126 dc->w.WndExtY = dc->w.devCaps->vertSize;
127 dc->w.VportExtX = (short)(254L * dc->w.devCaps->horzRes / 1000);
128 dc->w.VportExtY = (short)(-254L * dc->w.devCaps->vertRes / 1000);
132 dc->w.WndOrgX = dc->w.WndOrgY = 0;
133 dc->w.VportOrgX = dc->w.VportOrgY = 0;
134 dc->w.WndExtX = dc->w.devCaps->horzSize * 10;
135 dc->w.WndExtY = dc->w.devCaps->vertSize * 10;
136 dc->w.VportExtX = (short)(254L * dc->w.devCaps->horzRes / 1000);
137 dc->w.VportExtY = (short)(-254L * dc->w.devCaps->vertRes / 1000);
141 dc->w.WndOrgX = dc->w.WndOrgY = 0;
142 dc->w.VportOrgX = dc->w.VportOrgY = 0;
143 dc->w.WndExtX = (short)(144L * dc->w.devCaps->horzSize / 10);
144 dc->w.WndExtY = (short)(144L * dc->w.devCaps->vertSize / 10);
145 dc->w.VportExtX = (short)(254L * dc->w.devCaps->horzRes / 1000);
146 dc->w.VportExtY = (short)(-254L * dc->w.devCaps->vertRes / 1000);
155 dc->w.MapMode = mode;
160 /***********************************************************************
161 * SetViewportExt (GDI.14)
163 DWORD SetViewportExt( HDC hdc, short x, short y )
166 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
169 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
170 if (!dc) return FALSE;
171 MF_MetaParam2(dc, META_SETVIEWPORTEXT, x, y);
175 size.cx = dc->w.VportExtX;
176 size.cy = dc->w.VportExtY;
177 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
178 return size.cx | (size.cy << 16);
179 if (!x || !y) return 0;
182 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
183 return size.cx | (size.cy << 16);
187 /***********************************************************************
188 * SetViewportExtEx (GDI.479)
190 BOOL SetViewportExtEx( HDC hdc, short x, short y, LPSIZE size )
192 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
193 if (!dc) return FALSE;
196 size->cx = dc->w.VportExtX;
197 size->cy = dc->w.VportExtY;
199 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
201 if (!x || !y) return FALSE;
204 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
209 /***********************************************************************
210 * SetViewportOrg (GDI.13)
212 DWORD SetViewportOrg( HDC hdc, short x, short y )
215 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
218 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
219 if (!dc) return FALSE;
220 MF_MetaParam2(dc, META_SETVIEWPORTORG, x, y);
224 pt.x = dc->w.VportOrgX;
225 pt.y = dc->w.VportOrgY;
228 return pt.x | (pt.y << 16);
232 /***********************************************************************
233 * SetViewportOrgEx (GDI.480)
235 BOOL SetViewportOrgEx( HDC hdc, short x, short y, LPPOINT pt )
237 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
238 if (!dc) return FALSE;
241 pt->x = dc->w.VportOrgX;
242 pt->y = dc->w.VportOrgY;
250 /***********************************************************************
251 * SetWindowExt (GDI.12)
253 DWORD SetWindowExt( HDC hdc, short x, short y )
256 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
259 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
260 if (!dc) return FALSE;
261 MF_MetaParam2(dc, META_SETWINDOWEXT, x, y);
265 size.cx = dc->w.WndExtX;
266 size.cy = dc->w.WndExtY;
267 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
268 return size.cx | (size.cy << 16);
269 if (!x || !y) return 0;
272 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
273 return size.cx | (size.cy << 16);
277 /***********************************************************************
278 * SetWindowExtEx (GDI.481)
280 BOOL SetWindowExtEx( HDC hdc, short x, short y, LPSIZE size )
282 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
283 if (!dc) return FALSE;
286 size->cx = dc->w.WndExtX;
287 size->cy = dc->w.WndExtY;
289 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
291 if (!x || !y) return FALSE;
294 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
299 /***********************************************************************
300 * SetWindowOrg (GDI.11)
302 DWORD SetWindowOrg( HDC hdc, short x, short y )
305 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
308 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
309 if (!dc) return FALSE;
310 MF_MetaParam2(dc, META_SETWINDOWORG, x, y);
314 pt.x = dc->w.WndOrgX;
315 pt.y = dc->w.WndOrgY;
318 return pt.x | (pt.y << 16);
322 /***********************************************************************
323 * SetWindowOrgEx (GDI.482)
325 BOOL SetWindowOrgEx( HDC hdc, short x, short y, LPPOINT pt )
327 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
328 if (!dc) return FALSE;
331 pt->x = dc->w.WndOrgX;
332 pt->y = dc->w.WndOrgY;
340 /***********************************************************************
341 * OffsetViewportOrg (GDI.17)
343 DWORD OffsetViewportOrg( HDC hdc, short x, short y )
346 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
349 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
350 if (!dc) return FALSE;
351 MF_MetaParam2(dc, META_OFFSETVIEWPORTORG, x, y);
355 pt.x = dc->w.VportOrgX;
356 pt.y = dc->w.VportOrgY;
357 dc->w.VportOrgX += x;
358 dc->w.VportOrgY += y;
359 return pt.x | (pt.y << 16);
363 /***********************************************************************
364 * OffsetViewportOrgEx (GDI.476)
366 BOOL OffsetViewportOrgEx( HDC hdc, short x, short y, LPPOINT pt )
368 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
369 if (!dc) return FALSE;
372 pt->x = dc->w.VportOrgX;
373 pt->y = dc->w.VportOrgY;
375 dc->w.VportOrgX += x;
376 dc->w.VportOrgY += y;
381 /***********************************************************************
382 * OffsetWindowOrg (GDI.15)
384 DWORD OffsetWindowOrg( HDC hdc, short x, short y )
387 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
390 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
391 if (!dc) return FALSE;
392 MF_MetaParam2(dc, META_OFFSETWINDOWORG, x, y);
396 pt.x = dc->w.WndOrgX;
397 pt.y = dc->w.WndOrgY;
400 return pt.x | (pt.y << 16);
404 /***********************************************************************
405 * OffsetWindowOrgEx (GDI.477)
407 BOOL OffsetWindowOrgEx( HDC hdc, short x, short y, LPPOINT pt )
409 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
410 if (!dc) return FALSE;
413 pt->x = dc->w.WndOrgX;
414 pt->y = dc->w.WndOrgY;
422 /***********************************************************************
423 * ScaleViewportExt (GDI.18)
425 DWORD ScaleViewportExt( HDC hdc, short xNum, short xDenom,
426 short yNum, short yDenom )
429 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
432 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
433 if (!dc) return FALSE;
434 MF_MetaParam4(dc, META_SCALEVIEWPORTEXT, xNum, xDenom, yNum, yDenom);
438 size.cx = dc->w.VportExtX;
439 size.cy = dc->w.VportExtY;
440 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
441 return size.cx | (size.cy << 16);
442 if (!xNum || !xDenom || !xNum || !yDenom) return 0;
443 dc->w.VportExtX = (dc->w.VportExtX * xNum) / xDenom;
444 dc->w.VportExtY = (dc->w.VportExtY * yNum) / yDenom;
445 if (dc->w.VportExtX == 0) dc->w.VportExtX = 1;
446 if (dc->w.VportExtY == 0) dc->w.VportExtY = 1;
447 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
448 return size.cx | (size.cy << 16);
452 /***********************************************************************
453 * ScaleViewportExtEx (GDI.484)
455 BOOL ScaleViewportExtEx( HDC hdc, short xNum, short xDenom,
456 short yNum, short yDenom, LPSIZE size )
458 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
459 if (!dc) return FALSE;
462 size->cx = dc->w.VportExtX;
463 size->cy = dc->w.VportExtY;
465 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
467 if (!xNum || !xDenom || !xNum || !yDenom) return FALSE;
468 dc->w.VportExtX = (dc->w.VportExtX * xNum) / xDenom;
469 dc->w.VportExtY = (dc->w.VportExtY * yNum) / yDenom;
470 if (dc->w.VportExtX == 0) dc->w.VportExtX = 1;
471 if (dc->w.VportExtY == 0) dc->w.VportExtY = 1;
472 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
477 /***********************************************************************
478 * ScaleWindowExt (GDI.16)
480 DWORD ScaleWindowExt( HDC hdc, short xNum, short xDenom,
481 short yNum, short yDenom )
484 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
487 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
488 if (!dc) return FALSE;
489 MF_MetaParam4(dc, META_SCALEWINDOWEXT, xNum, xDenom, yNum, yDenom);
493 size.cx = dc->w.WndExtX;
494 size.cy = dc->w.WndExtY;
495 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
496 return size.cx | (size.cy << 16);
497 if (!xNum || !xDenom || !xNum || !yDenom) return FALSE;
498 dc->w.WndExtX = (dc->w.WndExtX * xNum) / xDenom;
499 dc->w.WndExtY = (dc->w.WndExtY * yNum) / yDenom;
500 if (dc->w.WndExtX == 0) dc->w.WndExtX = 1;
501 if (dc->w.WndExtY == 0) dc->w.WndExtY = 1;
502 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
503 return size.cx | (size.cy << 16);
507 /***********************************************************************
508 * ScaleWindowExtEx (GDI.485)
510 BOOL ScaleWindowExtEx( HDC hdc, short xNum, short xDenom,
511 short yNum, short yDenom, LPSIZE size )
513 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
514 if (!dc) return FALSE;
517 size->cx = dc->w.WndExtX;
518 size->cy = dc->w.WndExtY;
520 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
522 if (!xNum || !xDenom || !xNum || !yDenom) return FALSE;
523 dc->w.WndExtX = (dc->w.WndExtX * xNum) / xDenom;
524 dc->w.WndExtY = (dc->w.WndExtY * yNum) / yDenom;
525 if (dc->w.WndExtX == 0) dc->w.WndExtX = 1;
526 if (dc->w.WndExtY == 0) dc->w.WndExtY = 1;
527 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );