winegstreamer: Use WAVE_FORMAT_PCM when possible for demux.
[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 )
31 {
32     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
33     LOGBRUSH logbrush;
34
35     if (!GetObjectA( hbrush, sizeof(logbrush), &logbrush )) return 0;
36
37     TRACE("hbrush = %p\n", hbrush);
38
39     if (hbrush == GetStockObject( DC_BRUSH ))
40         logbrush.lbColor = GetDCBrushColor( dev->hdc );
41
42     switch(logbrush.lbStyle) {
43
44     case BS_SOLID:
45         PSDRV_CreateColor(dev, &physDev->brush.color, logbrush.lbColor);
46         break;
47
48     case BS_NULL:
49         break;
50
51     case BS_HATCHED:
52         PSDRV_CreateColor(dev, &physDev->brush.color, logbrush.lbColor);
53         break;
54
55     case BS_PATTERN:
56     case BS_DIBPATTERN:
57         break;
58
59     default:
60         FIXME("Unrecognized brush style %d\n", logbrush.lbStyle);
61         break;
62     }
63
64     physDev->brush.set = FALSE;
65     return hbrush;
66 }
67
68
69 /***********************************************************************
70  *           SetDCBrushColor (WINEPS.@)
71  */
72 COLORREF PSDRV_SetDCBrushColor( PHYSDEV dev, COLORREF color )
73 {
74     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
75
76     if (GetCurrentObject( dev->hdc, OBJ_BRUSH ) == GetStockObject( DC_BRUSH ))
77     {
78         PSDRV_CreateColor( dev, &physDev->brush.color, color );
79         physDev->brush.set = FALSE;
80     }
81     return color;
82 }
83
84
85 /**********************************************************************
86  *
87  *      PSDRV_SetBrush
88  *
89  */
90 static BOOL PSDRV_SetBrush( PHYSDEV dev )
91 {
92     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
93     LOGBRUSH logbrush;
94     BOOL ret = TRUE;
95
96     if (!GetObjectA( GetCurrentObject(dev->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush ))
97     {
98         ERR("Can't get BRUSHOBJ\n");
99         return FALSE;
100     }
101
102     switch (logbrush.lbStyle) {
103     case BS_SOLID:
104     case BS_HATCHED:
105         PSDRV_WriteSetColor(dev, &physDev->brush.color);
106         break;
107
108     case BS_NULL:
109         break;
110
111     default:
112         ret = FALSE;
113         break;
114
115     }
116     physDev->brush.set = TRUE;
117     return ret;
118 }
119
120
121 /**********************************************************************
122  *
123  *      PSDRV_Fill
124  *
125  */
126 static BOOL PSDRV_Fill(PHYSDEV dev, BOOL EO)
127 {
128     if(!EO)
129         return PSDRV_WriteFill(dev);
130     else
131         return PSDRV_WriteEOFill(dev);
132 }
133
134
135 /**********************************************************************
136  *
137  *      PSDRV_Clip
138  *
139  */
140 static BOOL PSDRV_Clip(PHYSDEV dev, BOOL EO)
141 {
142     if(!EO)
143         return PSDRV_WriteClip(dev);
144     else
145         return PSDRV_WriteEOClip(dev);
146 }
147
148 /**********************************************************************
149  *
150  *      PSDRV_Brush
151  *
152  */
153 BOOL PSDRV_Brush(PHYSDEV dev, BOOL EO)
154 {
155     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
156     LOGBRUSH logbrush;
157     BOOL ret = TRUE;
158
159     if(physDev->pathdepth)
160         return FALSE;
161
162     if (!GetObjectA( GetCurrentObject(dev->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush ))
163     {
164         ERR("Can't get BRUSHOBJ\n");
165         return FALSE;
166     }
167
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;
175
176     case BS_HATCHED:
177         PSDRV_WriteGSave(dev);
178         PSDRV_SetBrush(dev);
179
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 */
191
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;
200
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 */
212
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;
221
222         default:
223             ERR("Unknown hatch style\n");
224             ret = FALSE;
225             break;
226         }
227         PSDRV_WriteGRestore(dev);
228         break;
229
230     case BS_NULL:
231         break;
232
233     case BS_PATTERN:
234         {
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);
242
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;
251             }
252             HeapFree(PSDRV_Heap, 0, bits);
253         }
254         break;
255
256     case BS_DIBPATTERN:
257         {
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;
270             }
271             GlobalUnlock( (HGLOBAL)logbrush.lbHatch );
272         }
273         break;
274
275     default:
276         ret = FALSE;
277         break;
278     }
279     return ret;
280 }