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