Use DrawFrameControl instead of bitmaps in certain cases.
[wine] / dlls / wineps / brush.c
1 /*
2  *      PostScript brush handling
3  *
4  * Copyright 1998  Huw D M Davies
5  *
6  */
7
8 #include "psdrv.h"
9 #include "debugtools.h"
10 #include "winbase.h"
11
12 DEFAULT_DEBUG_CHANNEL(psdrv);
13
14 /***********************************************************************
15  *           PSDRV_BRUSH_SelectObject
16  */
17 HBRUSH PSDRV_BRUSH_SelectObject( DC * dc, HBRUSH hbrush )
18 {
19     LOGBRUSH logbrush;
20     HBRUSH prevbrush = dc->hBrush;
21     PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
22
23     if (!GetObjectA( hbrush, sizeof(logbrush), &logbrush )) return 0;
24
25     TRACE("hbrush = %08x\n", hbrush);
26     dc->hBrush = hbrush;
27
28     switch(logbrush.lbStyle) {
29
30     case BS_SOLID:
31         PSDRV_CreateColor(physDev, &physDev->brush.color, logbrush.lbColor);
32         break;
33
34     case BS_NULL:
35         break;
36
37     case BS_HATCHED:
38         PSDRV_CreateColor(physDev, &physDev->brush.color, logbrush.lbColor);
39         break;
40
41     case BS_PATTERN:
42         FIXME("Unsupported brush style %d\n", logbrush.lbStyle);
43         break;
44
45     default:
46         FIXME("Unrecognized brush style %d\n", logbrush.lbStyle);
47         break;
48     }
49
50     physDev->brush.set = FALSE;
51     return prevbrush;
52 }
53
54
55 /**********************************************************************
56  *
57  *      PSDRV_SetBrush
58  *
59  */
60 static BOOL PSDRV_SetBrush(DC *dc)
61 {
62     LOGBRUSH logbrush;
63     BOOL ret = TRUE;
64     PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
65
66     if (!GetObjectA( dc->hBrush, sizeof(logbrush), &logbrush ))
67     {
68         ERR("Can't get BRUSHOBJ\n");
69         return FALSE;
70     }
71
72     switch (logbrush.lbStyle) {
73     case BS_SOLID:
74     case BS_HATCHED:
75         PSDRV_WriteSetColor(dc, &physDev->brush.color);
76         break;
77
78     case BS_NULL:
79         break;
80
81     default:
82         ret = FALSE;
83         break;
84
85     }
86     physDev->brush.set = TRUE;
87     return TRUE;
88 }
89
90
91 /**********************************************************************
92  *
93  *      PSDRV_Fill
94  *
95  */
96 static BOOL PSDRV_Fill(DC *dc, BOOL EO)
97 {
98     if(!EO)
99         return PSDRV_WriteFill(dc);
100     else
101       return PSDRV_WriteEOFill(dc);
102 }
103
104
105 /**********************************************************************
106  *
107  *      PSDRV_Clip
108  *
109  */
110 static BOOL PSDRV_Clip(DC *dc, BOOL EO)
111 {
112     if(!EO)
113         return PSDRV_WriteClip(dc);
114     else
115         return PSDRV_WriteEOClip(dc);
116 }
117
118 /**********************************************************************
119  *
120  *      PSDRV_Brush
121  *
122  */
123 BOOL PSDRV_Brush(DC *dc, BOOL EO)
124 {
125     LOGBRUSH logbrush;
126     BOOL ret = TRUE;
127     PSDRV_PDEVICE *physDev = dc->physDev;
128
129     if (!GetObjectA( dc->hBrush, sizeof(logbrush), &logbrush ))
130     {
131         ERR("Can't get BRUSHOBJ\n");
132         return FALSE;
133     }
134
135     switch (logbrush.lbStyle) {
136     case BS_SOLID:
137         PSDRV_SetBrush(dc);
138         PSDRV_WriteGSave(dc);
139         PSDRV_Fill(dc, EO);
140         PSDRV_WriteGRestore(dc);
141         break;
142
143     case BS_HATCHED:
144         PSDRV_SetBrush(dc);
145
146         switch(logbrush.lbHatch) {
147         case HS_VERTICAL:
148         case HS_CROSS:
149             PSDRV_WriteGSave(dc);
150             PSDRV_Clip(dc, EO);
151             PSDRV_WriteHatch(dc);
152             PSDRV_WriteStroke(dc);
153             PSDRV_WriteGRestore(dc);
154             if(logbrush.lbHatch == HS_VERTICAL)
155                 break;
156             /* else fallthrough for HS_CROSS */
157
158         case HS_HORIZONTAL:
159             PSDRV_WriteGSave(dc);
160             PSDRV_Clip(dc, EO);
161             PSDRV_WriteRotate(dc, 90.0);
162             PSDRV_WriteHatch(dc);
163             PSDRV_WriteStroke(dc);
164             PSDRV_WriteGRestore(dc);
165             break;
166
167         case HS_FDIAGONAL:
168         case HS_DIAGCROSS:
169             PSDRV_WriteGSave(dc);
170             PSDRV_Clip(dc, EO);
171             PSDRV_WriteRotate(dc, -45.0);
172             PSDRV_WriteHatch(dc);
173             PSDRV_WriteStroke(dc);
174             PSDRV_WriteGRestore(dc);
175             if(logbrush.lbHatch == HS_FDIAGONAL)
176                 break;
177             /* else fallthrough for HS_DIAGCROSS */
178             
179         case HS_BDIAGONAL:
180             PSDRV_WriteGSave(dc);
181             PSDRV_Clip(dc, EO);
182             PSDRV_WriteRotate(dc, 45.0);
183             PSDRV_WriteHatch(dc);
184             PSDRV_WriteStroke(dc);
185             PSDRV_WriteGRestore(dc);
186             break;
187
188         default:
189             ERR("Unknown hatch style\n");
190             ret = FALSE;
191             break;
192         }
193         break;
194
195     case BS_NULL:
196         break;
197
198     case BS_PATTERN:
199         {
200             BITMAP bm;
201             BYTE *bits;
202             GetObjectA(logbrush.lbHatch, sizeof(BITMAP), &bm);
203             TRACE("BS_PATTERN %dx%d %d bpp\n", bm.bmWidth, bm.bmHeight,
204                   bm.bmBitsPixel);
205             bits = HeapAlloc(PSDRV_Heap, 0, bm.bmWidthBytes * bm.bmHeight);
206             GetBitmapBits(logbrush.lbHatch, bm.bmWidthBytes * bm.bmHeight, bits);
207
208             if(physDev->pi->ppd->LanguageLevel > 1) {
209                 PSDRV_WriteGSave(dc);
210                 PSDRV_WritePatternDict(dc, &bm, bits);
211                 PSDRV_Fill(dc, EO);
212                 PSDRV_WriteGRestore(dc);
213             } else {
214                 FIXME("Trying to set a pattern brush on a level 1 printer\n");
215                 ret = FALSE;
216             }
217             HeapFree(PSDRV_Heap, 0, bits);      
218         }
219         break;
220
221     default:
222         ret = FALSE;
223         break;
224     }
225     return ret;
226 }
227
228
229
230