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("(%lx, %.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 gp_pen
->compound_array
= NULL
;
175 gp_pen
->compound_array_size
= 0;
176 GdipSetMatrixElements(&gp_pen
->transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
178 if(!((gp_pen
->unit
== UnitWorld
) || (gp_pen
->unit
== UnitPixel
))) {
179 FIXME("UnitWorld, UnitPixel only supported units\n");
181 return NotImplemented
;
184 GdipCloneBrush(brush
, &clone_brush
);
185 gp_pen
->brush
= clone_brush
;
189 TRACE("<-- %p\n", *pen
);
194 GpStatus WINGDIPAPI
GdipDeletePen(GpPen
*pen
)
196 TRACE("(%p)\n", pen
);
198 if(!pen
) return InvalidParameter
;
200 GdipDeleteBrush(pen
->brush
);
201 GdipDeleteCustomLineCap(pen
->customstart
);
202 GdipDeleteCustomLineCap(pen
->customend
);
203 heap_free(pen
->compound_array
);
204 heap_free(pen
->dashes
);
210 GpStatus WINGDIPAPI
GdipGetPenBrushFill(GpPen
*pen
, GpBrush
**brush
)
212 TRACE("(%p, %p)\n", pen
, brush
);
215 return InvalidParameter
;
217 return GdipCloneBrush(pen
->brush
, brush
);
220 GpStatus WINGDIPAPI
GdipGetPenColor(GpPen
*pen
, ARGB
*argb
)
222 TRACE("(%p, %p)\n", pen
, argb
);
225 return InvalidParameter
;
227 if(pen
->brush
->bt
!= BrushTypeSolidColor
)
228 return NotImplemented
;
230 return GdipGetSolidFillColor(((GpSolidFill
*)pen
->brush
), argb
);
233 GpStatus WINGDIPAPI
GdipGetPenCustomEndCap(GpPen
*pen
, GpCustomLineCap
** customCap
)
235 TRACE("(%p, %p)\n", pen
, customCap
);
237 if(!pen
|| !customCap
)
238 return InvalidParameter
;
245 return GdipCloneCustomLineCap(pen
->customend
, customCap
);
248 GpStatus WINGDIPAPI
GdipGetPenCustomStartCap(GpPen
*pen
, GpCustomLineCap
** customCap
)
250 TRACE("(%p, %p)\n", pen
, customCap
);
252 if(!pen
|| !customCap
)
253 return InvalidParameter
;
255 if(!pen
->customstart
){
260 return GdipCloneCustomLineCap(pen
->customstart
, customCap
);
263 GpStatus WINGDIPAPI
GdipGetPenDashArray(GpPen
*pen
, REAL
*dash
, INT count
)
265 TRACE("(%p, %p, %d)\n", pen
, dash
, count
);
267 if(!pen
|| !dash
|| count
> pen
->numdashes
)
268 return InvalidParameter
;
270 /* note: if you pass a negative value for count, it crashes native gdiplus. */
274 memcpy(dash
, pen
->dashes
, count
* sizeof(REAL
));
279 GpStatus WINGDIPAPI
GdipGetPenDashCap197819(GpPen
*pen
, GpDashCap
*dashCap
)
281 TRACE("(%p, %p)\n", pen
, dashCap
);
284 return InvalidParameter
;
286 *dashCap
= pen
->dashcap
;
291 GpStatus WINGDIPAPI
GdipGetPenDashCount(GpPen
*pen
, INT
*count
)
293 TRACE("(%p, %p)\n", pen
, count
);
296 return InvalidParameter
;
298 *count
= pen
->numdashes
;
303 GpStatus WINGDIPAPI
GdipGetPenDashOffset(GpPen
*pen
, REAL
*offset
)
305 TRACE("(%p, %p)\n", pen
, offset
);
308 return InvalidParameter
;
310 *offset
= pen
->offset
;
315 GpStatus WINGDIPAPI
GdipGetPenDashStyle(GpPen
*pen
, GpDashStyle
*dash
)
317 TRACE("(%p, %p)\n", pen
, dash
);
320 return InvalidParameter
;
327 GpStatus WINGDIPAPI
GdipGetPenEndCap(GpPen
*pen
, GpLineCap
*endCap
)
329 TRACE("(%p, %p)\n", pen
, endCap
);
332 return InvalidParameter
;
334 *endCap
= pen
->endcap
;
339 GpStatus WINGDIPAPI
GdipGetPenFillType(GpPen
*pen
, GpPenType
* type
)
341 TRACE("(%p, %p)\n", pen
, type
);
344 return InvalidParameter
;
346 *type
= bt_to_pt(pen
->brush
->bt
);
351 GpStatus WINGDIPAPI
GdipGetPenLineJoin(GpPen
*pen
, GpLineJoin
*lineJoin
)
353 TRACE("(%p, %p)\n", pen
, lineJoin
);
355 if(!pen
|| !lineJoin
)
356 return InvalidParameter
;
358 *lineJoin
= pen
->join
;
363 GpStatus WINGDIPAPI
GdipGetPenMode(GpPen
*pen
, GpPenAlignment
*mode
)
365 TRACE("(%p, %p)\n", pen
, mode
);
368 return InvalidParameter
;
375 GpStatus WINGDIPAPI
GdipGetPenMiterLimit(GpPen
*pen
, REAL
*miterLimit
)
377 TRACE("(%p, %p)\n", pen
, miterLimit
);
379 if(!pen
|| !miterLimit
)
380 return InvalidParameter
;
382 *miterLimit
= pen
->miterlimit
;
387 GpStatus WINGDIPAPI
GdipGetPenStartCap(GpPen
*pen
, GpLineCap
*startCap
)
389 TRACE("(%p, %p)\n", pen
, startCap
);
391 if(!pen
|| !startCap
)
392 return InvalidParameter
;
394 *startCap
= pen
->startcap
;
399 GpStatus WINGDIPAPI
GdipGetPenUnit(GpPen
*pen
, GpUnit
*unit
)
401 TRACE("(%p, %p)\n", pen
, unit
);
404 return InvalidParameter
;
411 GpStatus WINGDIPAPI
GdipGetPenWidth(GpPen
*pen
, REAL
*width
)
413 TRACE("(%p, %p)\n", pen
, width
);
416 return InvalidParameter
;
423 GpStatus WINGDIPAPI
GdipResetPenTransform(GpPen
*pen
)
425 TRACE("(%p)\n", pen
);
428 return InvalidParameter
;
430 GdipSetMatrixElements(&pen
->transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
435 GpStatus WINGDIPAPI
GdipSetPenTransform(GpPen
*pen
, GpMatrix
*matrix
)
439 TRACE("(%p,%s)\n", pen
, debugstr_matrix(matrix
));
442 return InvalidParameter
;
445 FIXME("(%p,%p) Semi-stub\n", pen
, matrix
);
447 pen
->transform
= *matrix
;
452 GpStatus WINGDIPAPI
GdipGetPenTransform(GpPen
*pen
, GpMatrix
*matrix
)
454 TRACE("(%p,%s)\n", pen
, debugstr_matrix(matrix
));
457 return InvalidParameter
;
459 *matrix
= pen
->transform
;
464 GpStatus WINGDIPAPI
GdipTranslatePenTransform(GpPen
*pen
, REAL dx
, REAL dy
, GpMatrixOrder order
)
466 TRACE("(%p,%0.2f,%0.2f,%u)\n", pen
, dx
, dy
, order
);
469 return InvalidParameter
;
471 return GdipTranslateMatrix(&pen
->transform
, dx
, dy
, order
);
474 GpStatus WINGDIPAPI
GdipScalePenTransform(GpPen
*pen
, REAL sx
, REAL sy
, GpMatrixOrder order
)
476 TRACE("(%p,%0.2f,%0.2f,%u)\n", pen
, sx
, sy
, order
);
479 return InvalidParameter
;
481 return GdipScaleMatrix(&pen
->transform
, sx
, sy
, order
);
484 GpStatus WINGDIPAPI
GdipRotatePenTransform(GpPen
*pen
, REAL angle
, GpMatrixOrder order
)
486 TRACE("(%p,%0.2f,%u)\n", pen
, angle
, order
);
489 return InvalidParameter
;
491 return GdipRotateMatrix(&pen
->transform
, angle
, order
);
494 GpStatus WINGDIPAPI
GdipMultiplyPenTransform(GpPen
*pen
, GDIPCONST GpMatrix
*matrix
,
497 TRACE("(%p,%s,%u)\n", pen
, debugstr_matrix(matrix
), order
);
500 return InvalidParameter
;
502 return GdipMultiplyMatrix(&pen
->transform
, matrix
, order
);
505 GpStatus WINGDIPAPI
GdipSetPenBrushFill(GpPen
*pen
, GpBrush
*brush
)
507 TRACE("(%p, %p)\n", pen
, brush
);
510 return InvalidParameter
;
512 GdipDeleteBrush(pen
->brush
);
513 return GdipCloneBrush(brush
, &pen
->brush
);
516 GpStatus WINGDIPAPI
GdipSetPenColor(GpPen
*pen
, ARGB argb
)
518 TRACE("(%p, %lx)\n", pen
, argb
);
521 return InvalidParameter
;
523 if(pen
->brush
->bt
!= BrushTypeSolidColor
)
524 return NotImplemented
;
526 return GdipSetSolidFillColor(((GpSolidFill
*)pen
->brush
), argb
);
529 GpStatus WINGDIPAPI
GdipGetPenCompoundArray(GpPen
*pen
, REAL
*compoundarray
, INT count
)
531 TRACE("(%p, %p, %i)\n", pen
, compoundarray
, count
);
533 if (!pen
|| !compoundarray
|| count
> pen
->compound_array_size
)
534 return InvalidParameter
;
535 if (pen
->compound_array
&& count
> 0)
536 memcpy(compoundarray
, pen
->compound_array
, count
* sizeof(REAL
));
540 GpStatus WINGDIPAPI
GdipGetPenCompoundCount(GpPen
*pen
, INT
*count
)
542 TRACE("(%p, %p)\n", pen
, count
);
545 return InvalidParameter
;
546 *count
= pen
->compound_array_size
;
550 GpStatus WINGDIPAPI
GdipSetPenCompoundArray(GpPen
*pen
, GDIPCONST REAL
*compoundarray
,
555 TRACE("(%p, %p, %i)\n", pen
, compoundarray
, count
);
557 if(!pen
|| !compoundarray
|| count
< 2 || count
%2 == 1 || *compoundarray
< 0.0 || *compoundarray
> 1.0)
558 return InvalidParameter
;
560 for(i
= 1; i
<count
; i
++)
562 if((compoundarray
[i
] < compoundarray
[i
- 1]) || (compoundarray
[i
] > 1.0))
563 return InvalidParameter
;
566 tmp
= heap_alloc_zero(count
* sizeof(REAL
));
569 heap_free(pen
->compound_array
);
570 pen
->compound_array
= tmp
;
571 memcpy(pen
->compound_array
, compoundarray
, count
* sizeof(REAL
));
572 pen
->compound_array_size
= count
;
576 GpStatus WINGDIPAPI
GdipSetPenCustomEndCap(GpPen
*pen
, GpCustomLineCap
* customCap
)
578 GpCustomLineCap
* cap
;
581 TRACE("(%p, %p)\n", pen
, customCap
);
583 /* native crashes on pen == NULL, customCap != NULL */
584 if(!customCap
) return InvalidParameter
;
586 if((ret
= GdipCloneCustomLineCap(customCap
, &cap
)) == Ok
){
587 GdipDeleteCustomLineCap(pen
->customend
);
588 pen
->endcap
= LineCapCustom
;
589 pen
->customend
= cap
;
595 GpStatus WINGDIPAPI
GdipSetPenCustomStartCap(GpPen
*pen
, GpCustomLineCap
* customCap
)
597 GpCustomLineCap
* cap
;
600 TRACE("(%p, %p)\n", pen
, customCap
);
602 /* native crashes on pen == NULL, customCap != NULL */
603 if(!customCap
) return InvalidParameter
;
605 if((ret
= GdipCloneCustomLineCap(customCap
, &cap
)) == Ok
){
606 GdipDeleteCustomLineCap(pen
->customstart
);
607 pen
->startcap
= LineCapCustom
;
608 pen
->customstart
= cap
;
614 GpStatus WINGDIPAPI
GdipSetPenDashArray(GpPen
*pen
, GDIPCONST REAL
*dash
,
620 TRACE("(%p, %p, %d)\n", pen
, dash
, count
);
623 return InvalidParameter
;
628 for(i
= 0; i
< count
; i
++){
631 return InvalidParameter
;
634 heap_free(pen
->dashes
);
638 pen
->dashes
= heap_alloc_zero(count
* sizeof(REAL
));
644 GdipSetPenDashStyle(pen
, DashStyleCustom
);
645 memcpy(pen
->dashes
, dash
, count
* sizeof(REAL
));
646 pen
->numdashes
= count
;
651 GpStatus WINGDIPAPI
GdipSetPenDashCap197819(GpPen
*pen
, GpDashCap dashCap
)
653 TRACE("(%p, %d)\n", pen
, dashCap
);
656 return InvalidParameter
;
658 pen
->dashcap
= dashCap
;
663 /* FIXME: dash offset not used */
664 GpStatus WINGDIPAPI
GdipSetPenDashOffset(GpPen
*pen
, REAL offset
)
666 TRACE("(%p, %.2f)\n", pen
, offset
);
669 return InvalidParameter
;
671 pen
->offset
= offset
;
676 GpStatus WINGDIPAPI
GdipSetPenDashStyle(GpPen
*pen
, GpDashStyle dash
)
678 TRACE("(%p, %d)\n", pen
, dash
);
681 return InvalidParameter
;
683 if(dash
!= DashStyleCustom
){
684 heap_free(pen
->dashes
);
690 pen
->style
&= ~(PS_ALTERNATE
| PS_SOLID
| PS_DASH
| PS_DOT
| PS_DASHDOT
|
691 PS_DASHDOTDOT
| PS_NULL
| PS_USERSTYLE
| PS_INSIDEFRAME
);
692 pen
->style
|= gdip_to_gdi_dash(dash
);
697 GpStatus WINGDIPAPI
GdipSetPenEndCap(GpPen
*pen
, GpLineCap cap
)
699 TRACE("(%p, %d)\n", pen
, cap
);
701 if(!pen
) return InvalidParameter
;
703 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
704 GdipDeleteCustomLineCap(pen
->customend
);
705 pen
->customend
= NULL
;
711 /* FIXME: startcap, dashcap not used. */
712 GpStatus WINGDIPAPI
GdipSetPenLineCap197819(GpPen
*pen
, GpLineCap start
,
713 GpLineCap end
, GpDashCap dash
)
715 TRACE("%p, %d, %d, %d)\n", pen
, start
, end
, dash
);
718 return InvalidParameter
;
720 GdipDeleteCustomLineCap(pen
->customend
);
721 GdipDeleteCustomLineCap(pen
->customstart
);
722 pen
->customend
= NULL
;
723 pen
->customstart
= NULL
;
725 pen
->startcap
= start
;
732 /* FIXME: Miter line joins behave a bit differently than they do in windows.
733 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
734 GpStatus WINGDIPAPI
GdipSetPenLineJoin(GpPen
*pen
, GpLineJoin join
)
736 TRACE("(%p, %d)\n", pen
, join
);
738 if(!pen
) return InvalidParameter
;
741 pen
->style
&= ~(PS_JOIN_ROUND
| PS_JOIN_BEVEL
| PS_JOIN_MITER
);
742 pen
->style
|= gdip_to_gdi_join(join
);
747 GpStatus WINGDIPAPI
GdipSetPenMiterLimit(GpPen
*pen
, REAL limit
)
749 TRACE("(%p, %.2f)\n", pen
, limit
);
752 return InvalidParameter
;
754 pen
->miterlimit
= limit
;
759 GpStatus WINGDIPAPI
GdipSetPenStartCap(GpPen
*pen
, GpLineCap cap
)
761 TRACE("(%p, %d)\n", pen
, cap
);
763 if(!pen
) return InvalidParameter
;
765 GdipDeleteCustomLineCap(pen
->customstart
);
766 pen
->customstart
= NULL
;
772 GpStatus WINGDIPAPI
GdipSetPenWidth(GpPen
*pen
, REAL width
)
774 TRACE("(%p, %.2f)\n", pen
, width
);
776 if(!pen
) return InvalidParameter
;
783 GpStatus WINGDIPAPI
GdipSetPenMode(GpPen
*pen
, GpPenAlignment mode
)
785 TRACE("(%p, %d)\n", pen
, mode
);
787 if(!pen
) return InvalidParameter
;