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
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)
39 case DashStyleDashDot:
41 case DashStyleDashDotDot:
46 ERR("Not a member of GpDashStyle enumeration\n");
51 static DWORD gdip_to_gdi_join(GpLineJoin join)
59 case LineJoinMiterClipped:
62 ERR("Not a member of GpLineJoin enumeration\n");
67 GpStatus WINGDIPAPI GdipClonePen(GpPen *pen, GpPen **clonepen)
70 return InvalidParameter;
72 *clonepen = GdipAlloc(sizeof(GpPen));
73 if(!*clonepen) return OutOfMemory;
75 memcpy(*clonepen, pen, sizeof(GpPen));
77 GdipCloneCustomLineCap(pen->customstart, &(*clonepen)->customstart);
78 GdipCloneCustomLineCap(pen->customend, &(*clonepen)->customend);
79 GdipCloneBrush(pen->brush, &(*clonepen)->brush);
84 GpStatus WINGDIPAPI GdipCreatePen1(ARGB color, FLOAT width, GpUnit unit,
90 return InvalidParameter;
92 gp_pen = GdipAlloc(sizeof(GpPen));
93 if(!gp_pen) return OutOfMemory;
95 gp_pen->style = GP_DEFAULT_PENSTYLE;
96 gp_pen->width = width;
98 gp_pen->endcap = LineCapFlat;
99 gp_pen->join = LineJoinMiter;
100 gp_pen->miterlimit = 10.0;
101 gp_pen->dash = DashStyleSolid;
102 GdipCreateSolidFill(color, (GpSolidFill **)(&gp_pen->brush));
104 if(!((gp_pen->unit == UnitWorld) || (gp_pen->unit == UnitPixel))) {
105 FIXME("UnitWorld, UnitPixel only supported units\n");
107 return NotImplemented;
115 GpStatus WINGDIPAPI GdipDeletePen(GpPen *pen)
117 if(!pen) return InvalidParameter;
119 GdipDeleteBrush(pen->brush);
120 GdipDeleteCustomLineCap(pen->customstart);
121 GdipDeleteCustomLineCap(pen->customend);
122 GdipFree(pen->dashes);
128 GpStatus WINGDIPAPI GdipGetPenBrushFill(GpPen *pen, GpBrush **brush)
131 return InvalidParameter;
133 return GdipCloneBrush(pen->brush, brush);
136 GpStatus WINGDIPAPI GdipGetPenColor(GpPen *pen, ARGB *argb)
139 return InvalidParameter;
141 if(pen->brush->bt != BrushTypeSolidColor)
142 return NotImplemented;
144 return GdipGetSolidFillColor(((GpSolidFill*)pen->brush), argb);
147 GpStatus WINGDIPAPI GdipGetPenDashArray(GpPen *pen, REAL *dash, INT count)
149 if(!pen || !dash || count > pen->numdashes)
150 return InvalidParameter;
152 /* note: if you pass a negative value for count, it crashes native gdiplus. */
156 memcpy(dash, pen->dashes, count * sizeof(REAL));
161 GpStatus WINGDIPAPI GdipGetPenDashStyle(GpPen *pen, GpDashStyle *dash)
164 return InvalidParameter;
171 GpStatus WINGDIPAPI GdipSetPenBrushFill(GpPen *pen, GpBrush *brush)
174 return InvalidParameter;
176 GdipDeleteBrush(pen->brush);
177 return GdipCloneBrush(brush, &pen->brush);
180 GpStatus WINGDIPAPI GdipSetPenColor(GpPen *pen, ARGB argb)
183 return InvalidParameter;
185 if(pen->brush->bt != BrushTypeSolidColor)
186 return NotImplemented;
188 return GdipSetSolidFillColor(((GpSolidFill*)pen->brush), argb);
191 GpStatus WINGDIPAPI GdipSetPenCustomEndCap(GpPen *pen, GpCustomLineCap* customCap)
193 GpCustomLineCap * cap;
196 if(!pen || !customCap) return InvalidParameter;
198 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
199 GdipDeleteCustomLineCap(pen->customend);
200 pen->endcap = LineCapCustom;
201 pen->customend = cap;
207 GpStatus WINGDIPAPI GdipSetPenCustomStartCap(GpPen *pen, GpCustomLineCap* customCap)
209 GpCustomLineCap * cap;
212 if(!pen || !customCap) return InvalidParameter;
214 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
215 GdipDeleteCustomLineCap(pen->customstart);
216 pen->startcap = LineCapCustom;
217 pen->customstart = cap;
223 GpStatus WINGDIPAPI GdipSetPenDashArray(GpPen *pen, GDIPCONST REAL *dash,
230 return InvalidParameter;
232 for(i = 0; i < count; i++){
235 return InvalidParameter;
238 if(sum == 0.0 && count)
239 return InvalidParameter;
241 GdipFree(pen->dashes);
245 pen->dashes = GdipAlloc(count * sizeof(REAL));
251 GdipSetPenDashStyle(pen, DashStyleCustom);
252 memcpy(pen->dashes, dash, count * sizeof(REAL));
253 pen->numdashes = count;
258 GpStatus WINGDIPAPI GdipSetPenDashStyle(GpPen *pen, GpDashStyle dash)
261 return InvalidParameter;
263 if(dash != DashStyleCustom){
264 GdipFree(pen->dashes);
270 pen->style &= ~(PS_ALTERNATE | PS_SOLID | PS_DASH | PS_DOT | PS_DASHDOT |
271 PS_DASHDOTDOT | PS_NULL | PS_USERSTYLE | PS_INSIDEFRAME);
272 pen->style |= gdip_to_gdi_dash(dash);
277 GpStatus WINGDIPAPI GdipSetPenEndCap(GpPen *pen, GpLineCap cap)
279 if(!pen) return InvalidParameter;
281 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
282 GdipDeleteCustomLineCap(pen->customend);
283 pen->customend = NULL;
289 /* FIXME: startcap, dashcap not used. */
290 GpStatus WINGDIPAPI GdipSetPenLineCap197819(GpPen *pen, GpLineCap start,
291 GpLineCap end, GpDashCap dash)
294 return InvalidParameter;
296 GdipDeleteCustomLineCap(pen->customend);
297 GdipDeleteCustomLineCap(pen->customstart);
298 pen->customend = NULL;
299 pen->customstart = NULL;
301 pen->startcap = start;
308 /* FIXME: Miter line joins behave a bit differently than they do in windows.
309 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
310 GpStatus WINGDIPAPI GdipSetPenLineJoin(GpPen *pen, GpLineJoin join)
312 if(!pen) return InvalidParameter;
315 pen->style &= ~(PS_JOIN_ROUND | PS_JOIN_BEVEL | PS_JOIN_MITER);
316 pen->style |= gdip_to_gdi_join(join);
321 GpStatus WINGDIPAPI GdipSetPenMiterLimit(GpPen *pen, REAL limit)
324 return InvalidParameter;
326 pen->miterlimit = limit;
331 GpStatus WINGDIPAPI GdipSetPenStartCap(GpPen *pen, GpLineCap cap)
333 if(!pen) return InvalidParameter;
335 GdipDeleteCustomLineCap(pen->customstart);
336 pen->customstart = NULL;