mshtml: Wine Gecko 1.4 release.
[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 PSDRV_SelectBrush( PHYSDEV dev, HBRUSH hbrush, HBITMAP bitmap,
31                           const BITMAPINFO *info, void *bits, UINT usage )
32 {
33     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
34     LOGBRUSH logbrush;
35
36     if (!GetObjectA( hbrush, sizeof(logbrush), &logbrush )) return 0;
37
38     TRACE("hbrush = %p\n", hbrush);
39
40     if (hbrush == GetStockObject( DC_BRUSH ))
41         logbrush.lbColor = GetDCBrushColor( dev->hdc );
42
43     switch(logbrush.lbStyle) {
44
45     case BS_SOLID:
46         PSDRV_CreateColor(dev, &physDev->brush.color, logbrush.lbColor);
47         break;
48
49     case BS_NULL:
50         break;
51
52     case BS_HATCHED:
53         PSDRV_CreateColor(dev, &physDev->brush.color, logbrush.lbColor);
54         break;
55
56     case BS_PATTERN:
57     case BS_DIBPATTERN:
58         physDev->brush.info  = info;
59         physDev->brush.bits  = bits;
60         physDev->brush.usage = usage;
61         break;
62
63     default:
64         FIXME("Unrecognized brush style %d\n", logbrush.lbStyle);
65         break;
66     }
67
68     physDev->brush.set = FALSE;
69     return hbrush;
70 }
71
72
73 /***********************************************************************
74  *           SetDCBrushColor (WINEPS.@)
75  */
76 COLORREF PSDRV_SetDCBrushColor( PHYSDEV dev, COLORREF color )
77 {
78     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
79
80     if (GetCurrentObject( dev->hdc, OBJ_BRUSH ) == GetStockObject( DC_BRUSH ))
81     {
82         PSDRV_CreateColor( dev, &physDev->brush.color, color );
83         physDev->brush.set = FALSE;
84     }
85     return color;
86 }
87
88
89 /**********************************************************************
90  *
91  *      PSDRV_SetBrush
92  *
93  */
94 static BOOL PSDRV_SetBrush( PHYSDEV dev )
95 {
96     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
97     LOGBRUSH logbrush;
98     BOOL ret = TRUE;
99
100     if (!GetObjectA( GetCurrentObject(dev->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush ))
101     {
102         ERR("Can't get BRUSHOBJ\n");
103         return FALSE;
104     }
105
106     switch (logbrush.lbStyle) {
107     case BS_SOLID:
108     case BS_HATCHED:
109         PSDRV_WriteSetColor(dev, &physDev->brush.color);
110         break;
111
112     case BS_NULL:
113         break;
114
115     default:
116         ret = FALSE;
117         break;
118
119     }
120     physDev->brush.set = TRUE;
121     return ret;
122 }
123
124
125 /**********************************************************************
126  *
127  *      PSDRV_Fill
128  *
129  */
130 static BOOL PSDRV_Fill(PHYSDEV dev, BOOL EO)
131 {
132     if(!EO)
133         return PSDRV_WriteFill(dev);
134     else
135         return PSDRV_WriteEOFill(dev);
136 }
137
138
139 /**********************************************************************
140  *
141  *      PSDRV_Clip
142  *
143  */
144 static BOOL PSDRV_Clip(PHYSDEV dev, BOOL EO)
145 {
146     if(!EO)
147         return PSDRV_WriteClip(dev);
148     else
149         return PSDRV_WriteEOClip(dev);
150 }
151
152 /**********************************************************************
153  *
154  *      PSDRV_Brush
155  *
156  */
157 BOOL PSDRV_Brush(PHYSDEV dev, BOOL EO)
158 {
159     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
160     LOGBRUSH logbrush;
161     BOOL ret = TRUE;
162
163     if(physDev->pathdepth)
164         return FALSE;
165
166     if (!GetObjectA( GetCurrentObject(dev->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush ))
167     {
168         ERR("Can't get BRUSHOBJ\n");
169         return FALSE;
170     }
171
172     switch (logbrush.lbStyle) {
173     case BS_SOLID:
174         PSDRV_WriteGSave(dev);
175         PSDRV_SetBrush(dev);
176         PSDRV_Fill(dev, EO);
177         PSDRV_WriteGRestore(dev);
178         break;
179
180     case BS_HATCHED:
181         PSDRV_WriteGSave(dev);
182         PSDRV_SetBrush(dev);
183
184         switch(logbrush.lbHatch) {
185         case HS_VERTICAL:
186         case HS_CROSS:
187             PSDRV_WriteGSave(dev);
188             PSDRV_Clip(dev, EO);
189             PSDRV_WriteHatch(dev);
190             PSDRV_WriteStroke(dev);
191             PSDRV_WriteGRestore(dev);
192             if(logbrush.lbHatch == HS_VERTICAL)
193                 break;
194             /* else fallthrough for HS_CROSS */
195
196         case HS_HORIZONTAL:
197             PSDRV_WriteGSave(dev);
198             PSDRV_Clip(dev, EO);
199             PSDRV_WriteRotate(dev, 90.0);
200             PSDRV_WriteHatch(dev);
201             PSDRV_WriteStroke(dev);
202             PSDRV_WriteGRestore(dev);
203             break;
204
205         case HS_FDIAGONAL:
206         case HS_DIAGCROSS:
207             PSDRV_WriteGSave(dev);
208             PSDRV_Clip(dev, EO);
209             PSDRV_WriteRotate(dev, -45.0);
210             PSDRV_WriteHatch(dev);
211             PSDRV_WriteStroke(dev);
212             PSDRV_WriteGRestore(dev);
213             if(logbrush.lbHatch == HS_FDIAGONAL)
214                 break;
215             /* else fallthrough for HS_DIAGCROSS */
216
217         case HS_BDIAGONAL:
218             PSDRV_WriteGSave(dev);
219             PSDRV_Clip(dev, EO);
220             PSDRV_WriteRotate(dev, 45.0);
221             PSDRV_WriteHatch(dev);
222             PSDRV_WriteStroke(dev);
223             PSDRV_WriteGRestore(dev);
224             break;
225
226         default:
227             ERR("Unknown hatch style\n");
228             ret = FALSE;
229             break;
230         }
231         PSDRV_WriteGRestore(dev);
232         break;
233
234     case BS_NULL:
235         break;
236
237     case BS_PATTERN:
238     case BS_DIBPATTERN:
239         if(physDev->pi->ppd->LanguageLevel > 1) {
240             PSDRV_WriteGSave(dev);
241             ret = PSDRV_WriteDIBPatternDict(dev, physDev->brush.info,
242                                             physDev->brush.bits, physDev->brush.usage );
243             PSDRV_Fill(dev, EO);
244             PSDRV_WriteGRestore(dev);
245         } else {
246             FIXME("Trying to set a pattern brush on a level 1 printer\n");
247             ret = FALSE;
248         }
249         break;
250
251     default:
252         ret = FALSE;
253         break;
254     }
255     return ret;
256 }