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
;
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
= heap_alloc_zero(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
= heap_alloc_zero(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
= heap_alloc_zero(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 heap_free(pen
->compound_array
);
214 heap_free(pen
->dashes
);
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
)
449 TRACE("(%p,%s)\n", pen
, debugstr_matrix(matrix
));
452 return InvalidParameter
;
455 FIXME("(%p,%p) Semi-stub\n", pen
, matrix
);
457 pen
->transform
= *matrix
;
462 GpStatus WINGDIPAPI
GdipGetPenTransform(GpPen
*pen
, GpMatrix
*matrix
)
464 TRACE("(%p,%s)\n", pen
, debugstr_matrix(matrix
));
467 return InvalidParameter
;
469 *matrix
= pen
->transform
;
474 GpStatus WINGDIPAPI
GdipTranslatePenTransform(GpPen
*pen
, REAL dx
, REAL dy
, GpMatrixOrder order
)
476 TRACE("(%p,%0.2f,%0.2f,%u)\n", pen
, dx
, dy
, order
);
479 return InvalidParameter
;
481 return GdipTranslateMatrix(&pen
->transform
, dx
, dy
, order
);
484 GpStatus WINGDIPAPI
GdipScalePenTransform(GpPen
*pen
, REAL sx
, REAL sy
, GpMatrixOrder order
)
486 TRACE("(%p,%0.2f,%0.2f,%u)\n", pen
, sx
, sy
, order
);
489 return InvalidParameter
;
491 return GdipScaleMatrix(&pen
->transform
, sx
, sy
, order
);
494 GpStatus WINGDIPAPI
GdipRotatePenTransform(GpPen
*pen
, REAL angle
, GpMatrixOrder order
)
496 TRACE("(%p,%0.2f,%u)\n", pen
, angle
, order
);
499 return InvalidParameter
;
501 return GdipRotateMatrix(&pen
->transform
, angle
, order
);
504 GpStatus WINGDIPAPI
GdipMultiplyPenTransform(GpPen
*pen
, GDIPCONST GpMatrix
*matrix
,
507 TRACE("(%p,%s,%u)\n", pen
, debugstr_matrix(matrix
), order
);
510 return InvalidParameter
;
512 return GdipMultiplyMatrix(&pen
->transform
, matrix
, order
);
515 GpStatus WINGDIPAPI
GdipSetPenBrushFill(GpPen
*pen
, GpBrush
*brush
)
517 TRACE("(%p, %p)\n", pen
, brush
);
520 return InvalidParameter
;
522 GdipDeleteBrush(pen
->brush
);
523 return GdipCloneBrush(brush
, &pen
->brush
);
526 GpStatus WINGDIPAPI
GdipSetPenColor(GpPen
*pen
, ARGB argb
)
528 TRACE("(%p, %lx)\n", pen
, argb
);
531 return InvalidParameter
;
533 if(pen
->brush
->bt
!= BrushTypeSolidColor
)
534 return NotImplemented
;
536 return GdipSetSolidFillColor(((GpSolidFill
*)pen
->brush
), argb
);
539 GpStatus WINGDIPAPI
GdipGetPenCompoundArray(GpPen
*pen
, REAL
*compoundarray
, INT count
)
541 TRACE("(%p, %p, %i)\n", pen
, compoundarray
, count
);
543 if (!pen
|| !compoundarray
|| count
> pen
->compound_array_size
)
544 return InvalidParameter
;
545 if (pen
->compound_array
&& count
> 0)
546 memcpy(compoundarray
, pen
->compound_array
, count
* sizeof(REAL
));
550 GpStatus WINGDIPAPI
GdipGetPenCompoundCount(GpPen
*pen
, INT
*count
)
552 TRACE("(%p, %p)\n", pen
, count
);
555 return InvalidParameter
;
556 *count
= pen
->compound_array_size
;
560 GpStatus WINGDIPAPI
GdipSetPenCompoundArray(GpPen
*pen
, GDIPCONST REAL
*compoundarray
,
565 TRACE("(%p, %p, %i)\n", pen
, compoundarray
, count
);
567 if(!pen
|| !compoundarray
|| count
< 2 || count
%2 == 1 || *compoundarray
< 0.0 || *compoundarray
> 1.0)
568 return InvalidParameter
;
570 for(i
= 1; i
<count
; i
++)
572 if((compoundarray
[i
] < compoundarray
[i
- 1]) || (compoundarray
[i
] > 1.0))
573 return InvalidParameter
;
576 tmp
= heap_alloc_zero(count
* sizeof(REAL
));
579 heap_free(pen
->compound_array
);
580 pen
->compound_array
= tmp
;
581 memcpy(pen
->compound_array
, compoundarray
, count
* sizeof(REAL
));
582 pen
->compound_array_size
= count
;
586 GpStatus WINGDIPAPI
GdipSetPenCustomEndCap(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
->customend
);
598 pen
->endcap
= LineCapCustom
;
599 pen
->customend
= cap
;
605 GpStatus WINGDIPAPI
GdipSetPenCustomStartCap(GpPen
*pen
, GpCustomLineCap
* customCap
)
607 GpCustomLineCap
* cap
;
610 TRACE("(%p, %p)\n", pen
, customCap
);
612 /* native crashes on pen == NULL, customCap != NULL */
613 if(!customCap
) return InvalidParameter
;
615 if((ret
= GdipCloneCustomLineCap(customCap
, &cap
)) == Ok
){
616 GdipDeleteCustomLineCap(pen
->customstart
);
617 pen
->startcap
= LineCapCustom
;
618 pen
->customstart
= cap
;
624 GpStatus WINGDIPAPI
GdipSetPenDashArray(GpPen
*pen
, GDIPCONST REAL
*dash
,
630 TRACE("(%p, %p, %d)\n", pen
, dash
, count
);
633 return InvalidParameter
;
638 for(i
= 0; i
< count
; i
++){
641 return InvalidParameter
;
644 heap_free(pen
->dashes
);
648 pen
->dashes
= heap_alloc_zero(count
* sizeof(REAL
));
654 GdipSetPenDashStyle(pen
, DashStyleCustom
);
655 memcpy(pen
->dashes
, dash
, count
* sizeof(REAL
));
656 pen
->numdashes
= count
;
661 GpStatus WINGDIPAPI
GdipSetPenDashCap197819(GpPen
*pen
, GpDashCap dashCap
)
663 TRACE("(%p, %d)\n", pen
, dashCap
);
666 return InvalidParameter
;
668 pen
->dashcap
= dashCap
;
673 /* FIXME: dash offset not used */
674 GpStatus WINGDIPAPI
GdipSetPenDashOffset(GpPen
*pen
, REAL offset
)
676 TRACE("(%p, %.2f)\n", pen
, offset
);
679 return InvalidParameter
;
681 pen
->offset
= offset
;
686 GpStatus WINGDIPAPI
GdipSetPenDashStyle(GpPen
*pen
, GpDashStyle dash
)
688 TRACE("(%p, %d)\n", pen
, dash
);
691 return InvalidParameter
;
693 if(dash
!= DashStyleCustom
){
694 heap_free(pen
->dashes
);
700 pen
->style
&= ~(PS_ALTERNATE
| PS_SOLID
| PS_DASH
| PS_DOT
| PS_DASHDOT
|
701 PS_DASHDOTDOT
| PS_NULL
| PS_USERSTYLE
| PS_INSIDEFRAME
);
702 pen
->style
|= gdip_to_gdi_dash(dash
);
707 GpStatus WINGDIPAPI
GdipSetPenEndCap(GpPen
*pen
, GpLineCap cap
)
709 TRACE("(%p, %d)\n", pen
, cap
);
711 if(!pen
) return InvalidParameter
;
713 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
714 GdipDeleteCustomLineCap(pen
->customend
);
715 pen
->customend
= NULL
;
721 /* FIXME: startcap, dashcap not used. */
722 GpStatus WINGDIPAPI
GdipSetPenLineCap197819(GpPen
*pen
, GpLineCap start
,
723 GpLineCap end
, GpDashCap dash
)
725 TRACE("%p, %d, %d, %d)\n", pen
, start
, end
, dash
);
728 return InvalidParameter
;
730 GdipDeleteCustomLineCap(pen
->customend
);
731 GdipDeleteCustomLineCap(pen
->customstart
);
732 pen
->customend
= NULL
;
733 pen
->customstart
= NULL
;
735 pen
->startcap
= start
;
742 /* FIXME: Miter line joins behave a bit differently than they do in windows.
743 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
744 GpStatus WINGDIPAPI
GdipSetPenLineJoin(GpPen
*pen
, GpLineJoin join
)
746 TRACE("(%p, %d)\n", pen
, join
);
748 if(!pen
) return InvalidParameter
;
751 pen
->style
&= ~(PS_JOIN_ROUND
| PS_JOIN_BEVEL
| PS_JOIN_MITER
);
752 pen
->style
|= gdip_to_gdi_join(join
);
757 GpStatus WINGDIPAPI
GdipSetPenMiterLimit(GpPen
*pen
, REAL limit
)
759 TRACE("(%p, %.2f)\n", pen
, limit
);
762 return InvalidParameter
;
764 pen
->miterlimit
= limit
;
769 GpStatus WINGDIPAPI
GdipSetPenStartCap(GpPen
*pen
, GpLineCap cap
)
771 TRACE("(%p, %d)\n", pen
, cap
);
773 if(!pen
) return InvalidParameter
;
775 GdipDeleteCustomLineCap(pen
->customstart
);
776 pen
->customstart
= NULL
;
782 GpStatus WINGDIPAPI
GdipSetPenWidth(GpPen
*pen
, REAL width
)
784 TRACE("(%p, %.2f)\n", pen
, width
);
786 if(!pen
) return InvalidParameter
;
793 GpStatus WINGDIPAPI
GdipSetPenMode(GpPen
*pen
, GpPenAlignment mode
)
795 TRACE("(%p, %d)\n", pen
, mode
);
797 if(!pen
) return InvalidParameter
;