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
19 #include "gdiplus_private.h"
21 static DWORD
gdip_to_gdi_dash(GpDashStyle dash
)
30 case DashStyleDashDot
:
32 case DashStyleDashDotDot
:
37 ERR("Not a member of GpDashStyle enumeration\n");
42 static DWORD
gdip_to_gdi_join(GpLineJoin join
)
50 case LineJoinMiterClipped
:
53 ERR("Not a member of GpLineJoin enumeration\n");
58 static GpPenType
bt_to_pt(GpBrushType bt
)
61 case BrushTypeSolidColor
:
62 return PenTypeSolidColor
;
63 case BrushTypeHatchFill
:
64 return PenTypeHatchFill
;
65 case BrushTypeTextureFill
:
66 return PenTypeTextureFill
;
67 case BrushTypePathGradient
:
68 return PenTypePathGradient
;
69 case BrushTypeLinearGradient
:
70 return PenTypeLinearGradient
;
72 return PenTypeUnknown
;
76 GpStatus WINGDIPAPI
GdipClonePen(GpPen
*pen
, GpPen
**clonepen
)
80 TRACE("(%p, %p)\n", pen
, clonepen
);
83 return InvalidParameter
;
85 *clonepen
= GdipAlloc(sizeof(GpPen
));
86 if(!*clonepen
) return OutOfMemory
;
90 (*clonepen
)->customstart
= NULL
;
91 (*clonepen
)->customend
= NULL
;
92 (*clonepen
)->brush
= NULL
;
93 (*clonepen
)->dashes
= NULL
;
95 stat
= GdipCloneBrush(pen
->brush
, &(*clonepen
)->brush
);
97 if (stat
== Ok
&& pen
->customstart
)
98 stat
= GdipCloneCustomLineCap(pen
->customstart
, &(*clonepen
)->customstart
);
100 if (stat
== Ok
&& pen
->customend
)
101 stat
= GdipCloneCustomLineCap(pen
->customend
, &(*clonepen
)->customend
);
103 if (stat
== Ok
&& pen
->dashes
)
105 (*clonepen
)->dashes
= GdipAlloc(pen
->numdashes
* sizeof(REAL
));
106 if ((*clonepen
)->dashes
)
107 memcpy((*clonepen
)->dashes
, pen
->dashes
, pen
->numdashes
* sizeof(REAL
));
114 GdipDeletePen(*clonepen
);
119 TRACE("<-- %p\n", *clonepen
);
124 GpStatus WINGDIPAPI
GdipCreatePen1(ARGB color
, REAL width
, GpUnit unit
,
130 TRACE("(%x, %.2f, %d, %p)\n", color
, width
, unit
, pen
);
132 GdipCreateSolidFill(color
, (GpSolidFill
**)(&brush
));
133 status
= GdipCreatePen2(brush
, width
, unit
, pen
);
134 GdipDeleteBrush(brush
);
138 GpStatus WINGDIPAPI
GdipCreatePen2(GpBrush
*brush
, REAL width
, GpUnit unit
,
142 GpBrush
*clone_brush
;
144 TRACE("(%p, %.2f, %d, %p)\n", brush
, width
, unit
, pen
);
147 return InvalidParameter
;
149 gp_pen
= GdipAlloc(sizeof(GpPen
));
150 if(!gp_pen
) return OutOfMemory
;
152 gp_pen
->style
= GP_DEFAULT_PENSTYLE
;
153 gp_pen
->width
= width
;
155 gp_pen
->endcap
= LineCapFlat
;
156 gp_pen
->join
= LineJoinMiter
;
157 gp_pen
->miterlimit
= 10.0;
158 gp_pen
->dash
= DashStyleSolid
;
159 gp_pen
->offset
= 0.0;
160 gp_pen
->customstart
= NULL
;
161 gp_pen
->customend
= NULL
;
163 if(!((gp_pen
->unit
== UnitWorld
) || (gp_pen
->unit
== UnitPixel
))) {
164 FIXME("UnitWorld, UnitPixel only supported units\n");
166 return NotImplemented
;
169 GdipCloneBrush(brush
, &clone_brush
);
170 gp_pen
->brush
= clone_brush
;
174 TRACE("<-- %p\n", *pen
);
179 GpStatus WINGDIPAPI
GdipDeletePen(GpPen
*pen
)
181 TRACE("(%p)\n", pen
);
183 if(!pen
) return InvalidParameter
;
185 GdipDeleteBrush(pen
->brush
);
186 GdipDeleteCustomLineCap(pen
->customstart
);
187 GdipDeleteCustomLineCap(pen
->customend
);
188 GdipFree(pen
->dashes
);
194 GpStatus WINGDIPAPI
GdipGetPenBrushFill(GpPen
*pen
, GpBrush
**brush
)
196 TRACE("(%p, %p)\n", pen
, brush
);
199 return InvalidParameter
;
201 return GdipCloneBrush(pen
->brush
, brush
);
204 GpStatus WINGDIPAPI
GdipGetPenColor(GpPen
*pen
, ARGB
*argb
)
206 TRACE("(%p, %p)\n", pen
, argb
);
209 return InvalidParameter
;
211 if(pen
->brush
->bt
!= BrushTypeSolidColor
)
212 return NotImplemented
;
214 return GdipGetSolidFillColor(((GpSolidFill
*)pen
->brush
), argb
);
217 GpStatus WINGDIPAPI
GdipGetPenCustomEndCap(GpPen
*pen
, GpCustomLineCap
** customCap
)
219 TRACE("(%p, %p)\n", pen
, customCap
);
221 if(!pen
|| !customCap
)
222 return InvalidParameter
;
229 return GdipCloneCustomLineCap(pen
->customend
, customCap
);
232 GpStatus WINGDIPAPI
GdipGetPenCustomStartCap(GpPen
*pen
, GpCustomLineCap
** customCap
)
234 TRACE("(%p, %p)\n", pen
, customCap
);
236 if(!pen
|| !customCap
)
237 return InvalidParameter
;
239 if(!pen
->customstart
){
244 return GdipCloneCustomLineCap(pen
->customstart
, customCap
);
247 GpStatus WINGDIPAPI
GdipGetPenDashArray(GpPen
*pen
, REAL
*dash
, INT count
)
249 TRACE("(%p, %p, %d)\n", pen
, dash
, count
);
251 if(!pen
|| !dash
|| count
> pen
->numdashes
)
252 return InvalidParameter
;
254 /* note: if you pass a negative value for count, it crashes native gdiplus. */
258 memcpy(dash
, pen
->dashes
, count
* sizeof(REAL
));
263 GpStatus WINGDIPAPI
GdipGetPenDashCap197819(GpPen
*pen
, GpDashCap
*dashCap
)
265 TRACE("(%p, %p)\n", pen
, dashCap
);
268 return InvalidParameter
;
270 *dashCap
= pen
->dashcap
;
275 GpStatus WINGDIPAPI
GdipGetPenDashCount(GpPen
*pen
, INT
*count
)
277 TRACE("(%p, %p)\n", pen
, count
);
280 return InvalidParameter
;
282 *count
= pen
->numdashes
;
287 GpStatus WINGDIPAPI
GdipGetPenDashOffset(GpPen
*pen
, REAL
*offset
)
289 TRACE("(%p, %p)\n", pen
, offset
);
292 return InvalidParameter
;
294 *offset
= pen
->offset
;
299 GpStatus WINGDIPAPI
GdipGetPenDashStyle(GpPen
*pen
, GpDashStyle
*dash
)
301 TRACE("(%p, %p)\n", pen
, dash
);
304 return InvalidParameter
;
311 GpStatus WINGDIPAPI
GdipGetPenEndCap(GpPen
*pen
, GpLineCap
*endCap
)
313 TRACE("(%p, %p)\n", pen
, endCap
);
316 return InvalidParameter
;
318 *endCap
= pen
->endcap
;
323 GpStatus WINGDIPAPI
GdipGetPenFillType(GpPen
*pen
, GpPenType
* type
)
325 TRACE("(%p, %p)\n", pen
, type
);
328 return InvalidParameter
;
330 *type
= bt_to_pt(pen
->brush
->bt
);
335 GpStatus WINGDIPAPI
GdipGetPenLineJoin(GpPen
*pen
, GpLineJoin
*lineJoin
)
337 TRACE("(%p, %p)\n", pen
, lineJoin
);
339 if(!pen
|| !lineJoin
)
340 return InvalidParameter
;
342 *lineJoin
= pen
->join
;
347 GpStatus WINGDIPAPI
GdipGetPenMode(GpPen
*pen
, GpPenAlignment
*mode
)
349 TRACE("(%p, %p)\n", pen
, mode
);
352 return InvalidParameter
;
359 GpStatus WINGDIPAPI
GdipGetPenMiterLimit(GpPen
*pen
, REAL
*miterLimit
)
361 TRACE("(%p, %p)\n", pen
, miterLimit
);
363 if(!pen
|| !miterLimit
)
364 return InvalidParameter
;
366 *miterLimit
= pen
->miterlimit
;
371 GpStatus WINGDIPAPI
GdipGetPenStartCap(GpPen
*pen
, GpLineCap
*startCap
)
373 TRACE("(%p, %p)\n", pen
, startCap
);
375 if(!pen
|| !startCap
)
376 return InvalidParameter
;
378 *startCap
= pen
->startcap
;
383 GpStatus WINGDIPAPI
GdipGetPenUnit(GpPen
*pen
, GpUnit
*unit
)
385 TRACE("(%p, %p)\n", pen
, unit
);
388 return InvalidParameter
;
395 GpStatus WINGDIPAPI
GdipGetPenWidth(GpPen
*pen
, REAL
*width
)
397 TRACE("(%p, %p)\n", pen
, width
);
400 return InvalidParameter
;
407 GpStatus WINGDIPAPI
GdipResetPenTransform(GpPen
*pen
)
411 TRACE("(%p)\n", pen
);
414 return InvalidParameter
;
417 FIXME("(%p) stub\n", pen
);
419 return NotImplemented
;
422 GpStatus WINGDIPAPI
GdipSetPenTransform(GpPen
*pen
, GpMatrix
*matrix
)
426 TRACE("(%p,%p)\n", pen
, matrix
);
429 return InvalidParameter
;
432 FIXME("not implemented\n");
434 return NotImplemented
;
437 GpStatus WINGDIPAPI
GdipGetPenTransform(GpPen
*pen
, GpMatrix
*matrix
)
441 TRACE("(%p,%p)\n", pen
, matrix
);
444 return InvalidParameter
;
447 FIXME("not implemented\n");
449 return NotImplemented
;
452 GpStatus WINGDIPAPI
GdipTranslatePenTransform(GpPen
*pen
, REAL dx
, REAL dy
, GpMatrixOrder order
)
456 TRACE("(%p,%0.2f,%0.2f,%u)\n", pen
, dx
, dy
, order
);
459 return InvalidParameter
;
462 FIXME("not implemented\n");
464 return NotImplemented
;
467 GpStatus WINGDIPAPI
GdipScalePenTransform(GpPen
*pen
, REAL sx
, REAL sy
, GpMatrixOrder order
)
471 TRACE("(%p,%0.2f,%0.2f,%u)\n", pen
, sx
, sy
, order
);
474 return InvalidParameter
;
477 FIXME("(%p, %.2f, %.2f, %d) stub\n", pen
, sx
, sy
, order
);
479 return NotImplemented
;
482 GpStatus WINGDIPAPI
GdipRotatePenTransform(GpPen
*pen
, REAL angle
, GpMatrixOrder order
)
486 TRACE("(%p,%0.2f,%u)\n", pen
, angle
, order
);
489 return InvalidParameter
;
492 FIXME("not implemented\n");
494 return NotImplemented
;
497 GpStatus WINGDIPAPI
GdipMultiplyPenTransform(GpPen
*pen
, GDIPCONST GpMatrix
*matrix
,
502 TRACE("(%p,%p,%u)\n", pen
, matrix
, order
);
505 return InvalidParameter
;
508 FIXME("not implemented\n");
510 return NotImplemented
;
513 GpStatus WINGDIPAPI
GdipSetPenBrushFill(GpPen
*pen
, GpBrush
*brush
)
515 TRACE("(%p, %p)\n", pen
, brush
);
518 return InvalidParameter
;
520 GdipDeleteBrush(pen
->brush
);
521 return GdipCloneBrush(brush
, &pen
->brush
);
524 GpStatus WINGDIPAPI
GdipSetPenColor(GpPen
*pen
, ARGB argb
)
526 TRACE("(%p, %x)\n", pen
, argb
);
529 return InvalidParameter
;
531 if(pen
->brush
->bt
!= BrushTypeSolidColor
)
532 return NotImplemented
;
534 return GdipSetSolidFillColor(((GpSolidFill
*)pen
->brush
), argb
);
537 GpStatus WINGDIPAPI
GdipGetPenCompoundCount(GpPen
*pen
, INT
*count
)
539 FIXME("(%p, %p): stub\n", pen
, count
);
542 return InvalidParameter
;
544 return NotImplemented
;
547 GpStatus WINGDIPAPI
GdipSetPenCompoundArray(GpPen
*pen
, GDIPCONST REAL
*dash
,
550 FIXME("(%p, %p, %i): stub\n", pen
, dash
, count
);
552 if (!pen
|| !dash
|| count
< 2 || count
%2 == 1)
553 return InvalidParameter
;
555 return NotImplemented
;
558 GpStatus WINGDIPAPI
GdipSetPenCustomEndCap(GpPen
*pen
, GpCustomLineCap
* customCap
)
560 GpCustomLineCap
* cap
;
563 TRACE("(%p, %p)\n", pen
, customCap
);
565 /* native crashes on pen == NULL, customCap != NULL */
566 if(!customCap
) return InvalidParameter
;
568 if((ret
= GdipCloneCustomLineCap(customCap
, &cap
)) == Ok
){
569 GdipDeleteCustomLineCap(pen
->customend
);
570 pen
->endcap
= LineCapCustom
;
571 pen
->customend
= cap
;
577 GpStatus WINGDIPAPI
GdipSetPenCustomStartCap(GpPen
*pen
, GpCustomLineCap
* customCap
)
579 GpCustomLineCap
* cap
;
582 TRACE("(%p, %p)\n", pen
, customCap
);
584 /* native crashes on pen == NULL, customCap != NULL */
585 if(!customCap
) return InvalidParameter
;
587 if((ret
= GdipCloneCustomLineCap(customCap
, &cap
)) == Ok
){
588 GdipDeleteCustomLineCap(pen
->customstart
);
589 pen
->startcap
= LineCapCustom
;
590 pen
->customstart
= cap
;
596 GpStatus WINGDIPAPI
GdipSetPenDashArray(GpPen
*pen
, GDIPCONST REAL
*dash
,
602 TRACE("(%p, %p, %d)\n", pen
, dash
, count
);
605 return InvalidParameter
;
610 for(i
= 0; i
< count
; i
++){
613 return InvalidParameter
;
616 if(sum
== 0.0 && count
)
617 return InvalidParameter
;
619 GdipFree(pen
->dashes
);
623 pen
->dashes
= GdipAlloc(count
* sizeof(REAL
));
629 GdipSetPenDashStyle(pen
, DashStyleCustom
);
630 memcpy(pen
->dashes
, dash
, count
* sizeof(REAL
));
631 pen
->numdashes
= count
;
636 GpStatus WINGDIPAPI
GdipSetPenDashCap197819(GpPen
*pen
, GpDashCap dashCap
)
638 TRACE("(%p, %d)\n", pen
, dashCap
);
641 return InvalidParameter
;
643 pen
->dashcap
= dashCap
;
648 /* FIXME: dash offset not used */
649 GpStatus WINGDIPAPI
GdipSetPenDashOffset(GpPen
*pen
, REAL offset
)
651 TRACE("(%p, %.2f)\n", pen
, offset
);
654 return InvalidParameter
;
656 pen
->offset
= offset
;
661 GpStatus WINGDIPAPI
GdipSetPenDashStyle(GpPen
*pen
, GpDashStyle dash
)
663 TRACE("(%p, %d)\n", pen
, dash
);
666 return InvalidParameter
;
668 if(dash
!= DashStyleCustom
){
669 GdipFree(pen
->dashes
);
675 pen
->style
&= ~(PS_ALTERNATE
| PS_SOLID
| PS_DASH
| PS_DOT
| PS_DASHDOT
|
676 PS_DASHDOTDOT
| PS_NULL
| PS_USERSTYLE
| PS_INSIDEFRAME
);
677 pen
->style
|= gdip_to_gdi_dash(dash
);
682 GpStatus WINGDIPAPI
GdipSetPenEndCap(GpPen
*pen
, GpLineCap cap
)
684 TRACE("(%p, %d)\n", pen
, cap
);
686 if(!pen
) return InvalidParameter
;
688 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
689 GdipDeleteCustomLineCap(pen
->customend
);
690 pen
->customend
= NULL
;
696 /* FIXME: startcap, dashcap not used. */
697 GpStatus WINGDIPAPI
GdipSetPenLineCap197819(GpPen
*pen
, GpLineCap start
,
698 GpLineCap end
, GpDashCap dash
)
700 TRACE("%p, %d, %d, %d)\n", pen
, start
, end
, dash
);
703 return InvalidParameter
;
705 GdipDeleteCustomLineCap(pen
->customend
);
706 GdipDeleteCustomLineCap(pen
->customstart
);
707 pen
->customend
= NULL
;
708 pen
->customstart
= NULL
;
710 pen
->startcap
= start
;
717 /* FIXME: Miter line joins behave a bit differently than they do in windows.
718 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
719 GpStatus WINGDIPAPI
GdipSetPenLineJoin(GpPen
*pen
, GpLineJoin join
)
721 TRACE("(%p, %d)\n", pen
, join
);
723 if(!pen
) return InvalidParameter
;
726 pen
->style
&= ~(PS_JOIN_ROUND
| PS_JOIN_BEVEL
| PS_JOIN_MITER
);
727 pen
->style
|= gdip_to_gdi_join(join
);
732 GpStatus WINGDIPAPI
GdipSetPenMiterLimit(GpPen
*pen
, REAL limit
)
734 TRACE("(%p, %.2f)\n", pen
, limit
);
737 return InvalidParameter
;
739 pen
->miterlimit
= limit
;
744 GpStatus WINGDIPAPI
GdipSetPenStartCap(GpPen
*pen
, GpLineCap cap
)
746 TRACE("(%p, %d)\n", pen
, cap
);
748 if(!pen
) return InvalidParameter
;
750 GdipDeleteCustomLineCap(pen
->customstart
);
751 pen
->customstart
= NULL
;
757 GpStatus WINGDIPAPI
GdipSetPenWidth(GpPen
*pen
, REAL width
)
759 TRACE("(%p, %.2f)\n", pen
, width
);
761 if(!pen
) return InvalidParameter
;
768 GpStatus WINGDIPAPI
GdipSetPenMode(GpPen
*pen
, GpPenAlignment mode
)
770 TRACE("(%p, %d)\n", pen
, mode
);
772 if(!pen
) return InvalidParameter
;