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
;
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
,
91 GdipCreateSolidFill(color
, (GpSolidFill
**)(&brush
));
92 return GdipCreatePen2(brush
, width
, unit
, pen
);
95 GpStatus WINGDIPAPI
GdipCreatePen2(GpBrush
*brush
, REAL width
, GpUnit unit
,
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
;
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");
119 return NotImplemented
;
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
);
140 GpStatus WINGDIPAPI
GdipGetPenBrushFill(GpPen
*pen
, GpBrush
**brush
)
143 return InvalidParameter
;
145 return GdipCloneBrush(pen
->brush
, brush
);
148 GpStatus WINGDIPAPI
GdipGetPenColor(GpPen
*pen
, ARGB
*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. */
168 memcpy(dash
, pen
->dashes
, count
* sizeof(REAL
));
173 GpStatus WINGDIPAPI
GdipGetPenDashOffset(GpPen
*pen
, REAL
*offset
)
176 return InvalidParameter
;
178 *offset
= pen
->offset
;
183 GpStatus WINGDIPAPI
GdipGetPenDashStyle(GpPen
*pen
, GpDashStyle
*dash
)
186 return InvalidParameter
;
193 GpStatus WINGDIPAPI
GdipSetPenBrushFill(GpPen
*pen
, GpBrush
*brush
)
196 return InvalidParameter
;
198 GdipDeleteBrush(pen
->brush
);
199 return GdipCloneBrush(brush
, &pen
->brush
);
202 GpStatus WINGDIPAPI
GdipSetPenColor(GpPen
*pen
, ARGB argb
)
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
;
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
;
229 GpStatus WINGDIPAPI
GdipSetPenCustomStartCap(GpPen
*pen
, GpCustomLineCap
* customCap
)
231 GpCustomLineCap
* cap
;
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
;
245 GpStatus WINGDIPAPI
GdipSetPenDashArray(GpPen
*pen
, GDIPCONST REAL
*dash
,
252 return InvalidParameter
;
257 for(i
= 0; i
< count
; i
++){
260 return InvalidParameter
;
263 if(sum
== 0.0 && count
)
264 return InvalidParameter
;
266 GdipFree(pen
->dashes
);
270 pen
->dashes
= GdipAlloc(count
* sizeof(REAL
));
276 GdipSetPenDashStyle(pen
, DashStyleCustom
);
277 memcpy(pen
->dashes
, dash
, count
* sizeof(REAL
));
278 pen
->numdashes
= count
;
283 /* FIXME: dash offset not used */
284 GpStatus WINGDIPAPI
GdipSetPenDashOffset(GpPen
*pen
, REAL offset
)
287 return InvalidParameter
;
289 pen
->offset
= offset
;
294 GpStatus WINGDIPAPI
GdipSetPenDashStyle(GpPen
*pen
, GpDashStyle dash
)
297 return InvalidParameter
;
299 if(dash
!= DashStyleCustom
){
300 GdipFree(pen
->dashes
);
306 pen
->style
&= ~(PS_ALTERNATE
| PS_SOLID
| PS_DASH
| PS_DOT
| PS_DASHDOT
|
307 PS_DASHDOTDOT
| PS_NULL
| PS_USERSTYLE
| PS_INSIDEFRAME
);
308 pen
->style
|= gdip_to_gdi_dash(dash
);
313 GpStatus WINGDIPAPI
GdipSetPenEndCap(GpPen
*pen
, GpLineCap cap
)
315 if(!pen
) return InvalidParameter
;
317 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
318 GdipDeleteCustomLineCap(pen
->customend
);
319 pen
->customend
= NULL
;
325 /* FIXME: startcap, dashcap not used. */
326 GpStatus WINGDIPAPI
GdipSetPenLineCap197819(GpPen
*pen
, GpLineCap start
,
327 GpLineCap end
, GpDashCap dash
)
330 return InvalidParameter
;
332 GdipDeleteCustomLineCap(pen
->customend
);
333 GdipDeleteCustomLineCap(pen
->customstart
);
334 pen
->customend
= NULL
;
335 pen
->customstart
= NULL
;
337 pen
->startcap
= start
;
344 /* FIXME: Miter line joins behave a bit differently than they do in windows.
345 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
346 GpStatus WINGDIPAPI
GdipSetPenLineJoin(GpPen
*pen
, GpLineJoin join
)
348 if(!pen
) return InvalidParameter
;
351 pen
->style
&= ~(PS_JOIN_ROUND
| PS_JOIN_BEVEL
| PS_JOIN_MITER
);
352 pen
->style
|= gdip_to_gdi_join(join
);
357 GpStatus WINGDIPAPI
GdipSetPenMiterLimit(GpPen
*pen
, REAL limit
)
360 return InvalidParameter
;
362 pen
->miterlimit
= limit
;
367 GpStatus WINGDIPAPI
GdipSetPenStartCap(GpPen
*pen
, GpLineCap cap
)
369 if(!pen
) return InvalidParameter
;
371 GdipDeleteCustomLineCap(pen
->customstart
);
372 pen
->customstart
= NULL
;
378 GpStatus WINGDIPAPI
GdipSetPenWidth(GpPen
*pen
, REAL width
)
380 if(!pen
) return InvalidParameter
;
388 GpStatus WINGDIPAPI
GdipSetPenMode(GpPen
*pen
, GpPenAlignment penAlignment
)
390 if(!pen
) return InvalidParameter
;
392 FIXME("stub (%d)\n", penAlignment
);