ddraw: Add a test for DDSD_ZBUFFERBITDEPTH and DDSD_PIXELFORMAT.
[wine/wine-gecko.git] / dlls / wineps.drv / brush.c
blob1e42c1f5626f8a6004f749bfdbaf5feccf2c57b0
1 /*
2 * PostScript brush handling
4 * Copyright 1998 Huw D M Davies
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.
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.
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
21 #include "psdrv.h"
22 #include "wine/debug.h"
23 #include "winbase.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
27 /***********************************************************************
28 * SelectBrush (WINEPS.@)
30 HBRUSH PSDRV_SelectBrush( PHYSDEV dev, HBRUSH hbrush )
32 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
33 LOGBRUSH logbrush;
35 if (!GetObjectA( hbrush, sizeof(logbrush), &logbrush )) return 0;
37 TRACE("hbrush = %p\n", hbrush);
39 if (hbrush == GetStockObject( DC_BRUSH ))
40 logbrush.lbColor = GetDCBrushColor( dev->hdc );
42 switch(logbrush.lbStyle) {
44 case BS_SOLID:
45 PSDRV_CreateColor(dev, &physDev->brush.color, logbrush.lbColor);
46 break;
48 case BS_NULL:
49 break;
51 case BS_HATCHED:
52 PSDRV_CreateColor(dev, &physDev->brush.color, logbrush.lbColor);
53 break;
55 case BS_PATTERN:
56 case BS_DIBPATTERN:
57 break;
59 default:
60 FIXME("Unrecognized brush style %d\n", logbrush.lbStyle);
61 break;
64 physDev->brush.set = FALSE;
65 return hbrush;
69 /***********************************************************************
70 * SetDCBrushColor (WINEPS.@)
72 COLORREF PSDRV_SetDCBrushColor( PHYSDEV dev, COLORREF color )
74 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
76 if (GetCurrentObject( dev->hdc, OBJ_BRUSH ) == GetStockObject( DC_BRUSH ))
78 PSDRV_CreateColor( dev, &physDev->brush.color, color );
79 physDev->brush.set = FALSE;
81 return color;
85 /**********************************************************************
87 * PSDRV_SetBrush
90 static BOOL PSDRV_SetBrush( PHYSDEV dev )
92 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
93 LOGBRUSH logbrush;
94 BOOL ret = TRUE;
96 if (!GetObjectA( GetCurrentObject(dev->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush ))
98 ERR("Can't get BRUSHOBJ\n");
99 return FALSE;
102 switch (logbrush.lbStyle) {
103 case BS_SOLID:
104 case BS_HATCHED:
105 PSDRV_WriteSetColor(dev, &physDev->brush.color);
106 break;
108 case BS_NULL:
109 break;
111 default:
112 ret = FALSE;
113 break;
116 physDev->brush.set = TRUE;
117 return ret;
121 /**********************************************************************
123 * PSDRV_Fill
126 static BOOL PSDRV_Fill(PHYSDEV dev, BOOL EO)
128 if(!EO)
129 return PSDRV_WriteFill(dev);
130 else
131 return PSDRV_WriteEOFill(dev);
135 /**********************************************************************
137 * PSDRV_Clip
140 static BOOL PSDRV_Clip(PHYSDEV dev, BOOL EO)
142 if(!EO)
143 return PSDRV_WriteClip(dev);
144 else
145 return PSDRV_WriteEOClip(dev);
148 /**********************************************************************
150 * PSDRV_Brush
153 BOOL PSDRV_Brush(PHYSDEV dev, BOOL EO)
155 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
156 LOGBRUSH logbrush;
157 BOOL ret = TRUE;
159 if(physDev->pathdepth)
160 return FALSE;
162 if (!GetObjectA( GetCurrentObject(dev->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush ))
164 ERR("Can't get BRUSHOBJ\n");
165 return FALSE;
168 switch (logbrush.lbStyle) {
169 case BS_SOLID:
170 PSDRV_WriteGSave(dev);
171 PSDRV_SetBrush(dev);
172 PSDRV_Fill(dev, EO);
173 PSDRV_WriteGRestore(dev);
174 break;
176 case BS_HATCHED:
177 PSDRV_WriteGSave(dev);
178 PSDRV_SetBrush(dev);
180 switch(logbrush.lbHatch) {
181 case HS_VERTICAL:
182 case HS_CROSS:
183 PSDRV_WriteGSave(dev);
184 PSDRV_Clip(dev, EO);
185 PSDRV_WriteHatch(dev);
186 PSDRV_WriteStroke(dev);
187 PSDRV_WriteGRestore(dev);
188 if(logbrush.lbHatch == HS_VERTICAL)
189 break;
190 /* else fallthrough for HS_CROSS */
192 case HS_HORIZONTAL:
193 PSDRV_WriteGSave(dev);
194 PSDRV_Clip(dev, EO);
195 PSDRV_WriteRotate(dev, 90.0);
196 PSDRV_WriteHatch(dev);
197 PSDRV_WriteStroke(dev);
198 PSDRV_WriteGRestore(dev);
199 break;
201 case HS_FDIAGONAL:
202 case HS_DIAGCROSS:
203 PSDRV_WriteGSave(dev);
204 PSDRV_Clip(dev, EO);
205 PSDRV_WriteRotate(dev, -45.0);
206 PSDRV_WriteHatch(dev);
207 PSDRV_WriteStroke(dev);
208 PSDRV_WriteGRestore(dev);
209 if(logbrush.lbHatch == HS_FDIAGONAL)
210 break;
211 /* else fallthrough for HS_DIAGCROSS */
213 case HS_BDIAGONAL:
214 PSDRV_WriteGSave(dev);
215 PSDRV_Clip(dev, EO);
216 PSDRV_WriteRotate(dev, 45.0);
217 PSDRV_WriteHatch(dev);
218 PSDRV_WriteStroke(dev);
219 PSDRV_WriteGRestore(dev);
220 break;
222 default:
223 ERR("Unknown hatch style\n");
224 ret = FALSE;
225 break;
227 PSDRV_WriteGRestore(dev);
228 break;
230 case BS_NULL:
231 break;
233 case BS_PATTERN:
235 BITMAP bm;
236 BYTE *bits;
237 GetObjectA( (HBITMAP)logbrush.lbHatch, sizeof(BITMAP), &bm);
238 TRACE("BS_PATTERN %dx%d %d bpp\n", bm.bmWidth, bm.bmHeight,
239 bm.bmBitsPixel);
240 bits = HeapAlloc(PSDRV_Heap, 0, bm.bmWidthBytes * bm.bmHeight);
241 GetBitmapBits( (HBITMAP)logbrush.lbHatch, bm.bmWidthBytes * bm.bmHeight, bits);
243 if(physDev->pi->ppd->LanguageLevel > 1) {
244 PSDRV_WriteGSave(dev);
245 PSDRV_WritePatternDict(dev, &bm, bits);
246 PSDRV_Fill(dev, EO);
247 PSDRV_WriteGRestore(dev);
248 } else {
249 FIXME("Trying to set a pattern brush on a level 1 printer\n");
250 ret = FALSE;
252 HeapFree(PSDRV_Heap, 0, bits);
254 break;
256 case BS_DIBPATTERN:
258 BITMAPINFO *bmi = GlobalLock( (HGLOBAL)logbrush.lbHatch );
259 UINT usage = logbrush.lbColor;
260 TRACE("size %dx%dx%d\n", bmi->bmiHeader.biWidth,
261 bmi->bmiHeader.biHeight, bmi->bmiHeader.biBitCount);
262 if(physDev->pi->ppd->LanguageLevel > 1) {
263 PSDRV_WriteGSave(dev);
264 ret = PSDRV_WriteDIBPatternDict(dev, bmi, usage);
265 PSDRV_Fill(dev, EO);
266 PSDRV_WriteGRestore(dev);
267 } else {
268 FIXME("Trying to set a pattern brush on a level 1 printer\n");
269 ret = FALSE;
271 GlobalUnlock( (HGLOBAL)logbrush.lbHatch );
273 break;
275 default:
276 ret = FALSE;
277 break;
279 return ret;