wined3d: Move max_ffp_textures to wined3d_d3d_info.
[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(PHYSDEV dev, 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( PHYSDEV dev, INT x, INT y, UINT flags, const RECT *lprect, LPCWSTR str, UINT count,
40                        const INT *lpDx )
41 {
42     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
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     if(physDev->job.id == 0) return FALSE;
51
52     /* write font if not already written */
53     PSDRV_SetFont(dev);
54
55     PSDRV_SetClip(dev);
56
57     /* set clipping and/or draw background */
58     if ((flags & (ETO_CLIPPED | ETO_OPAQUE)) && (lprect != NULL))
59     {
60         PSDRV_WriteGSave(dev);
61         PSDRV_WriteRectangle(dev, 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(dev);
68             PSDRV_WriteSetColor(dev, &physDev->bkColor);
69             PSDRV_WriteFill(dev);
70             PSDRV_WriteGRestore(dev);
71         }
72
73         if (flags & ETO_CLIPPED)
74         {
75             bClipped = TRUE;
76             PSDRV_WriteClip(dev);
77         }
78
79         bResult = PSDRV_Text(dev, x, y, flags, str, count, !(bClipped && bOpaque), lpDx);
80         PSDRV_WriteGRestore(dev);
81     }
82     else
83     {
84         bResult = PSDRV_Text(dev, x, y, flags, str, count, TRUE, lpDx);
85     }
86
87     PSDRV_ResetClip(dev);
88     return bResult;
89 }
90
91 /***********************************************************************
92  *           PSDRV_Text
93  */
94 static BOOL PSDRV_Text(PHYSDEV dev, INT x, INT y, UINT flags, LPCWSTR str,
95                        UINT count, BOOL bDrawBackground, const INT *lpDx)
96 {
97     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
98     WORD *glyphs = NULL;
99
100     if (!count)
101         return TRUE;
102
103     if(physDev->font.fontloc == Download && !(flags & ETO_GLYPH_INDEX))
104     {
105         glyphs = HeapAlloc( GetProcessHeap(), 0, count * sizeof(WORD) );
106         GetGlyphIndicesW( dev->hdc, str, count, glyphs, 0 );
107         str = glyphs;
108     }
109
110     PSDRV_WriteMoveTo(dev, x, y);
111
112     if(!lpDx) {
113         if(physDev->font.fontloc == Download)
114             PSDRV_WriteDownloadGlyphShow(dev, str, count);
115         else
116             PSDRV_WriteBuiltinGlyphShow(dev, str, count);
117     }
118     else {
119         UINT i;
120         POINT offset = {0, 0};
121
122         for(i = 0; i < count-1; i++) {
123             if(physDev->font.fontloc == Download)
124                 PSDRV_WriteDownloadGlyphShow(dev, str + i, 1);
125             else
126                 PSDRV_WriteBuiltinGlyphShow(dev, str + i, 1);
127             if(flags & ETO_PDY)
128             {
129                 offset.x += lpDx[i * 2];
130                 offset.y += lpDx[i * 2 + 1];
131             }
132             else
133                 offset.x += lpDx[i];
134             PSDRV_WriteMoveTo(dev, x + offset.x, y + offset.y);
135         }
136         if(physDev->font.fontloc == Download)
137             PSDRV_WriteDownloadGlyphShow(dev, str + i, 1);
138         else
139             PSDRV_WriteBuiltinGlyphShow(dev, str + i, 1);
140     }
141
142     HeapFree( GetProcessHeap(), 0, glyphs );
143     return TRUE;
144 }