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);
104 TRACE("<-- %p\n", *clonepen);
109 GpStatus WINGDIPAPI GdipCreatePen1(ARGB color, REAL width, GpUnit unit,
115 TRACE("(%x, %.2f, %d, %p)\n", color, width, unit, pen);
117 GdipCreateSolidFill(color, (GpSolidFill **)(&brush));
118 status = GdipCreatePen2(brush, width, unit, pen);
119 GdipDeleteBrush(brush);
123 GpStatus WINGDIPAPI GdipCreatePen2(GpBrush *brush, REAL width, GpUnit unit,
127 GpBrush *clone_brush;
129 TRACE("(%p, %.2f, %d, %p)\n", brush, width, unit, pen);
132 return InvalidParameter;
134 gp_pen = GdipAlloc(sizeof(GpPen));
135 if(!gp_pen) return OutOfMemory;
137 gp_pen->style = GP_DEFAULT_PENSTYLE;
138 gp_pen->width = width;
140 gp_pen->endcap = LineCapFlat;
141 gp_pen->join = LineJoinMiter;
142 gp_pen->miterlimit = 10.0;
143 gp_pen->dash = DashStyleSolid;
144 gp_pen->offset = 0.0;
145 gp_pen->customstart = NULL;
146 gp_pen->customend = NULL;
148 if(!((gp_pen->unit == UnitWorld) || (gp_pen->unit == UnitPixel))) {
149 FIXME("UnitWorld, UnitPixel only supported units\n");
151 return NotImplemented;
154 GdipCloneBrush(brush, &clone_brush);
155 gp_pen->brush = clone_brush;
159 TRACE("<-- %p\n", *pen);
164 GpStatus WINGDIPAPI GdipDeletePen(GpPen *pen)
166 TRACE("(%p)\n", pen);
168 if(!pen) return InvalidParameter;
170 GdipDeleteBrush(pen->brush);
171 GdipDeleteCustomLineCap(pen->customstart);
172 GdipDeleteCustomLineCap(pen->customend);
173 GdipFree(pen->dashes);
179 GpStatus WINGDIPAPI GdipGetPenBrushFill(GpPen *pen, GpBrush **brush)
181 TRACE("(%p, %p)\n", pen, brush);
184 return InvalidParameter;
186 return GdipCloneBrush(pen->brush, brush);
189 GpStatus WINGDIPAPI GdipGetPenColor(GpPen *pen, ARGB *argb)
191 TRACE("(%p, %p)\n", pen, argb);
194 return InvalidParameter;
196 if(pen->brush->bt != BrushTypeSolidColor)
197 return NotImplemented;
199 return GdipGetSolidFillColor(((GpSolidFill*)pen->brush), argb);
202 GpStatus WINGDIPAPI GdipGetPenCustomEndCap(GpPen *pen, GpCustomLineCap** customCap)
204 TRACE("(%p, %p)\n", pen, customCap);
206 if(!pen || !customCap)
207 return InvalidParameter;
214 return GdipCloneCustomLineCap(pen->customend, customCap);
217 GpStatus WINGDIPAPI GdipGetPenCustomStartCap(GpPen *pen, GpCustomLineCap** customCap)
219 TRACE("(%p, %p)\n", pen, customCap);
221 if(!pen || !customCap)
222 return InvalidParameter;
224 if(!pen->customstart){
229 return GdipCloneCustomLineCap(pen->customstart, customCap);
232 GpStatus WINGDIPAPI GdipGetPenDashArray(GpPen *pen, REAL *dash, INT count)
234 TRACE("(%p, %p, %d)\n", pen, dash, count);
236 if(!pen || !dash || count > pen->numdashes)
237 return InvalidParameter;
239 /* note: if you pass a negative value for count, it crashes native gdiplus. */
243 memcpy(dash, pen->dashes, count * sizeof(REAL));
248 GpStatus WINGDIPAPI GdipGetPenDashCap197819(GpPen *pen, GpDashCap *dashCap)
250 TRACE("(%p, %p)\n", pen, dashCap);
253 return InvalidParameter;
255 *dashCap = pen->dashcap;
260 GpStatus WINGDIPAPI GdipGetPenDashCount(GpPen *pen, INT *count)
262 TRACE("(%p, %p)\n", pen, count);
265 return InvalidParameter;
267 *count = pen->numdashes;
272 GpStatus WINGDIPAPI GdipGetPenDashOffset(GpPen *pen, REAL *offset)
274 TRACE("(%p, %p)\n", pen, offset);
277 return InvalidParameter;
279 *offset = pen->offset;
284 GpStatus WINGDIPAPI GdipGetPenDashStyle(GpPen *pen, GpDashStyle *dash)
286 TRACE("(%p, %p)\n", pen, dash);
289 return InvalidParameter;
296 GpStatus WINGDIPAPI GdipGetPenEndCap(GpPen *pen, GpLineCap *endCap)
298 TRACE("(%p, %p)\n", pen, endCap);
301 return InvalidParameter;
303 *endCap = pen->endcap;
308 GpStatus WINGDIPAPI GdipGetPenFillType(GpPen *pen, GpPenType* type)
310 TRACE("(%p, %p)\n", pen, type);
313 return InvalidParameter;
315 *type = bt_to_pt(pen->brush->bt);
320 GpStatus WINGDIPAPI GdipGetPenLineJoin(GpPen *pen, GpLineJoin *lineJoin)
322 TRACE("(%p, %p)\n", pen, lineJoin);
324 if(!pen || !lineJoin)
325 return InvalidParameter;
327 *lineJoin = pen->join;
332 GpStatus WINGDIPAPI GdipGetPenMode(GpPen *pen, GpPenAlignment *mode)
334 TRACE("(%p, %p)\n", pen, mode);
337 return InvalidParameter;
344 GpStatus WINGDIPAPI GdipGetPenMiterLimit(GpPen *pen, REAL *miterLimit)
346 TRACE("(%p, %p)\n", pen, miterLimit);
348 if(!pen || !miterLimit)
349 return InvalidParameter;
351 *miterLimit = pen->miterlimit;
356 GpStatus WINGDIPAPI GdipGetPenStartCap(GpPen *pen, GpLineCap *startCap)
358 TRACE("(%p, %p)\n", pen, startCap);
360 if(!pen || !startCap)
361 return InvalidParameter;
363 *startCap = pen->startcap;
368 GpStatus WINGDIPAPI GdipGetPenUnit(GpPen *pen, GpUnit *unit)
370 TRACE("(%p, %p)\n", pen, unit);
373 return InvalidParameter;
380 GpStatus WINGDIPAPI GdipGetPenWidth(GpPen *pen, REAL *width)
382 TRACE("(%p, %p)\n", pen, width);
385 return InvalidParameter;
392 GpStatus WINGDIPAPI GdipResetPenTransform(GpPen *pen)
396 TRACE("(%p)\n", pen);
399 return InvalidParameter;
402 FIXME("(%p) stub\n", pen);
404 return NotImplemented;
407 GpStatus WINGDIPAPI GdipSetPenTransform(GpPen *pen, GpMatrix *matrix)
411 TRACE("(%p,%p)\n", pen, matrix);
414 return InvalidParameter;
417 FIXME("not implemented\n");
419 return NotImplemented;
422 GpStatus WINGDIPAPI GdipGetPenTransform(GpPen *pen, GpMatrix *matrix)
426 TRACE("(%p,%p)\n", pen, matrix);
429 return InvalidParameter;
432 FIXME("not implemented\n");
434 return NotImplemented;
437 GpStatus WINGDIPAPI GdipScalePenTransform(GpPen *pen, REAL sx, REAL sy, GpMatrixOrder order)
441 TRACE("(%p,%0.2f,%0.2f,%u)\n", pen, sx, sy, order);
444 return InvalidParameter;
447 FIXME("(%p, %.2f, %.2f, %d) stub\n", pen, sx, sy, order);
449 return NotImplemented;
452 GpStatus WINGDIPAPI GdipRotatePenTransform(GpPen *pen, REAL angle, GpMatrixOrder order)
456 TRACE("(%p,%0.2f,%u)\n", pen, angle, order);
459 return InvalidParameter;
462 FIXME("not implemented\n");
464 return NotImplemented;
467 GpStatus WINGDIPAPI GdipMultiplyPenTransform(GpPen *pen, GDIPCONST GpMatrix *matrix,
472 TRACE("(%p,%p,%u)\n", pen, matrix, order);
475 return InvalidParameter;
478 FIXME("not implemented\n");
480 return NotImplemented;
483 GpStatus WINGDIPAPI GdipSetPenBrushFill(GpPen *pen, GpBrush *brush)
485 TRACE("(%p, %p)\n", pen, brush);
488 return InvalidParameter;
490 GdipDeleteBrush(pen->brush);
491 return GdipCloneBrush(brush, &pen->brush);
494 GpStatus WINGDIPAPI GdipSetPenColor(GpPen *pen, ARGB argb)
496 TRACE("(%p, %x)\n", pen, argb);
499 return InvalidParameter;
501 if(pen->brush->bt != BrushTypeSolidColor)
502 return NotImplemented;
504 return GdipSetSolidFillColor(((GpSolidFill*)pen->brush), argb);
507 GpStatus WINGDIPAPI GdipGetPenCompoundCount(GpPen *pen, INT *count)
509 FIXME("(%p, %p): stub\n", pen, count);
512 return InvalidParameter;
514 return NotImplemented;
517 GpStatus WINGDIPAPI GdipSetPenCompoundArray(GpPen *pen, GDIPCONST REAL *dash,
520 FIXME("(%p, %p, %i): stub\n", pen, dash, count);
522 if (!pen || !dash || count < 2 || count%2 == 1)
523 return InvalidParameter;
525 return NotImplemented;
528 GpStatus WINGDIPAPI GdipSetPenCustomEndCap(GpPen *pen, GpCustomLineCap* customCap)
530 GpCustomLineCap * cap;
533 TRACE("(%p, %p)\n", pen, customCap);
535 /* native crashes on pen == NULL, customCap != NULL */
536 if(!customCap) return InvalidParameter;
538 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
539 GdipDeleteCustomLineCap(pen->customend);
540 pen->endcap = LineCapCustom;
541 pen->customend = cap;
547 GpStatus WINGDIPAPI GdipSetPenCustomStartCap(GpPen *pen, GpCustomLineCap* customCap)
549 GpCustomLineCap * cap;
552 TRACE("(%p, %p)\n", pen, customCap);
554 /* native crashes on pen == NULL, customCap != NULL */
555 if(!customCap) return InvalidParameter;
557 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
558 GdipDeleteCustomLineCap(pen->customstart);
559 pen->startcap = LineCapCustom;
560 pen->customstart = cap;
566 GpStatus WINGDIPAPI GdipSetPenDashArray(GpPen *pen, GDIPCONST REAL *dash,
572 TRACE("(%p, %p, %d)\n", pen, dash, count);
575 return InvalidParameter;
580 for(i = 0; i < count; i++){
583 return InvalidParameter;
586 if(sum == 0.0 && count)
587 return InvalidParameter;
589 GdipFree(pen->dashes);
593 pen->dashes = GdipAlloc(count * sizeof(REAL));
599 GdipSetPenDashStyle(pen, DashStyleCustom);
600 memcpy(pen->dashes, dash, count * sizeof(REAL));
601 pen->numdashes = count;
606 GpStatus WINGDIPAPI GdipSetPenDashCap197819(GpPen *pen, GpDashCap dashCap)
608 TRACE("(%p, %d)\n", pen, dashCap);
611 return InvalidParameter;
613 pen->dashcap = dashCap;
618 /* FIXME: dash offset not used */
619 GpStatus WINGDIPAPI GdipSetPenDashOffset(GpPen *pen, REAL offset)
621 TRACE("(%p, %.2f)\n", pen, offset);
624 return InvalidParameter;
626 pen->offset = offset;
631 GpStatus WINGDIPAPI GdipSetPenDashStyle(GpPen *pen, GpDashStyle dash)
633 TRACE("(%p, %d)\n", pen, dash);
636 return InvalidParameter;
638 if(dash != DashStyleCustom){
639 GdipFree(pen->dashes);
645 pen->style &= ~(PS_ALTERNATE | PS_SOLID | PS_DASH | PS_DOT | PS_DASHDOT |
646 PS_DASHDOTDOT | PS_NULL | PS_USERSTYLE | PS_INSIDEFRAME);
647 pen->style |= gdip_to_gdi_dash(dash);
652 GpStatus WINGDIPAPI GdipSetPenEndCap(GpPen *pen, GpLineCap cap)
654 TRACE("(%p, %d)\n", pen, cap);
656 if(!pen) return InvalidParameter;
658 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
659 GdipDeleteCustomLineCap(pen->customend);
660 pen->customend = NULL;
666 /* FIXME: startcap, dashcap not used. */
667 GpStatus WINGDIPAPI GdipSetPenLineCap197819(GpPen *pen, GpLineCap start,
668 GpLineCap end, GpDashCap dash)
670 TRACE("%p, %d, %d, %d)\n", pen, start, end, dash);
673 return InvalidParameter;
675 GdipDeleteCustomLineCap(pen->customend);
676 GdipDeleteCustomLineCap(pen->customstart);
677 pen->customend = NULL;
678 pen->customstart = NULL;
680 pen->startcap = start;
687 /* FIXME: Miter line joins behave a bit differently than they do in windows.
688 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
689 GpStatus WINGDIPAPI GdipSetPenLineJoin(GpPen *pen, GpLineJoin join)
691 TRACE("(%p, %d)\n", pen, join);
693 if(!pen) return InvalidParameter;
696 pen->style &= ~(PS_JOIN_ROUND | PS_JOIN_BEVEL | PS_JOIN_MITER);
697 pen->style |= gdip_to_gdi_join(join);
702 GpStatus WINGDIPAPI GdipSetPenMiterLimit(GpPen *pen, REAL limit)
704 TRACE("(%p, %.2f)\n", pen, limit);
707 return InvalidParameter;
709 pen->miterlimit = limit;
714 GpStatus WINGDIPAPI GdipSetPenStartCap(GpPen *pen, GpLineCap cap)
716 TRACE("(%p, %d)\n", pen, cap);
718 if(!pen) return InvalidParameter;
720 GdipDeleteCustomLineCap(pen->customstart);
721 pen->customstart = NULL;
727 GpStatus WINGDIPAPI GdipSetPenWidth(GpPen *pen, REAL width)
729 TRACE("(%p, %.2f)\n", pen, width);
731 if(!pen) return InvalidParameter;
738 GpStatus WINGDIPAPI GdipSetPenMode(GpPen *pen, GpPenAlignment mode)
740 TRACE("(%p, %d)\n", pen, mode);
742 if(!pen) return InvalidParameter;