Update shell xxxAW wrapper prototypes for fixed SHLWAPI functions.
[wine] / dlls / wineps / 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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  *           PSDRV_BRUSH_SelectObject
29  */
30 HBRUSH PSDRV_BRUSH_SelectObject( DC * dc, HBRUSH hbrush )
31 {
32     LOGBRUSH logbrush;
33     HBRUSH prevbrush = dc->hBrush;
34     PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
35
36     if (!GetObjectA( hbrush, sizeof(logbrush), &logbrush )) return 0;
37
38     TRACE("hbrush = %08x\n", hbrush);
39     dc->hBrush = hbrush;
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         FIXME("Unsupported brush style %d\n", logbrush.lbStyle);
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 prevbrush;
65 }
66
67
68 /**********************************************************************
69  *
70  *      PSDRV_SetBrush
71  *
72  */
73 static BOOL PSDRV_SetBrush(DC *dc)
74 {
75     LOGBRUSH logbrush;
76     BOOL ret = TRUE;
77     PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
78
79     if (!GetObjectA( dc->hBrush, sizeof(logbrush), &logbrush ))
80     {
81         ERR("Can't get BRUSHOBJ\n");
82         return FALSE;
83     }
84
85     switch (logbrush.lbStyle) {
86     case BS_SOLID:
87     case BS_HATCHED:
88         PSDRV_WriteSetColor(dc, &physDev->brush.color);
89         break;
90
91     case BS_NULL:
92         break;
93
94     default:
95         ret = FALSE;
96         break;
97
98     }
99     physDev->brush.set = TRUE;
100     return TRUE;
101 }
102
103
104 /**********************************************************************
105  *
106  *      PSDRV_Fill
107  *
108  */
109 static BOOL PSDRV_Fill(DC *dc, BOOL EO)
110 {
111     if(!EO)
112         return PSDRV_WriteFill(dc);
113     else
114       return PSDRV_WriteEOFill(dc);
115 }
116
117
118 /**********************************************************************
119  *
120  *      PSDRV_Clip
121  *
122  */
123 static BOOL PSDRV_Clip(DC *dc, BOOL EO)
124 {
125     if(!EO)
126         return PSDRV_WriteClip(dc);
127     else
128         return PSDRV_WriteEOClip(dc);
129 }
130
131 /**********************************************************************
132  *
133  *      PSDRV_Brush
134  *
135  */
136 BOOL PSDRV_Brush(DC *dc, BOOL EO)
137 {
138     LOGBRUSH logbrush;
139     BOOL ret = TRUE;
140     PSDRV_PDEVICE *physDev = dc->physDev;
141
142     if (!GetObjectA( dc->hBrush, sizeof(logbrush), &logbrush ))
143     {
144         ERR("Can't get BRUSHOBJ\n");
145         return FALSE;
146     }
147
148     switch (logbrush.lbStyle) {
149     case BS_SOLID:
150         PSDRV_SetBrush(dc);
151         PSDRV_WriteGSave(dc);
152         PSDRV_Fill(dc, EO);
153         PSDRV_WriteGRestore(dc);
154         break;
155
156     case BS_HATCHED:
157         PSDRV_SetBrush(dc);
158
159         switch(logbrush.lbHatch) {
160         case HS_VERTICAL:
161         case HS_CROSS:
162             PSDRV_WriteGSave(dc);
163             PSDRV_Clip(dc, EO);
164             PSDRV_WriteHatch(dc);
165             PSDRV_WriteStroke(dc);
166             PSDRV_WriteGRestore(dc);
167             if(logbrush.lbHatch == HS_VERTICAL)
168                 break;
169             /* else fallthrough for HS_CROSS */
170
171         case HS_HORIZONTAL:
172             PSDRV_WriteGSave(dc);
173             PSDRV_Clip(dc, EO);
174             PSDRV_WriteRotate(dc, 90.0);
175             PSDRV_WriteHatch(dc);
176             PSDRV_WriteStroke(dc);
177             PSDRV_WriteGRestore(dc);
178             break;
179
180         case HS_FDIAGONAL:
181         case HS_DIAGCROSS:
182             PSDRV_WriteGSave(dc);
183             PSDRV_Clip(dc, EO);
184             PSDRV_WriteRotate(dc, -45.0);
185             PSDRV_WriteHatch(dc);
186             PSDRV_WriteStroke(dc);
187             PSDRV_WriteGRestore(dc);
188             if(logbrush.lbHatch == HS_FDIAGONAL)
189                 break;
190             /* else fallthrough for HS_DIAGCROSS */
191             
192         case HS_BDIAGONAL:
193             PSDRV_WriteGSave(dc);
194             PSDRV_Clip(dc, EO);
195             PSDRV_WriteRotate(dc, 45.0);
196             PSDRV_WriteHatch(dc);
197             PSDRV_WriteStroke(dc);
198             PSDRV_WriteGRestore(dc);
199             break;
200
201         default:
202             ERR("Unknown hatch style\n");
203             ret = FALSE;
204             break;
205         }
206         break;
207
208     case BS_NULL:
209         break;
210
211     case BS_PATTERN:
212         {
213             BITMAP bm;
214             BYTE *bits;
215             GetObjectA(logbrush.lbHatch, sizeof(BITMAP), &bm);
216             TRACE("BS_PATTERN %dx%d %d bpp\n", bm.bmWidth, bm.bmHeight,
217                   bm.bmBitsPixel);
218             bits = HeapAlloc(PSDRV_Heap, 0, bm.bmWidthBytes * bm.bmHeight);
219             GetBitmapBits(logbrush.lbHatch, bm.bmWidthBytes * bm.bmHeight, bits);
220
221             if(physDev->pi->ppd->LanguageLevel > 1) {
222                 PSDRV_WriteGSave(dc);
223                 PSDRV_WritePatternDict(dc, &bm, bits);
224                 PSDRV_Fill(dc, EO);
225                 PSDRV_WriteGRestore(dc);
226             } else {
227                 FIXME("Trying to set a pattern brush on a level 1 printer\n");
228                 ret = FALSE;
229             }
230             HeapFree(PSDRV_Heap, 0, bits);      
231         }
232         break;
233
234     default:
235         ret = FALSE;
236         break;
237     }
238     return ret;
239 }
240
241
242
243