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
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)
42 case DashStyleDashDot:
44 case DashStyleDashDotDot:
49 ERR("Not a member of GpDashStyle enumeration\n");
54 static DWORD gdip_to_gdi_join(GpLineJoin join)
62 case LineJoinMiterClipped:
65 ERR("Not a member of GpLineJoin enumeration\n");
70 GpStatus WINGDIPAPI GdipClonePen(GpPen *pen, GpPen **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);
87 GpStatus WINGDIPAPI GdipCreatePen1(ARGB color, REAL width, GpUnit unit,
93 return InvalidParameter;
95 gp_pen = GdipAlloc(sizeof(GpPen));
96 if(!gp_pen) return OutOfMemory;
98 gp_pen->style = GP_DEFAULT_PENSTYLE;
99 gp_pen->width = width;
101 gp_pen->endcap = LineCapFlat;
102 gp_pen->join = LineJoinMiter;
103 gp_pen->miterlimit = 10.0;
104 gp_pen->dash = DashStyleSolid;
105 gp_pen->offset = 0.0;
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");
111 return NotImplemented;
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);
132 GpStatus WINGDIPAPI GdipGetPenBrushFill(GpPen *pen, GpBrush **brush)
135 return InvalidParameter;
137 return GdipCloneBrush(pen->brush, brush);
140 GpStatus WINGDIPAPI GdipGetPenColor(GpPen *pen, ARGB *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. */
160 memcpy(dash, pen->dashes, count * sizeof(REAL));
165 GpStatus WINGDIPAPI GdipGetPenDashOffset(GpPen *pen, REAL *offset)
168 return InvalidParameter;
170 *offset = pen->offset;
175 GpStatus WINGDIPAPI GdipGetPenDashStyle(GpPen *pen, GpDashStyle *dash)
178 return InvalidParameter;
185 GpStatus WINGDIPAPI GdipSetPenBrushFill(GpPen *pen, GpBrush *brush)
188 return InvalidParameter;
190 GdipDeleteBrush(pen->brush);
191 return GdipCloneBrush(brush, &pen->brush);
194 GpStatus WINGDIPAPI GdipSetPenColor(GpPen *pen, ARGB argb)
197 return InvalidParameter;
199 if(pen->brush->bt != BrushTypeSolidColor)
200 return NotImplemented;
202 return GdipSetSolidFillColor(((GpSolidFill*)pen->brush), argb);
205 GpStatus WINGDIPAPI GdipSetPenCustomEndCap(GpPen *pen, GpCustomLineCap* customCap)
207 GpCustomLineCap * cap;
210 if(!pen || !customCap) return InvalidParameter;
212 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
213 GdipDeleteCustomLineCap(pen->customend);
214 pen->endcap = LineCapCustom;
215 pen->customend = cap;
221 GpStatus WINGDIPAPI GdipSetPenCustomStartCap(GpPen *pen, GpCustomLineCap* customCap)
223 GpCustomLineCap * cap;
226 if(!pen || !customCap) return InvalidParameter;
228 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
229 GdipDeleteCustomLineCap(pen->customstart);
230 pen->startcap = LineCapCustom;
231 pen->customstart = cap;
237 GpStatus WINGDIPAPI GdipSetPenDashArray(GpPen *pen, GDIPCONST REAL *dash,
244 return InvalidParameter;
246 for(i = 0; i < count; i++){
249 return InvalidParameter;
252 if(sum == 0.0 && count)
253 return InvalidParameter;
255 GdipFree(pen->dashes);
259 pen->dashes = GdipAlloc(count * sizeof(REAL));
265 GdipSetPenDashStyle(pen, DashStyleCustom);
266 memcpy(pen->dashes, dash, count * sizeof(REAL));
267 pen->numdashes = count;
272 /* FIXME: dash offset not used */
273 GpStatus WINGDIPAPI GdipSetPenDashOffset(GpPen *pen, REAL offset)
276 return InvalidParameter;
278 pen->offset = offset;
283 GpStatus WINGDIPAPI GdipSetPenDashStyle(GpPen *pen, GpDashStyle dash)
286 return InvalidParameter;
288 if(dash != DashStyleCustom){
289 GdipFree(pen->dashes);
295 pen->style &= ~(PS_ALTERNATE | PS_SOLID | PS_DASH | PS_DOT | PS_DASHDOT |
296 PS_DASHDOTDOT | PS_NULL | PS_USERSTYLE | PS_INSIDEFRAME);
297 pen->style |= gdip_to_gdi_dash(dash);
302 GpStatus WINGDIPAPI GdipSetPenEndCap(GpPen *pen, GpLineCap cap)
304 if(!pen) return InvalidParameter;
306 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
307 GdipDeleteCustomLineCap(pen->customend);
308 pen->customend = NULL;
314 /* FIXME: startcap, dashcap not used. */
315 GpStatus WINGDIPAPI GdipSetPenLineCap197819(GpPen *pen, GpLineCap start,
316 GpLineCap end, GpDashCap dash)
319 return InvalidParameter;
321 GdipDeleteCustomLineCap(pen->customend);
322 GdipDeleteCustomLineCap(pen->customstart);
323 pen->customend = NULL;
324 pen->customstart = NULL;
326 pen->startcap = start;
333 /* FIXME: Miter line joins behave a bit differently than they do in windows.
334 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
335 GpStatus WINGDIPAPI GdipSetPenLineJoin(GpPen *pen, GpLineJoin join)
337 if(!pen) return InvalidParameter;
340 pen->style &= ~(PS_JOIN_ROUND | PS_JOIN_BEVEL | PS_JOIN_MITER);
341 pen->style |= gdip_to_gdi_join(join);
346 GpStatus WINGDIPAPI GdipSetPenMiterLimit(GpPen *pen, REAL limit)
349 return InvalidParameter;
351 pen->miterlimit = limit;
356 GpStatus WINGDIPAPI GdipSetPenStartCap(GpPen *pen, GpLineCap cap)
358 if(!pen) return InvalidParameter;
360 GdipDeleteCustomLineCap(pen->customstart);
361 pen->customstart = NULL;
367 GpStatus WINGDIPAPI GdipSetPenWidth(GpPen *pen, REAL width)
369 if(!pen) return InvalidParameter;