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
31 #include "gdiplus_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
36 /* make sure path has enough space for len more points */
37 static BOOL
lengthen_path(GpPath
*path
, INT len
)
39 /* initial allocation */
40 if(path
->datalen
== 0){
41 path
->datalen
= len
* 2;
43 path
->pathdata
.Points
= GdipAlloc(path
->datalen
* sizeof(PointF
));
44 if(!path
->pathdata
.Points
) return FALSE
;
46 path
->pathdata
.Types
= GdipAlloc(path
->datalen
);
47 if(!path
->pathdata
.Types
){
48 GdipFree(path
->pathdata
.Points
);
52 /* reallocation, double size of arrays */
53 else if(path
->datalen
- path
->pathdata
.Count
< len
){
54 while(path
->datalen
- path
->pathdata
.Count
< len
)
57 path
->pathdata
.Points
= HeapReAlloc(GetProcessHeap(), 0,
58 path
->pathdata
.Points
, path
->datalen
* sizeof(PointF
));
59 if(!path
->pathdata
.Points
) return FALSE
;
61 path
->pathdata
.Types
= HeapReAlloc(GetProcessHeap(), 0,
62 path
->pathdata
.Types
, path
->datalen
);
63 if(!path
->pathdata
.Types
) return FALSE
;
69 GpStatus WINGDIPAPI
GdipAddPathArc(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
,
70 REAL y2
, REAL startAngle
, REAL sweepAngle
)
72 INT count
, old_count
, i
;
75 return InvalidParameter
;
77 count
= arc2polybezier(NULL
, x1
, y1
, x2
, y2
, startAngle
, sweepAngle
);
81 if(!lengthen_path(path
, count
))
84 old_count
= path
->pathdata
.Count
;
85 arc2polybezier(&path
->pathdata
.Points
[old_count
], x1
, y1
, x2
, y2
,
86 startAngle
, sweepAngle
);
88 for(i
= 0; i
< count
; i
++){
89 path
->pathdata
.Types
[old_count
+ i
] = PathPointTypeBezier
;
92 path
->pathdata
.Types
[old_count
] =
93 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
94 path
->newfigure
= FALSE
;
95 path
->pathdata
.Count
+= count
;
100 GpStatus WINGDIPAPI
GdipAddPathArcI(GpPath
*path
, INT x1
, INT y1
, INT x2
,
101 INT y2
, REAL startAngle
, REAL sweepAngle
)
103 return GdipAddPathArc(path
,(REAL
)x1
,(REAL
)y1
,(REAL
)x2
,(REAL
)y2
,startAngle
,sweepAngle
);
106 GpStatus WINGDIPAPI
GdipAddPathBezier(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
,
107 REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
112 return InvalidParameter
;
114 if(!lengthen_path(path
, 4))
117 old_count
= path
->pathdata
.Count
;
119 path
->pathdata
.Points
[old_count
].X
= x1
;
120 path
->pathdata
.Points
[old_count
].Y
= y1
;
121 path
->pathdata
.Points
[old_count
+ 1].X
= x2
;
122 path
->pathdata
.Points
[old_count
+ 1].Y
= y2
;
123 path
->pathdata
.Points
[old_count
+ 2].X
= x3
;
124 path
->pathdata
.Points
[old_count
+ 2].Y
= y3
;
125 path
->pathdata
.Points
[old_count
+ 3].X
= x4
;
126 path
->pathdata
.Points
[old_count
+ 3].Y
= y4
;
128 path
->pathdata
.Types
[old_count
] =
129 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
130 path
->pathdata
.Types
[old_count
+ 1] = PathPointTypeBezier
;
131 path
->pathdata
.Types
[old_count
+ 2] = PathPointTypeBezier
;
132 path
->pathdata
.Types
[old_count
+ 3] = PathPointTypeBezier
;
134 path
->newfigure
= FALSE
;
135 path
->pathdata
.Count
+= 4;
140 GpStatus WINGDIPAPI
GdipAddPathBezierI(GpPath
*path
, INT x1
, INT y1
, INT x2
,
141 INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
143 return GdipAddPathBezier(path
,(REAL
)x1
,(REAL
)y1
,(REAL
)x2
,(REAL
)y2
,(REAL
)x3
,(REAL
)y3
,
147 GpStatus WINGDIPAPI
GdipAddPathBeziers(GpPath
*path
, GDIPCONST GpPointF
*points
,
152 if(!path
|| !points
|| ((count
- 1) % 3))
153 return InvalidParameter
;
155 if(!lengthen_path(path
, count
))
158 old_count
= path
->pathdata
.Count
;
160 for(i
= 0; i
< count
; i
++){
161 path
->pathdata
.Points
[old_count
+ i
].X
= points
[i
].X
;
162 path
->pathdata
.Points
[old_count
+ i
].Y
= points
[i
].Y
;
163 path
->pathdata
.Types
[old_count
+ i
] = PathPointTypeBezier
;
166 path
->pathdata
.Types
[old_count
] =
167 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
168 path
->newfigure
= FALSE
;
169 path
->pathdata
.Count
+= count
;
174 GpStatus WINGDIPAPI
GdipAddPathBeziersI(GpPath
*path
, GDIPCONST GpPoint
*points
,
181 if(!points
|| ((count
- 1) % 3))
182 return InvalidParameter
;
184 ptsF
= GdipAlloc(sizeof(GpPointF
) * count
);
188 for(i
= 0; i
< count
; i
++){
189 ptsF
[i
].X
= (REAL
)points
[i
].X
;
190 ptsF
[i
].Y
= (REAL
)points
[i
].Y
;
193 ret
= GdipAddPathBeziers(path
, ptsF
, count
);
199 GpStatus WINGDIPAPI
GdipAddPathClosedCurve(GpPath
*path
, GDIPCONST GpPointF
*points
,
202 return GdipAddPathClosedCurve2(path
, points
, count
, 1.0);
205 GpStatus WINGDIPAPI
GdipAddPathClosedCurveI(GpPath
*path
, GDIPCONST GpPoint
*points
,
208 return GdipAddPathClosedCurve2I(path
, points
, count
, 1.0);
211 GpStatus WINGDIPAPI
GdipAddPathClosedCurve2(GpPath
*path
, GDIPCONST GpPointF
*points
,
212 INT count
, REAL tension
)
214 INT i
, len_pt
= (count
+ 1)*3-2;
220 if(!path
|| !points
|| count
<= 1)
221 return InvalidParameter
;
223 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
224 pts
= GdipAlloc((count
+ 1)*sizeof(GpPointF
));
231 /* copy source points to extend with the last one */
232 memcpy(pts
, points
, sizeof(GpPointF
)*count
);
235 tension
= tension
* TENSION_CONST
;
237 for(i
= 0; i
< count
-1; i
++){
238 calc_curve_bezier(&(pts
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
242 pt
[3*i
+3].X
= pts
[i
+1].X
;
243 pt
[3*i
+3].Y
= pts
[i
+1].Y
;
248 /* points [len_pt-2] and [0] are calculated
249 separetely to connect splines properly */
250 pts
[0] = points
[count
-1];
251 pts
[1] = points
[0]; /* equals to start and end of a resulting path */
254 calc_curve_bezier(pts
, tension
, &x1
, &y1
, &x2
, &y2
);
262 pt
[len_pt
-1].X
= pt
[0].X
;
263 pt
[len_pt
-1].Y
= pt
[0].Y
;
265 stat
= GdipAddPathBeziers(path
, pt
, len_pt
);
269 INT count
= path
->pathdata
.Count
;
270 path
->pathdata
.Types
[count
- 1] |= PathPointTypeCloseSubpath
;
271 path
->newfigure
= TRUE
;
280 GpStatus WINGDIPAPI
GdipAddPathClosedCurve2I(GpPath
*path
, GDIPCONST GpPoint
*points
,
281 INT count
, REAL tension
)
287 if(!path
|| !points
|| count
<= 1)
288 return InvalidParameter
;
290 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
294 for(i
= 0; i
< count
; i
++){
295 ptf
[i
].X
= (REAL
)points
[i
].X
;
296 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
299 stat
= GdipAddPathClosedCurve2(path
, ptf
, count
, tension
);
306 GpStatus WINGDIPAPI
GdipAddPathCurve(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
)
308 if(!path
|| !points
|| count
<= 1)
309 return InvalidParameter
;
311 return GdipAddPathCurve2(path
, points
, count
, 1.0);
314 GpStatus WINGDIPAPI
GdipAddPathCurveI(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
316 if(!path
|| !points
|| count
<= 1)
317 return InvalidParameter
;
319 return GdipAddPathCurve2I(path
, points
, count
, 1.0);
322 GpStatus WINGDIPAPI
GdipAddPathCurve2(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
,
325 INT i
, len_pt
= count
*3-2;
330 if(!path
|| !points
|| count
<= 1)
331 return InvalidParameter
;
333 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
337 tension
= tension
* TENSION_CONST
;
339 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
342 pt
[0].X
= points
[0].X
;
343 pt
[0].Y
= points
[0].Y
;
347 for(i
= 0; i
< count
-2; i
++){
348 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
352 pt
[3*i
+3].X
= points
[i
+1].X
;
353 pt
[3*i
+3].Y
= points
[i
+1].Y
;
358 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
359 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
363 pt
[len_pt
-1].X
= points
[count
-1].X
;
364 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
366 stat
= GdipAddPathBeziers(path
, pt
, len_pt
);
373 GpStatus WINGDIPAPI
GdipAddPathCurve2I(GpPath
*path
, GDIPCONST GpPoint
*points
,
374 INT count
, REAL tension
)
380 if(!path
|| !points
|| count
<= 1)
381 return InvalidParameter
;
383 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
387 for(i
= 0; i
< count
; i
++){
388 ptf
[i
].X
= (REAL
)points
[i
].X
;
389 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
392 stat
= GdipAddPathCurve2(path
, ptf
, count
, tension
);
399 GpStatus WINGDIPAPI
GdipAddPathEllipse(GpPath
*path
, REAL x
, REAL y
, REAL width
,
402 INT old_count
, numpts
;
405 return InvalidParameter
;
407 if(!lengthen_path(path
, MAX_ARC_PTS
))
410 old_count
= path
->pathdata
.Count
;
411 if((numpts
= arc2polybezier(&path
->pathdata
.Points
[old_count
], x
, y
, width
,
412 height
, 0.0, 360.0)) != MAX_ARC_PTS
){
413 ERR("expected %d points but got %d\n", MAX_ARC_PTS
, numpts
);
417 memset(&path
->pathdata
.Types
[old_count
+ 1], PathPointTypeBezier
,
420 /* An ellipse is an intrinsic figure (always is its own subpath). */
421 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
422 path
->pathdata
.Types
[old_count
+ MAX_ARC_PTS
- 1] |= PathPointTypeCloseSubpath
;
423 path
->newfigure
= TRUE
;
424 path
->pathdata
.Count
+= MAX_ARC_PTS
;
429 GpStatus WINGDIPAPI
GdipAddPathEllipseI(GpPath
*path
, INT x
, INT y
, INT width
,
432 return GdipAddPathEllipse(path
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
435 GpStatus WINGDIPAPI
GdipAddPathLine2(GpPath
*path
, GDIPCONST GpPointF
*points
,
441 return InvalidParameter
;
443 if(!lengthen_path(path
, count
))
446 old_count
= path
->pathdata
.Count
;
448 for(i
= 0; i
< count
; i
++){
449 path
->pathdata
.Points
[old_count
+ i
].X
= points
[i
].X
;
450 path
->pathdata
.Points
[old_count
+ i
].Y
= points
[i
].Y
;
451 path
->pathdata
.Types
[old_count
+ i
] = PathPointTypeLine
;
455 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
456 path
->newfigure
= FALSE
;
459 path
->pathdata
.Count
+= count
;
464 GpStatus WINGDIPAPI
GdipAddPathLine2I(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
471 return InvalidParameter
;
473 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
474 if(!pointsF
) return OutOfMemory
;
476 for(i
= 0;i
< count
; i
++){
477 pointsF
[i
].X
= (REAL
)points
[i
].X
;
478 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
481 stat
= GdipAddPathLine2(path
, pointsF
, count
);
488 GpStatus WINGDIPAPI
GdipAddPathLine(GpPath
*path
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
493 return InvalidParameter
;
495 if(!lengthen_path(path
, 2))
498 old_count
= path
->pathdata
.Count
;
500 path
->pathdata
.Points
[old_count
].X
= x1
;
501 path
->pathdata
.Points
[old_count
].Y
= y1
;
502 path
->pathdata
.Points
[old_count
+ 1].X
= x2
;
503 path
->pathdata
.Points
[old_count
+ 1].Y
= y2
;
505 path
->pathdata
.Types
[old_count
] =
506 (path
->newfigure
? PathPointTypeStart
: PathPointTypeLine
);
507 path
->pathdata
.Types
[old_count
+ 1] = PathPointTypeLine
;
509 path
->newfigure
= FALSE
;
510 path
->pathdata
.Count
+= 2;
515 GpStatus WINGDIPAPI
GdipAddPathLineI(GpPath
*path
, INT x1
, INT y1
, INT x2
, INT y2
)
517 return GdipAddPathLine(path
, (REAL
)x1
, (REAL
)y1
, (REAL
)x2
, (REAL
)y2
);
520 GpStatus WINGDIPAPI
GdipAddPathPath(GpPath
*path
, GDIPCONST GpPath
* addingPath
,
523 INT old_count
, count
;
525 if(!path
|| !addingPath
)
526 return InvalidParameter
;
528 old_count
= path
->pathdata
.Count
;
529 count
= addingPath
->pathdata
.Count
;
531 if(!lengthen_path(path
, count
))
534 memcpy(&path
->pathdata
.Points
[old_count
], addingPath
->pathdata
.Points
,
535 count
* sizeof(GpPointF
));
536 memcpy(&path
->pathdata
.Types
[old_count
], addingPath
->pathdata
.Types
, count
);
538 if(path
->newfigure
|| !connect
)
539 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
541 path
->pathdata
.Types
[old_count
] = PathPointTypeLine
;
543 path
->newfigure
= FALSE
;
544 path
->pathdata
.Count
+= count
;
549 GpStatus WINGDIPAPI
GdipAddPathPie(GpPath
*path
, REAL x
, REAL y
, REAL width
, REAL height
,
550 REAL startAngle
, REAL sweepAngle
)
557 return InvalidParameter
;
559 count
= arc2polybezier(NULL
, x
, y
, width
, height
, startAngle
, sweepAngle
);
564 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
568 arc2polybezier(ptf
, x
, y
, width
, height
, startAngle
, sweepAngle
);
570 status
= GdipAddPathLine(path
, (width
- x
)/2, (height
- y
)/2, ptf
[0].X
, ptf
[0].Y
);
575 /* one spline is already added as a line endpoint */
576 if(!lengthen_path(path
, count
- 1)){
581 memcpy(&(path
->pathdata
.Points
[path
->pathdata
.Count
]), &(ptf
[1]),sizeof(GpPointF
)*(count
-1));
582 for(i
= 0; i
< count
-1; i
++)
583 path
->pathdata
.Types
[path
->pathdata
.Count
+i
] = PathPointTypeBezier
;
585 path
->pathdata
.Count
+= count
-1;
587 GdipClosePathFigure(path
);
594 GpStatus WINGDIPAPI
GdipAddPathPieI(GpPath
*path
, INT x
, INT y
, INT width
, INT height
,
595 REAL startAngle
, REAL sweepAngle
)
597 return GdipAddPathPieI(path
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, startAngle
, sweepAngle
);
600 GpStatus WINGDIPAPI
GdipAddPathPolygon(GpPath
*path
, GDIPCONST GpPointF
*points
, INT count
)
604 if(!path
|| !points
|| count
< 3)
605 return InvalidParameter
;
607 if(!lengthen_path(path
, count
))
610 old_count
= path
->pathdata
.Count
;
612 memcpy(&path
->pathdata
.Points
[old_count
], points
, count
*sizeof(GpPointF
));
613 memset(&path
->pathdata
.Types
[old_count
+ 1], PathPointTypeLine
, count
- 1);
615 /* A polygon is an intrinsic figure */
616 path
->pathdata
.Types
[old_count
] = PathPointTypeStart
;
617 path
->pathdata
.Types
[old_count
+ count
- 1] |= PathPointTypeCloseSubpath
;
618 path
->newfigure
= TRUE
;
619 path
->pathdata
.Count
+= count
;
624 GpStatus WINGDIPAPI
GdipAddPathPolygonI(GpPath
*path
, GDIPCONST GpPoint
*points
, INT count
)
630 if(!points
|| count
< 3)
631 return InvalidParameter
;
633 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
637 for(i
= 0; i
< count
; i
++){
638 ptf
[i
].X
= (REAL
)points
[i
].X
;
639 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
642 status
= GdipAddPathPolygon(path
, ptf
, count
);
649 GpStatus WINGDIPAPI
GdipClonePath(GpPath
* path
, GpPath
**clone
)
652 return InvalidParameter
;
654 *clone
= GdipAlloc(sizeof(GpPath
));
655 if(!*clone
) return OutOfMemory
;
659 (*clone
)->pathdata
.Points
= GdipAlloc(path
->datalen
* sizeof(PointF
));
660 (*clone
)->pathdata
.Types
= GdipAlloc(path
->datalen
);
661 if(!(*clone
)->pathdata
.Points
|| !(*clone
)->pathdata
.Types
){
663 GdipFree((*clone
)->pathdata
.Points
);
664 GdipFree((*clone
)->pathdata
.Types
);
668 memcpy((*clone
)->pathdata
.Points
, path
->pathdata
.Points
,
669 path
->datalen
* sizeof(PointF
));
670 memcpy((*clone
)->pathdata
.Types
, path
->pathdata
.Types
, path
->datalen
);
675 GpStatus WINGDIPAPI
GdipClosePathFigure(GpPath
* path
)
678 return InvalidParameter
;
680 if(path
->pathdata
.Count
> 0){
681 path
->pathdata
.Types
[path
->pathdata
.Count
- 1] |= PathPointTypeCloseSubpath
;
682 path
->newfigure
= TRUE
;
688 GpStatus WINGDIPAPI
GdipClosePathFigures(GpPath
* path
)
693 return InvalidParameter
;
695 for(i
= 1; i
< path
->pathdata
.Count
; i
++){
696 if(path
->pathdata
.Types
[i
] == PathPointTypeStart
)
697 path
->pathdata
.Types
[i
-1] |= PathPointTypeCloseSubpath
;
700 path
->newfigure
= TRUE
;
705 GpStatus WINGDIPAPI
GdipCreatePath(GpFillMode fill
, GpPath
**path
)
708 return InvalidParameter
;
710 *path
= GdipAlloc(sizeof(GpPath
));
711 if(!*path
) return OutOfMemory
;
713 (*path
)->fill
= fill
;
714 (*path
)->newfigure
= TRUE
;
719 GpStatus WINGDIPAPI
GdipCreatePath2(GDIPCONST GpPointF
* points
,
720 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
723 return InvalidParameter
;
725 *path
= GdipAlloc(sizeof(GpPath
));
726 if(!*path
) return OutOfMemory
;
728 (*path
)->pathdata
.Points
= GdipAlloc(count
* sizeof(PointF
));
729 (*path
)->pathdata
.Types
= GdipAlloc(count
);
731 if(!(*path
)->pathdata
.Points
|| !(*path
)->pathdata
.Types
){
732 GdipFree((*path
)->pathdata
.Points
);
733 GdipFree((*path
)->pathdata
.Types
);
738 memcpy((*path
)->pathdata
.Points
, points
, count
* sizeof(PointF
));
739 memcpy((*path
)->pathdata
.Types
, types
, count
);
740 (*path
)->pathdata
.Count
= count
;
741 (*path
)->datalen
= count
;
743 (*path
)->fill
= fill
;
744 (*path
)->newfigure
= TRUE
;
749 GpStatus WINGDIPAPI
GdipCreatePath2I(GDIPCONST GpPoint
* points
,
750 GDIPCONST BYTE
* types
, INT count
, GpFillMode fill
, GpPath
**path
)
756 ptF
= GdipAlloc(sizeof(GpPointF
)*count
);
758 for(i
= 0;i
< count
; i
++){
759 ptF
[i
].X
= (REAL
)points
[i
].X
;
760 ptF
[i
].Y
= (REAL
)points
[i
].Y
;
763 ret
= GdipCreatePath2(ptF
, types
, count
, fill
, path
);
770 GpStatus WINGDIPAPI
GdipDeletePath(GpPath
*path
)
773 return InvalidParameter
;
775 GdipFree(path
->pathdata
.Points
);
776 GdipFree(path
->pathdata
.Types
);
782 GpStatus WINGDIPAPI
GdipGetPathData(GpPath
*path
, GpPathData
* pathData
)
784 if(!path
|| !pathData
)
785 return InvalidParameter
;
787 /* Only copy data. pathData allocation/freeing controlled by wrapper class.
788 Assumed that pathData is enough wide to get all data - controlled by wrapper too. */
789 memcpy(pathData
->Points
, path
->pathdata
.Points
, sizeof(PointF
) * pathData
->Count
);
790 memcpy(pathData
->Types
, path
->pathdata
.Types
, pathData
->Count
);
795 GpStatus WINGDIPAPI
GdipGetPathFillMode(GpPath
*path
, GpFillMode
*fillmode
)
797 if(!path
|| !fillmode
)
798 return InvalidParameter
;
800 *fillmode
= path
->fill
;
805 GpStatus WINGDIPAPI
GdipGetPathLastPoint(GpPath
* path
, GpPointF
* lastPoint
)
809 if(!path
|| !lastPoint
)
810 return InvalidParameter
;
812 count
= path
->pathdata
.Count
;
814 *lastPoint
= path
->pathdata
.Points
[count
-1];
819 GpStatus WINGDIPAPI
GdipGetPathPoints(GpPath
*path
, GpPointF
* points
, INT count
)
822 return InvalidParameter
;
824 if(count
< path
->pathdata
.Count
)
825 return InsufficientBuffer
;
827 memcpy(points
, path
->pathdata
.Points
, path
->pathdata
.Count
* sizeof(GpPointF
));
832 GpStatus WINGDIPAPI
GdipGetPathPointsI(GpPath
*path
, GpPoint
* points
, INT count
)
839 return InvalidParameter
;
841 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
842 if(!ptf
) return OutOfMemory
;
844 ret
= GdipGetPathPoints(path
,ptf
,count
);
846 for(i
= 0;i
< count
;i
++){
847 points
[i
].X
= roundr(ptf
[i
].X
);
848 points
[i
].Y
= roundr(ptf
[i
].Y
);
855 GpStatus WINGDIPAPI
GdipGetPathTypes(GpPath
*path
, BYTE
* types
, INT count
)
858 return InvalidParameter
;
860 if(count
< path
->pathdata
.Count
)
861 return InsufficientBuffer
;
863 memcpy(types
, path
->pathdata
.Types
, path
->pathdata
.Count
);
868 /* Windows expands the bounding box to the maximum possible bounding box
869 * for a given pen. For example, if a line join can extend past the point
870 * it's joining by x units, the bounding box is extended by x units in every
871 * direction (even though this is too conservative for most cases). */
872 GpStatus WINGDIPAPI
GdipGetPathWorldBounds(GpPath
* path
, GpRectF
* bounds
,
873 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
875 GpPointF
* points
, temp_pts
[4];
877 REAL path_width
= 1.0, width
, height
, temp
, low_x
, low_y
, high_x
, high_y
;
879 /* Matrix and pen can be null. */
881 return InvalidParameter
;
883 /* If path is empty just return. */
884 count
= path
->pathdata
.Count
;
886 bounds
->X
= bounds
->Y
= bounds
->Width
= bounds
->Height
= 0.0;
890 points
= path
->pathdata
.Points
;
892 low_x
= high_x
= points
[0].X
;
893 low_y
= high_y
= points
[0].Y
;
895 for(i
= 1; i
< count
; i
++){
896 low_x
= min(low_x
, points
[i
].X
);
897 low_y
= min(low_y
, points
[i
].Y
);
898 high_x
= max(high_x
, points
[i
].X
);
899 high_y
= max(high_y
, points
[i
].Y
);
902 width
= high_x
- low_x
;
903 height
= high_y
- low_y
;
905 /* This looks unusual but it's the only way I can imitate windows. */
907 temp_pts
[0].X
= low_x
;
908 temp_pts
[0].Y
= low_y
;
909 temp_pts
[1].X
= low_x
;
910 temp_pts
[1].Y
= high_y
;
911 temp_pts
[2].X
= high_x
;
912 temp_pts
[2].Y
= high_y
;
913 temp_pts
[3].X
= high_x
;
914 temp_pts
[3].Y
= low_y
;
916 GdipTransformMatrixPoints((GpMatrix
*)matrix
, temp_pts
, 4);
917 low_x
= temp_pts
[0].X
;
918 low_y
= temp_pts
[0].Y
;
920 for(i
= 1; i
< 4; i
++){
921 low_x
= min(low_x
, temp_pts
[i
].X
);
922 low_y
= min(low_y
, temp_pts
[i
].Y
);
926 width
= height
* fabs(matrix
->matrix
[2]) + width
* fabs(matrix
->matrix
[0]);
927 height
= height
* fabs(matrix
->matrix
[3]) + temp
* fabs(matrix
->matrix
[1]);
931 path_width
= pen
->width
/ 2.0;
934 path_width
= max(path_width
, pen
->width
* pen
->miterlimit
/ 2.0);
935 /* FIXME: this should probably also check for the startcap */
936 if(pen
->endcap
& LineCapNoAnchor
)
937 path_width
= max(path_width
, pen
->width
* 2.2);
941 width
+= 2.0 * path_width
;
942 height
+= 2.0 * path_width
;
947 bounds
->Width
= width
;
948 bounds
->Height
= height
;
953 GpStatus WINGDIPAPI
GdipGetPathWorldBoundsI(GpPath
* path
, GpRect
* bounds
,
954 GDIPCONST GpMatrix
*matrix
, GDIPCONST GpPen
*pen
)
959 ret
= GdipGetPathWorldBounds(path
,&boundsF
,matrix
,pen
);
962 bounds
->X
= roundr(boundsF
.X
);
963 bounds
->Y
= roundr(boundsF
.Y
);
964 bounds
->Width
= roundr(boundsF
.Width
);
965 bounds
->Height
= roundr(boundsF
.Height
);
971 GpStatus WINGDIPAPI
GdipGetPointCount(GpPath
*path
, INT
*count
)
974 return InvalidParameter
;
976 *count
= path
->pathdata
.Count
;
981 GpStatus WINGDIPAPI
GdipReversePath(GpPath
* path
)
984 INT start
= 0; /* position in reversed path */
988 return InvalidParameter
;
990 count
= path
->pathdata
.Count
;
992 if(count
== 0) return Ok
;
994 revpath
.Points
= GdipAlloc(sizeof(GpPointF
)*count
);
995 revpath
.Types
= GdipAlloc(sizeof(BYTE
)*count
);
996 revpath
.Count
= count
;
997 if(!revpath
.Points
|| !revpath
.Types
){
998 GdipFree(revpath
.Points
);
999 GdipFree(revpath
.Types
);
1003 for(i
= 0; i
< count
; i
++){
1005 /* find next start point */
1006 if(path
->pathdata
.Types
[count
-i
-1] == PathPointTypeStart
){
1008 for(j
= start
; j
<= i
; j
++){
1009 revpath
.Points
[j
] = path
->pathdata
.Points
[count
-j
-1];
1010 revpath
.Types
[j
] = path
->pathdata
.Types
[count
-j
-1];
1012 /* mark start point */
1013 revpath
.Types
[start
] = PathPointTypeStart
;
1014 /* set 'figure' endpoint type */
1016 revpath
.Types
[i
] = path
->pathdata
.Types
[count
-start
-1] & ~PathPointTypePathTypeMask
;
1017 revpath
.Types
[i
] |= revpath
.Types
[i
-1];
1020 revpath
.Types
[i
] = path
->pathdata
.Types
[start
];
1026 memcpy(path
->pathdata
.Points
, revpath
.Points
, sizeof(GpPointF
)*count
);
1027 memcpy(path
->pathdata
.Types
, revpath
.Types
, sizeof(BYTE
)*count
);
1029 GdipFree(revpath
.Points
);
1030 GdipFree(revpath
.Types
);
1035 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPointI(GpPath
* path
, INT x
, INT y
,
1036 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
1038 return GdipIsOutlineVisiblePathPoint(path
, x
, y
, pen
, graphics
, result
);
1041 GpStatus WINGDIPAPI
GdipIsOutlineVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
,
1042 GpPen
*pen
, GpGraphics
*graphics
, BOOL
*result
)
1047 return InvalidParameter
;
1050 FIXME("not implemented\n");
1052 return NotImplemented
;
1055 GpStatus WINGDIPAPI
GdipIsVisiblePathPointI(GpPath
* path
, INT x
, INT y
, GpGraphics
*graphics
, BOOL
*result
)
1057 return GdipIsVisiblePathPoint(path
, x
, y
, graphics
, result
);
1060 GpStatus WINGDIPAPI
GdipIsVisiblePathPoint(GpPath
* path
, REAL x
, REAL y
, GpGraphics
*graphics
, BOOL
*result
)
1064 if(!path
) return InvalidParameter
;
1067 FIXME("not implemented\n");
1069 return NotImplemented
;
1072 GpStatus WINGDIPAPI
GdipStartPathFigure(GpPath
*path
)
1075 return InvalidParameter
;
1077 path
->newfigure
= TRUE
;
1082 GpStatus WINGDIPAPI
GdipResetPath(GpPath
*path
)
1085 return InvalidParameter
;
1087 path
->pathdata
.Count
= 0;
1088 path
->newfigure
= TRUE
;
1089 path
->fill
= FillModeAlternate
;
1094 GpStatus WINGDIPAPI
GdipSetPathFillMode(GpPath
*path
, GpFillMode fill
)
1097 return InvalidParameter
;
1104 GpStatus WINGDIPAPI
GdipTransformPath(GpPath
*path
, GpMatrix
*matrix
)
1107 return InvalidParameter
;
1109 if(path
->pathdata
.Count
== 0)
1112 return GdipTransformMatrixPoints(matrix
, path
->pathdata
.Points
,
1113 path
->pathdata
.Count
);
1116 GpStatus WINGDIPAPI
GdipAddPathRectangle(GpPath
*path
, REAL x
, REAL y
,
1117 REAL width
, REAL height
)
1124 if(!path
|| width
< 0.0 || height
< 0.0)
1125 return InvalidParameter
;
1127 /* make a backup copy of path data */
1128 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
1131 /* rectangle should start as new path */
1132 old_new
= path
->newfigure
;
1133 path
->newfigure
= TRUE
;
1134 if((retstat
= GdipAddPathLine(path
,x
,y
,x
+width
,y
)) != Ok
){
1135 path
->newfigure
= old_new
;
1140 ptf
[0].Y
= y
+height
;
1142 ptf
[1].Y
= y
+height
;
1144 if((retstat
= GdipAddPathLine2(path
, ptf
, 2)) != Ok
) goto fail
;
1145 path
->pathdata
.Types
[path
->pathdata
.Count
-1] |= PathPointTypeCloseSubpath
;
1148 GdipDeletePath(backup
);
1153 GdipDeletePath(path
);
1154 GdipClonePath(backup
, &path
);
1155 GdipDeletePath(backup
);
1160 GpStatus WINGDIPAPI
GdipAddPathRectangleI(GpPath
*path
, INT x
, INT y
,
1161 INT width
, INT height
)
1163 return GdipAddPathRectangle(path
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1166 GpStatus WINGDIPAPI
GdipAddPathRectangles(GpPath
*path
, GDIPCONST GpRectF
*rects
, INT count
)
1172 /* count == 0 - verified condition */
1173 if(!path
|| !rects
|| count
== 0)
1174 return InvalidParameter
;
1179 /* make a backup copy */
1180 if((retstat
= GdipClonePath(path
, &backup
)) != Ok
)
1183 for(i
= 0; i
< count
; i
++){
1184 if((retstat
= GdipAddPathRectangle(path
,rects
[i
].X
,rects
[i
].Y
,rects
[i
].Width
,rects
[i
].Height
)) != Ok
)
1189 GdipDeletePath(backup
);
1194 GdipDeletePath(path
);
1195 GdipClonePath(backup
, &path
);
1196 GdipDeletePath(backup
);
1201 GpStatus WINGDIPAPI
GdipAddPathRectanglesI(GpPath
*path
, GDIPCONST GpRect
*rects
, INT count
)
1207 if(!rects
|| count
== 0)
1208 return InvalidParameter
;
1213 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
1215 for(i
= 0;i
< count
;i
++){
1216 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
1217 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
1218 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
1219 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
1222 retstat
= GdipAddPathRectangles(path
, rectsF
, count
);
1228 GpStatus WINGDIPAPI
GdipSetPathMarker(GpPath
* path
)
1233 return InvalidParameter
;
1235 count
= path
->pathdata
.Count
;
1237 /* set marker flag */
1239 path
->pathdata
.Types
[count
-1] |= PathPointTypePathMarker
;
1244 GpStatus WINGDIPAPI
GdipClearPathMarkers(GpPath
* path
)
1250 return InvalidParameter
;
1252 count
= path
->pathdata
.Count
;
1254 for(i
= 0; i
< count
- 1; i
++){
1255 path
->pathdata
.Types
[i
] &= ~PathPointTypePathMarker
;