Consistently use SUBLANG_NEUTRAL for Italian resources.
[wine] / dlls / wineps.drv / text.c
1 /*
2  *      PostScript driver text functions
3  *
4  *      Copyright 1998  Huw D M Davies
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 #include <string.h>
21 #include <stdarg.h>
22 #include <stdlib.h>
23 #include <math.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "psdrv.h"
29 #include "winspool.h"
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
33
34 static BOOL PSDRV_Text(PSDRV_PDEVICE *physDev, INT x, INT y, UINT flags,
35                        LPCWSTR str, UINT count,
36                        BOOL bDrawBackground, const INT *lpDx);
37
38 /***********************************************************************
39  *           PSDRV_ExtTextOut
40  */
41 BOOL PSDRV_ExtTextOut( PSDRV_PDEVICE *physDev, INT x, INT y, UINT flags,
42                        const RECT *lprect, LPCWSTR str, UINT count,
43                        const INT *lpDx )
44 {
45     BOOL bResult = TRUE;
46     BOOL bClipped = FALSE;
47     BOOL bOpaque = FALSE;
48
49     TRACE("(x=%d, y=%d, flags=0x%08x, str=%s, count=%d, lpDx=%p)\n", x, y,
50           flags, debugstr_wn(str, count), count, lpDx);
51
52     /* write font if not already written */
53     PSDRV_SetFont(physDev);
54
55     PSDRV_SetClip(physDev);
56
57     /* set clipping and/or draw background */
58     if ((flags & (ETO_CLIPPED | ETO_OPAQUE)) && (lprect != NULL))
59     {
60         PSDRV_WriteGSave(physDev);
61         PSDRV_WriteRectangle(physDev, lprect->left, lprect->top, lprect->right - lprect->left,
62                              lprect->bottom - lprect->top);
63
64         if (flags & ETO_OPAQUE)
65         {
66             bOpaque = TRUE;
67             PSDRV_WriteGSave(physDev);
68             PSDRV_WriteSetColor(physDev, &physDev->bkColor);
69             PSDRV_WriteFill(physDev);
70             PSDRV_WriteGRestore(physDev);
71         }
72
73         if (flags & ETO_CLIPPED)
74         {
75             bClipped = TRUE;
76             PSDRV_WriteClip(physDev);
77         }
78
79         bResult = PSDRV_Text(physDev, x, y, flags, str, count, !(bClipped && bOpaque), lpDx);
80         PSDRV_WriteGRestore(physDev);
81     }
82     else
83     {
84         bResult = PSDRV_Text(physDev, x, y, flags, str, count, TRUE, lpDx);
85     }
86
87     PSDRV_ResetClip(physDev);
88     return bResult;
89 }
90
91 /***********************************************************************
92  *           PSDRV_Text
93  */
94 static BOOL PSDRV_Text(PSDRV_PDEVICE *physDev, INT x, INT y, UINT flags, LPCWSTR str,
95                        UINT count, BOOL bDrawBackground, const INT *lpDx)
96 {
97     WORD *glyphs = NULL;
98     double cosEsc, sinEsc;
99     LOGFONTW lf;
100
101     if (!count)
102         return TRUE;
103
104     GetObjectW(GetCurrentObject(physDev->hdc, OBJ_FONT), sizeof(lf), &lf);
105     if(lf.lfEscapement != 0) {
106         cosEsc = cos(lf.lfEscapement * M_PI / 1800);
107         sinEsc = sin(lf.lfEscapement * M_PI / 1800);
108     } else {
109         cosEsc = 1;
110         sinEsc = 0;
111     }
112
113     if(physDev->font.fontloc == Download)
114         glyphs = (LPWORD)str;
115
116     PSDRV_WriteMoveTo(physDev, x, y);
117
118     if(!lpDx) {
119         if(physDev->font.fontloc == Download)
120             PSDRV_WriteDownloadGlyphShow(physDev, glyphs, count);
121         else
122             PSDRV_WriteBuiltinGlyphShow(physDev, str, count);
123     }
124     else {
125         UINT i;
126         float dx = 0.0, dy = 0.0;
127         float cos_theta = cos(physDev->font.escapement * M_PI / 1800.0);
128         float sin_theta = sin(physDev->font.escapement * M_PI / 1800.0);
129         for(i = 0; i < count-1; i++) {
130             TRACE("lpDx[%d] = %d\n", i, lpDx[i]);
131             if(physDev->font.fontloc == Download)
132                 PSDRV_WriteDownloadGlyphShow(physDev, glyphs + i, 1);
133             else
134                 PSDRV_WriteBuiltinGlyphShow(physDev, str + i, 1);
135             dx += lpDx[i] * cos_theta;
136             dy -= lpDx[i] * sin_theta;
137             PSDRV_WriteMoveTo(physDev, x + dx, y + dy);
138         }
139         if(physDev->font.fontloc == Download)
140             PSDRV_WriteDownloadGlyphShow(physDev, glyphs + i, 1);
141         else
142             PSDRV_WriteBuiltinGlyphShow(physDev, str + i, 1);
143     }
144
145     return TRUE;
146 }