winspool/tests: Add tests for EnumPrinterDrivers.
[wine/wine64.git] / dlls / gdi32 / mapping.c
blob33ba1cb3be711c1f3390b617e28df181bbb7a6ab
1 /*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "wownt32.h"
27 #include "gdi_private.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
33 /***********************************************************************
34 * MAPPING_FixIsotropic
36 * Fix viewport extensions for isotropic mode.
38 static void MAPPING_FixIsotropic( DC * dc )
40 double xdim = fabs((double)dc->vportExtX * GetDeviceCaps( dc->hSelf, HORZSIZE ) /
41 (GetDeviceCaps( dc->hSelf, HORZRES ) * dc->wndExtX));
42 double ydim = fabs((double)dc->vportExtY * GetDeviceCaps( dc->hSelf, VERTSIZE ) /
43 (GetDeviceCaps( dc->hSelf, VERTRES ) * dc->wndExtY));
45 if (xdim > ydim)
47 INT mincx = (dc->vportExtX >= 0) ? 1 : -1;
48 dc->vportExtX = floor(dc->vportExtX * ydim / xdim + 0.5);
49 if (!dc->vportExtX) dc->vportExtX = mincx;
51 else
53 INT mincy = (dc->vportExtY >= 0) ? 1 : -1;
54 dc->vportExtY = floor(dc->vportExtY * xdim / ydim + 0.5);
55 if (!dc->vportExtY) dc->vportExtY = mincy;
60 /***********************************************************************
61 * DPtoLP (GDI.67)
63 BOOL16 WINAPI DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
65 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
66 if (!dc) return FALSE;
68 while (count--)
70 points->x = MulDiv( points->x - dc->vportOrgX, dc->wndExtX, dc->vportExtX ) + dc->wndOrgX;
71 points->y = MulDiv( points->y - dc->vportOrgY, dc->wndExtY, dc->vportExtY ) + dc->wndOrgY;
72 points++;
74 GDI_ReleaseObj( HDC_32(hdc) );
75 return TRUE;
79 /***********************************************************************
80 * DPtoLP (GDI32.@)
82 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
84 DC * dc = DC_GetDCPtr( hdc );
85 if (!dc) return FALSE;
87 if (dc->vport2WorldValid)
89 while (count--)
91 FLOAT x = points->x;
92 FLOAT y = points->y;
93 points->x = floor( x * dc->xformVport2World.eM11 +
94 y * dc->xformVport2World.eM21 +
95 dc->xformVport2World.eDx + 0.5 );
96 points->y = floor( x * dc->xformVport2World.eM12 +
97 y * dc->xformVport2World.eM22 +
98 dc->xformVport2World.eDy + 0.5 );
99 points++;
102 GDI_ReleaseObj( hdc );
103 return (count < 0);
107 /***********************************************************************
108 * LPtoDP (GDI.99)
110 BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
112 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
113 if (!dc) return FALSE;
115 while (count--)
117 points->x = MulDiv( points->x - dc->wndOrgX, dc->vportExtX, dc->wndExtX ) + dc->vportOrgX;
118 points->y = MulDiv( points->y - dc->wndOrgY, dc->vportExtY, dc->wndExtY ) + dc->vportOrgY;
119 points++;
121 GDI_ReleaseObj( HDC_32(hdc) );
122 return TRUE;
126 /***********************************************************************
127 * LPtoDP (GDI32.@)
129 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
131 DC * dc = DC_GetDCPtr( hdc );
132 if (!dc) return FALSE;
134 while (count--)
136 FLOAT x = points->x;
137 FLOAT y = points->y;
138 points->x = floor( x * dc->xformWorld2Vport.eM11 +
139 y * dc->xformWorld2Vport.eM21 +
140 dc->xformWorld2Vport.eDx + 0.5 );
141 points->y = floor( x * dc->xformWorld2Vport.eM12 +
142 y * dc->xformWorld2Vport.eM22 +
143 dc->xformWorld2Vport.eDy + 0.5 );
144 points++;
146 GDI_ReleaseObj( hdc );
147 return TRUE;
151 /***********************************************************************
152 * SetMapMode (GDI32.@)
154 INT WINAPI SetMapMode( HDC hdc, INT mode )
156 INT ret;
157 INT horzSize, vertSize, horzRes, vertRes;
159 DC * dc = DC_GetDCPtr( hdc );
160 if (!dc) return 0;
161 if (dc->funcs->pSetMapMode)
163 if((ret = dc->funcs->pSetMapMode( dc->physDev, mode )) != TRUE)
165 if(ret == GDI_NO_MORE_WORK)
166 ret = TRUE;
167 goto done;
171 TRACE("%p %d\n", hdc, mode );
173 ret = dc->MapMode;
175 if (mode == dc->MapMode && (mode == MM_ISOTROPIC || mode == MM_ANISOTROPIC))
176 goto done;
178 horzSize = GetDeviceCaps( hdc, HORZSIZE );
179 vertSize = GetDeviceCaps( hdc, VERTSIZE );
180 horzRes = GetDeviceCaps( hdc, HORZRES );
181 vertRes = GetDeviceCaps( hdc, VERTRES );
182 switch(mode)
184 case MM_TEXT:
185 dc->wndExtX = 1;
186 dc->wndExtY = 1;
187 dc->vportExtX = 1;
188 dc->vportExtY = 1;
189 break;
190 case MM_LOMETRIC:
191 case MM_ISOTROPIC:
192 dc->wndExtX = horzSize * 10;
193 dc->wndExtY = vertSize * 10;
194 dc->vportExtX = horzRes;
195 dc->vportExtY = -vertRes;
196 break;
197 case MM_HIMETRIC:
198 dc->wndExtX = horzSize * 100;
199 dc->wndExtY = vertSize * 100;
200 dc->vportExtX = horzRes;
201 dc->vportExtY = -vertRes;
202 break;
203 case MM_LOENGLISH:
204 dc->wndExtX = MulDiv(1000, horzSize, 254);
205 dc->wndExtY = MulDiv(1000, vertSize, 254);
206 dc->vportExtX = horzRes;
207 dc->vportExtY = -vertRes;
208 break;
209 case MM_HIENGLISH:
210 dc->wndExtX = MulDiv(10000, horzSize, 254);
211 dc->wndExtY = MulDiv(10000, vertSize, 254);
212 dc->vportExtX = horzRes;
213 dc->vportExtY = -vertRes;
214 break;
215 case MM_TWIPS:
216 dc->wndExtX = MulDiv(14400, horzSize, 254);
217 dc->wndExtY = MulDiv(14400, vertSize, 254);
218 dc->vportExtX = horzRes;
219 dc->vportExtY = -vertRes;
220 break;
221 case MM_ANISOTROPIC:
222 break;
223 default:
224 goto done;
226 dc->MapMode = mode;
227 DC_UpdateXforms( dc );
228 done:
229 GDI_ReleaseObj( hdc );
230 return ret;
234 /***********************************************************************
235 * SetViewportExtEx (GDI32.@)
237 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
239 INT ret = TRUE;
240 DC * dc = DC_GetDCPtr( hdc );
241 if (!dc) return FALSE;
242 if (dc->funcs->pSetViewportExt)
244 if((ret = dc->funcs->pSetViewportExt( dc->physDev, x, y )) != TRUE)
246 if(ret == GDI_NO_MORE_WORK)
247 ret = TRUE;
248 goto done;
251 if (size)
253 size->cx = dc->vportExtX;
254 size->cy = dc->vportExtY;
256 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
257 goto done;
258 if (!x || !y)
260 ret = FALSE;
261 goto done;
263 dc->vportExtX = x;
264 dc->vportExtY = y;
265 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
266 DC_UpdateXforms( dc );
267 done:
268 GDI_ReleaseObj( hdc );
269 return ret;
273 /***********************************************************************
274 * SetViewportOrgEx (GDI32.@)
276 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
278 INT ret = TRUE;
279 DC * dc = DC_GetDCPtr( hdc );
280 if (!dc) return FALSE;
281 if (dc->funcs->pSetViewportOrg)
283 if((ret = dc->funcs->pSetViewportOrg( dc->physDev, x, y )) != TRUE)
285 if(ret == GDI_NO_MORE_WORK)
286 ret = TRUE;
287 goto done;
290 if (pt)
292 pt->x = dc->vportOrgX;
293 pt->y = dc->vportOrgY;
295 dc->vportOrgX = x;
296 dc->vportOrgY = y;
297 DC_UpdateXforms( dc );
299 done:
300 GDI_ReleaseObj( hdc );
301 return ret;
305 /***********************************************************************
306 * SetWindowExtEx (GDI32.@)
308 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
310 INT ret = TRUE;
311 DC * dc = DC_GetDCPtr( hdc );
312 if (!dc) return FALSE;
313 if (dc->funcs->pSetWindowExt)
315 if((ret = dc->funcs->pSetWindowExt( dc->physDev, x, y )) != TRUE)
317 if(ret == GDI_NO_MORE_WORK)
318 ret = TRUE;
319 goto done;
322 if (size)
324 size->cx = dc->wndExtX;
325 size->cy = dc->wndExtY;
327 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
328 goto done;
329 if (!x || !y)
331 ret = FALSE;
332 goto done;
334 dc->wndExtX = x;
335 dc->wndExtY = y;
336 /* The API docs say that you should call SetWindowExtEx before
337 SetViewportExtEx. This advice does not imply that Windows
338 doesn't ensure the isotropic mapping after SetWindowExtEx! */
339 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
340 DC_UpdateXforms( dc );
341 done:
342 GDI_ReleaseObj( hdc );
343 return ret;
347 /***********************************************************************
348 * SetWindowOrgEx (GDI32.@)
350 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
352 INT ret = TRUE;
353 DC * dc = DC_GetDCPtr( hdc );
354 if (!dc) return FALSE;
355 if (dc->funcs->pSetWindowOrg)
357 if((ret = dc->funcs->pSetWindowOrg( dc->physDev, x, y )) != TRUE)
359 if(ret == GDI_NO_MORE_WORK)
360 ret = TRUE;
361 goto done;
364 if (pt)
366 pt->x = dc->wndOrgX;
367 pt->y = dc->wndOrgY;
369 dc->wndOrgX = x;
370 dc->wndOrgY = y;
371 DC_UpdateXforms( dc );
372 done:
373 GDI_ReleaseObj( hdc );
374 return ret;
378 /***********************************************************************
379 * OffsetViewportOrgEx (GDI32.@)
381 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
383 INT ret = TRUE;
384 DC * dc = DC_GetDCPtr( hdc );
385 if (!dc) return FALSE;
386 if (dc->funcs->pOffsetViewportOrg)
388 if((ret = dc->funcs->pOffsetViewportOrg( dc->physDev, x, y )) != TRUE)
390 if(ret == GDI_NO_MORE_WORK)
391 ret = TRUE;
392 goto done;
395 if (pt)
397 pt->x = dc->vportOrgX;
398 pt->y = dc->vportOrgY;
400 dc->vportOrgX += x;
401 dc->vportOrgY += y;
402 DC_UpdateXforms( dc );
403 done:
404 GDI_ReleaseObj( hdc );
405 return ret;
409 /***********************************************************************
410 * OffsetWindowOrgEx (GDI32.@)
412 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
414 INT ret = TRUE;
415 DC * dc = DC_GetDCPtr( hdc );
416 if (!dc) return FALSE;
417 if (dc->funcs->pOffsetWindowOrg)
419 if((ret = dc->funcs->pOffsetWindowOrg( dc->physDev, x, y )) != TRUE)
421 if(ret == GDI_NO_MORE_WORK)
422 ret = TRUE;
423 goto done;
426 if (pt)
428 pt->x = dc->wndOrgX;
429 pt->y = dc->wndOrgY;
431 dc->wndOrgX += x;
432 dc->wndOrgY += y;
433 DC_UpdateXforms( dc );
434 done:
435 GDI_ReleaseObj( hdc );
436 return ret;
440 /***********************************************************************
441 * ScaleViewportExtEx (GDI32.@)
443 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
444 INT yNum, INT yDenom, LPSIZE size )
446 INT ret = TRUE;
447 DC * dc = DC_GetDCPtr( hdc );
448 if (!dc) return FALSE;
449 if (dc->funcs->pScaleViewportExt)
451 if((ret = dc->funcs->pScaleViewportExt( dc->physDev, xNum, xDenom, yNum, yDenom )) != TRUE)
453 if(ret == GDI_NO_MORE_WORK)
454 ret = TRUE;
455 goto done;
458 if (size)
460 size->cx = dc->vportExtX;
461 size->cy = dc->vportExtY;
463 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
464 goto done;
465 if (!xNum || !xDenom || !xNum || !yDenom)
467 ret = FALSE;
468 goto done;
470 dc->vportExtX = (dc->vportExtX * xNum) / xDenom;
471 dc->vportExtY = (dc->vportExtY * yNum) / yDenom;
472 if (dc->vportExtX == 0) dc->vportExtX = 1;
473 if (dc->vportExtY == 0) dc->vportExtY = 1;
474 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
475 DC_UpdateXforms( dc );
476 done:
477 GDI_ReleaseObj( hdc );
478 return ret;
482 /***********************************************************************
483 * ScaleWindowExtEx (GDI32.@)
485 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
486 INT yNum, INT yDenom, LPSIZE size )
488 INT ret = TRUE;
489 DC * dc = DC_GetDCPtr( hdc );
490 if (!dc) return FALSE;
491 if (dc->funcs->pScaleWindowExt)
493 if((ret = dc->funcs->pScaleWindowExt( dc->physDev, xNum, xDenom, yNum, yDenom )) != TRUE)
495 if(ret == GDI_NO_MORE_WORK)
496 ret = TRUE;
497 goto done;
500 if (size)
502 size->cx = dc->wndExtX;
503 size->cy = dc->wndExtY;
505 if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
506 goto done;
507 if (!xNum || !xDenom || !xNum || !yDenom)
509 ret = FALSE;
510 goto done;
512 dc->wndExtX = (dc->wndExtX * xNum) / xDenom;
513 dc->wndExtY = (dc->wndExtY * yNum) / yDenom;
514 if (dc->wndExtX == 0) dc->wndExtX = 1;
515 if (dc->wndExtY == 0) dc->wndExtY = 1;
516 if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
517 DC_UpdateXforms( dc );
518 done:
519 GDI_ReleaseObj( hdc );
520 return ret;