push a18c97e3310ae68c9cf1d09430f25ca292f320eb
[wine/hacks.git] / dlls / gdiplus / pen.c
blob97fc99dacdf947502a95ab36ffb48ace63a48a53
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"
25 #include "objbase.h"
27 #include "gdiplus.h"
28 #include "gdiplus_private.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
33 static DWORD gdip_to_gdi_dash(GpDashStyle dash)
35 switch(dash){
36 case DashStyleSolid:
37 return PS_SOLID;
38 case DashStyleDash:
39 return PS_DASH;
40 case DashStyleDot:
41 return PS_DOT;
42 case DashStyleDashDot:
43 return PS_DASHDOT;
44 case DashStyleDashDotDot:
45 return PS_DASHDOTDOT;
46 case DashStyleCustom:
47 return PS_USERSTYLE;
48 default:
49 ERR("Not a member of GpDashStyle enumeration\n");
50 return 0;
54 static DWORD gdip_to_gdi_join(GpLineJoin join)
56 switch(join){
57 case LineJoinRound:
58 return PS_JOIN_ROUND;
59 case LineJoinBevel:
60 return PS_JOIN_BEVEL;
61 case LineJoinMiter:
62 case LineJoinMiterClipped:
63 return PS_JOIN_MITER;
64 default:
65 ERR("Not a member of GpLineJoin enumeration\n");
66 return 0;
70 GpStatus WINGDIPAPI GdipClonePen(GpPen *pen, GpPen **clonepen)
72 if(!pen || !clonepen)
73 return InvalidParameter;
75 *clonepen = GdipAlloc(sizeof(GpPen));
76 if(!*clonepen) return OutOfMemory;
78 memcpy(*clonepen, pen, sizeof(GpPen));
80 GdipCloneCustomLineCap(pen->customstart, &(*clonepen)->customstart);
81 GdipCloneCustomLineCap(pen->customend, &(*clonepen)->customend);
82 GdipCloneBrush(pen->brush, &(*clonepen)->brush);
84 return Ok;
87 GpStatus WINGDIPAPI GdipCreatePen1(ARGB color, REAL width, GpUnit unit,
88 GpPen **pen)
90 GpBrush *brush;
91 GdipCreateSolidFill(color, (GpSolidFill **)(&brush));
92 return GdipCreatePen2(brush, width, unit, pen);
95 GpStatus WINGDIPAPI GdipCreatePen2(GpBrush *brush, REAL width, GpUnit unit,
96 GpPen **pen)
98 GpPen *gp_pen;
100 if(!pen || !brush)
101 return InvalidParameter;
103 gp_pen = GdipAlloc(sizeof(GpPen));
104 if(!gp_pen) return OutOfMemory;
106 gp_pen->style = GP_DEFAULT_PENSTYLE;
107 gp_pen->width = width;
108 gp_pen->unit = unit;
109 gp_pen->endcap = LineCapFlat;
110 gp_pen->join = LineJoinMiter;
111 gp_pen->miterlimit = 10.0;
112 gp_pen->dash = DashStyleSolid;
113 gp_pen->offset = 0.0;
114 gp_pen->brush = brush;
116 if(!((gp_pen->unit == UnitWorld) || (gp_pen->unit == UnitPixel))) {
117 FIXME("UnitWorld, UnitPixel only supported units\n");
118 GdipFree(gp_pen);
119 return NotImplemented;
122 *pen = gp_pen;
124 return Ok;
127 GpStatus WINGDIPAPI GdipDeletePen(GpPen *pen)
129 if(!pen) return InvalidParameter;
131 GdipDeleteBrush(pen->brush);
132 GdipDeleteCustomLineCap(pen->customstart);
133 GdipDeleteCustomLineCap(pen->customend);
134 GdipFree(pen->dashes);
135 GdipFree(pen);
137 return Ok;
140 GpStatus WINGDIPAPI GdipGetPenBrushFill(GpPen *pen, GpBrush **brush)
142 if(!pen || !brush)
143 return InvalidParameter;
145 return GdipCloneBrush(pen->brush, brush);
148 GpStatus WINGDIPAPI GdipGetPenColor(GpPen *pen, ARGB *argb)
150 if(!pen || !argb)
151 return InvalidParameter;
153 if(pen->brush->bt != BrushTypeSolidColor)
154 return NotImplemented;
156 return GdipGetSolidFillColor(((GpSolidFill*)pen->brush), argb);
159 GpStatus WINGDIPAPI GdipGetPenDashArray(GpPen *pen, REAL *dash, INT count)
161 if(!pen || !dash || count > pen->numdashes)
162 return InvalidParameter;
164 /* note: if you pass a negative value for count, it crashes native gdiplus. */
165 if(count < 0)
166 return GenericError;
168 memcpy(dash, pen->dashes, count * sizeof(REAL));
170 return Ok;
173 GpStatus WINGDIPAPI GdipGetPenDashOffset(GpPen *pen, REAL *offset)
175 if(!pen || !offset)
176 return InvalidParameter;
178 *offset = pen->offset;
180 return Ok;
183 GpStatus WINGDIPAPI GdipGetPenDashStyle(GpPen *pen, GpDashStyle *dash)
185 if(!pen || !dash)
186 return InvalidParameter;
188 *dash = pen->dash;
190 return Ok;
193 GpStatus WINGDIPAPI GdipSetPenBrushFill(GpPen *pen, GpBrush *brush)
195 if(!pen || !brush)
196 return InvalidParameter;
198 GdipDeleteBrush(pen->brush);
199 return GdipCloneBrush(brush, &pen->brush);
202 GpStatus WINGDIPAPI GdipSetPenColor(GpPen *pen, ARGB argb)
204 if(!pen)
205 return InvalidParameter;
207 if(pen->brush->bt != BrushTypeSolidColor)
208 return NotImplemented;
210 return GdipSetSolidFillColor(((GpSolidFill*)pen->brush), argb);
213 GpStatus WINGDIPAPI GdipSetPenCustomEndCap(GpPen *pen, GpCustomLineCap* customCap)
215 GpCustomLineCap * cap;
216 GpStatus ret;
218 if(!pen || !customCap) return InvalidParameter;
220 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
221 GdipDeleteCustomLineCap(pen->customend);
222 pen->endcap = LineCapCustom;
223 pen->customend = cap;
226 return ret;
229 GpStatus WINGDIPAPI GdipSetPenCustomStartCap(GpPen *pen, GpCustomLineCap* customCap)
231 GpCustomLineCap * cap;
232 GpStatus ret;
234 if(!pen || !customCap) return InvalidParameter;
236 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
237 GdipDeleteCustomLineCap(pen->customstart);
238 pen->startcap = LineCapCustom;
239 pen->customstart = cap;
242 return ret;
245 GpStatus WINGDIPAPI GdipSetPenDashArray(GpPen *pen, GDIPCONST REAL *dash,
246 INT count)
248 INT i;
249 REAL sum = 0;
251 if(!pen || !dash)
252 return InvalidParameter;
254 for(i = 0; i < count; i++){
255 sum += dash[i];
256 if(dash[i] < 0.0)
257 return InvalidParameter;
260 if(sum == 0.0 && count)
261 return InvalidParameter;
263 GdipFree(pen->dashes);
264 pen->dashes = NULL;
266 if(count > 0)
267 pen->dashes = GdipAlloc(count * sizeof(REAL));
268 if(!pen->dashes){
269 pen->numdashes = 0;
270 return OutOfMemory;
273 GdipSetPenDashStyle(pen, DashStyleCustom);
274 memcpy(pen->dashes, dash, count * sizeof(REAL));
275 pen->numdashes = count;
277 return Ok;
280 /* FIXME: dash offset not used */
281 GpStatus WINGDIPAPI GdipSetPenDashOffset(GpPen *pen, REAL offset)
283 if(!pen)
284 return InvalidParameter;
286 pen->offset = offset;
288 return Ok;
291 GpStatus WINGDIPAPI GdipSetPenDashStyle(GpPen *pen, GpDashStyle dash)
293 if(!pen)
294 return InvalidParameter;
296 if(dash != DashStyleCustom){
297 GdipFree(pen->dashes);
298 pen->dashes = NULL;
299 pen->numdashes = 0;
302 pen->dash = dash;
303 pen->style &= ~(PS_ALTERNATE | PS_SOLID | PS_DASH | PS_DOT | PS_DASHDOT |
304 PS_DASHDOTDOT | PS_NULL | PS_USERSTYLE | PS_INSIDEFRAME);
305 pen->style |= gdip_to_gdi_dash(dash);
307 return Ok;
310 GpStatus WINGDIPAPI GdipSetPenEndCap(GpPen *pen, GpLineCap cap)
312 if(!pen) return InvalidParameter;
314 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
315 GdipDeleteCustomLineCap(pen->customend);
316 pen->customend = NULL;
317 pen->endcap = cap;
319 return Ok;
322 /* FIXME: startcap, dashcap not used. */
323 GpStatus WINGDIPAPI GdipSetPenLineCap197819(GpPen *pen, GpLineCap start,
324 GpLineCap end, GpDashCap dash)
326 if(!pen)
327 return InvalidParameter;
329 GdipDeleteCustomLineCap(pen->customend);
330 GdipDeleteCustomLineCap(pen->customstart);
331 pen->customend = NULL;
332 pen->customstart = NULL;
334 pen->startcap = start;
335 pen->endcap = end;
336 pen->dashcap = dash;
338 return Ok;
341 /* FIXME: Miter line joins behave a bit differently than they do in windows.
342 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
343 GpStatus WINGDIPAPI GdipSetPenLineJoin(GpPen *pen, GpLineJoin join)
345 if(!pen) return InvalidParameter;
347 pen->join = join;
348 pen->style &= ~(PS_JOIN_ROUND | PS_JOIN_BEVEL | PS_JOIN_MITER);
349 pen->style |= gdip_to_gdi_join(join);
351 return Ok;
354 GpStatus WINGDIPAPI GdipSetPenMiterLimit(GpPen *pen, REAL limit)
356 if(!pen)
357 return InvalidParameter;
359 pen->miterlimit = limit;
361 return Ok;
364 GpStatus WINGDIPAPI GdipSetPenStartCap(GpPen *pen, GpLineCap cap)
366 if(!pen) return InvalidParameter;
368 GdipDeleteCustomLineCap(pen->customstart);
369 pen->customstart = NULL;
370 pen->startcap = cap;
372 return Ok;
375 GpStatus WINGDIPAPI GdipSetPenWidth(GpPen *pen, REAL width)
377 if(!pen) return InvalidParameter;
379 pen->width = width;
381 return Ok;
385 GpStatus WINGDIPAPI GdipSetPenMode(GpPen *pen, GpPenAlignment penAlignment)
387 if(!pen) return InvalidParameter;
389 FIXME("stub (%d)\n", penAlignment);
391 return Ok;