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
= malloc(sizeof(GpPen
));
98 if(!*clonepen
) return OutOfMemory
;
102 (*clonepen
)->customstart
= NULL
;
103 (*clonepen
)->customend
= NULL
;
104 (*clonepen
)->brush
= NULL
;
105 (*clonepen
)->dashes
= NULL
;
106 (*clonepen
)->compound_array
= NULL
;
108 stat
= GdipCloneBrush(pen
->brush
, &(*clonepen
)->brush
);
110 if (stat
== Ok
&& pen
->customstart
)
111 stat
= GdipCloneCustomLineCap(pen
->customstart
, &(*clonepen
)->customstart
);
113 if (stat
== Ok
&& pen
->customend
)
114 stat
= GdipCloneCustomLineCap(pen
->customend
, &(*clonepen
)->customend
);
116 if (stat
== Ok
&& pen
->dashes
)
118 (*clonepen
)->dashes
= malloc(pen
->numdashes
* sizeof(REAL
));
119 if ((*clonepen
)->dashes
)
120 memcpy((*clonepen
)->dashes
, pen
->dashes
, pen
->numdashes
* sizeof(REAL
));
125 if (stat
== Ok
&& pen
->compound_array
)
127 (*clonepen
)->compound_array
= malloc(pen
->compound_array_size
* sizeof(REAL
));
128 if ((*clonepen
)->compound_array
)
129 memcpy((*clonepen
)->compound_array
, pen
->compound_array
, pen
->compound_array_size
* sizeof(REAL
));
136 GdipDeletePen(*clonepen
);
141 TRACE("<-- %p\n", *clonepen
);
146 GpStatus WINGDIPAPI
GdipCreatePen1(ARGB color
, REAL width
, GpUnit unit
,
152 TRACE("(%lx, %.2f, %d, %p)\n", color
, width
, unit
, pen
);
154 GdipCreateSolidFill(color
, (GpSolidFill
**)(&brush
));
155 status
= GdipCreatePen2(brush
, width
, unit
, pen
);
156 GdipDeleteBrush(brush
);
160 GpStatus WINGDIPAPI
GdipCreatePen2(GpBrush
*brush
, REAL width
, GpUnit unit
,
164 GpBrush
*clone_brush
;
166 TRACE("(%p, %.2f, %d, %p)\n", brush
, width
, unit
, pen
);
169 return InvalidParameter
;
171 gp_pen
= calloc(1, sizeof(GpPen
));
172 if(!gp_pen
) return OutOfMemory
;
174 gp_pen
->style
= GP_DEFAULT_PENSTYLE
;
175 gp_pen
->width
= width
;
177 gp_pen
->endcap
= LineCapFlat
;
178 gp_pen
->join
= LineJoinMiter
;
179 gp_pen
->miterlimit
= 10.0;
180 gp_pen
->dash
= DashStyleSolid
;
181 gp_pen
->offset
= 0.0;
182 gp_pen
->customstart
= NULL
;
183 gp_pen
->customend
= NULL
;
184 gp_pen
->compound_array
= NULL
;
185 gp_pen
->compound_array_size
= 0;
186 GdipSetMatrixElements(&gp_pen
->transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
188 if(!((gp_pen
->unit
== UnitWorld
) || (gp_pen
->unit
== UnitPixel
))) {
189 FIXME("UnitWorld, UnitPixel only supported units\n");
191 return NotImplemented
;
194 GdipCloneBrush(brush
, &clone_brush
);
195 gp_pen
->brush
= clone_brush
;
199 TRACE("<-- %p\n", *pen
);
204 GpStatus WINGDIPAPI
GdipDeletePen(GpPen
*pen
)
206 TRACE("(%p)\n", pen
);
208 if(!pen
) return InvalidParameter
;
210 GdipDeleteBrush(pen
->brush
);
211 GdipDeleteCustomLineCap(pen
->customstart
);
212 GdipDeleteCustomLineCap(pen
->customend
);
213 free(pen
->compound_array
);
220 GpStatus WINGDIPAPI
GdipGetPenBrushFill(GpPen
*pen
, GpBrush
**brush
)
222 TRACE("(%p, %p)\n", pen
, brush
);
225 return InvalidParameter
;
227 return GdipCloneBrush(pen
->brush
, brush
);
230 GpStatus WINGDIPAPI
GdipGetPenColor(GpPen
*pen
, ARGB
*argb
)
232 TRACE("(%p, %p)\n", pen
, argb
);
235 return InvalidParameter
;
237 if(pen
->brush
->bt
!= BrushTypeSolidColor
)
238 return NotImplemented
;
240 return GdipGetSolidFillColor(((GpSolidFill
*)pen
->brush
), argb
);
243 GpStatus WINGDIPAPI
GdipGetPenCustomEndCap(GpPen
*pen
, GpCustomLineCap
** customCap
)
245 TRACE("(%p, %p)\n", pen
, customCap
);
247 if(!pen
|| !customCap
)
248 return InvalidParameter
;
255 return GdipCloneCustomLineCap(pen
->customend
, customCap
);
258 GpStatus WINGDIPAPI
GdipGetPenCustomStartCap(GpPen
*pen
, GpCustomLineCap
** customCap
)
260 TRACE("(%p, %p)\n", pen
, customCap
);
262 if(!pen
|| !customCap
)
263 return InvalidParameter
;
265 if(!pen
->customstart
){
270 return GdipCloneCustomLineCap(pen
->customstart
, customCap
);
273 GpStatus WINGDIPAPI
GdipGetPenDashArray(GpPen
*pen
, REAL
*dash
, INT count
)
275 TRACE("(%p, %p, %d)\n", pen
, dash
, count
);
277 if(!pen
|| !dash
|| count
> pen
->numdashes
)
278 return InvalidParameter
;
280 /* note: if you pass a negative value for count, it crashes native gdiplus. */
284 memcpy(dash
, pen
->dashes
, count
* sizeof(REAL
));
289 GpStatus WINGDIPAPI
GdipGetPenDashCap197819(GpPen
*pen
, GpDashCap
*dashCap
)
291 TRACE("(%p, %p)\n", pen
, dashCap
);
294 return InvalidParameter
;
296 *dashCap
= pen
->dashcap
;
301 GpStatus WINGDIPAPI
GdipGetPenDashCount(GpPen
*pen
, INT
*count
)
303 TRACE("(%p, %p)\n", pen
, count
);
306 return InvalidParameter
;
308 *count
= pen
->numdashes
;
313 GpStatus WINGDIPAPI
GdipGetPenDashOffset(GpPen
*pen
, REAL
*offset
)
315 TRACE("(%p, %p)\n", pen
, offset
);
318 return InvalidParameter
;
320 *offset
= pen
->offset
;
325 GpStatus WINGDIPAPI
GdipGetPenDashStyle(GpPen
*pen
, GpDashStyle
*dash
)
327 TRACE("(%p, %p)\n", pen
, dash
);
330 return InvalidParameter
;
337 GpStatus WINGDIPAPI
GdipGetPenEndCap(GpPen
*pen
, GpLineCap
*endCap
)
339 TRACE("(%p, %p)\n", pen
, endCap
);
342 return InvalidParameter
;
344 *endCap
= pen
->endcap
;
349 GpStatus WINGDIPAPI
GdipGetPenFillType(GpPen
*pen
, GpPenType
* type
)
351 TRACE("(%p, %p)\n", pen
, type
);
354 return InvalidParameter
;
356 *type
= bt_to_pt(pen
->brush
->bt
);
361 GpStatus WINGDIPAPI
GdipGetPenLineJoin(GpPen
*pen
, GpLineJoin
*lineJoin
)
363 TRACE("(%p, %p)\n", pen
, lineJoin
);
365 if(!pen
|| !lineJoin
)
366 return InvalidParameter
;
368 *lineJoin
= pen
->join
;
373 GpStatus WINGDIPAPI
GdipGetPenMode(GpPen
*pen
, GpPenAlignment
*mode
)
375 TRACE("(%p, %p)\n", pen
, mode
);
378 return InvalidParameter
;
385 GpStatus WINGDIPAPI
GdipGetPenMiterLimit(GpPen
*pen
, REAL
*miterLimit
)
387 TRACE("(%p, %p)\n", pen
, miterLimit
);
389 if(!pen
|| !miterLimit
)
390 return InvalidParameter
;
392 *miterLimit
= pen
->miterlimit
;
397 GpStatus WINGDIPAPI
GdipGetPenStartCap(GpPen
*pen
, GpLineCap
*startCap
)
399 TRACE("(%p, %p)\n", pen
, startCap
);
401 if(!pen
|| !startCap
)
402 return InvalidParameter
;
404 *startCap
= pen
->startcap
;
409 GpStatus WINGDIPAPI
GdipGetPenUnit(GpPen
*pen
, GpUnit
*unit
)
411 TRACE("(%p, %p)\n", pen
, unit
);
414 return InvalidParameter
;
421 GpStatus WINGDIPAPI
GdipGetPenWidth(GpPen
*pen
, REAL
*width
)
423 TRACE("(%p, %p)\n", pen
, width
);
426 return InvalidParameter
;
433 GpStatus WINGDIPAPI
GdipResetPenTransform(GpPen
*pen
)
435 TRACE("(%p)\n", pen
);
438 return InvalidParameter
;
440 GdipSetMatrixElements(&pen
->transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
445 GpStatus WINGDIPAPI
GdipSetPenTransform(GpPen
*pen
, GpMatrix
*matrix
)
450 TRACE("(%p, %s)\n", pen
, debugstr_matrix(matrix
));
453 return InvalidParameter
;
456 FIXME("(%p,%p) Semi-stub\n", pen
, matrix
);
458 GdipIsMatrixInvertible(matrix
, &result
);
460 return InvalidParameter
;
461 pen
->transform
= *matrix
;
466 GpStatus WINGDIPAPI
GdipGetPenTransform(GpPen
*pen
, GpMatrix
*matrix
)
468 TRACE("(%p,%s)\n", pen
, debugstr_matrix(matrix
));
471 return InvalidParameter
;
473 *matrix
= pen
->transform
;
478 GpStatus WINGDIPAPI
GdipTranslatePenTransform(GpPen
*pen
, REAL dx
, REAL dy
, GpMatrixOrder order
)
480 TRACE("(%p,%0.2f,%0.2f,%u)\n", pen
, dx
, dy
, order
);
483 return InvalidParameter
;
485 return GdipTranslateMatrix(&pen
->transform
, dx
, dy
, order
);
488 GpStatus WINGDIPAPI
GdipScalePenTransform(GpPen
*pen
, REAL sx
, REAL sy
, GpMatrixOrder order
)
490 TRACE("(%p,%0.2f,%0.2f,%u)\n", pen
, sx
, sy
, order
);
493 return InvalidParameter
;
495 return GdipScaleMatrix(&pen
->transform
, sx
, sy
, order
);
498 GpStatus WINGDIPAPI
GdipRotatePenTransform(GpPen
*pen
, REAL angle
, GpMatrixOrder order
)
500 TRACE("(%p,%0.2f,%u)\n", pen
, angle
, order
);
503 return InvalidParameter
;
505 return GdipRotateMatrix(&pen
->transform
, angle
, order
);
508 GpStatus WINGDIPAPI
GdipMultiplyPenTransform(GpPen
*pen
, GDIPCONST GpMatrix
*matrix
,
511 TRACE("(%p,%s,%u)\n", pen
, debugstr_matrix(matrix
), order
);
514 return InvalidParameter
;
516 return GdipMultiplyMatrix(&pen
->transform
, matrix
, order
);
519 GpStatus WINGDIPAPI
GdipSetPenBrushFill(GpPen
*pen
, GpBrush
*brush
)
521 TRACE("(%p, %p)\n", pen
, brush
);
524 return InvalidParameter
;
526 GdipDeleteBrush(pen
->brush
);
527 return GdipCloneBrush(brush
, &pen
->brush
);
530 GpStatus WINGDIPAPI
GdipSetPenColor(GpPen
*pen
, ARGB argb
)
532 TRACE("(%p, %lx)\n", pen
, argb
);
535 return InvalidParameter
;
537 if(pen
->brush
->bt
!= BrushTypeSolidColor
)
538 return NotImplemented
;
540 return GdipSetSolidFillColor(((GpSolidFill
*)pen
->brush
), argb
);
543 GpStatus WINGDIPAPI
GdipGetPenCompoundArray(GpPen
*pen
, REAL
*compoundarray
, INT count
)
545 TRACE("(%p, %p, %i)\n", pen
, compoundarray
, count
);
547 if (!pen
|| !compoundarray
|| count
> pen
->compound_array_size
)
548 return InvalidParameter
;
549 if (pen
->compound_array
&& count
> 0)
550 memcpy(compoundarray
, pen
->compound_array
, count
* sizeof(REAL
));
554 GpStatus WINGDIPAPI
GdipGetPenCompoundCount(GpPen
*pen
, INT
*count
)
556 TRACE("(%p, %p)\n", pen
, count
);
559 return InvalidParameter
;
560 *count
= pen
->compound_array_size
;
564 GpStatus WINGDIPAPI
GdipSetPenCompoundArray(GpPen
*pen
, GDIPCONST REAL
*compoundarray
,
569 TRACE("(%p, %p, %i)\n", pen
, compoundarray
, count
);
571 if(!pen
|| !compoundarray
|| count
< 2 || count
%2 == 1 || *compoundarray
< 0.0 || *compoundarray
> 1.0)
572 return InvalidParameter
;
574 for(i
= 1; i
<count
; i
++)
576 if((compoundarray
[i
] < compoundarray
[i
- 1]) || (compoundarray
[i
] > 1.0))
577 return InvalidParameter
;
580 tmp
= malloc(count
* sizeof(REAL
));
583 free(pen
->compound_array
);
584 pen
->compound_array
= tmp
;
585 memcpy(pen
->compound_array
, compoundarray
, count
* sizeof(REAL
));
586 pen
->compound_array_size
= count
;
590 GpStatus WINGDIPAPI
GdipSetPenCustomEndCap(GpPen
*pen
, GpCustomLineCap
* customCap
)
592 GpCustomLineCap
* cap
;
595 TRACE("(%p, %p)\n", pen
, customCap
);
597 /* native crashes on pen == NULL, customCap != NULL */
598 if(!customCap
) return InvalidParameter
;
600 if((ret
= GdipCloneCustomLineCap(customCap
, &cap
)) == Ok
){
601 GdipDeleteCustomLineCap(pen
->customend
);
602 pen
->endcap
= LineCapCustom
;
603 pen
->customend
= cap
;
609 GpStatus WINGDIPAPI
GdipSetPenCustomStartCap(GpPen
*pen
, GpCustomLineCap
* customCap
)
611 GpCustomLineCap
* cap
;
614 TRACE("(%p, %p)\n", pen
, customCap
);
616 /* native crashes on pen == NULL, customCap != NULL */
617 if(!customCap
) return InvalidParameter
;
619 if((ret
= GdipCloneCustomLineCap(customCap
, &cap
)) == Ok
){
620 GdipDeleteCustomLineCap(pen
->customstart
);
621 pen
->startcap
= LineCapCustom
;
622 pen
->customstart
= cap
;
628 GpStatus WINGDIPAPI
GdipSetPenDashArray(GpPen
*pen
, GDIPCONST REAL
*dash
,
633 TRACE("(%p, %p, %d)\n", pen
, dash
, count
);
636 return InvalidParameter
;
641 for(i
= 0; i
< count
; i
++){
643 return InvalidParameter
;
650 pen
->dashes
= malloc(count
* sizeof(REAL
));
656 GdipSetPenDashStyle(pen
, DashStyleCustom
);
657 memcpy(pen
->dashes
, dash
, count
* sizeof(REAL
));
658 pen
->numdashes
= count
;
663 GpStatus WINGDIPAPI
GdipSetPenDashCap197819(GpPen
*pen
, GpDashCap dashCap
)
665 TRACE("(%p, %d)\n", pen
, dashCap
);
668 return InvalidParameter
;
670 pen
->dashcap
= dashCap
;
675 /* FIXME: dash offset not used */
676 GpStatus WINGDIPAPI
GdipSetPenDashOffset(GpPen
*pen
, REAL offset
)
678 TRACE("(%p, %.2f)\n", pen
, offset
);
681 return InvalidParameter
;
683 pen
->offset
= offset
;
688 GpStatus WINGDIPAPI
GdipSetPenDashStyle(GpPen
*pen
, GpDashStyle dash
)
690 TRACE("(%p, %d)\n", pen
, dash
);
693 return InvalidParameter
;
695 if(dash
!= DashStyleCustom
){
702 pen
->style
&= ~(PS_ALTERNATE
| PS_SOLID
| PS_DASH
| PS_DOT
| PS_DASHDOT
|
703 PS_DASHDOTDOT
| PS_NULL
| PS_USERSTYLE
| PS_INSIDEFRAME
);
704 pen
->style
|= gdip_to_gdi_dash(dash
);
709 GpStatus WINGDIPAPI
GdipSetPenEndCap(GpPen
*pen
, GpLineCap cap
)
711 TRACE("(%p, %d)\n", pen
, cap
);
713 if(!pen
) return InvalidParameter
;
715 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
716 GdipDeleteCustomLineCap(pen
->customend
);
717 pen
->customend
= NULL
;
723 /* FIXME: startcap, dashcap not used. */
724 GpStatus WINGDIPAPI
GdipSetPenLineCap197819(GpPen
*pen
, GpLineCap start
,
725 GpLineCap end
, GpDashCap dash
)
727 TRACE("%p, %d, %d, %d)\n", pen
, start
, end
, dash
);
730 return InvalidParameter
;
732 GdipDeleteCustomLineCap(pen
->customend
);
733 GdipDeleteCustomLineCap(pen
->customstart
);
734 pen
->customend
= NULL
;
735 pen
->customstart
= NULL
;
737 pen
->startcap
= start
;
744 /* FIXME: Miter line joins behave a bit differently than they do in windows.
745 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
746 GpStatus WINGDIPAPI
GdipSetPenLineJoin(GpPen
*pen
, GpLineJoin join
)
748 TRACE("(%p, %d)\n", pen
, join
);
750 if(!pen
) return InvalidParameter
;
753 pen
->style
&= ~(PS_JOIN_ROUND
| PS_JOIN_BEVEL
| PS_JOIN_MITER
);
754 pen
->style
|= gdip_to_gdi_join(join
);
759 GpStatus WINGDIPAPI
GdipSetPenMiterLimit(GpPen
*pen
, REAL limit
)
761 TRACE("(%p, %.2f)\n", pen
, limit
);
764 return InvalidParameter
;
766 pen
->miterlimit
= limit
;
771 GpStatus WINGDIPAPI
GdipSetPenStartCap(GpPen
*pen
, GpLineCap cap
)
773 TRACE("(%p, %d)\n", pen
, cap
);
775 if(!pen
) return InvalidParameter
;
777 GdipDeleteCustomLineCap(pen
->customstart
);
778 pen
->customstart
= NULL
;
784 GpStatus WINGDIPAPI
GdipSetPenWidth(GpPen
*pen
, REAL width
)
786 TRACE("(%p, %.2f)\n", pen
, width
);
788 if(!pen
) return InvalidParameter
;
795 GpStatus WINGDIPAPI
GdipSetPenMode(GpPen
*pen
, GpPenAlignment mode
)
797 TRACE("(%p, %d)\n", pen
, mode
);
799 if(!pen
) return InvalidParameter
;