Fix the case of product and company names.
[wine] / graphics / mapping.c
1 /*
2  * GDI mapping mode functions
3  *
4  * Copyright 1993 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "gdi.h"
22 #include "wownt32.h"
23 #include "wine/debug.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
26
27
28 /***********************************************************************
29  *           MAPPING_FixIsotropic
30  *
31  * Fix viewport extensions for isotropic mode.
32  */
33 void MAPPING_FixIsotropic( DC * dc )
34 {
35     double xdim = (double)dc->vportExtX * GetDeviceCaps( dc->hSelf, HORZSIZE ) /
36                   (GetDeviceCaps( dc->hSelf, HORZRES ) * dc->wndExtX);
37     double ydim = (double)dc->vportExtY * GetDeviceCaps( dc->hSelf, VERTSIZE ) /
38                   (GetDeviceCaps( dc->hSelf, VERTRES ) * dc->wndExtY);
39     if (xdim > ydim)
40     {
41         dc->vportExtX = floor(dc->vportExtX * fabs( ydim / xdim ) + 0.5);
42         if (!dc->vportExtX) dc->vportExtX = 1;
43     }
44     else
45     {
46         dc->vportExtY = floor(dc->vportExtY * fabs( xdim / ydim ) + 0.5);
47         if (!dc->vportExtY) dc->vportExtY = 1;
48     }
49 }
50
51
52 /***********************************************************************
53  *           DPtoLP    (GDI.67)
54  */
55 BOOL16 WINAPI DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
56 {
57     DC * dc = DC_GetDCPtr( HDC_32(hdc) );
58     if (!dc) return FALSE;
59
60     while (count--)
61     {
62         points->x = MulDiv( points->x - dc->vportOrgX, dc->wndExtX, dc->vportExtX ) + dc->wndOrgX;
63         points->y = MulDiv( points->y - dc->vportOrgY, dc->wndExtY, dc->vportExtY ) + dc->wndOrgY;
64         points++;
65     }
66     GDI_ReleaseObj( HDC_32(hdc) );
67     return TRUE;
68 }
69
70
71 /***********************************************************************
72  *           DPtoLP    (GDI32.@)
73  */
74 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
75 {
76     DC * dc = DC_GetDCPtr( hdc );
77     if (!dc) return FALSE;
78
79     if (dc->vport2WorldValid)
80     {
81         while (count--)
82         {
83             FLOAT x = points->x;
84             FLOAT y = points->y;
85             points->x = floor( x * dc->xformVport2World.eM11 +
86                                y * dc->xformVport2World.eM21 +
87                                dc->xformVport2World.eDx + 0.5 );
88             points->y = floor( x * dc->xformVport2World.eM12 +
89                                y * dc->xformVport2World.eM22 +
90                                dc->xformVport2World.eDy + 0.5 );
91             points++;
92         }
93     }
94     GDI_ReleaseObj( hdc );
95     return (count < 0);
96 }
97
98
99 /***********************************************************************
100  *           LPtoDP    (GDI.99)
101  */
102 BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
103 {
104     DC * dc = DC_GetDCPtr( HDC_32(hdc) );
105     if (!dc) return FALSE;
106
107     while (count--)
108     {
109         points->x = MulDiv( points->x - dc->wndOrgX, dc->vportExtX, dc->wndExtX ) + dc->vportOrgX;
110         points->y = MulDiv( points->y - dc->wndOrgY, dc->vportExtY, dc->wndExtY ) + dc->vportOrgY;
111         points++;
112     }
113     GDI_ReleaseObj( HDC_32(hdc) );
114     return TRUE;
115 }
116
117
118 /***********************************************************************
119  *           LPtoDP    (GDI32.@)
120  */
121 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
122 {
123     DC * dc = DC_GetDCPtr( hdc );
124     if (!dc) return FALSE;
125
126     while (count--)
127     {
128         FLOAT x = points->x;
129         FLOAT y = points->y;
130         points->x = floor( x * dc->xformWorld2Vport.eM11 +
131                            y * dc->xformWorld2Vport.eM21 +
132                            dc->xformWorld2Vport.eDx + 0.5 );
133         points->y = floor( x * dc->xformWorld2Vport.eM12 +
134                            y * dc->xformWorld2Vport.eM22 +
135                            dc->xformWorld2Vport.eDy + 0.5 );
136         points++;
137     }
138     GDI_ReleaseObj( hdc );
139     return TRUE;
140 }
141
142
143 /***********************************************************************
144  *           SetMapMode    (GDI32.@)
145  */
146 INT WINAPI SetMapMode( HDC hdc, INT mode )
147 {
148     INT ret;
149     INT horzSize, vertSize, horzRes, vertRes;
150
151     DC * dc = DC_GetDCPtr( hdc );
152     if (!dc) return 0;
153     if (dc->funcs->pSetMapMode)
154     {
155         if((ret = dc->funcs->pSetMapMode( dc->physDev, mode )) != TRUE)
156         {
157             if(ret == GDI_NO_MORE_WORK)
158                 ret = TRUE;
159             goto done;
160         }
161     }
162
163     TRACE("%p %d\n", hdc, mode );
164
165     ret = dc->MapMode;
166
167     if (mode == dc->MapMode && (mode == MM_ISOTROPIC || mode == MM_ANISOTROPIC))
168         goto done;
169
170     horzSize = GetDeviceCaps( hdc, HORZSIZE );
171     vertSize = GetDeviceCaps( hdc, VERTSIZE );
172     horzRes  = GetDeviceCaps( hdc, HORZRES );
173     vertRes  = GetDeviceCaps( hdc, VERTRES );
174     switch(mode)
175     {
176     case MM_TEXT:
177         dc->wndExtX   = 1;
178         dc->wndExtY   = 1;
179         dc->vportExtX = 1;
180         dc->vportExtY = 1;
181         break;
182     case MM_LOMETRIC:
183     case MM_ISOTROPIC:
184         dc->wndExtX   = horzSize * 10;
185         dc->wndExtY   = vertSize * 10;
186         dc->vportExtX = horzRes;
187         dc->vportExtY = -vertRes;
188         break;
189     case MM_HIMETRIC:
190         dc->wndExtX   = horzSize * 100;
191         dc->wndExtY   = vertSize * 100;
192         dc->vportExtX = horzRes;
193         dc->vportExtY = -vertRes;
194         break;
195     case MM_LOENGLISH:
196         dc->wndExtX   = MulDiv(1000, horzSize, 254);
197         dc->wndExtY   = MulDiv(1000, vertSize, 254);
198         dc->vportExtX = horzRes;
199         dc->vportExtY = -vertRes;
200         break;
201     case MM_HIENGLISH:
202         dc->wndExtX   = MulDiv(10000, horzSize, 254);
203         dc->wndExtY   = MulDiv(10000, vertSize, 254);
204         dc->vportExtX = horzRes;
205         dc->vportExtY = -vertRes;
206         break;
207     case MM_TWIPS:
208         dc->wndExtX   = MulDiv(14400, horzSize, 254);
209         dc->wndExtY   = MulDiv(14400, vertSize, 254);
210         dc->vportExtX = horzRes;
211         dc->vportExtY = -vertRes;
212         break;
213     case MM_ANISOTROPIC:
214         break;
215     default:
216         goto done;
217     }
218     dc->MapMode = mode;
219     DC_UpdateXforms( dc );
220  done:
221     GDI_ReleaseObj( hdc );
222     return ret;
223 }
224
225
226 /***********************************************************************
227  *           SetViewportExtEx    (GDI32.@)
228  */
229 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
230 {
231     INT ret = TRUE;
232     DC * dc = DC_GetDCPtr( hdc );
233     if (!dc) return FALSE;
234     if (dc->funcs->pSetViewportExt)
235     {
236         if((ret = dc->funcs->pSetViewportExt( dc->physDev, x, y )) != TRUE)
237         {
238             if(ret == GDI_NO_MORE_WORK)
239                 ret = TRUE;
240             goto done;
241         }
242     }
243     if (size)
244     {
245         size->cx = dc->vportExtX;
246         size->cy = dc->vportExtY;
247     }
248     if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
249         goto done;
250     if (!x || !y)
251     {
252         ret = FALSE;
253         goto done;
254     }
255     dc->vportExtX = x;
256     dc->vportExtY = y;
257     if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
258     DC_UpdateXforms( dc );
259  done:
260     GDI_ReleaseObj( hdc );
261     return ret;
262 }
263
264
265 /***********************************************************************
266  *           SetViewportOrgEx    (GDI32.@)
267  */
268 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
269 {
270     INT ret = TRUE;
271     DC * dc = DC_GetDCPtr( hdc );
272     if (!dc) return FALSE;
273     if (dc->funcs->pSetViewportOrg)
274     {
275         if((ret = dc->funcs->pSetViewportOrg( dc->physDev, x, y )) != TRUE)
276         {
277             if(ret == GDI_NO_MORE_WORK)
278                 ret = TRUE;
279             goto done;
280         }
281     }
282     if (pt)
283     {
284         pt->x = dc->vportOrgX;
285         pt->y = dc->vportOrgY;
286     }
287     dc->vportOrgX = x;
288     dc->vportOrgY = y;
289     DC_UpdateXforms( dc );
290
291  done:
292     GDI_ReleaseObj( hdc );
293     return ret;
294 }
295
296
297 /***********************************************************************
298  *           SetWindowExtEx    (GDI32.@)
299  */
300 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
301 {
302     INT ret = TRUE;
303     DC * dc = DC_GetDCPtr( hdc );
304     if (!dc) return FALSE;
305     if (dc->funcs->pSetWindowExt)
306     {
307         if((ret = dc->funcs->pSetWindowExt( dc->physDev, x, y )) != TRUE)
308         {
309             if(ret == GDI_NO_MORE_WORK)
310                 ret = TRUE;
311             goto done;
312         }
313     }
314     if (size)
315     {
316         size->cx = dc->wndExtX;
317         size->cy = dc->wndExtY;
318     }
319     if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
320         goto done;
321     if (!x || !y)
322     {
323         ret = FALSE;
324         goto done;
325     }
326     dc->wndExtX = x;
327     dc->wndExtY = y;
328     /* Windows fixes MM_ISOTROPIC mode only in SetViewportExtEx() */
329     DC_UpdateXforms( dc );
330  done:
331     GDI_ReleaseObj( hdc );
332     return ret;
333 }
334
335
336 /***********************************************************************
337  *           SetWindowOrgEx    (GDI32.@)
338  */
339 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
340 {
341     INT ret = TRUE;
342     DC * dc = DC_GetDCPtr( hdc );
343     if (!dc) return FALSE;
344     if (dc->funcs->pSetWindowOrg)
345     {
346         if((ret = dc->funcs->pSetWindowOrg( dc->physDev, x, y )) != TRUE)
347         {
348             if(ret == GDI_NO_MORE_WORK)
349                 ret = TRUE;
350             goto done;
351         }
352     }
353     if (pt)
354     {
355         pt->x = dc->wndOrgX;
356         pt->y = dc->wndOrgY;
357     }
358     dc->wndOrgX = x;
359     dc->wndOrgY = y;
360     DC_UpdateXforms( dc );
361  done:
362     GDI_ReleaseObj( hdc );
363     return ret;
364 }
365
366
367 /***********************************************************************
368  *           OffsetViewportOrgEx    (GDI32.@)
369  */
370 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
371 {
372     INT ret = TRUE;
373     DC * dc = DC_GetDCPtr( hdc );
374     if (!dc) return FALSE;
375     if (dc->funcs->pOffsetViewportOrg)
376     {
377         if((ret = dc->funcs->pOffsetViewportOrg( dc->physDev, x, y )) != TRUE)
378         {
379             if(ret == GDI_NO_MORE_WORK)
380                 ret = TRUE;
381             goto done;
382         }
383     }
384     if (pt)
385     {
386         pt->x = dc->vportOrgX;
387         pt->y = dc->vportOrgY;
388     }
389     dc->vportOrgX += x;
390     dc->vportOrgY += y;
391     DC_UpdateXforms( dc );
392  done:
393     GDI_ReleaseObj( hdc );
394     return ret;
395 }
396
397
398 /***********************************************************************
399  *           OffsetWindowOrgEx    (GDI32.@)
400  */
401 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
402 {
403     INT ret = TRUE;
404     DC * dc = DC_GetDCPtr( hdc );
405     if (!dc) return FALSE;
406     if (dc->funcs->pOffsetWindowOrg)
407     {
408         if((ret = dc->funcs->pOffsetWindowOrg( dc->physDev, x, y )) != TRUE)
409         {
410             if(ret == GDI_NO_MORE_WORK)
411                 ret = TRUE;
412             goto done;
413         }
414     }
415     if (pt)
416     {
417         pt->x = dc->wndOrgX;
418         pt->y = dc->wndOrgY;
419     }
420     dc->wndOrgX += x;
421     dc->wndOrgY += y;
422     DC_UpdateXforms( dc );
423  done:
424     GDI_ReleaseObj( hdc );
425     return ret;
426 }
427
428
429 /***********************************************************************
430  *           ScaleViewportExtEx    (GDI32.@)
431  */
432 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
433                                     INT yNum, INT yDenom, LPSIZE size )
434 {
435     INT ret = TRUE;
436     DC * dc = DC_GetDCPtr( hdc );
437     if (!dc) return FALSE;
438     if (dc->funcs->pScaleViewportExt)
439     {
440         if((ret = dc->funcs->pScaleViewportExt( dc->physDev, xNum, xDenom, yNum, yDenom )) != TRUE)
441         {
442             if(ret == GDI_NO_MORE_WORK)
443                 ret = TRUE;
444             goto done;
445         }
446     }
447     if (size)
448     {
449         size->cx = dc->vportExtX;
450         size->cy = dc->vportExtY;
451     }
452     if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
453         goto done;
454     if (!xNum || !xDenom || !xNum || !yDenom)
455     {
456         ret = FALSE;
457         goto done;
458     }
459     dc->vportExtX = (dc->vportExtX * xNum) / xDenom;
460     dc->vportExtY = (dc->vportExtY * yNum) / yDenom;
461     if (dc->vportExtX == 0) dc->vportExtX = 1;
462     if (dc->vportExtY == 0) dc->vportExtY = 1;
463     if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
464     DC_UpdateXforms( dc );
465  done:
466     GDI_ReleaseObj( hdc );
467     return ret;
468 }
469
470
471 /***********************************************************************
472  *           ScaleWindowExtEx    (GDI32.@)
473  */
474 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
475                                   INT yNum, INT yDenom, LPSIZE size )
476 {
477     INT ret = TRUE;
478     DC * dc = DC_GetDCPtr( hdc );
479     if (!dc) return FALSE;
480     if (dc->funcs->pScaleWindowExt)
481     {
482         if((ret = dc->funcs->pScaleWindowExt( dc->physDev, xNum, xDenom, yNum, yDenom )) != TRUE)
483         {
484             if(ret == GDI_NO_MORE_WORK)
485                 ret = TRUE;
486             goto done;
487         }
488     }
489     if (size)
490     {
491         size->cx = dc->wndExtX;
492         size->cy = dc->wndExtY;
493     }
494     if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
495         goto done;
496     if (!xNum || !xDenom || !xNum || !yDenom)
497     {
498         ret = FALSE;
499         goto done;
500     }
501     dc->wndExtX = (dc->wndExtX * xNum) / xDenom;
502     dc->wndExtY = (dc->wndExtY * yNum) / yDenom;
503     if (dc->wndExtX == 0) dc->wndExtX = 1;
504     if (dc->wndExtY == 0) dc->wndExtY = 1;
505     if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
506     DC_UpdateXforms( dc );
507  done:
508     GDI_ReleaseObj( hdc );
509     return ret;
510 }