mshtml.idl: Added some missing attributes.
[wine.git] / dlls / gdiplus / pen.c
blobe582f7644c6f1f23ad34f507e5d63f1384b81589
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 static int calls;
34 switch(dash){
35 case DashStyleSolid:
36 return PS_SOLID;
37 case DashStyleDash:
38 return PS_DASH;
39 case DashStyleDot:
40 return PS_DOT;
41 case DashStyleDashDot:
42 return PS_DASHDOT;
43 case DashStyleDashDotDot:
44 return PS_DASHDOTDOT;
45 case DashStyleCustom:
46 if(!(calls++))
47 FIXME("DashStyleCustom not implemented\n");
48 return PS_SOLID;
49 default:
50 ERR("Not a member of GpDashStyle enumeration\n");
51 return 0;
55 static DWORD gdip_to_gdi_join(GpLineJoin join)
57 switch(join){
58 case LineJoinRound:
59 return PS_JOIN_ROUND;
60 case LineJoinBevel:
61 return PS_JOIN_BEVEL;
62 case LineJoinMiter:
63 case LineJoinMiterClipped:
64 return PS_JOIN_MITER;
65 default:
66 ERR("Not a member of GpLineJoin enumeration\n");
67 return 0;
71 GpStatus WINGDIPAPI GdipClonePen(GpPen *pen, GpPen **clonepen)
73 if(!pen || !clonepen)
74 return InvalidParameter;
76 *clonepen = GdipAlloc(sizeof(GpPen));
77 if(!*clonepen) return OutOfMemory;
79 memcpy(*clonepen, pen, sizeof(GpPen));
81 GdipCloneCustomLineCap(pen->customstart, &(*clonepen)->customstart);
82 GdipCloneCustomLineCap(pen->customend, &(*clonepen)->customend);
83 GdipCloneBrush(pen->brush, &(*clonepen)->brush);
85 return Ok;
88 GpStatus WINGDIPAPI GdipCreatePen1(ARGB color, FLOAT width, GpUnit unit,
89 GpPen **pen)
91 GpPen *gp_pen;
93 if(!pen)
94 return InvalidParameter;
96 gp_pen = GdipAlloc(sizeof(GpPen));
97 if(!gp_pen) return OutOfMemory;
99 gp_pen->style = GP_DEFAULT_PENSTYLE;
100 gp_pen->width = width;
101 gp_pen->unit = unit;
102 gp_pen->endcap = LineCapFlat;
103 gp_pen->join = LineJoinMiter;
104 gp_pen->miterlimit = 10.0;
105 gp_pen->dash = DashStyleSolid;
106 GdipCreateSolidFill(color, (GpSolidFill **)(&gp_pen->brush));
108 if(!((gp_pen->unit == UnitWorld) || (gp_pen->unit == UnitPixel))) {
109 FIXME("UnitWorld, UnitPixel only supported units\n");
110 GdipFree(gp_pen);
111 return NotImplemented;
114 *pen = gp_pen;
116 return Ok;
119 GpStatus WINGDIPAPI GdipDeletePen(GpPen *pen)
121 if(!pen) return InvalidParameter;
123 GdipDeleteBrush(pen->brush);
124 GdipDeleteCustomLineCap(pen->customstart);
125 GdipDeleteCustomLineCap(pen->customend);
126 GdipFree(pen->dashes);
127 GdipFree(pen);
129 return Ok;
132 GpStatus WINGDIPAPI GdipGetPenBrushFill(GpPen *pen, GpBrush **brush)
134 if(!pen || !brush)
135 return InvalidParameter;
137 return GdipCloneBrush(pen->brush, brush);
140 GpStatus WINGDIPAPI GdipGetPenColor(GpPen *pen, ARGB *argb)
142 if(!pen || !argb)
143 return InvalidParameter;
145 if(pen->brush->bt != BrushTypeSolidColor)
146 return NotImplemented;
148 return GdipGetSolidFillColor(((GpSolidFill*)pen->brush), argb);
151 GpStatus WINGDIPAPI GdipGetPenDashArray(GpPen *pen, REAL *dash, INT count)
153 if(!pen || !dash || count > pen->numdashes)
154 return InvalidParameter;
156 /* note: if you pass a negative value for count, it crashes native gdiplus. */
157 if(count < 0)
158 return GenericError;
160 memcpy(dash, pen->dashes, count * sizeof(REAL));
162 return Ok;
165 GpStatus WINGDIPAPI GdipGetPenDashStyle(GpPen *pen, GpDashStyle *dash)
167 if(!pen || !dash)
168 return InvalidParameter;
170 *dash = pen->dash;
172 return Ok;
175 GpStatus WINGDIPAPI GdipSetPenBrushFill(GpPen *pen, GpBrush *brush)
177 if(!pen || !brush)
178 return InvalidParameter;
180 GdipDeleteBrush(pen->brush);
181 return GdipCloneBrush(brush, &pen->brush);
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 GdipSetPenDashArray(GpPen *pen, GDIPCONST REAL *dash,
228 INT count)
230 if(!pen || !dash)
231 return InvalidParameter;
233 GdipFree(pen->dashes);
234 pen->dashes = NULL;
236 if(count > 0)
237 pen->dashes = GdipAlloc(count * sizeof(REAL));
238 if(!pen->dashes){
239 pen->numdashes = 0;
240 return OutOfMemory;
243 pen->dash = DashStyleCustom;
244 memcpy(pen->dashes, dash, count * sizeof(REAL));
245 pen->numdashes = count;
247 return Ok;
250 GpStatus WINGDIPAPI GdipSetPenDashStyle(GpPen *pen, GpDashStyle dash)
252 if(!pen)
253 return InvalidParameter;
255 if(dash != DashStyleCustom){
256 GdipFree(pen->dashes);
257 pen->dashes = NULL;
258 pen->numdashes = 0;
261 pen->dash = dash;
262 pen->style &= ~(PS_ALTERNATE | PS_SOLID | PS_DASH | PS_DOT | PS_DASHDOT |
263 PS_DASHDOTDOT | PS_NULL | PS_USERSTYLE | PS_INSIDEFRAME);
264 pen->style |= gdip_to_gdi_dash(dash);
266 return Ok;
269 GpStatus WINGDIPAPI GdipSetPenEndCap(GpPen *pen, GpLineCap cap)
271 if(!pen) return InvalidParameter;
273 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
274 GdipDeleteCustomLineCap(pen->customend);
275 pen->customend = NULL;
276 pen->endcap = cap;
278 return Ok;
281 /* FIXME: startcap, dashcap not used. */
282 GpStatus WINGDIPAPI GdipSetPenLineCap197819(GpPen *pen, GpLineCap start,
283 GpLineCap end, GpDashCap dash)
285 if(!pen)
286 return InvalidParameter;
288 GdipDeleteCustomLineCap(pen->customend);
289 GdipDeleteCustomLineCap(pen->customstart);
290 pen->customend = NULL;
291 pen->customstart = NULL;
293 pen->startcap = start;
294 pen->endcap = end;
295 pen->dashcap = dash;
297 return Ok;
300 /* FIXME: Miter line joins behave a bit differently than they do in windows.
301 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
302 GpStatus WINGDIPAPI GdipSetPenLineJoin(GpPen *pen, GpLineJoin join)
304 if(!pen) return InvalidParameter;
306 pen->join = join;
307 pen->style &= ~(PS_JOIN_ROUND | PS_JOIN_BEVEL | PS_JOIN_MITER);
308 pen->style |= gdip_to_gdi_join(join);
310 return Ok;
313 GpStatus WINGDIPAPI GdipSetPenMiterLimit(GpPen *pen, REAL limit)
315 if(!pen)
316 return InvalidParameter;
318 pen->miterlimit = limit;
320 return Ok;
323 GpStatus WINGDIPAPI GdipSetPenStartCap(GpPen *pen, GpLineCap cap)
325 if(!pen) return InvalidParameter;
327 GdipDeleteCustomLineCap(pen->customstart);
328 pen->customstart = NULL;
329 pen->startcap = cap;
331 return Ok;