winewayland.drv: Update desktop window size on display changes.
[wine.git] / dlls / wineps.drv / brush.c
blob0c3dabd387f4812d1ee898e25abed282fd21d4d6
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 CDECL PSDRV_SelectBrush( print_ctx *ctx, HBRUSH hbrush, const struct brush_pattern *pattern )
32 LOGBRUSH logbrush;
34 if (!GetObjectA( hbrush, sizeof(logbrush), &logbrush )) return 0;
36 TRACE("hbrush = %p\n", hbrush);
38 if (hbrush == GetStockObject( DC_BRUSH ))
39 logbrush.lbColor = GetDCBrushColor( ctx->hdc );
41 switch(logbrush.lbStyle) {
43 case BS_SOLID:
44 PSDRV_CreateColor(ctx, &ctx->brush.color, logbrush.lbColor);
45 break;
47 case BS_NULL:
48 break;
50 case BS_HATCHED:
51 PSDRV_CreateColor(ctx, &ctx->brush.color, logbrush.lbColor);
52 break;
54 case BS_PATTERN:
55 case BS_DIBPATTERN:
56 ctx->brush.pattern = *pattern;
57 break;
59 default:
60 FIXME("Unrecognized brush style %d\n", logbrush.lbStyle);
61 break;
64 ctx->brush.set = FALSE;
65 return hbrush;
69 /***********************************************************************
70 * SetDCBrushColor (WINEPS.@)
72 COLORREF CDECL PSDRV_SetDCBrushColor( print_ctx *ctx, COLORREF color )
74 if (GetCurrentObject( ctx->hdc, OBJ_BRUSH ) == GetStockObject( DC_BRUSH ))
76 PSDRV_CreateColor( ctx, &ctx->brush.color, color );
77 ctx->brush.set = FALSE;
79 return color;
83 /**********************************************************************
85 * PSDRV_SetBrush
88 static BOOL PSDRV_SetBrush( print_ctx *ctx )
90 LOGBRUSH logbrush;
91 BOOL ret = TRUE;
93 if (!GetObjectA( GetCurrentObject(ctx->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush ))
95 ERR("Can't get BRUSHOBJ\n");
96 return FALSE;
99 switch (logbrush.lbStyle) {
100 case BS_SOLID:
101 case BS_HATCHED:
102 PSDRV_WriteSetColor(ctx, &ctx->brush.color);
103 break;
105 case BS_NULL:
106 break;
108 default:
109 ret = FALSE;
110 break;
113 ctx->brush.set = TRUE;
114 return ret;
118 /**********************************************************************
120 * PSDRV_Fill
123 static BOOL PSDRV_Fill(print_ctx *ctx, BOOL EO)
125 if(!EO)
126 return PSDRV_WriteFill(ctx);
127 else
128 return PSDRV_WriteEOFill(ctx);
132 /**********************************************************************
134 * PSDRV_Clip
137 static BOOL PSDRV_Clip(print_ctx *ctx, BOOL EO)
139 if(!EO)
140 return PSDRV_WriteClip(ctx);
141 else
142 return PSDRV_WriteEOClip(ctx);
145 /**********************************************************************
147 * PSDRV_Brush
150 BOOL PSDRV_Brush(print_ctx *ctx, BOOL EO)
152 LOGBRUSH logbrush;
153 BOOL ret = TRUE;
155 if(ctx->pathdepth)
156 return FALSE;
158 if (!GetObjectA( GetCurrentObject(ctx->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush ))
160 ERR("Can't get BRUSHOBJ\n");
161 return FALSE;
164 switch (logbrush.lbStyle) {
165 case BS_SOLID:
166 PSDRV_WriteGSave(ctx);
167 PSDRV_SetBrush(ctx);
168 PSDRV_Fill(ctx, EO);
169 PSDRV_WriteGRestore(ctx);
170 break;
172 case BS_HATCHED:
173 PSDRV_WriteGSave(ctx);
174 PSDRV_SetBrush(ctx);
176 switch(logbrush.lbHatch) {
177 case HS_VERTICAL:
178 case HS_CROSS:
179 PSDRV_WriteGSave(ctx);
180 PSDRV_Clip(ctx, EO);
181 PSDRV_WriteHatch(ctx);
182 PSDRV_WriteStroke(ctx);
183 PSDRV_WriteGRestore(ctx);
184 if(logbrush.lbHatch == HS_VERTICAL)
185 break;
186 /* else fallthrough for HS_CROSS */
188 case HS_HORIZONTAL:
189 PSDRV_WriteGSave(ctx);
190 PSDRV_Clip(ctx, EO);
191 PSDRV_WriteRotate(ctx, 90.0);
192 PSDRV_WriteHatch(ctx);
193 PSDRV_WriteStroke(ctx);
194 PSDRV_WriteGRestore(ctx);
195 break;
197 case HS_FDIAGONAL:
198 case HS_DIAGCROSS:
199 PSDRV_WriteGSave(ctx);
200 PSDRV_Clip(ctx, EO);
201 PSDRV_WriteRotate(ctx, -45.0);
202 PSDRV_WriteHatch(ctx);
203 PSDRV_WriteStroke(ctx);
204 PSDRV_WriteGRestore(ctx);
205 if(logbrush.lbHatch == HS_FDIAGONAL)
206 break;
207 /* else fallthrough for HS_DIAGCROSS */
209 case HS_BDIAGONAL:
210 PSDRV_WriteGSave(ctx);
211 PSDRV_Clip(ctx, EO);
212 PSDRV_WriteRotate(ctx, 45.0);
213 PSDRV_WriteHatch(ctx);
214 PSDRV_WriteStroke(ctx);
215 PSDRV_WriteGRestore(ctx);
216 break;
218 default:
219 ERR("Unknown hatch style\n");
220 ret = FALSE;
221 break;
223 PSDRV_WriteGRestore(ctx);
224 break;
226 case BS_NULL:
227 break;
229 case BS_PATTERN:
230 case BS_DIBPATTERN:
231 if(ctx->pi->ppd->LanguageLevel > 1) {
232 PSDRV_WriteGSave(ctx);
233 ret = PSDRV_WriteDIBPatternDict(ctx, ctx->brush.pattern.info,
234 ctx->brush.pattern.bits.ptr, ctx->brush.pattern.usage );
235 PSDRV_Fill(ctx, EO);
236 PSDRV_WriteGRestore(ctx);
237 } else {
238 FIXME("Trying to set a pattern brush on a level 1 printer\n");
239 ret = FALSE;
241 break;
243 default:
244 ret = FALSE;
245 break;
247 return ret;