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
;
174 GdipSetMatrixElements(&gp_pen
->transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
176 if(!((gp_pen
->unit
== UnitWorld
) || (gp_pen
->unit
== UnitPixel
))) {
177 FIXME("UnitWorld, UnitPixel only supported units\n");
179 return NotImplemented
;
182 GdipCloneBrush(brush
, &clone_brush
);
183 gp_pen
->brush
= clone_brush
;
187 TRACE("<-- %p\n", *pen
);
192 GpStatus WINGDIPAPI
GdipDeletePen(GpPen
*pen
)
194 TRACE("(%p)\n", pen
);
196 if(!pen
) return InvalidParameter
;
198 GdipDeleteBrush(pen
->brush
);
199 GdipDeleteCustomLineCap(pen
->customstart
);
200 GdipDeleteCustomLineCap(pen
->customend
);
201 heap_free(pen
->dashes
);
207 GpStatus WINGDIPAPI
GdipGetPenBrushFill(GpPen
*pen
, GpBrush
**brush
)
209 TRACE("(%p, %p)\n", pen
, brush
);
212 return InvalidParameter
;
214 return GdipCloneBrush(pen
->brush
, brush
);
217 GpStatus WINGDIPAPI
GdipGetPenColor(GpPen
*pen
, ARGB
*argb
)
219 TRACE("(%p, %p)\n", pen
, argb
);
222 return InvalidParameter
;
224 if(pen
->brush
->bt
!= BrushTypeSolidColor
)
225 return NotImplemented
;
227 return GdipGetSolidFillColor(((GpSolidFill
*)pen
->brush
), argb
);
230 GpStatus WINGDIPAPI
GdipGetPenCustomEndCap(GpPen
*pen
, GpCustomLineCap
** customCap
)
232 TRACE("(%p, %p)\n", pen
, customCap
);
234 if(!pen
|| !customCap
)
235 return InvalidParameter
;
242 return GdipCloneCustomLineCap(pen
->customend
, customCap
);
245 GpStatus WINGDIPAPI
GdipGetPenCustomStartCap(GpPen
*pen
, GpCustomLineCap
** customCap
)
247 TRACE("(%p, %p)\n", pen
, customCap
);
249 if(!pen
|| !customCap
)
250 return InvalidParameter
;
252 if(!pen
->customstart
){
257 return GdipCloneCustomLineCap(pen
->customstart
, customCap
);
260 GpStatus WINGDIPAPI
GdipGetPenDashArray(GpPen
*pen
, REAL
*dash
, INT count
)
262 TRACE("(%p, %p, %d)\n", pen
, dash
, count
);
264 if(!pen
|| !dash
|| count
> pen
->numdashes
)
265 return InvalidParameter
;
267 /* note: if you pass a negative value for count, it crashes native gdiplus. */
271 memcpy(dash
, pen
->dashes
, count
* sizeof(REAL
));
276 GpStatus WINGDIPAPI
GdipGetPenDashCap197819(GpPen
*pen
, GpDashCap
*dashCap
)
278 TRACE("(%p, %p)\n", pen
, dashCap
);
281 return InvalidParameter
;
283 *dashCap
= pen
->dashcap
;
288 GpStatus WINGDIPAPI
GdipGetPenDashCount(GpPen
*pen
, INT
*count
)
290 TRACE("(%p, %p)\n", pen
, count
);
293 return InvalidParameter
;
295 *count
= pen
->numdashes
;
300 GpStatus WINGDIPAPI
GdipGetPenDashOffset(GpPen
*pen
, REAL
*offset
)
302 TRACE("(%p, %p)\n", pen
, offset
);
305 return InvalidParameter
;
307 *offset
= pen
->offset
;
312 GpStatus WINGDIPAPI
GdipGetPenDashStyle(GpPen
*pen
, GpDashStyle
*dash
)
314 TRACE("(%p, %p)\n", pen
, dash
);
317 return InvalidParameter
;
324 GpStatus WINGDIPAPI
GdipGetPenEndCap(GpPen
*pen
, GpLineCap
*endCap
)
326 TRACE("(%p, %p)\n", pen
, endCap
);
329 return InvalidParameter
;
331 *endCap
= pen
->endcap
;
336 GpStatus WINGDIPAPI
GdipGetPenFillType(GpPen
*pen
, GpPenType
* type
)
338 TRACE("(%p, %p)\n", pen
, type
);
341 return InvalidParameter
;
343 *type
= bt_to_pt(pen
->brush
->bt
);
348 GpStatus WINGDIPAPI
GdipGetPenLineJoin(GpPen
*pen
, GpLineJoin
*lineJoin
)
350 TRACE("(%p, %p)\n", pen
, lineJoin
);
352 if(!pen
|| !lineJoin
)
353 return InvalidParameter
;
355 *lineJoin
= pen
->join
;
360 GpStatus WINGDIPAPI
GdipGetPenMode(GpPen
*pen
, GpPenAlignment
*mode
)
362 TRACE("(%p, %p)\n", pen
, mode
);
365 return InvalidParameter
;
372 GpStatus WINGDIPAPI
GdipGetPenMiterLimit(GpPen
*pen
, REAL
*miterLimit
)
374 TRACE("(%p, %p)\n", pen
, miterLimit
);
376 if(!pen
|| !miterLimit
)
377 return InvalidParameter
;
379 *miterLimit
= pen
->miterlimit
;
384 GpStatus WINGDIPAPI
GdipGetPenStartCap(GpPen
*pen
, GpLineCap
*startCap
)
386 TRACE("(%p, %p)\n", pen
, startCap
);
388 if(!pen
|| !startCap
)
389 return InvalidParameter
;
391 *startCap
= pen
->startcap
;
396 GpStatus WINGDIPAPI
GdipGetPenUnit(GpPen
*pen
, GpUnit
*unit
)
398 TRACE("(%p, %p)\n", pen
, unit
);
401 return InvalidParameter
;
408 GpStatus WINGDIPAPI
GdipGetPenWidth(GpPen
*pen
, REAL
*width
)
410 TRACE("(%p, %p)\n", pen
, width
);
413 return InvalidParameter
;
420 GpStatus WINGDIPAPI
GdipResetPenTransform(GpPen
*pen
)
422 TRACE("(%p)\n", pen
);
425 return InvalidParameter
;
427 GdipSetMatrixElements(&pen
->transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
432 GpStatus WINGDIPAPI
GdipSetPenTransform(GpPen
*pen
, GpMatrix
*matrix
)
436 TRACE("(%p,%p)\n", pen
, matrix
);
439 return InvalidParameter
;
442 FIXME("(%p,%p) Semi-stub\n", pen
, matrix
);
444 pen
->transform
= *matrix
;
449 GpStatus WINGDIPAPI
GdipGetPenTransform(GpPen
*pen
, GpMatrix
*matrix
)
451 TRACE("(%p,%p)\n", pen
, matrix
);
454 return InvalidParameter
;
456 *matrix
= pen
->transform
;
461 GpStatus WINGDIPAPI
GdipTranslatePenTransform(GpPen
*pen
, REAL dx
, REAL dy
, GpMatrixOrder order
)
465 TRACE("(%p,%0.2f,%0.2f,%u)\n", pen
, dx
, dy
, order
);
468 return InvalidParameter
;
471 FIXME("not implemented\n");
473 return NotImplemented
;
476 GpStatus WINGDIPAPI
GdipScalePenTransform(GpPen
*pen
, REAL sx
, REAL sy
, GpMatrixOrder order
)
480 TRACE("(%p,%0.2f,%0.2f,%u)\n", pen
, sx
, sy
, order
);
483 return InvalidParameter
;
486 FIXME("(%p, %.2f, %.2f, %d) stub\n", pen
, sx
, sy
, order
);
488 return NotImplemented
;
491 GpStatus WINGDIPAPI
GdipRotatePenTransform(GpPen
*pen
, REAL angle
, GpMatrixOrder order
)
495 TRACE("(%p,%0.2f,%u)\n", pen
, angle
, order
);
498 return InvalidParameter
;
501 FIXME("not implemented\n");
503 return NotImplemented
;
506 GpStatus WINGDIPAPI
GdipMultiplyPenTransform(GpPen
*pen
, GDIPCONST GpMatrix
*matrix
,
511 TRACE("(%p,%p,%u)\n", pen
, matrix
, order
);
514 return InvalidParameter
;
517 FIXME("not implemented\n");
519 return NotImplemented
;
522 GpStatus WINGDIPAPI
GdipSetPenBrushFill(GpPen
*pen
, GpBrush
*brush
)
524 TRACE("(%p, %p)\n", pen
, brush
);
527 return InvalidParameter
;
529 GdipDeleteBrush(pen
->brush
);
530 return GdipCloneBrush(brush
, &pen
->brush
);
533 GpStatus WINGDIPAPI
GdipSetPenColor(GpPen
*pen
, ARGB argb
)
535 TRACE("(%p, %x)\n", pen
, argb
);
538 return InvalidParameter
;
540 if(pen
->brush
->bt
!= BrushTypeSolidColor
)
541 return NotImplemented
;
543 return GdipSetSolidFillColor(((GpSolidFill
*)pen
->brush
), argb
);
546 GpStatus WINGDIPAPI
GdipGetPenCompoundCount(GpPen
*pen
, INT
*count
)
548 FIXME("(%p, %p): stub\n", pen
, count
);
551 return InvalidParameter
;
553 return NotImplemented
;
556 GpStatus WINGDIPAPI
GdipSetPenCompoundArray(GpPen
*pen
, GDIPCONST REAL
*dash
,
559 FIXME("(%p, %p, %i): stub\n", pen
, dash
, count
);
561 if (!pen
|| !dash
|| count
< 2 || count
%2 == 1)
562 return InvalidParameter
;
564 return NotImplemented
;
567 GpStatus WINGDIPAPI
GdipSetPenCustomEndCap(GpPen
*pen
, GpCustomLineCap
* customCap
)
569 GpCustomLineCap
* cap
;
572 TRACE("(%p, %p)\n", pen
, customCap
);
574 /* native crashes on pen == NULL, customCap != NULL */
575 if(!customCap
) return InvalidParameter
;
577 if((ret
= GdipCloneCustomLineCap(customCap
, &cap
)) == Ok
){
578 GdipDeleteCustomLineCap(pen
->customend
);
579 pen
->endcap
= LineCapCustom
;
580 pen
->customend
= cap
;
586 GpStatus WINGDIPAPI
GdipSetPenCustomStartCap(GpPen
*pen
, GpCustomLineCap
* customCap
)
588 GpCustomLineCap
* cap
;
591 TRACE("(%p, %p)\n", pen
, customCap
);
593 /* native crashes on pen == NULL, customCap != NULL */
594 if(!customCap
) return InvalidParameter
;
596 if((ret
= GdipCloneCustomLineCap(customCap
, &cap
)) == Ok
){
597 GdipDeleteCustomLineCap(pen
->customstart
);
598 pen
->startcap
= LineCapCustom
;
599 pen
->customstart
= cap
;
605 GpStatus WINGDIPAPI
GdipSetPenDashArray(GpPen
*pen
, GDIPCONST REAL
*dash
,
611 TRACE("(%p, %p, %d)\n", pen
, dash
, count
);
614 return InvalidParameter
;
619 for(i
= 0; i
< count
; i
++){
622 return InvalidParameter
;
625 if(sum
== 0.0 && count
)
626 return InvalidParameter
;
628 heap_free(pen
->dashes
);
632 pen
->dashes
= heap_alloc_zero(count
* sizeof(REAL
));
638 GdipSetPenDashStyle(pen
, DashStyleCustom
);
639 memcpy(pen
->dashes
, dash
, count
* sizeof(REAL
));
640 pen
->numdashes
= count
;
645 GpStatus WINGDIPAPI
GdipSetPenDashCap197819(GpPen
*pen
, GpDashCap dashCap
)
647 TRACE("(%p, %d)\n", pen
, dashCap
);
650 return InvalidParameter
;
652 pen
->dashcap
= dashCap
;
657 /* FIXME: dash offset not used */
658 GpStatus WINGDIPAPI
GdipSetPenDashOffset(GpPen
*pen
, REAL offset
)
660 TRACE("(%p, %.2f)\n", pen
, offset
);
663 return InvalidParameter
;
665 pen
->offset
= offset
;
670 GpStatus WINGDIPAPI
GdipSetPenDashStyle(GpPen
*pen
, GpDashStyle dash
)
672 TRACE("(%p, %d)\n", pen
, dash
);
675 return InvalidParameter
;
677 if(dash
!= DashStyleCustom
){
678 heap_free(pen
->dashes
);
684 pen
->style
&= ~(PS_ALTERNATE
| PS_SOLID
| PS_DASH
| PS_DOT
| PS_DASHDOT
|
685 PS_DASHDOTDOT
| PS_NULL
| PS_USERSTYLE
| PS_INSIDEFRAME
);
686 pen
->style
|= gdip_to_gdi_dash(dash
);
691 GpStatus WINGDIPAPI
GdipSetPenEndCap(GpPen
*pen
, GpLineCap cap
)
693 TRACE("(%p, %d)\n", pen
, cap
);
695 if(!pen
) return InvalidParameter
;
697 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
698 GdipDeleteCustomLineCap(pen
->customend
);
699 pen
->customend
= NULL
;
705 /* FIXME: startcap, dashcap not used. */
706 GpStatus WINGDIPAPI
GdipSetPenLineCap197819(GpPen
*pen
, GpLineCap start
,
707 GpLineCap end
, GpDashCap dash
)
709 TRACE("%p, %d, %d, %d)\n", pen
, start
, end
, dash
);
712 return InvalidParameter
;
714 GdipDeleteCustomLineCap(pen
->customend
);
715 GdipDeleteCustomLineCap(pen
->customstart
);
716 pen
->customend
= NULL
;
717 pen
->customstart
= NULL
;
719 pen
->startcap
= start
;
726 /* FIXME: Miter line joins behave a bit differently than they do in windows.
727 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
728 GpStatus WINGDIPAPI
GdipSetPenLineJoin(GpPen
*pen
, GpLineJoin join
)
730 TRACE("(%p, %d)\n", pen
, join
);
732 if(!pen
) return InvalidParameter
;
735 pen
->style
&= ~(PS_JOIN_ROUND
| PS_JOIN_BEVEL
| PS_JOIN_MITER
);
736 pen
->style
|= gdip_to_gdi_join(join
);
741 GpStatus WINGDIPAPI
GdipSetPenMiterLimit(GpPen
*pen
, REAL limit
)
743 TRACE("(%p, %.2f)\n", pen
, limit
);
746 return InvalidParameter
;
748 pen
->miterlimit
= limit
;
753 GpStatus WINGDIPAPI
GdipSetPenStartCap(GpPen
*pen
, GpLineCap cap
)
755 TRACE("(%p, %d)\n", pen
, cap
);
757 if(!pen
) return InvalidParameter
;
759 GdipDeleteCustomLineCap(pen
->customstart
);
760 pen
->customstart
= NULL
;
766 GpStatus WINGDIPAPI
GdipSetPenWidth(GpPen
*pen
, REAL width
)
768 TRACE("(%p, %.2f)\n", pen
, width
);
770 if(!pen
) return InvalidParameter
;
777 GpStatus WINGDIPAPI
GdipSetPenMode(GpPen
*pen
, GpPenAlignment mode
)
779 TRACE("(%p, %d)\n", pen
, mode
);
781 if(!pen
) return InvalidParameter
;