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
)
92 TRACE("(%p, %p)\n", pen
, clonepen
);
95 return InvalidParameter
;
97 *clonepen
= heap_alloc_zero(sizeof(GpPen
));
98 if(!*clonepen
) return OutOfMemory
;
102 (*clonepen
)->customstart
= NULL
;
103 (*clonepen
)->customend
= NULL
;
104 (*clonepen
)->brush
= NULL
;
105 (*clonepen
)->dashes
= NULL
;
107 stat
= GdipCloneBrush(pen
->brush
, &(*clonepen
)->brush
);
109 if (stat
== Ok
&& pen
->customstart
)
110 stat
= GdipCloneCustomLineCap(pen
->customstart
, &(*clonepen
)->customstart
);
112 if (stat
== Ok
&& pen
->customend
)
113 stat
= GdipCloneCustomLineCap(pen
->customend
, &(*clonepen
)->customend
);
115 if (stat
== Ok
&& pen
->dashes
)
117 (*clonepen
)->dashes
= heap_alloc_zero(pen
->numdashes
* sizeof(REAL
));
118 if ((*clonepen
)->dashes
)
119 memcpy((*clonepen
)->dashes
, pen
->dashes
, pen
->numdashes
* sizeof(REAL
));
126 GdipDeletePen(*clonepen
);
131 TRACE("<-- %p\n", *clonepen
);
136 GpStatus WINGDIPAPI
GdipCreatePen1(ARGB color
, REAL width
, GpUnit unit
,
142 TRACE("(%x, %.2f, %d, %p)\n", color
, width
, unit
, pen
);
144 GdipCreateSolidFill(color
, (GpSolidFill
**)(&brush
));
145 status
= GdipCreatePen2(brush
, width
, unit
, pen
);
146 GdipDeleteBrush(brush
);
150 GpStatus WINGDIPAPI
GdipCreatePen2(GpBrush
*brush
, REAL width
, GpUnit unit
,
154 GpBrush
*clone_brush
;
156 TRACE("(%p, %.2f, %d, %p)\n", brush
, width
, unit
, pen
);
159 return InvalidParameter
;
161 gp_pen
= heap_alloc_zero(sizeof(GpPen
));
162 if(!gp_pen
) return OutOfMemory
;
164 gp_pen
->style
= GP_DEFAULT_PENSTYLE
;
165 gp_pen
->width
= width
;
167 gp_pen
->endcap
= LineCapFlat
;
168 gp_pen
->join
= LineJoinMiter
;
169 gp_pen
->miterlimit
= 10.0;
170 gp_pen
->dash
= DashStyleSolid
;
171 gp_pen
->offset
= 0.0;
172 gp_pen
->customstart
= NULL
;
173 gp_pen
->customend
= NULL
;
175 if(!((gp_pen
->unit
== UnitWorld
) || (gp_pen
->unit
== UnitPixel
))) {
176 FIXME("UnitWorld, UnitPixel only supported units\n");
178 return NotImplemented
;
181 GdipCloneBrush(brush
, &clone_brush
);
182 gp_pen
->brush
= clone_brush
;
186 TRACE("<-- %p\n", *pen
);
191 GpStatus WINGDIPAPI
GdipDeletePen(GpPen
*pen
)
193 TRACE("(%p)\n", pen
);
195 if(!pen
) return InvalidParameter
;
197 GdipDeleteBrush(pen
->brush
);
198 GdipDeleteCustomLineCap(pen
->customstart
);
199 GdipDeleteCustomLineCap(pen
->customend
);
200 heap_free(pen
->dashes
);
206 GpStatus WINGDIPAPI
GdipGetPenBrushFill(GpPen
*pen
, GpBrush
**brush
)
208 TRACE("(%p, %p)\n", pen
, brush
);
211 return InvalidParameter
;
213 return GdipCloneBrush(pen
->brush
, brush
);
216 GpStatus WINGDIPAPI
GdipGetPenColor(GpPen
*pen
, ARGB
*argb
)
218 TRACE("(%p, %p)\n", pen
, argb
);
221 return InvalidParameter
;
223 if(pen
->brush
->bt
!= BrushTypeSolidColor
)
224 return NotImplemented
;
226 return GdipGetSolidFillColor(((GpSolidFill
*)pen
->brush
), argb
);
229 GpStatus WINGDIPAPI
GdipGetPenCustomEndCap(GpPen
*pen
, GpCustomLineCap
** customCap
)
231 TRACE("(%p, %p)\n", pen
, customCap
);
233 if(!pen
|| !customCap
)
234 return InvalidParameter
;
241 return GdipCloneCustomLineCap(pen
->customend
, customCap
);
244 GpStatus WINGDIPAPI
GdipGetPenCustomStartCap(GpPen
*pen
, GpCustomLineCap
** customCap
)
246 TRACE("(%p, %p)\n", pen
, customCap
);
248 if(!pen
|| !customCap
)
249 return InvalidParameter
;
251 if(!pen
->customstart
){
256 return GdipCloneCustomLineCap(pen
->customstart
, customCap
);
259 GpStatus WINGDIPAPI
GdipGetPenDashArray(GpPen
*pen
, REAL
*dash
, INT count
)
261 TRACE("(%p, %p, %d)\n", pen
, dash
, count
);
263 if(!pen
|| !dash
|| count
> pen
->numdashes
)
264 return InvalidParameter
;
266 /* note: if you pass a negative value for count, it crashes native gdiplus. */
270 memcpy(dash
, pen
->dashes
, count
* sizeof(REAL
));
275 GpStatus WINGDIPAPI
GdipGetPenDashCap197819(GpPen
*pen
, GpDashCap
*dashCap
)
277 TRACE("(%p, %p)\n", pen
, dashCap
);
280 return InvalidParameter
;
282 *dashCap
= pen
->dashcap
;
287 GpStatus WINGDIPAPI
GdipGetPenDashCount(GpPen
*pen
, INT
*count
)
289 TRACE("(%p, %p)\n", pen
, count
);
292 return InvalidParameter
;
294 *count
= pen
->numdashes
;
299 GpStatus WINGDIPAPI
GdipGetPenDashOffset(GpPen
*pen
, REAL
*offset
)
301 TRACE("(%p, %p)\n", pen
, offset
);
304 return InvalidParameter
;
306 *offset
= pen
->offset
;
311 GpStatus WINGDIPAPI
GdipGetPenDashStyle(GpPen
*pen
, GpDashStyle
*dash
)
313 TRACE("(%p, %p)\n", pen
, dash
);
316 return InvalidParameter
;
323 GpStatus WINGDIPAPI
GdipGetPenEndCap(GpPen
*pen
, GpLineCap
*endCap
)
325 TRACE("(%p, %p)\n", pen
, endCap
);
328 return InvalidParameter
;
330 *endCap
= pen
->endcap
;
335 GpStatus WINGDIPAPI
GdipGetPenFillType(GpPen
*pen
, GpPenType
* type
)
337 TRACE("(%p, %p)\n", pen
, type
);
340 return InvalidParameter
;
342 *type
= bt_to_pt(pen
->brush
->bt
);
347 GpStatus WINGDIPAPI
GdipGetPenLineJoin(GpPen
*pen
, GpLineJoin
*lineJoin
)
349 TRACE("(%p, %p)\n", pen
, lineJoin
);
351 if(!pen
|| !lineJoin
)
352 return InvalidParameter
;
354 *lineJoin
= pen
->join
;
359 GpStatus WINGDIPAPI
GdipGetPenMode(GpPen
*pen
, GpPenAlignment
*mode
)
361 TRACE("(%p, %p)\n", pen
, mode
);
364 return InvalidParameter
;
371 GpStatus WINGDIPAPI
GdipGetPenMiterLimit(GpPen
*pen
, REAL
*miterLimit
)
373 TRACE("(%p, %p)\n", pen
, miterLimit
);
375 if(!pen
|| !miterLimit
)
376 return InvalidParameter
;
378 *miterLimit
= pen
->miterlimit
;
383 GpStatus WINGDIPAPI
GdipGetPenStartCap(GpPen
*pen
, GpLineCap
*startCap
)
385 TRACE("(%p, %p)\n", pen
, startCap
);
387 if(!pen
|| !startCap
)
388 return InvalidParameter
;
390 *startCap
= pen
->startcap
;
395 GpStatus WINGDIPAPI
GdipGetPenUnit(GpPen
*pen
, GpUnit
*unit
)
397 TRACE("(%p, %p)\n", pen
, unit
);
400 return InvalidParameter
;
407 GpStatus WINGDIPAPI
GdipGetPenWidth(GpPen
*pen
, REAL
*width
)
409 TRACE("(%p, %p)\n", pen
, width
);
412 return InvalidParameter
;
419 GpStatus WINGDIPAPI
GdipResetPenTransform(GpPen
*pen
)
423 TRACE("(%p)\n", pen
);
426 return InvalidParameter
;
429 FIXME("(%p) stub\n", pen
);
431 return NotImplemented
;
434 GpStatus WINGDIPAPI
GdipSetPenTransform(GpPen
*pen
, GpMatrix
*matrix
)
438 TRACE("(%p,%p)\n", pen
, matrix
);
441 return InvalidParameter
;
444 FIXME("not implemented\n");
446 return NotImplemented
;
449 GpStatus WINGDIPAPI
GdipGetPenTransform(GpPen
*pen
, GpMatrix
*matrix
)
453 TRACE("(%p,%p)\n", pen
, matrix
);
456 return InvalidParameter
;
459 FIXME("not implemented\n");
461 return NotImplemented
;
464 GpStatus WINGDIPAPI
GdipTranslatePenTransform(GpPen
*pen
, REAL dx
, REAL dy
, GpMatrixOrder order
)
468 TRACE("(%p,%0.2f,%0.2f,%u)\n", pen
, dx
, dy
, order
);
471 return InvalidParameter
;
474 FIXME("not implemented\n");
476 return NotImplemented
;
479 GpStatus WINGDIPAPI
GdipScalePenTransform(GpPen
*pen
, REAL sx
, REAL sy
, GpMatrixOrder order
)
483 TRACE("(%p,%0.2f,%0.2f,%u)\n", pen
, sx
, sy
, order
);
486 return InvalidParameter
;
489 FIXME("(%p, %.2f, %.2f, %d) stub\n", pen
, sx
, sy
, order
);
491 return NotImplemented
;
494 GpStatus WINGDIPAPI
GdipRotatePenTransform(GpPen
*pen
, REAL angle
, GpMatrixOrder order
)
498 TRACE("(%p,%0.2f,%u)\n", pen
, angle
, order
);
501 return InvalidParameter
;
504 FIXME("not implemented\n");
506 return NotImplemented
;
509 GpStatus WINGDIPAPI
GdipMultiplyPenTransform(GpPen
*pen
, GDIPCONST GpMatrix
*matrix
,
514 TRACE("(%p,%p,%u)\n", pen
, matrix
, order
);
517 return InvalidParameter
;
520 FIXME("not implemented\n");
522 return NotImplemented
;
525 GpStatus WINGDIPAPI
GdipSetPenBrushFill(GpPen
*pen
, GpBrush
*brush
)
527 TRACE("(%p, %p)\n", pen
, brush
);
530 return InvalidParameter
;
532 GdipDeleteBrush(pen
->brush
);
533 return GdipCloneBrush(brush
, &pen
->brush
);
536 GpStatus WINGDIPAPI
GdipSetPenColor(GpPen
*pen
, ARGB argb
)
538 TRACE("(%p, %x)\n", pen
, argb
);
541 return InvalidParameter
;
543 if(pen
->brush
->bt
!= BrushTypeSolidColor
)
544 return NotImplemented
;
546 return GdipSetSolidFillColor(((GpSolidFill
*)pen
->brush
), argb
);
549 GpStatus WINGDIPAPI
GdipGetPenCompoundCount(GpPen
*pen
, INT
*count
)
551 FIXME("(%p, %p): stub\n", pen
, count
);
554 return InvalidParameter
;
556 return NotImplemented
;
559 GpStatus WINGDIPAPI
GdipSetPenCompoundArray(GpPen
*pen
, GDIPCONST REAL
*dash
,
562 FIXME("(%p, %p, %i): stub\n", pen
, dash
, count
);
564 if (!pen
|| !dash
|| count
< 2 || count
%2 == 1)
565 return InvalidParameter
;
567 return NotImplemented
;
570 GpStatus WINGDIPAPI
GdipSetPenCustomEndCap(GpPen
*pen
, GpCustomLineCap
* customCap
)
572 GpCustomLineCap
* cap
;
575 TRACE("(%p, %p)\n", pen
, customCap
);
577 /* native crashes on pen == NULL, customCap != NULL */
578 if(!customCap
) return InvalidParameter
;
580 if((ret
= GdipCloneCustomLineCap(customCap
, &cap
)) == Ok
){
581 GdipDeleteCustomLineCap(pen
->customend
);
582 pen
->endcap
= LineCapCustom
;
583 pen
->customend
= cap
;
589 GpStatus WINGDIPAPI
GdipSetPenCustomStartCap(GpPen
*pen
, GpCustomLineCap
* customCap
)
591 GpCustomLineCap
* cap
;
594 TRACE("(%p, %p)\n", pen
, customCap
);
596 /* native crashes on pen == NULL, customCap != NULL */
597 if(!customCap
) return InvalidParameter
;
599 if((ret
= GdipCloneCustomLineCap(customCap
, &cap
)) == Ok
){
600 GdipDeleteCustomLineCap(pen
->customstart
);
601 pen
->startcap
= LineCapCustom
;
602 pen
->customstart
= cap
;
608 GpStatus WINGDIPAPI
GdipSetPenDashArray(GpPen
*pen
, GDIPCONST REAL
*dash
,
614 TRACE("(%p, %p, %d)\n", pen
, dash
, count
);
617 return InvalidParameter
;
622 for(i
= 0; i
< count
; i
++){
625 return InvalidParameter
;
628 if(sum
== 0.0 && count
)
629 return InvalidParameter
;
631 heap_free(pen
->dashes
);
635 pen
->dashes
= heap_alloc_zero(count
* sizeof(REAL
));
641 GdipSetPenDashStyle(pen
, DashStyleCustom
);
642 memcpy(pen
->dashes
, dash
, count
* sizeof(REAL
));
643 pen
->numdashes
= count
;
648 GpStatus WINGDIPAPI
GdipSetPenDashCap197819(GpPen
*pen
, GpDashCap dashCap
)
650 TRACE("(%p, %d)\n", pen
, dashCap
);
653 return InvalidParameter
;
655 pen
->dashcap
= dashCap
;
660 /* FIXME: dash offset not used */
661 GpStatus WINGDIPAPI
GdipSetPenDashOffset(GpPen
*pen
, REAL offset
)
663 TRACE("(%p, %.2f)\n", pen
, offset
);
666 return InvalidParameter
;
668 pen
->offset
= offset
;
673 GpStatus WINGDIPAPI
GdipSetPenDashStyle(GpPen
*pen
, GpDashStyle dash
)
675 TRACE("(%p, %d)\n", pen
, dash
);
678 return InvalidParameter
;
680 if(dash
!= DashStyleCustom
){
681 heap_free(pen
->dashes
);
687 pen
->style
&= ~(PS_ALTERNATE
| PS_SOLID
| PS_DASH
| PS_DOT
| PS_DASHDOT
|
688 PS_DASHDOTDOT
| PS_NULL
| PS_USERSTYLE
| PS_INSIDEFRAME
);
689 pen
->style
|= gdip_to_gdi_dash(dash
);
694 GpStatus WINGDIPAPI
GdipSetPenEndCap(GpPen
*pen
, GpLineCap cap
)
696 TRACE("(%p, %d)\n", pen
, cap
);
698 if(!pen
) return InvalidParameter
;
700 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
701 GdipDeleteCustomLineCap(pen
->customend
);
702 pen
->customend
= NULL
;
708 /* FIXME: startcap, dashcap not used. */
709 GpStatus WINGDIPAPI
GdipSetPenLineCap197819(GpPen
*pen
, GpLineCap start
,
710 GpLineCap end
, GpDashCap dash
)
712 TRACE("%p, %d, %d, %d)\n", pen
, start
, end
, dash
);
715 return InvalidParameter
;
717 GdipDeleteCustomLineCap(pen
->customend
);
718 GdipDeleteCustomLineCap(pen
->customstart
);
719 pen
->customend
= NULL
;
720 pen
->customstart
= NULL
;
722 pen
->startcap
= start
;
729 /* FIXME: Miter line joins behave a bit differently than they do in windows.
730 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
731 GpStatus WINGDIPAPI
GdipSetPenLineJoin(GpPen
*pen
, GpLineJoin join
)
733 TRACE("(%p, %d)\n", pen
, join
);
735 if(!pen
) return InvalidParameter
;
738 pen
->style
&= ~(PS_JOIN_ROUND
| PS_JOIN_BEVEL
| PS_JOIN_MITER
);
739 pen
->style
|= gdip_to_gdi_join(join
);
744 GpStatus WINGDIPAPI
GdipSetPenMiterLimit(GpPen
*pen
, REAL limit
)
746 TRACE("(%p, %.2f)\n", pen
, limit
);
749 return InvalidParameter
;
751 pen
->miterlimit
= limit
;
756 GpStatus WINGDIPAPI
GdipSetPenStartCap(GpPen
*pen
, GpLineCap cap
)
758 TRACE("(%p, %d)\n", pen
, cap
);
760 if(!pen
) return InvalidParameter
;
762 GdipDeleteCustomLineCap(pen
->customstart
);
763 pen
->customstart
= NULL
;
769 GpStatus WINGDIPAPI
GdipSetPenWidth(GpPen
*pen
, REAL width
)
771 TRACE("(%p, %.2f)\n", pen
, width
);
773 if(!pen
) return InvalidParameter
;
780 GpStatus WINGDIPAPI
GdipSetPenMode(GpPen
*pen
, GpPenAlignment mode
)
782 TRACE("(%p, %d)\n", pen
, mode
);
784 if(!pen
) return InvalidParameter
;