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 static GpPenType bt_to_pt(GpBrushType bt)
73 case BrushTypeSolidColor:
74 return PenTypeSolidColor;
75 case BrushTypeHatchFill:
76 return PenTypeHatchFill;
77 case BrushTypeTextureFill:
78 return PenTypeTextureFill;
79 case BrushTypePathGradient:
80 return PenTypePathGradient;
81 case BrushTypeLinearGradient:
82 return PenTypeLinearGradient;
84 return PenTypeUnknown;
88 GpStatus WINGDIPAPI GdipClonePen(GpPen *pen, GpPen **clonepen)
90 TRACE("(%p, %p)\n", pen, clonepen);
93 return InvalidParameter;
95 *clonepen = GdipAlloc(sizeof(GpPen));
96 if(!*clonepen) return OutOfMemory;
100 GdipCloneCustomLineCap(pen->customstart, &(*clonepen)->customstart);
101 GdipCloneCustomLineCap(pen->customend, &(*clonepen)->customend);
102 GdipCloneBrush(pen->brush, &(*clonepen)->brush);
107 GpStatus WINGDIPAPI GdipCreatePen1(ARGB color, REAL width, GpUnit unit,
113 TRACE("(%x, %.2f, %d, %p)\n", color, width, unit, pen);
115 GdipCreateSolidFill(color, (GpSolidFill **)(&brush));
116 status = GdipCreatePen2(brush, width, unit, pen);
117 GdipDeleteBrush(brush);
121 GpStatus WINGDIPAPI GdipCreatePen2(GpBrush *brush, REAL width, GpUnit unit,
125 GpBrush *clone_brush;
127 TRACE("(%p, %.2f, %d, %p)\n", brush, width, unit, pen);
130 return InvalidParameter;
132 gp_pen = GdipAlloc(sizeof(GpPen));
133 if(!gp_pen) return OutOfMemory;
135 gp_pen->style = GP_DEFAULT_PENSTYLE;
136 gp_pen->width = width;
138 gp_pen->endcap = LineCapFlat;
139 gp_pen->join = LineJoinMiter;
140 gp_pen->miterlimit = 10.0;
141 gp_pen->dash = DashStyleSolid;
142 gp_pen->offset = 0.0;
143 gp_pen->customstart = NULL;
144 gp_pen->customend = NULL;
146 if(!((gp_pen->unit == UnitWorld) || (gp_pen->unit == UnitPixel))) {
147 FIXME("UnitWorld, UnitPixel only supported units\n");
149 return NotImplemented;
152 GdipCloneBrush(brush, &clone_brush);
153 gp_pen->brush = clone_brush;
160 GpStatus WINGDIPAPI GdipDeletePen(GpPen *pen)
162 TRACE("(%p)\n", pen);
164 if(!pen) return InvalidParameter;
166 GdipDeleteBrush(pen->brush);
167 GdipDeleteCustomLineCap(pen->customstart);
168 GdipDeleteCustomLineCap(pen->customend);
169 GdipFree(pen->dashes);
175 GpStatus WINGDIPAPI GdipGetPenBrushFill(GpPen *pen, GpBrush **brush)
177 TRACE("(%p, %p)\n", pen, brush);
180 return InvalidParameter;
182 return GdipCloneBrush(pen->brush, brush);
185 GpStatus WINGDIPAPI GdipGetPenColor(GpPen *pen, ARGB *argb)
187 TRACE("(%p, %p)\n", pen, argb);
190 return InvalidParameter;
192 if(pen->brush->bt != BrushTypeSolidColor)
193 return NotImplemented;
195 return GdipGetSolidFillColor(((GpSolidFill*)pen->brush), argb);
198 GpStatus WINGDIPAPI GdipGetPenCustomEndCap(GpPen *pen, GpCustomLineCap** customCap)
200 TRACE("(%p, %p)\n", pen, customCap);
202 if(!pen || !customCap)
203 return InvalidParameter;
210 return GdipCloneCustomLineCap(pen->customend, customCap);
213 GpStatus WINGDIPAPI GdipGetPenCustomStartCap(GpPen *pen, GpCustomLineCap** customCap)
215 TRACE("(%p, %p)\n", pen, customCap);
217 if(!pen || !customCap)
218 return InvalidParameter;
220 if(!pen->customstart){
225 return GdipCloneCustomLineCap(pen->customstart, customCap);
228 GpStatus WINGDIPAPI GdipGetPenDashArray(GpPen *pen, REAL *dash, INT count)
230 TRACE("(%p, %p, %d)\n", pen, dash, count);
232 if(!pen || !dash || count > pen->numdashes)
233 return InvalidParameter;
235 /* note: if you pass a negative value for count, it crashes native gdiplus. */
239 memcpy(dash, pen->dashes, count * sizeof(REAL));
244 GpStatus WINGDIPAPI GdipGetPenDashCap197819(GpPen *pen, GpDashCap *dashCap)
246 TRACE("(%p, %p)\n", pen, dashCap);
249 return InvalidParameter;
251 *dashCap = pen->dashcap;
256 GpStatus WINGDIPAPI GdipGetPenDashCount(GpPen *pen, INT *count)
258 TRACE("(%p, %p)\n", pen, count);
261 return InvalidParameter;
263 *count = pen->numdashes;
268 GpStatus WINGDIPAPI GdipGetPenDashOffset(GpPen *pen, REAL *offset)
270 TRACE("(%p, %p)\n", pen, offset);
273 return InvalidParameter;
275 *offset = pen->offset;
280 GpStatus WINGDIPAPI GdipGetPenDashStyle(GpPen *pen, GpDashStyle *dash)
282 TRACE("(%p, %p)\n", pen, dash);
285 return InvalidParameter;
292 GpStatus WINGDIPAPI GdipGetPenEndCap(GpPen *pen, GpLineCap *endCap)
294 TRACE("(%p, %p)\n", pen, endCap);
297 return InvalidParameter;
299 *endCap = pen->endcap;
304 GpStatus WINGDIPAPI GdipGetPenFillType(GpPen *pen, GpPenType* type)
306 TRACE("(%p, %p)\n", pen, type);
309 return InvalidParameter;
311 *type = bt_to_pt(pen->brush->bt);
316 GpStatus WINGDIPAPI GdipGetPenLineJoin(GpPen *pen, GpLineJoin *lineJoin)
318 TRACE("(%p, %p)\n", pen, lineJoin);
320 if(!pen || !lineJoin)
321 return InvalidParameter;
323 *lineJoin = pen->join;
328 GpStatus WINGDIPAPI GdipGetPenMode(GpPen *pen, GpPenAlignment *mode)
330 TRACE("(%p, %p)\n", pen, mode);
333 return InvalidParameter;
340 GpStatus WINGDIPAPI GdipGetPenMiterLimit(GpPen *pen, REAL *miterLimit)
342 TRACE("(%p, %p)\n", pen, miterLimit);
344 if(!pen || !miterLimit)
345 return InvalidParameter;
347 *miterLimit = pen->miterlimit;
352 GpStatus WINGDIPAPI GdipGetPenStartCap(GpPen *pen, GpLineCap *startCap)
354 TRACE("(%p, %p)\n", pen, startCap);
356 if(!pen || !startCap)
357 return InvalidParameter;
359 *startCap = pen->startcap;
364 GpStatus WINGDIPAPI GdipGetPenUnit(GpPen *pen, GpUnit *unit)
366 TRACE("(%p, %p)\n", pen, unit);
369 return InvalidParameter;
376 GpStatus WINGDIPAPI GdipGetPenWidth(GpPen *pen, REAL *width)
378 TRACE("(%p, %p)\n", pen, width);
381 return InvalidParameter;
388 GpStatus WINGDIPAPI GdipResetPenTransform(GpPen *pen)
393 return InvalidParameter;
396 FIXME("(%p) stub\n", pen);
398 return NotImplemented;
401 GpStatus WINGDIPAPI GdipScalePenTransform(GpPen *pen, REAL sx, REAL sy, GpMatrixOrder order)
406 return InvalidParameter;
409 FIXME("(%p, %.2f, %.2f, %d) stub\n", pen, sx, sy, order);
411 return NotImplemented;
414 GpStatus WINGDIPAPI GdipSetPenBrushFill(GpPen *pen, GpBrush *brush)
416 TRACE("(%p, %p)\n", pen, brush);
419 return InvalidParameter;
421 GdipDeleteBrush(pen->brush);
422 return GdipCloneBrush(brush, &pen->brush);
425 GpStatus WINGDIPAPI GdipSetPenColor(GpPen *pen, ARGB argb)
427 TRACE("(%p, %x)\n", pen, argb);
430 return InvalidParameter;
432 if(pen->brush->bt != BrushTypeSolidColor)
433 return NotImplemented;
435 return GdipSetSolidFillColor(((GpSolidFill*)pen->brush), argb);
438 GpStatus WINGDIPAPI GdipSetPenCompoundArray(GpPen *pen, GDIPCONST REAL *dash,
441 FIXME("(%p, %p, %i): stub\n", pen, dash, count);
443 if (!pen || !dash || count < 2 || count%2 == 1)
444 return InvalidParameter;
446 return NotImplemented;
449 GpStatus WINGDIPAPI GdipSetPenCustomEndCap(GpPen *pen, GpCustomLineCap* customCap)
451 GpCustomLineCap * cap;
454 TRACE("(%p, %p)\n", pen, customCap);
456 /* native crashes on pen == NULL, customCap != NULL */
457 if(!customCap) return InvalidParameter;
459 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
460 GdipDeleteCustomLineCap(pen->customend);
461 pen->endcap = LineCapCustom;
462 pen->customend = cap;
468 GpStatus WINGDIPAPI GdipSetPenCustomStartCap(GpPen *pen, GpCustomLineCap* customCap)
470 GpCustomLineCap * cap;
473 TRACE("(%p, %p)\n", pen, customCap);
475 /* native crashes on pen == NULL, customCap != NULL */
476 if(!customCap) return InvalidParameter;
478 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
479 GdipDeleteCustomLineCap(pen->customstart);
480 pen->startcap = LineCapCustom;
481 pen->customstart = cap;
487 GpStatus WINGDIPAPI GdipSetPenDashArray(GpPen *pen, GDIPCONST REAL *dash,
493 TRACE("(%p, %p, %d)\n", pen, dash, count);
496 return InvalidParameter;
501 for(i = 0; i < count; i++){
504 return InvalidParameter;
507 if(sum == 0.0 && count)
508 return InvalidParameter;
510 GdipFree(pen->dashes);
514 pen->dashes = GdipAlloc(count * sizeof(REAL));
520 GdipSetPenDashStyle(pen, DashStyleCustom);
521 memcpy(pen->dashes, dash, count * sizeof(REAL));
522 pen->numdashes = count;
527 GpStatus WINGDIPAPI GdipSetPenDashCap197819(GpPen *pen, GpDashCap dashCap)
529 TRACE("(%p, %d)\n", pen, dashCap);
532 return InvalidParameter;
534 pen->dashcap = dashCap;
539 /* FIXME: dash offset not used */
540 GpStatus WINGDIPAPI GdipSetPenDashOffset(GpPen *pen, REAL offset)
542 TRACE("(%p, %.2f)\n", pen, offset);
545 return InvalidParameter;
547 pen->offset = offset;
552 GpStatus WINGDIPAPI GdipSetPenDashStyle(GpPen *pen, GpDashStyle dash)
554 TRACE("(%p, %d)\n", pen, dash);
557 return InvalidParameter;
559 if(dash != DashStyleCustom){
560 GdipFree(pen->dashes);
566 pen->style &= ~(PS_ALTERNATE | PS_SOLID | PS_DASH | PS_DOT | PS_DASHDOT |
567 PS_DASHDOTDOT | PS_NULL | PS_USERSTYLE | PS_INSIDEFRAME);
568 pen->style |= gdip_to_gdi_dash(dash);
573 GpStatus WINGDIPAPI GdipSetPenEndCap(GpPen *pen, GpLineCap cap)
575 TRACE("(%p, %d)\n", pen, cap);
577 if(!pen) return InvalidParameter;
579 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
580 GdipDeleteCustomLineCap(pen->customend);
581 pen->customend = NULL;
587 /* FIXME: startcap, dashcap not used. */
588 GpStatus WINGDIPAPI GdipSetPenLineCap197819(GpPen *pen, GpLineCap start,
589 GpLineCap end, GpDashCap dash)
591 TRACE("%p, %d, %d, %d)\n", pen, start, end, dash);
594 return InvalidParameter;
596 GdipDeleteCustomLineCap(pen->customend);
597 GdipDeleteCustomLineCap(pen->customstart);
598 pen->customend = NULL;
599 pen->customstart = NULL;
601 pen->startcap = start;
608 /* FIXME: Miter line joins behave a bit differently than they do in windows.
609 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
610 GpStatus WINGDIPAPI GdipSetPenLineJoin(GpPen *pen, GpLineJoin join)
612 TRACE("(%p, %d)\n", pen, join);
614 if(!pen) return InvalidParameter;
617 pen->style &= ~(PS_JOIN_ROUND | PS_JOIN_BEVEL | PS_JOIN_MITER);
618 pen->style |= gdip_to_gdi_join(join);
623 GpStatus WINGDIPAPI GdipSetPenMiterLimit(GpPen *pen, REAL limit)
625 TRACE("(%p, %.2f)\n", pen, limit);
628 return InvalidParameter;
630 pen->miterlimit = limit;
635 GpStatus WINGDIPAPI GdipSetPenStartCap(GpPen *pen, GpLineCap cap)
637 TRACE("(%p, %d)\n", pen, cap);
639 if(!pen) return InvalidParameter;
641 GdipDeleteCustomLineCap(pen->customstart);
642 pen->customstart = NULL;
648 GpStatus WINGDIPAPI GdipSetPenWidth(GpPen *pen, REAL width)
650 TRACE("(%p, %.2f)\n", pen, width);
652 if(!pen) return InvalidParameter;
659 GpStatus WINGDIPAPI GdipSetPenMode(GpPen *pen, GpPenAlignment mode)
661 TRACE("(%p, %d)\n", pen, mode);
663 if(!pen) return InvalidParameter;