wined3d: Get rid of the haveHardwareCursor flag.
[wine] / dlls / wineps.drv / brush.c
1 /*
2  *      PostScript brush handling
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
21 #include "psdrv.h"
22 #include "wine/debug.h"
23 #include "winbase.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
26
27 /***********************************************************************
28  *           SelectBrush   (WINEPS.@)
29  */
30 HBRUSH CDECL PSDRV_SelectBrush( PSDRV_PDEVICE *physDev, HBRUSH hbrush )
31 {
32     LOGBRUSH logbrush;
33
34     if (!GetObjectA( hbrush, sizeof(logbrush), &logbrush )) return 0;
35
36     TRACE("hbrush = %p\n", hbrush);
37
38     if (hbrush == GetStockObject( DC_BRUSH ))
39         logbrush.lbColor = GetDCBrushColor( physDev->hdc );
40
41     switch(logbrush.lbStyle) {
42
43     case BS_SOLID:
44         PSDRV_CreateColor(physDev, &physDev->brush.color, logbrush.lbColor);
45         break;
46
47     case BS_NULL:
48         break;
49
50     case BS_HATCHED:
51         PSDRV_CreateColor(physDev, &physDev->brush.color, logbrush.lbColor);
52         break;
53
54     case BS_PATTERN:
55     case BS_DIBPATTERN:
56         break;
57
58     default:
59         FIXME("Unrecognized brush style %d\n", logbrush.lbStyle);
60         break;
61     }
62
63     physDev->brush.set = FALSE;
64     return hbrush;
65 }
66
67
68 /***********************************************************************
69  *           SetDCBrushColor (WINEPS.@)
70  */
71 COLORREF CDECL PSDRV_SetDCBrushColor( PSDRV_PDEVICE *physDev, COLORREF color )
72 {
73     if (GetCurrentObject( physDev->hdc, OBJ_BRUSH ) == GetStockObject( DC_BRUSH ))
74     {
75         PSDRV_CreateColor( physDev, &physDev->brush.color, color );
76         physDev->brush.set = FALSE;
77     }
78     return color;
79 }
80
81
82 /**********************************************************************
83  *
84  *      PSDRV_SetBrush
85  *
86  */
87 static BOOL PSDRV_SetBrush(PSDRV_PDEVICE *physDev)
88 {
89     LOGBRUSH logbrush;
90     BOOL ret = TRUE;
91
92     if (!GetObjectA( GetCurrentObject(physDev->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush ))
93     {
94         ERR("Can't get BRUSHOBJ\n");
95         return FALSE;
96     }
97
98     switch (logbrush.lbStyle) {
99     case BS_SOLID:
100     case BS_HATCHED:
101         PSDRV_WriteSetColor(physDev, &physDev->brush.color);
102         break;
103
104     case BS_NULL:
105         break;
106
107     default:
108         ret = FALSE;
109         break;
110
111     }
112     physDev->brush.set = TRUE;
113     return ret;
114 }
115
116
117 /**********************************************************************
118  *
119  *      PSDRV_Fill
120  *
121  */
122 static BOOL PSDRV_Fill(PSDRV_PDEVICE *physDev, BOOL EO)
123 {
124     if(!EO)
125         return PSDRV_WriteFill(physDev);
126     else
127         return PSDRV_WriteEOFill(physDev);
128 }
129
130
131 /**********************************************************************
132  *
133  *      PSDRV_Clip
134  *
135  */
136 static BOOL PSDRV_Clip(PSDRV_PDEVICE *physDev, BOOL EO)
137 {
138     if(!EO)
139         return PSDRV_WriteClip(physDev);
140     else
141         return PSDRV_WriteEOClip(physDev);
142 }
143
144 /**********************************************************************
145  *
146  *      PSDRV_Brush
147  *
148  */
149 BOOL PSDRV_Brush(PSDRV_PDEVICE *physDev, BOOL EO)
150 {
151     LOGBRUSH logbrush;
152     BOOL ret = TRUE;
153
154     if(physDev->pathdepth)
155         return FALSE;
156
157     if (!GetObjectA( GetCurrentObject(physDev->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush ))
158     {
159         ERR("Can't get BRUSHOBJ\n");
160         return FALSE;
161     }
162
163     switch (logbrush.lbStyle) {
164     case BS_SOLID:
165         PSDRV_WriteGSave(physDev);
166         PSDRV_SetBrush(physDev);
167         PSDRV_Fill(physDev, EO);
168         PSDRV_WriteGRestore(physDev);
169         break;
170
171     case BS_HATCHED:
172         PSDRV_WriteGSave(physDev);
173         PSDRV_SetBrush(physDev);
174
175         switch(logbrush.lbHatch) {
176         case HS_VERTICAL:
177         case HS_CROSS:
178             PSDRV_WriteGSave(physDev);
179             PSDRV_Clip(physDev, EO);
180             PSDRV_WriteHatch(physDev);
181             PSDRV_WriteStroke(physDev);
182             PSDRV_WriteGRestore(physDev);
183             if(logbrush.lbHatch == HS_VERTICAL)
184                 break;
185             /* else fallthrough for HS_CROSS */
186
187         case HS_HORIZONTAL:
188             PSDRV_WriteGSave(physDev);
189             PSDRV_Clip(physDev, EO);
190             PSDRV_WriteRotate(physDev, 90.0);
191             PSDRV_WriteHatch(physDev);
192             PSDRV_WriteStroke(physDev);
193             PSDRV_WriteGRestore(physDev);
194             break;
195
196         case HS_FDIAGONAL:
197         case HS_DIAGCROSS:
198             PSDRV_WriteGSave(physDev);
199             PSDRV_Clip(physDev, EO);
200             PSDRV_WriteRotate(physDev, -45.0);
201             PSDRV_WriteHatch(physDev);
202             PSDRV_WriteStroke(physDev);
203             PSDRV_WriteGRestore(physDev);
204             if(logbrush.lbHatch == HS_FDIAGONAL)
205                 break;
206             /* else fallthrough for HS_DIAGCROSS */
207
208         case HS_BDIAGONAL:
209             PSDRV_WriteGSave(physDev);
210             PSDRV_Clip(physDev, EO);
211             PSDRV_WriteRotate(physDev, 45.0);
212             PSDRV_WriteHatch(physDev);
213             PSDRV_WriteStroke(physDev);
214             PSDRV_WriteGRestore(physDev);
215             break;
216
217         default:
218             ERR("Unknown hatch style\n");
219             ret = FALSE;
220             break;
221         }
222         PSDRV_WriteGRestore(physDev);
223         break;
224
225     case BS_NULL:
226         break;
227
228     case BS_PATTERN:
229         {
230             BITMAP bm;
231             BYTE *bits;
232             GetObjectA( (HBITMAP)logbrush.lbHatch, sizeof(BITMAP), &bm);
233             TRACE("BS_PATTERN %dx%d %d bpp\n", bm.bmWidth, bm.bmHeight,
234                   bm.bmBitsPixel);
235             bits = HeapAlloc(PSDRV_Heap, 0, bm.bmWidthBytes * bm.bmHeight);
236             GetBitmapBits( (HBITMAP)logbrush.lbHatch, bm.bmWidthBytes * bm.bmHeight, bits);
237
238             if(physDev->pi->ppd->LanguageLevel > 1) {
239                 PSDRV_WriteGSave(physDev);
240                 PSDRV_WritePatternDict(physDev, &bm, bits);
241                 PSDRV_Fill(physDev, EO);
242                 PSDRV_WriteGRestore(physDev);
243             } else {
244                 FIXME("Trying to set a pattern brush on a level 1 printer\n");
245                 ret = FALSE;
246             }
247             HeapFree(PSDRV_Heap, 0, bits);
248         }
249         break;
250
251     case BS_DIBPATTERN:
252         {
253             BITMAPINFO *bmi = GlobalLock( (HGLOBAL)logbrush.lbHatch );
254             UINT usage = logbrush.lbColor;
255             TRACE("size %dx%dx%d\n", bmi->bmiHeader.biWidth,
256                   bmi->bmiHeader.biHeight, bmi->bmiHeader.biBitCount);
257             if(physDev->pi->ppd->LanguageLevel > 1) {
258                 PSDRV_WriteGSave(physDev);
259                 ret = PSDRV_WriteDIBPatternDict(physDev, bmi, usage);
260                 PSDRV_Fill(physDev, EO);
261                 PSDRV_WriteGRestore(physDev);
262             } else {
263                 FIXME("Trying to set a pattern brush on a level 1 printer\n");
264                 ret = FALSE;
265             }
266             GlobalUnlock( (HGLOBAL)logbrush.lbHatch );
267         }
268         break;
269
270     default:
271         ret = FALSE;
272         break;
273     }
274     return ret;
275 }