usp10: Add Ethiopic script.
[wine.git] / dlls / wineps.drv / brush.c
blob706af2f4348eb5419295b76fe6f7273bf5bad34f
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, HBITMAP bitmap,
31 const BITMAPINFO *info, void *bits, UINT usage )
33 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
34 LOGBRUSH logbrush;
36 if (!GetObjectA( hbrush, sizeof(logbrush), &logbrush )) return 0;
38 TRACE("hbrush = %p\n", hbrush);
40 if (hbrush == GetStockObject( DC_BRUSH ))
41 logbrush.lbColor = GetDCBrushColor( dev->hdc );
43 switch(logbrush.lbStyle) {
45 case BS_SOLID:
46 PSDRV_CreateColor(dev, &physDev->brush.color, logbrush.lbColor);
47 break;
49 case BS_NULL:
50 break;
52 case BS_HATCHED:
53 PSDRV_CreateColor(dev, &physDev->brush.color, logbrush.lbColor);
54 break;
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;
63 default:
64 FIXME("Unrecognized brush style %d\n", logbrush.lbStyle);
65 break;
68 physDev->brush.set = FALSE;
69 return hbrush;
73 /***********************************************************************
74 * SetDCBrushColor (WINEPS.@)
76 COLORREF PSDRV_SetDCBrushColor( PHYSDEV dev, COLORREF color )
78 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
80 if (GetCurrentObject( dev->hdc, OBJ_BRUSH ) == GetStockObject( DC_BRUSH ))
82 PSDRV_CreateColor( dev, &physDev->brush.color, color );
83 physDev->brush.set = FALSE;
85 return color;
89 /**********************************************************************
91 * PSDRV_SetBrush
94 static BOOL PSDRV_SetBrush( PHYSDEV dev )
96 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
97 LOGBRUSH logbrush;
98 BOOL ret = TRUE;
100 if (!GetObjectA( GetCurrentObject(dev->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush ))
102 ERR("Can't get BRUSHOBJ\n");
103 return FALSE;
106 switch (logbrush.lbStyle) {
107 case BS_SOLID:
108 case BS_HATCHED:
109 PSDRV_WriteSetColor(dev, &physDev->brush.color);
110 break;
112 case BS_NULL:
113 break;
115 default:
116 ret = FALSE;
117 break;
120 physDev->brush.set = TRUE;
121 return ret;
125 /**********************************************************************
127 * PSDRV_Fill
130 static BOOL PSDRV_Fill(PHYSDEV dev, BOOL EO)
132 if(!EO)
133 return PSDRV_WriteFill(dev);
134 else
135 return PSDRV_WriteEOFill(dev);
139 /**********************************************************************
141 * PSDRV_Clip
144 static BOOL PSDRV_Clip(PHYSDEV dev, BOOL EO)
146 if(!EO)
147 return PSDRV_WriteClip(dev);
148 else
149 return PSDRV_WriteEOClip(dev);
152 /**********************************************************************
154 * PSDRV_Brush
157 BOOL PSDRV_Brush(PHYSDEV dev, BOOL EO)
159 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
160 LOGBRUSH logbrush;
161 BOOL ret = TRUE;
163 if(physDev->pathdepth)
164 return FALSE;
166 if (!GetObjectA( GetCurrentObject(dev->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush ))
168 ERR("Can't get BRUSHOBJ\n");
169 return FALSE;
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;
180 case BS_HATCHED:
181 PSDRV_WriteGSave(dev);
182 PSDRV_SetBrush(dev);
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 */
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;
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 */
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;
226 default:
227 ERR("Unknown hatch style\n");
228 ret = FALSE;
229 break;
231 PSDRV_WriteGRestore(dev);
232 break;
234 case BS_NULL:
235 break;
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;
249 break;
251 default:
252 ret = FALSE;
253 break;
255 return ret;