Use hard-coded font name bindings only with the ANSI_CHARSET (non-US
[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 "wine/debug.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
25
26
27 /***********************************************************************
28  *           MAPPING_FixIsotropic
29  *
30  * Fix viewport extensions for isotropic mode.
31  */
32 void MAPPING_FixIsotropic( DC * dc )
33 {
34     double xdim = (double)dc->vportExtX * GetDeviceCaps( dc->hSelf, HORZSIZE ) /
35                   (GetDeviceCaps( dc->hSelf, HORZRES ) * dc->wndExtX);
36     double ydim = (double)dc->vportExtY * GetDeviceCaps( dc->hSelf, VERTSIZE ) /
37                   (GetDeviceCaps( dc->hSelf, VERTRES ) * dc->wndExtY);
38     if (xdim > ydim)
39     {
40         dc->vportExtX = dc->vportExtX * fabs( ydim / xdim );
41         if (!dc->vportExtX) dc->vportExtX = 1;
42     }
43     else
44     {
45         dc->vportExtY = dc->vportExtY * fabs( xdim / ydim );
46         if (!dc->vportExtY) dc->vportExtY = 1;
47     }
48 }
49
50
51 /***********************************************************************
52  *           DPtoLP    (GDI.67)
53  */
54 BOOL16 WINAPI DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
55 {
56     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
57     if (!dc) return FALSE;
58
59     while (count--)
60     {
61         points->x = XDPTOLP( dc, points->x );
62         points->y = YDPTOLP( dc, points->y );
63         points++;
64     }
65     GDI_ReleaseObj( hdc );
66     return TRUE;
67 }
68
69
70 /***********************************************************************
71  *           DPtoLP    (GDI32.@)
72  */
73 BOOL WINAPI DPtoLP( HDC hdc, LPPOINT points, INT count )
74 {
75     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
76     if (!dc) return FALSE;
77
78     while (count--)
79     {
80         if (!INTERNAL_DPTOLP( dc, points ))
81             break;
82         points++;
83     }
84     GDI_ReleaseObj( hdc );
85     return (count < 0);
86 }
87
88
89 /***********************************************************************
90  *           LPtoDP    (GDI.99)
91  */
92 BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
93 {
94     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
95     if (!dc) return FALSE;
96
97     while (count--)
98     {
99         points->x = XLPTODP( dc, points->x );
100         points->y = YLPTODP( dc, points->y );
101         points++;
102     }
103     GDI_ReleaseObj( hdc );
104     return TRUE;
105 }
106
107
108 /***********************************************************************
109  *           LPtoDP    (GDI32.@)
110  */
111 BOOL WINAPI LPtoDP( HDC hdc, LPPOINT points, INT count )
112 {
113     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
114     if (!dc) return FALSE;
115
116     while (count--)
117     {
118         INTERNAL_LPTODP( dc, points );
119         points++;
120     }
121     GDI_ReleaseObj( hdc );
122     return TRUE;
123 }
124
125
126 /***********************************************************************
127  *           SetMapMode    (GDI.3)
128  */
129 INT16 WINAPI SetMapMode16( HDC16 hdc, INT16 mode )
130 {
131     return SetMapMode( hdc, mode );
132 }
133
134
135 /***********************************************************************
136  *           SetMapMode    (GDI32.@)
137  */
138 INT WINAPI SetMapMode( HDC hdc, INT mode )
139 {
140     INT prevMode;
141     INT horzSize, vertSize, horzRes, vertRes;
142
143     DC * dc = DC_GetDCPtr( hdc );
144     if (!dc) return 0;
145     if (dc->funcs->pSetMapMode)
146     {
147         prevMode = dc->funcs->pSetMapMode( dc->physDev, mode );
148         goto done;
149     }
150
151     TRACE("%04x %d\n", hdc, mode );
152
153     prevMode = dc->MapMode;
154     horzSize = GetDeviceCaps( hdc, HORZSIZE );
155     vertSize = GetDeviceCaps( hdc, VERTSIZE );
156     horzRes  = GetDeviceCaps( hdc, HORZRES );
157     vertRes  = GetDeviceCaps( hdc, VERTRES );
158     switch(mode)
159     {
160     case MM_TEXT:
161         dc->wndExtX   = 1;
162         dc->wndExtY   = 1;
163         dc->vportExtX = 1;
164         dc->vportExtY = 1;
165         break;
166     case MM_LOMETRIC:
167     case MM_ISOTROPIC:
168         dc->wndExtX   = horzSize;
169         dc->wndExtY   = vertSize;
170         dc->vportExtX = horzRes / 10;
171         dc->vportExtY = vertRes / -10;
172         break;
173     case MM_HIMETRIC:
174         dc->wndExtX   = horzSize * 10;
175         dc->wndExtY   = vertSize * 10;
176         dc->vportExtX = horzRes / 10;
177         dc->vportExtY = vertRes / -10;
178         break;
179     case MM_LOENGLISH:
180         dc->wndExtX   = horzSize;
181         dc->wndExtY   = vertSize;
182         dc->vportExtX = 254L * horzRes / 1000;
183         dc->vportExtY = -254L * vertRes / 1000;
184         break;
185     case MM_HIENGLISH:
186         dc->wndExtX   = horzSize * 10;
187         dc->wndExtY   = vertSize * 10;
188         dc->vportExtX = 254L * horzRes / 1000;
189         dc->vportExtY = -254L * vertRes / 1000;
190         break;
191     case MM_TWIPS:
192         dc->wndExtX   = 144L * horzSize / 10;
193         dc->wndExtY   = 144L * vertSize / 10;
194         dc->vportExtX = 254L * horzRes / 1000;
195         dc->vportExtY = -254L * vertRes / 1000;
196         break;
197     case MM_ANISOTROPIC:
198         break;
199     default:
200         goto done;
201     }
202     dc->MapMode = mode;
203     DC_UpdateXforms( dc );
204  done:
205     GDI_ReleaseObj( hdc );
206     return prevMode;
207 }
208
209
210 /***********************************************************************
211  *           SetViewportExt    (GDI.14)
212  */
213 DWORD WINAPI SetViewportExt16( HDC16 hdc, INT16 x, INT16 y )
214 {
215     SIZE size;
216     if (!SetViewportExtEx( hdc, x, y, &size )) return 0;
217     return MAKELONG( size.cx, size.cy );
218 }
219
220
221 /***********************************************************************
222  *           SetViewportExtEx    (GDI.479)
223  */
224 BOOL16 WINAPI SetViewportExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
225 {
226     SIZE size32;
227     BOOL16 ret = SetViewportExtEx( hdc, x, y, &size32 );
228     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
229     return ret;
230 }
231
232
233 /***********************************************************************
234  *           SetViewportExtEx    (GDI32.@)
235  */
236 BOOL WINAPI SetViewportExtEx( HDC hdc, INT x, INT y, LPSIZE size )
237 {
238     BOOL ret = TRUE;
239     DC * dc = DC_GetDCPtr( hdc );
240     if (!dc) return FALSE;
241     if (dc->funcs->pSetViewportExt)
242     {
243         ret = dc->funcs->pSetViewportExt( dc->physDev, x, y );
244         goto done;
245     }
246     if (size)
247     {
248         size->cx = dc->vportExtX;
249         size->cy = dc->vportExtY;
250     }
251     if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
252         goto done;
253     if (!x || !y)
254     {
255         ret = FALSE;
256         goto done;
257     }
258     dc->vportExtX = x;
259     dc->vportExtY = y;
260     if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
261     DC_UpdateXforms( dc );
262  done:
263     GDI_ReleaseObj( hdc );
264     return ret;
265 }
266
267
268 /***********************************************************************
269  *           SetViewportOrg    (GDI.13)
270  */
271 DWORD WINAPI SetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
272 {
273     POINT pt;
274     if (!SetViewportOrgEx( hdc, x, y, &pt )) return 0;
275     return MAKELONG( pt.x, pt.y );
276 }
277
278
279 /***********************************************************************
280  *           SetViewportOrgEx    (GDI.480)
281  */
282 BOOL16 WINAPI SetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
283 {
284     POINT pt32;
285     BOOL16 ret = SetViewportOrgEx( hdc, x, y, &pt32 );
286     if (pt) CONV_POINT32TO16( &pt32, pt );
287     return ret;
288 }
289
290
291 /***********************************************************************
292  *           SetViewportOrgEx    (GDI32.@)
293  */
294 BOOL WINAPI SetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
295 {
296     BOOL ret = TRUE;
297     DC * dc = DC_GetDCPtr( hdc );
298     if (!dc) return FALSE;
299     if (dc->funcs->pSetViewportOrg)
300         ret = dc->funcs->pSetViewportOrg( dc->physDev, x, y );
301     else
302     {
303         if (pt)
304         {
305             pt->x = dc->vportOrgX;
306             pt->y = dc->vportOrgY;
307         }
308         dc->vportOrgX = x;
309         dc->vportOrgY = y;
310         DC_UpdateXforms( dc );
311     }
312     GDI_ReleaseObj( hdc );
313     return ret;
314 }
315
316
317 /***********************************************************************
318  *           SetWindowExt    (GDI.12)
319  */
320 DWORD WINAPI SetWindowExt16( HDC16 hdc, INT16 x, INT16 y )
321 {
322     SIZE size;
323     if (!SetWindowExtEx( hdc, x, y, &size )) return 0;
324     return MAKELONG( size.cx, size.cy );
325 }
326
327
328 /***********************************************************************
329  *           SetWindowExtEx    (GDI.481)
330  */
331 BOOL16 WINAPI SetWindowExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
332 {
333     SIZE size32;
334     BOOL16 ret = SetWindowExtEx( hdc, x, y, &size32 );
335     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
336     return ret;
337 }
338
339
340 /***********************************************************************
341  *           SetWindowExtEx    (GDI32.@)
342  */
343 BOOL WINAPI SetWindowExtEx( HDC hdc, INT x, INT y, LPSIZE size )
344 {
345     BOOL ret = TRUE;
346     DC * dc = DC_GetDCPtr( hdc );
347     if (!dc) return FALSE;
348     if (dc->funcs->pSetWindowExt)
349     {
350         ret = dc->funcs->pSetWindowExt( dc->physDev, x, y );
351         goto done;
352     }
353     if (size)
354     {
355         size->cx = dc->wndExtX;
356         size->cy = dc->wndExtY;
357     }
358     if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
359         goto done;
360     if (!x || !y)
361     {
362         ret = FALSE;
363         goto done;
364     }
365     dc->wndExtX = x;
366     dc->wndExtY = y;
367     if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
368     DC_UpdateXforms( dc );
369  done:
370     GDI_ReleaseObj( hdc );
371     return ret;
372 }
373
374
375 /***********************************************************************
376  *           SetWindowOrg    (GDI.11)
377  */
378 DWORD WINAPI SetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
379 {
380     POINT pt;
381     if (!SetWindowOrgEx( hdc, x, y, &pt )) return 0;
382     return MAKELONG( pt.x, pt.y );
383 }
384
385
386 /***********************************************************************
387  *           SetWindowOrgEx    (GDI.482)
388  */
389 BOOL16 WINAPI SetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
390 {
391     POINT pt32;
392     BOOL16 ret = SetWindowOrgEx( hdc, x, y, &pt32 );
393     if (pt) CONV_POINT32TO16( &pt32, pt );
394     return ret;
395 }
396
397
398 /***********************************************************************
399  *           SetWindowOrgEx    (GDI32.@)
400  */
401 BOOL WINAPI SetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
402 {
403     BOOL ret = TRUE;
404     DC * dc = DC_GetDCPtr( hdc );
405     if (!dc) return FALSE;
406     if (dc->funcs->pSetWindowOrg) ret = dc->funcs->pSetWindowOrg( dc->physDev, x, y );
407     else
408     {
409         if (pt)
410         {
411             pt->x = dc->wndOrgX;
412             pt->y = dc->wndOrgY;
413         }
414         dc->wndOrgX = x;
415         dc->wndOrgY = y;
416         DC_UpdateXforms( dc );
417     }
418     GDI_ReleaseObj( hdc );
419     return ret;
420 }
421
422
423 /***********************************************************************
424  *           OffsetViewportOrg    (GDI.17)
425  */
426 DWORD WINAPI OffsetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
427 {
428     POINT pt;
429     if (!OffsetViewportOrgEx( hdc, x, y, &pt )) return 0;
430     return MAKELONG( pt.x, pt.y );
431 }
432
433
434 /***********************************************************************
435  *           OffsetViewportOrgEx    (GDI.476)
436  */
437 BOOL16 WINAPI OffsetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt)
438 {
439     POINT pt32;
440     BOOL16 ret = OffsetViewportOrgEx( hdc, x, y, &pt32 );
441     if (pt) CONV_POINT32TO16( &pt32, pt );
442     return ret;
443 }
444
445
446 /***********************************************************************
447  *           OffsetViewportOrgEx    (GDI32.@)
448  */
449 BOOL WINAPI OffsetViewportOrgEx( HDC hdc, INT x, INT y, LPPOINT pt)
450 {
451     BOOL ret = TRUE;
452     DC * dc = DC_GetDCPtr( hdc );
453     if (!dc) return FALSE;
454     if (dc->funcs->pOffsetViewportOrg)
455         ret = dc->funcs->pOffsetViewportOrg( dc->physDev, x, y );
456     else
457     {
458         if (pt)
459         {
460             pt->x = dc->vportOrgX;
461             pt->y = dc->vportOrgY;
462         }
463         dc->vportOrgX += x;
464         dc->vportOrgY += y;
465         DC_UpdateXforms( dc );
466     }
467     GDI_ReleaseObj( hdc );
468     return ret;
469 }
470
471
472 /***********************************************************************
473  *           OffsetWindowOrg    (GDI.15)
474  */
475 DWORD WINAPI OffsetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
476 {
477     POINT pt;
478     if (!OffsetWindowOrgEx( hdc, x, y, &pt )) return 0;
479     return MAKELONG( pt.x, pt.y );
480 }
481
482
483 /***********************************************************************
484  *           OffsetWindowOrgEx    (GDI.477)
485  */
486 BOOL16 WINAPI OffsetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
487 {
488     POINT pt32;
489     BOOL16 ret = OffsetWindowOrgEx( hdc, x, y, &pt32 );
490     if (pt) CONV_POINT32TO16( &pt32, pt );
491     return ret;
492 }
493
494
495 /***********************************************************************
496  *           OffsetWindowOrgEx    (GDI32.@)
497  */
498 BOOL WINAPI OffsetWindowOrgEx( HDC hdc, INT x, INT y, LPPOINT pt )
499 {
500     BOOL ret = TRUE;
501     DC * dc = DC_GetDCPtr( hdc );
502     if (!dc) return FALSE;
503     if (dc->funcs->pOffsetWindowOrg)
504         ret = dc->funcs->pOffsetWindowOrg( dc->physDev, x, y );
505     else
506     {
507         if (pt)
508         {
509             pt->x = dc->wndOrgX;
510             pt->y = dc->wndOrgY;
511         }
512         dc->wndOrgX += x;
513         dc->wndOrgY += y;
514         DC_UpdateXforms( dc );
515     }
516     GDI_ReleaseObj( hdc );
517     return ret;
518 }
519
520
521 /***********************************************************************
522  *           ScaleViewportExt    (GDI.18)
523  */
524 DWORD WINAPI ScaleViewportExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
525                                INT16 yNum, INT16 yDenom )
526 {
527     SIZE size;
528     if (!ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
529         return FALSE;
530     return MAKELONG( size.cx,  size.cy );
531 }
532
533
534 /***********************************************************************
535  *           ScaleViewportExtEx    (GDI.484)
536  */
537 BOOL16 WINAPI ScaleViewportExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
538                                     INT16 yNum, INT16 yDenom, LPSIZE16 size )
539 {
540     SIZE size32;
541     BOOL16 ret = ScaleViewportExtEx( hdc, xNum, xDenom, yNum, yDenom,
542                                        &size32 );
543     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
544     return ret;
545 }
546
547
548 /***********************************************************************
549  *           ScaleViewportExtEx    (GDI32.@)
550  */
551 BOOL WINAPI ScaleViewportExtEx( HDC hdc, INT xNum, INT xDenom,
552                                     INT yNum, INT yDenom, LPSIZE size )
553 {
554     BOOL ret = TRUE;
555     DC * dc = DC_GetDCPtr( hdc );
556     if (!dc) return FALSE;
557     if (dc->funcs->pScaleViewportExt)
558     {
559         ret = dc->funcs->pScaleViewportExt( dc->physDev, xNum, xDenom, yNum, yDenom );
560         goto done;
561     }
562     if (size)
563     {
564         size->cx = dc->vportExtX;
565         size->cy = dc->vportExtY;
566     }
567     if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
568         goto done;
569     if (!xNum || !xDenom || !xNum || !yDenom)
570     {
571         ret = FALSE;
572         goto done;
573     }
574     dc->vportExtX = (dc->vportExtX * xNum) / xDenom;
575     dc->vportExtY = (dc->vportExtY * yNum) / yDenom;
576     if (dc->vportExtX == 0) dc->vportExtX = 1;
577     if (dc->vportExtY == 0) dc->vportExtY = 1;
578     if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
579     DC_UpdateXforms( dc );
580  done:
581     GDI_ReleaseObj( hdc );
582     return ret;
583 }
584
585
586 /***********************************************************************
587  *           ScaleWindowExt    (GDI.16)
588  */
589 DWORD WINAPI ScaleWindowExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
590                              INT16 yNum, INT16 yDenom )
591 {
592     SIZE size;
593     if (!ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom, &size ))
594         return FALSE;
595     return MAKELONG( size.cx,  size.cy );
596 }
597
598
599 /***********************************************************************
600  *           ScaleWindowExtEx    (GDI.485)
601  */
602 BOOL16 WINAPI ScaleWindowExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
603                                   INT16 yNum, INT16 yDenom, LPSIZE16 size )
604 {
605     SIZE size32;
606     BOOL16 ret = ScaleWindowExtEx( hdc, xNum, xDenom, yNum, yDenom,
607                                      &size32 );
608     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
609     return ret;
610 }
611
612
613 /***********************************************************************
614  *           ScaleWindowExtEx    (GDI32.@)
615  */
616 BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT xNum, INT xDenom,
617                                   INT yNum, INT yDenom, LPSIZE size )
618 {
619     BOOL ret = TRUE;
620     DC * dc = DC_GetDCPtr( hdc );
621     if (!dc) return FALSE;
622     if (dc->funcs->pScaleWindowExt)
623     {
624         ret = dc->funcs->pScaleWindowExt( dc->physDev, xNum, xDenom, yNum, yDenom );
625         goto done;
626     }
627     if (size)
628     {
629         size->cx = dc->wndExtX;
630         size->cy = dc->wndExtY;
631     }
632     if ((dc->MapMode != MM_ISOTROPIC) && (dc->MapMode != MM_ANISOTROPIC))
633         goto done;
634     if (!xNum || !xDenom || !xNum || !yDenom)
635     {
636         ret = FALSE;
637         goto done;
638     }
639     dc->wndExtX = (dc->wndExtX * xNum) / xDenom;
640     dc->wndExtY = (dc->wndExtY * yNum) / yDenom;
641     if (dc->wndExtX == 0) dc->wndExtX = 1;
642     if (dc->wndExtY == 0) dc->wndExtY = 1;
643     if (dc->MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
644     DC_UpdateXforms( dc );
645  done:
646     GDI_ReleaseObj( hdc );
647     return ret;
648 }