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
)
41 case DashStyleDashDot
:
43 case DashStyleDashDotDot
:
47 FIXME("DashStyleCustom not implemented\n");
50 ERR("Not a member of GpDashStyle enumeration\n");
55 static DWORD
gdip_to_gdi_join(GpLineJoin join
)
63 case LineJoinMiterClipped
:
66 ERR("Not a member of GpLineJoin enumeration\n");
71 GpStatus WINGDIPAPI
GdipClonePen(GpPen
*pen
, GpPen
**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
);
88 GpStatus WINGDIPAPI
GdipCreatePen1(ARGB color
, FLOAT width
, GpUnit unit
,
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
;
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");
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
GdipGetPenDashStyle(GpPen
*pen
, GpDashStyle
*dash
)
168 return InvalidParameter
;
175 GpStatus WINGDIPAPI
GdipSetPenBrushFill(GpPen
*pen
, GpBrush
*brush
)
178 return InvalidParameter
;
180 GdipDeleteBrush(pen
->brush
);
181 return GdipCloneBrush(brush
, &pen
->brush
);
184 GpStatus WINGDIPAPI
GdipSetPenColor(GpPen
*pen
, ARGB argb
)
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
;
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
;
211 GpStatus WINGDIPAPI
GdipSetPenCustomStartCap(GpPen
*pen
, GpCustomLineCap
* customCap
)
213 GpCustomLineCap
* cap
;
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
;
227 GpStatus WINGDIPAPI
GdipSetPenDashArray(GpPen
*pen
, GDIPCONST REAL
*dash
,
231 return InvalidParameter
;
233 GdipFree(pen
->dashes
);
237 pen
->dashes
= GdipAlloc(count
* sizeof(REAL
));
243 pen
->dash
= DashStyleCustom
;
244 memcpy(pen
->dashes
, dash
, count
* sizeof(REAL
));
245 pen
->numdashes
= count
;
250 GpStatus WINGDIPAPI
GdipSetPenDashStyle(GpPen
*pen
, GpDashStyle dash
)
253 return InvalidParameter
;
255 if(dash
!= DashStyleCustom
){
256 GdipFree(pen
->dashes
);
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
);
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
;
281 /* FIXME: startcap, dashcap not used. */
282 GpStatus WINGDIPAPI
GdipSetPenLineCap197819(GpPen
*pen
, GpLineCap start
,
283 GpLineCap end
, GpDashCap dash
)
286 return InvalidParameter
;
288 GdipDeleteCustomLineCap(pen
->customend
);
289 GdipDeleteCustomLineCap(pen
->customstart
);
290 pen
->customend
= NULL
;
291 pen
->customstart
= NULL
;
293 pen
->startcap
= start
;
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
;
307 pen
->style
&= ~(PS_JOIN_ROUND
| PS_JOIN_BEVEL
| PS_JOIN_MITER
);
308 pen
->style
|= gdip_to_gdi_join(join
);
313 GpStatus WINGDIPAPI
GdipSetPenMiterLimit(GpPen
*pen
, REAL limit
)
316 return InvalidParameter
;
318 pen
->miterlimit
= limit
;
323 GpStatus WINGDIPAPI
GdipSetPenStartCap(GpPen
*pen
, GpLineCap cap
)
325 if(!pen
) return InvalidParameter
;
327 GdipDeleteCustomLineCap(pen
->customstart
);
328 pen
->customstart
= NULL
;