push b8ecebbd387de253bc88d2c382ef272048a0b089
[wine/hacks.git] / dlls / gdiplus / pen.c
blob0f58b25d0f7db838dac04996c0db239932ab6e93
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "wingdi.h"
24 #include "gdiplus.h"
25 #include "gdiplus_private.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
30 static DWORD gdip_to_gdi_dash(GpDashStyle dash)
32 switch(dash){
33 case DashStyleSolid:
34 return PS_SOLID;
35 case DashStyleDash:
36 return PS_DASH;
37 case DashStyleDot:
38 return PS_DOT;
39 case DashStyleDashDot:
40 return PS_DASHDOT;
41 case DashStyleDashDotDot:
42 return PS_DASHDOTDOT;
43 case DashStyleCustom:
44 FIXME("DashStyleCustom not implemented\n");
45 return PS_SOLID;
46 default:
47 ERR("Not a member of GpDashStyle enumeration\n");
48 return 0;
52 static DWORD gdip_to_gdi_join(GpLineJoin join)
54 switch(join){
55 case LineJoinRound:
56 return PS_JOIN_ROUND;
57 case LineJoinBevel:
58 return PS_JOIN_BEVEL;
59 case LineJoinMiter:
60 case LineJoinMiterClipped:
61 return PS_JOIN_MITER;
62 default:
63 ERR("Not a member of GpLineJoin enumeration\n");
64 return 0;
68 GpStatus WINGDIPAPI GdipClonePen(GpPen *pen, GpPen **clonepen)
70 if(!pen || !clonepen)
71 return InvalidParameter;
73 *clonepen = GdipAlloc(sizeof(GpPen));
74 if(!*clonepen) return OutOfMemory;
76 memcpy(*clonepen, pen, sizeof(GpPen));
78 GdipCloneCustomLineCap(pen->customstart, &(*clonepen)->customstart);
79 GdipCloneCustomLineCap(pen->customend, &(*clonepen)->customend);
80 GdipCloneBrush(pen->brush, &(*clonepen)->brush);
82 (*clonepen)->gdipen = ExtCreatePen((*clonepen)->style,
83 roundr((*clonepen)->width),
84 &(*clonepen)->brush->lb, 0, NULL);
86 return Ok;
89 GpStatus WINGDIPAPI GdipCreatePen1(ARGB color, FLOAT width, GpUnit unit,
90 GpPen **pen)
92 GpPen *gp_pen;
94 if(!pen)
95 return InvalidParameter;
97 gp_pen = GdipAlloc(sizeof(GpPen));
98 if(!gp_pen) return OutOfMemory;
100 gp_pen->style = GP_DEFAULT_PENSTYLE;
101 gp_pen->width = width;
102 gp_pen->unit = unit;
103 gp_pen->endcap = LineCapFlat;
104 gp_pen->join = LineJoinMiter;
105 gp_pen->miterlimit = 10.0;
106 gp_pen->dash = DashStyleSolid;
107 GdipCreateSolidFill(color, (GpSolidFill **)(&gp_pen->brush));
109 if((gp_pen->unit == UnitWorld) || (gp_pen->unit == UnitPixel)) {
110 gp_pen->gdipen = ExtCreatePen(gp_pen->style, (INT) gp_pen->width,
111 &gp_pen->brush->lb, 0, NULL);
112 } else {
113 FIXME("UnitWorld, UnitPixel only supported units\n");
114 GdipFree(gp_pen);
115 return NotImplemented;
118 *pen = gp_pen;
120 return Ok;
123 GpStatus WINGDIPAPI GdipDeletePen(GpPen *pen)
125 if(!pen) return InvalidParameter;
126 DeleteObject(pen->gdipen);
128 GdipDeleteBrush(pen->brush);
129 GdipDeleteCustomLineCap(pen->customstart);
130 GdipDeleteCustomLineCap(pen->customend);
131 GdipFree(pen);
133 return Ok;
136 GpStatus WINGDIPAPI GdipGetPenBrushFill(GpPen *pen, GpBrush **brush)
138 if(!pen || !brush)
139 return InvalidParameter;
141 return GdipCloneBrush(pen->brush, brush);
144 GpStatus WINGDIPAPI GdipGetPenColor(GpPen *pen, ARGB *argb)
146 if(!pen || !argb)
147 return InvalidParameter;
149 if(pen->brush->bt != BrushTypeSolidColor)
150 return NotImplemented;
152 return GdipGetSolidFillColor(((GpSolidFill*)pen->brush), argb);
155 GpStatus WINGDIPAPI GdipGetPenDashStyle(GpPen *pen, GpDashStyle *dash)
157 if(!pen || !dash)
158 return InvalidParameter;
160 *dash = pen->dash;
162 return Ok;
165 GpStatus WINGDIPAPI GdipSetPenBrushFill(GpPen *pen, GpBrush *brush)
167 GpStatus retval;
169 if(!pen || !brush)
170 return InvalidParameter;
172 GdipDeleteBrush(pen->brush);
173 retval = GdipCloneBrush(brush, &pen->brush);
174 if(retval != Ok)
175 return retval;
177 DeleteObject(pen->gdipen);
178 pen->gdipen = ExtCreatePen(pen->style, roundr(pen->width), &pen->brush->lb, 0,
179 NULL);
181 return Ok;
184 GpStatus WINGDIPAPI GdipSetPenColor(GpPen *pen, ARGB argb)
186 if(!pen)
187 return InvalidParameter;
189 if(pen->brush->bt != BrushTypeSolidColor)
190 return NotImplemented;
192 return GdipSetSolidFillColor(((GpSolidFill*)pen->brush), argb);
195 GpStatus WINGDIPAPI GdipSetPenCustomEndCap(GpPen *pen, GpCustomLineCap* customCap)
197 GpCustomLineCap * cap;
198 GpStatus ret;
200 if(!pen || !customCap) return InvalidParameter;
202 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
203 GdipDeleteCustomLineCap(pen->customend);
204 pen->endcap = LineCapCustom;
205 pen->customend = cap;
208 return ret;
211 GpStatus WINGDIPAPI GdipSetPenCustomStartCap(GpPen *pen, GpCustomLineCap* customCap)
213 GpCustomLineCap * cap;
214 GpStatus ret;
216 if(!pen || !customCap) return InvalidParameter;
218 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
219 GdipDeleteCustomLineCap(pen->customstart);
220 pen->startcap = LineCapCustom;
221 pen->customstart = cap;
224 return ret;
227 GpStatus WINGDIPAPI GdipSetPenDashStyle(GpPen *pen, GpDashStyle dash)
229 if(!pen)
230 return InvalidParameter;
232 DeleteObject(pen->gdipen);
233 pen->dash = dash;
234 pen->style &= ~(PS_ALTERNATE | PS_SOLID | PS_DASH | PS_DOT | PS_DASHDOT |
235 PS_DASHDOTDOT | PS_NULL | PS_USERSTYLE | PS_INSIDEFRAME);
236 pen->style |= gdip_to_gdi_dash(dash);
238 pen->gdipen = ExtCreatePen(pen->style, (INT) pen->width, &pen->brush->lb, 0, NULL);
240 return Ok;
243 GpStatus WINGDIPAPI GdipSetPenEndCap(GpPen *pen, GpLineCap cap)
245 if(!pen) return InvalidParameter;
247 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
248 GdipDeleteCustomLineCap(pen->customend);
249 pen->customend = NULL;
250 pen->endcap = cap;
252 return Ok;
255 /* FIXME: startcap, dashcap not used. */
256 GpStatus WINGDIPAPI GdipSetPenLineCap197819(GpPen *pen, GpLineCap start,
257 GpLineCap end, GpDashCap dash)
259 if(!pen)
260 return InvalidParameter;
262 GdipDeleteCustomLineCap(pen->customend);
263 GdipDeleteCustomLineCap(pen->customstart);
264 pen->customend = NULL;
265 pen->customstart = NULL;
267 pen->startcap = start;
268 pen->endcap = end;
269 pen->dashcap = dash;
271 return Ok;
274 /* FIXME: Miter line joins behave a bit differently than they do in windows.
275 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
276 GpStatus WINGDIPAPI GdipSetPenLineJoin(GpPen *pen, GpLineJoin join)
278 if(!pen) return InvalidParameter;
280 DeleteObject(pen->gdipen);
281 pen->join = join;
282 pen->style &= ~(PS_JOIN_ROUND | PS_JOIN_BEVEL | PS_JOIN_MITER);
283 pen->style |= gdip_to_gdi_join(join);
285 pen->gdipen = ExtCreatePen(pen->style, (INT) pen->width, &pen->brush->lb, 0, NULL);
287 return Ok;
290 GpStatus WINGDIPAPI GdipSetPenMiterLimit(GpPen *pen, REAL limit)
292 if(!pen)
293 return InvalidParameter;
295 pen->miterlimit = limit;
297 return Ok;
300 GpStatus WINGDIPAPI GdipSetPenStartCap(GpPen *pen, GpLineCap cap)
302 if(!pen) return InvalidParameter;
304 GdipDeleteCustomLineCap(pen->customstart);
305 pen->customstart = NULL;
306 pen->startcap = cap;
308 return Ok;