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
,
93 GdipCreateSolidFill(color
, (GpSolidFill
**)(&brush
));
94 status
= GdipCreatePen2(brush
, width
, unit
, pen
);
95 GdipDeleteBrush(brush
);
99 GpStatus WINGDIPAPI
GdipCreatePen2(GpBrush
*brush
, REAL width
, GpUnit unit
,
103 GpBrush
*clone_brush
;
106 return InvalidParameter
;
108 gp_pen
= GdipAlloc(sizeof(GpPen
));
109 if(!gp_pen
) return OutOfMemory
;
111 gp_pen
->style
= GP_DEFAULT_PENSTYLE
;
112 gp_pen
->width
= width
;
114 gp_pen
->endcap
= LineCapFlat
;
115 gp_pen
->join
= LineJoinMiter
;
116 gp_pen
->miterlimit
= 10.0;
117 gp_pen
->dash
= DashStyleSolid
;
118 gp_pen
->offset
= 0.0;
120 if(!((gp_pen
->unit
== UnitWorld
) || (gp_pen
->unit
== UnitPixel
))) {
121 FIXME("UnitWorld, UnitPixel only supported units\n");
123 return NotImplemented
;
126 GdipCloneBrush(brush
, &clone_brush
);
127 gp_pen
->brush
= clone_brush
;
134 GpStatus WINGDIPAPI
GdipDeletePen(GpPen
*pen
)
136 if(!pen
) return InvalidParameter
;
138 GdipDeleteBrush(pen
->brush
);
139 GdipDeleteCustomLineCap(pen
->customstart
);
140 GdipDeleteCustomLineCap(pen
->customend
);
141 GdipFree(pen
->dashes
);
147 GpStatus WINGDIPAPI
GdipGetPenBrushFill(GpPen
*pen
, GpBrush
**brush
)
150 return InvalidParameter
;
152 return GdipCloneBrush(pen
->brush
, brush
);
155 GpStatus WINGDIPAPI
GdipGetPenColor(GpPen
*pen
, ARGB
*argb
)
158 return InvalidParameter
;
160 if(pen
->brush
->bt
!= BrushTypeSolidColor
)
161 return NotImplemented
;
163 return GdipGetSolidFillColor(((GpSolidFill
*)pen
->brush
), argb
);
166 GpStatus WINGDIPAPI
GdipGetPenDashArray(GpPen
*pen
, REAL
*dash
, INT count
)
168 if(!pen
|| !dash
|| count
> pen
->numdashes
)
169 return InvalidParameter
;
171 /* note: if you pass a negative value for count, it crashes native gdiplus. */
175 memcpy(dash
, pen
->dashes
, count
* sizeof(REAL
));
180 GpStatus WINGDIPAPI
GdipGetPenDashOffset(GpPen
*pen
, REAL
*offset
)
183 return InvalidParameter
;
185 *offset
= pen
->offset
;
190 GpStatus WINGDIPAPI
GdipGetPenDashStyle(GpPen
*pen
, GpDashStyle
*dash
)
193 return InvalidParameter
;
200 GpStatus WINGDIPAPI
GdipGetPenEndCap(GpPen
*pen
, GpLineCap
*endCap
)
203 return InvalidParameter
;
205 *endCap
= pen
->endcap
;
210 GpStatus WINGDIPAPI
GdipGetPenLineJoin(GpPen
*pen
, GpLineJoin
*lineJoin
)
212 if(!pen
|| !lineJoin
)
213 return InvalidParameter
;
215 *lineJoin
= pen
->join
;
220 GpStatus WINGDIPAPI
GdipGetPenMiterLimit(GpPen
*pen
, REAL
*miterLimit
)
222 if(!pen
|| !miterLimit
)
223 return InvalidParameter
;
225 *miterLimit
= pen
->miterlimit
;
230 GpStatus WINGDIPAPI
GdipGetPenStartCap(GpPen
*pen
, GpLineCap
*startCap
)
232 if(!pen
|| !startCap
)
233 return InvalidParameter
;
235 *startCap
= pen
->startcap
;
240 GpStatus WINGDIPAPI
GdipGetPenUnit(GpPen
*pen
, GpUnit
*unit
)
243 return InvalidParameter
;
250 GpStatus WINGDIPAPI
GdipGetPenWidth(GpPen
*pen
, REAL
*width
)
253 return InvalidParameter
;
260 GpStatus WINGDIPAPI
GdipSetPenBrushFill(GpPen
*pen
, GpBrush
*brush
)
263 return InvalidParameter
;
265 GdipDeleteBrush(pen
->brush
);
266 return GdipCloneBrush(brush
, &pen
->brush
);
269 GpStatus WINGDIPAPI
GdipSetPenColor(GpPen
*pen
, ARGB argb
)
272 return InvalidParameter
;
274 if(pen
->brush
->bt
!= BrushTypeSolidColor
)
275 return NotImplemented
;
277 return GdipSetSolidFillColor(((GpSolidFill
*)pen
->brush
), argb
);
280 GpStatus WINGDIPAPI
GdipSetPenCustomEndCap(GpPen
*pen
, GpCustomLineCap
* customCap
)
282 GpCustomLineCap
* cap
;
285 if(!pen
|| !customCap
) return InvalidParameter
;
287 if((ret
= GdipCloneCustomLineCap(customCap
, &cap
)) == Ok
){
288 GdipDeleteCustomLineCap(pen
->customend
);
289 pen
->endcap
= LineCapCustom
;
290 pen
->customend
= cap
;
296 GpStatus WINGDIPAPI
GdipSetPenCustomStartCap(GpPen
*pen
, GpCustomLineCap
* customCap
)
298 GpCustomLineCap
* cap
;
301 if(!pen
|| !customCap
) return InvalidParameter
;
303 if((ret
= GdipCloneCustomLineCap(customCap
, &cap
)) == Ok
){
304 GdipDeleteCustomLineCap(pen
->customstart
);
305 pen
->startcap
= LineCapCustom
;
306 pen
->customstart
= cap
;
312 GpStatus WINGDIPAPI
GdipSetPenDashArray(GpPen
*pen
, GDIPCONST REAL
*dash
,
319 return InvalidParameter
;
324 for(i
= 0; i
< count
; i
++){
327 return InvalidParameter
;
330 if(sum
== 0.0 && count
)
331 return InvalidParameter
;
333 GdipFree(pen
->dashes
);
337 pen
->dashes
= GdipAlloc(count
* sizeof(REAL
));
343 GdipSetPenDashStyle(pen
, DashStyleCustom
);
344 memcpy(pen
->dashes
, dash
, count
* sizeof(REAL
));
345 pen
->numdashes
= count
;
350 /* FIXME: dash offset not used */
351 GpStatus WINGDIPAPI
GdipSetPenDashOffset(GpPen
*pen
, REAL offset
)
354 return InvalidParameter
;
356 pen
->offset
= offset
;
361 GpStatus WINGDIPAPI
GdipSetPenDashStyle(GpPen
*pen
, GpDashStyle dash
)
364 return InvalidParameter
;
366 if(dash
!= DashStyleCustom
){
367 GdipFree(pen
->dashes
);
373 pen
->style
&= ~(PS_ALTERNATE
| PS_SOLID
| PS_DASH
| PS_DOT
| PS_DASHDOT
|
374 PS_DASHDOTDOT
| PS_NULL
| PS_USERSTYLE
| PS_INSIDEFRAME
);
375 pen
->style
|= gdip_to_gdi_dash(dash
);
380 GpStatus WINGDIPAPI
GdipSetPenEndCap(GpPen
*pen
, GpLineCap cap
)
382 if(!pen
) return InvalidParameter
;
384 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
385 GdipDeleteCustomLineCap(pen
->customend
);
386 pen
->customend
= NULL
;
392 /* FIXME: startcap, dashcap not used. */
393 GpStatus WINGDIPAPI
GdipSetPenLineCap197819(GpPen
*pen
, GpLineCap start
,
394 GpLineCap end
, GpDashCap dash
)
397 return InvalidParameter
;
399 GdipDeleteCustomLineCap(pen
->customend
);
400 GdipDeleteCustomLineCap(pen
->customstart
);
401 pen
->customend
= NULL
;
402 pen
->customstart
= NULL
;
404 pen
->startcap
= start
;
411 /* FIXME: Miter line joins behave a bit differently than they do in windows.
412 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
413 GpStatus WINGDIPAPI
GdipSetPenLineJoin(GpPen
*pen
, GpLineJoin join
)
415 if(!pen
) return InvalidParameter
;
418 pen
->style
&= ~(PS_JOIN_ROUND
| PS_JOIN_BEVEL
| PS_JOIN_MITER
);
419 pen
->style
|= gdip_to_gdi_join(join
);
424 GpStatus WINGDIPAPI
GdipSetPenMiterLimit(GpPen
*pen
, REAL limit
)
427 return InvalidParameter
;
429 pen
->miterlimit
= limit
;
434 GpStatus WINGDIPAPI
GdipSetPenStartCap(GpPen
*pen
, GpLineCap cap
)
436 if(!pen
) return InvalidParameter
;
438 GdipDeleteCustomLineCap(pen
->customstart
);
439 pen
->customstart
= NULL
;
445 GpStatus WINGDIPAPI
GdipSetPenWidth(GpPen
*pen
, REAL width
)
447 if(!pen
) return InvalidParameter
;
455 GpStatus WINGDIPAPI
GdipSetPenMode(GpPen
*pen
, GpPenAlignment penAlignment
)
457 if(!pen
) return InvalidParameter
;
459 FIXME("stub (%d)\n", penAlignment
);