Corrected operand sizes for the "enter" instruction.
[wine.git] / graphics / psdrv / brush.c
blob4a7b1be17b904322d12ed7e47d449833b0b3aa13
1 /*
2 * PostScript brush handling
4 * Copyright 1998 Huw D M Davies
6 */
8 #include "psdrv.h"
9 #include "brush.h"
10 #include "debugtools.h"
11 #include "gdi.h"
12 #include "winbase.h"
14 DEFAULT_DEBUG_CHANNEL(psdrv)
16 /***********************************************************************
17 * PSDRV_BRUSH_SelectObject
19 HBRUSH PSDRV_BRUSH_SelectObject( DC * dc, HBRUSH hbrush, BRUSHOBJ * brush )
21 HBRUSH prevbrush = dc->w.hBrush;
22 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
24 TRACE("hbrush = %08x\n", hbrush);
25 dc->w.hBrush = hbrush;
27 switch(brush->logbrush.lbStyle) {
29 case BS_SOLID:
30 PSDRV_CreateColor(physDev, &physDev->brush.color,
31 brush->logbrush.lbColor);
32 break;
34 case BS_NULL:
35 break;
37 case BS_HATCHED:
38 PSDRV_CreateColor(physDev, &physDev->brush.color,
39 brush->logbrush.lbColor);
40 break;
42 case BS_PATTERN:
43 FIXME("Unsupported brush style %d\n", brush->logbrush.lbStyle);
44 break;
46 default:
47 FIXME("Unrecognized brush style %d\n", brush->logbrush.lbStyle);
48 break;
51 physDev->brush.set = FALSE;
52 return prevbrush;
56 /**********************************************************************
58 * PSDRV_SetBrush
61 static BOOL PSDRV_SetBrush(DC *dc)
63 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
64 BRUSHOBJ *brush = (BRUSHOBJ *)GDI_GetObjPtr( dc->w.hBrush, BRUSH_MAGIC );
66 if(!brush) {
67 ERR("Can't get BRUSHOBJ\n");
68 return FALSE;
71 switch (brush->logbrush.lbStyle) {
72 case BS_SOLID:
73 case BS_HATCHED:
74 PSDRV_WriteSetColor(dc, &physDev->brush.color);
75 break;
77 case BS_NULL:
78 break;
80 default:
81 return FALSE;
82 break;
85 physDev->brush.set = TRUE;
86 return TRUE;
90 /**********************************************************************
92 * PSDRV_Fill
95 static BOOL PSDRV_Fill(DC *dc, BOOL EO)
97 if(!EO)
98 return PSDRV_WriteFill(dc);
99 else
100 return PSDRV_WriteEOFill(dc);
104 /**********************************************************************
106 * PSDRV_Clip
109 static BOOL PSDRV_Clip(DC *dc, BOOL EO)
111 if(!EO)
112 return PSDRV_WriteClip(dc);
113 else
114 return PSDRV_WriteEOClip(dc);
117 /**********************************************************************
119 * PSDRV_Brush
122 BOOL PSDRV_Brush(DC *dc, BOOL EO)
124 BRUSHOBJ *brush = (BRUSHOBJ *)GDI_GetObjPtr( dc->w.hBrush, BRUSH_MAGIC );
126 if(!brush) {
127 ERR("Can't get BRUSHOBJ\n");
128 return FALSE;
131 switch (brush->logbrush.lbStyle) {
132 case BS_SOLID:
133 PSDRV_SetBrush(dc);
134 PSDRV_WriteGSave(dc);
135 PSDRV_Fill(dc, EO);
136 PSDRV_WriteGRestore(dc);
137 return TRUE;
138 break;
140 case BS_HATCHED:
141 PSDRV_SetBrush(dc);
143 switch(brush->logbrush.lbHatch) {
144 case HS_VERTICAL:
145 case HS_CROSS:
146 PSDRV_WriteGSave(dc);
147 PSDRV_Clip(dc, EO);
148 PSDRV_WriteHatch(dc);
149 PSDRV_WriteStroke(dc);
150 PSDRV_WriteGRestore(dc);
151 if(brush->logbrush.lbHatch == HS_VERTICAL)
152 break;
153 /* else fallthrough for HS_CROSS */
155 case HS_HORIZONTAL:
156 PSDRV_WriteGSave(dc);
157 PSDRV_Clip(dc, EO);
158 PSDRV_WriteRotate(dc, 90.0);
159 PSDRV_WriteHatch(dc);
160 PSDRV_WriteStroke(dc);
161 PSDRV_WriteGRestore(dc);
162 break;
164 case HS_FDIAGONAL:
165 case HS_DIAGCROSS:
166 PSDRV_WriteGSave(dc);
167 PSDRV_Clip(dc, EO);
168 PSDRV_WriteRotate(dc, -45.0);
169 PSDRV_WriteHatch(dc);
170 PSDRV_WriteStroke(dc);
171 PSDRV_WriteGRestore(dc);
172 if(brush->logbrush.lbHatch == HS_FDIAGONAL)
173 break;
174 /* else fallthrough for HS_DIAGCROSS */
176 case HS_BDIAGONAL:
177 PSDRV_WriteGSave(dc);
178 PSDRV_Clip(dc, EO);
179 PSDRV_WriteRotate(dc, 45.0);
180 PSDRV_WriteHatch(dc);
181 PSDRV_WriteStroke(dc);
182 PSDRV_WriteGRestore(dc);
183 break;
185 default:
186 ERR("Unknown hatch style\n");
187 return FALSE;
189 return TRUE;
190 break;
192 case BS_NULL:
193 return TRUE;
194 break;
196 case BS_PATTERN:
198 BITMAP bm;
199 BYTE *bits;
200 GetObjectA(brush->logbrush.lbHatch, sizeof(BITMAP), &bm);
201 TRACE("BS_PATTERN %dx%d %d bpp\n", bm.bmWidth, bm.bmHeight,
202 bm.bmBitsPixel);
203 bits = HeapAlloc(PSDRV_Heap, 0, bm.bmWidthBytes * bm.bmHeight);
204 GetBitmapBits(brush->logbrush.lbHatch,
205 bm.bmWidthBytes * bm.bmHeight, bits);
207 PSDRV_WriteGSave(dc);
208 PSDRV_WritePatternDict(dc, &bm, bits);
209 HeapFree(PSDRV_Heap, 0, bits);
210 PSDRV_Fill(dc, EO);
211 PSDRV_WriteGRestore(dc);
212 return TRUE;
214 break;
218 default:
219 return FALSE;
220 break;