sane.ds: Rearrange function position to avoid the need for forward function declarations.
[wine/multimedia.git] / dlls / gdiplus / graphicspath.c
blob4703ace60b45553782c68e21c9335e5c48e98d79
1 /*
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
20 #include <stdarg.h>
21 #include <math.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wingdi.h"
28 #include "objbase.h"
30 #include "gdiplus.h"
31 #include "gdiplus_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
36 typedef struct path_list_node_t path_list_node_t;
37 struct path_list_node_t {
38 GpPointF pt;
39 BYTE type; /* PathPointTypeStart or PathPointTypeLine */
40 path_list_node_t *next;
43 /* init list */
44 static BOOL init_path_list(path_list_node_t **node, REAL x, REAL y)
46 *node = GdipAlloc(sizeof(path_list_node_t));
47 if(!*node)
48 return FALSE;
50 (*node)->pt.X = x;
51 (*node)->pt.Y = y;
52 (*node)->type = PathPointTypeStart;
53 (*node)->next = NULL;
55 return TRUE;
58 /* free all nodes including argument */
59 static void free_path_list(path_list_node_t *node)
61 path_list_node_t *n = node;
63 while(n){
64 n = n->next;
65 GdipFree(node);
66 node = n;
70 /* Add a node after 'node' */
72 * Returns
73 * pointer on success
74 * NULL on allocation problems
76 static path_list_node_t* add_path_list_node(path_list_node_t *node, REAL x, REAL y, BOOL type)
78 path_list_node_t *new;
80 new = GdipAlloc(sizeof(path_list_node_t));
81 if(!new)
82 return NULL;
84 new->pt.X = x;
85 new->pt.Y = y;
86 new->type = type;
87 new->next = node->next;
88 node->next = new;
90 return new;
93 /* returns element count */
94 static INT path_list_count(path_list_node_t *node)
96 INT count = 1;
98 while((node = node->next))
99 ++count;
101 return count;
104 /* GdipFlattenPath helper */
106 * Used to recursively flatten single Bezier curve
107 * Parameters:
108 * - start : pointer to start point node;
109 * - (x2, y2): first control point;
110 * - (x3, y3): second control point;
111 * - end : pointer to end point node
112 * - flatness: admissible error of linear approximation.
114 * Return value:
115 * TRUE : success
116 * FALSE: out of memory
118 * TODO: used quality criteria should be revised to match native as
119 * closer as possible.
121 static BOOL flatten_bezier(path_list_node_t *start, REAL x2, REAL y2, REAL x3, REAL y3,
122 path_list_node_t *end, REAL flatness)
124 /* this 5 middle points with start/end define to half-curves */
125 GpPointF mp[5];
126 GpPointF pt, pt_st;
127 path_list_node_t *node;
129 /* calculate bezier curve middle points == new control points */
130 mp[0].X = (start->pt.X + x2) / 2.0;
131 mp[0].Y = (start->pt.Y + y2) / 2.0;
132 /* middle point between control points */
133 pt.X = (x2 + x3) / 2.0;
134 pt.Y = (y2 + y3) / 2.0;
135 mp[1].X = (mp[0].X + pt.X) / 2.0;
136 mp[1].Y = (mp[0].Y + pt.Y) / 2.0;
137 mp[4].X = (end->pt.X + x3) / 2.0;
138 mp[4].Y = (end->pt.Y + y3) / 2.0;
139 mp[3].X = (mp[4].X + pt.X) / 2.0;
140 mp[3].Y = (mp[4].Y + pt.Y) / 2.0;
142 mp[2].X = (mp[1].X + mp[3].X) / 2.0;
143 mp[2].Y = (mp[1].Y + mp[3].Y) / 2.0;
145 pt = end->pt;
146 pt_st = start->pt;
147 /* check flatness as a half of distance between middle point and a linearized path */
148 if(fabs(((pt.Y - pt_st.Y)*mp[2].X + (pt_st.X - pt.X)*mp[2].Y +
149 (pt_st.Y*pt.X - pt_st.X*pt.Y))) <=
150 (0.5 * flatness*sqrtf((powf(pt.Y - pt_st.Y, 2.0) + powf(pt_st.X - pt.X, 2.0))))){
151 return TRUE;
153 else
154 /* add a middle point */
155 if(!(node = add_path_list_node(start, mp[2].X, mp[2].Y, PathPointTypeLine)))
156 return FALSE;
158 /* do the same with halfs */
159 flatten_bezier(start, mp[0].X, mp[0].Y, mp[1].X, mp[1].Y, node, flatness);
160 flatten_bezier(node, mp[3].X, mp[3].Y, mp[4].X, mp[4].Y, end, flatness);
162 return TRUE;
165 GpStatus WINGDIPAPI GdipAddPathArc(GpPath *path, REAL x1, REAL y1, REAL x2,
166 REAL y2, REAL startAngle, REAL sweepAngle)
168 INT count, old_count, i;
170 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
171 path, x1, y1, x2, y2, startAngle, sweepAngle);
173 if(!path)
174 return InvalidParameter;
176 count = arc2polybezier(NULL, x1, y1, x2, y2, startAngle, sweepAngle);
178 if(count == 0)
179 return Ok;
180 if(!lengthen_path(path, count))
181 return OutOfMemory;
183 old_count = path->pathdata.Count;
184 arc2polybezier(&path->pathdata.Points[old_count], x1, y1, x2, y2,
185 startAngle, sweepAngle);
187 for(i = 0; i < count; i++){
188 path->pathdata.Types[old_count + i] = PathPointTypeBezier;
191 path->pathdata.Types[old_count] =
192 (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
193 path->newfigure = FALSE;
194 path->pathdata.Count += count;
196 return Ok;
199 GpStatus WINGDIPAPI GdipAddPathArcI(GpPath *path, INT x1, INT y1, INT x2,
200 INT y2, REAL startAngle, REAL sweepAngle)
202 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
203 path, x1, y1, x2, y2, startAngle, sweepAngle);
205 return GdipAddPathArc(path,(REAL)x1,(REAL)y1,(REAL)x2,(REAL)y2,startAngle,sweepAngle);
208 GpStatus WINGDIPAPI GdipAddPathBezier(GpPath *path, REAL x1, REAL y1, REAL x2,
209 REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
211 INT old_count;
213 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
214 path, x1, y1, x2, y2, x3, y3, x4, y4);
216 if(!path)
217 return InvalidParameter;
219 if(!lengthen_path(path, 4))
220 return OutOfMemory;
222 old_count = path->pathdata.Count;
224 path->pathdata.Points[old_count].X = x1;
225 path->pathdata.Points[old_count].Y = y1;
226 path->pathdata.Points[old_count + 1].X = x2;
227 path->pathdata.Points[old_count + 1].Y = y2;
228 path->pathdata.Points[old_count + 2].X = x3;
229 path->pathdata.Points[old_count + 2].Y = y3;
230 path->pathdata.Points[old_count + 3].X = x4;
231 path->pathdata.Points[old_count + 3].Y = y4;
233 path->pathdata.Types[old_count] =
234 (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
235 path->pathdata.Types[old_count + 1] = PathPointTypeBezier;
236 path->pathdata.Types[old_count + 2] = PathPointTypeBezier;
237 path->pathdata.Types[old_count + 3] = PathPointTypeBezier;
239 path->newfigure = FALSE;
240 path->pathdata.Count += 4;
242 return Ok;
245 GpStatus WINGDIPAPI GdipAddPathBezierI(GpPath *path, INT x1, INT y1, INT x2,
246 INT y2, INT x3, INT y3, INT x4, INT y4)
248 TRACE("(%p, %d, %d, %d, %d, %d, %d, %d, %d)\n",
249 path, x1, y1, x2, y2, x3, y3, x4, y4);
251 return GdipAddPathBezier(path,(REAL)x1,(REAL)y1,(REAL)x2,(REAL)y2,(REAL)x3,(REAL)y3,
252 (REAL)x4,(REAL)y4);
255 GpStatus WINGDIPAPI GdipAddPathBeziers(GpPath *path, GDIPCONST GpPointF *points,
256 INT count)
258 INT i, old_count;
260 TRACE("(%p, %p, %d)\n", path, points, count);
262 if(!path || !points || ((count - 1) % 3))
263 return InvalidParameter;
265 if(!lengthen_path(path, count))
266 return OutOfMemory;
268 old_count = path->pathdata.Count;
270 for(i = 0; i < count; i++){
271 path->pathdata.Points[old_count + i].X = points[i].X;
272 path->pathdata.Points[old_count + i].Y = points[i].Y;
273 path->pathdata.Types[old_count + i] = PathPointTypeBezier;
276 path->pathdata.Types[old_count] =
277 (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
278 path->newfigure = FALSE;
279 path->pathdata.Count += count;
281 return Ok;
284 GpStatus WINGDIPAPI GdipAddPathBeziersI(GpPath *path, GDIPCONST GpPoint *points,
285 INT count)
287 GpPointF *ptsF;
288 GpStatus ret;
289 INT i;
291 TRACE("(%p, %p, %d)\n", path, points, count);
293 if(!points || ((count - 1) % 3))
294 return InvalidParameter;
296 ptsF = GdipAlloc(sizeof(GpPointF) * count);
297 if(!ptsF)
298 return OutOfMemory;
300 for(i = 0; i < count; i++){
301 ptsF[i].X = (REAL)points[i].X;
302 ptsF[i].Y = (REAL)points[i].Y;
305 ret = GdipAddPathBeziers(path, ptsF, count);
306 GdipFree(ptsF);
308 return ret;
311 GpStatus WINGDIPAPI GdipAddPathClosedCurve(GpPath *path, GDIPCONST GpPointF *points,
312 INT count)
314 TRACE("(%p, %p, %d)\n", path, points, count);
316 return GdipAddPathClosedCurve2(path, points, count, 1.0);
319 GpStatus WINGDIPAPI GdipAddPathClosedCurveI(GpPath *path, GDIPCONST GpPoint *points,
320 INT count)
322 TRACE("(%p, %p, %d)\n", path, points, count);
324 return GdipAddPathClosedCurve2I(path, points, count, 1.0);
327 GpStatus WINGDIPAPI GdipAddPathClosedCurve2(GpPath *path, GDIPCONST GpPointF *points,
328 INT count, REAL tension)
330 INT i, len_pt = (count + 1)*3-2;
331 GpPointF *pt;
332 GpPointF *pts;
333 REAL x1, x2, y1, y2;
334 GpStatus stat;
336 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
338 if(!path || !points || count <= 1)
339 return InvalidParameter;
341 pt = GdipAlloc(len_pt * sizeof(GpPointF));
342 pts = GdipAlloc((count + 1)*sizeof(GpPointF));
343 if(!pt || !pts){
344 GdipFree(pt);
345 GdipFree(pts);
346 return OutOfMemory;
349 /* copy source points to extend with the last one */
350 memcpy(pts, points, sizeof(GpPointF)*count);
351 pts[count] = pts[0];
353 tension = tension * TENSION_CONST;
355 for(i = 0; i < count-1; i++){
356 calc_curve_bezier(&(pts[i]), tension, &x1, &y1, &x2, &y2);
358 pt[3*i+2].X = x1;
359 pt[3*i+2].Y = y1;
360 pt[3*i+3].X = pts[i+1].X;
361 pt[3*i+3].Y = pts[i+1].Y;
362 pt[3*i+4].X = x2;
363 pt[3*i+4].Y = y2;
366 /* points [len_pt-2] and [0] are calculated
367 separetely to connect splines properly */
368 pts[0] = points[count-1];
369 pts[1] = points[0]; /* equals to start and end of a resulting path */
370 pts[2] = points[1];
372 calc_curve_bezier(pts, tension, &x1, &y1, &x2, &y2);
373 pt[len_pt-2].X = x1;
374 pt[len_pt-2].Y = y1;
375 pt[0].X = pts[1].X;
376 pt[0].Y = pts[1].Y;
377 pt[1].X = x2;
378 pt[1].Y = y2;
379 /* close path */
380 pt[len_pt-1].X = pt[0].X;
381 pt[len_pt-1].Y = pt[0].Y;
383 stat = GdipAddPathBeziers(path, pt, len_pt);
385 /* close figure */
386 if(stat == Ok){
387 INT count = path->pathdata.Count;
388 path->pathdata.Types[count - 1] |= PathPointTypeCloseSubpath;
389 path->newfigure = TRUE;
392 GdipFree(pts);
393 GdipFree(pt);
395 return stat;
398 GpStatus WINGDIPAPI GdipAddPathClosedCurve2I(GpPath *path, GDIPCONST GpPoint *points,
399 INT count, REAL tension)
401 GpPointF *ptf;
402 INT i;
403 GpStatus stat;
405 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
407 if(!path || !points || count <= 1)
408 return InvalidParameter;
410 ptf = GdipAlloc(sizeof(GpPointF)*count);
411 if(!ptf)
412 return OutOfMemory;
414 for(i = 0; i < count; i++){
415 ptf[i].X = (REAL)points[i].X;
416 ptf[i].Y = (REAL)points[i].Y;
419 stat = GdipAddPathClosedCurve2(path, ptf, count, tension);
421 GdipFree(ptf);
423 return stat;
426 GpStatus WINGDIPAPI GdipAddPathCurve(GpPath *path, GDIPCONST GpPointF *points, INT count)
428 TRACE("(%p, %p, %d)\n", path, points, count);
430 if(!path || !points || count <= 1)
431 return InvalidParameter;
433 return GdipAddPathCurve2(path, points, count, 1.0);
436 GpStatus WINGDIPAPI GdipAddPathCurveI(GpPath *path, GDIPCONST GpPoint *points, INT count)
438 TRACE("(%p, %p, %d)\n", path, points, count);
440 if(!path || !points || count <= 1)
441 return InvalidParameter;
443 return GdipAddPathCurve2I(path, points, count, 1.0);
446 GpStatus WINGDIPAPI GdipAddPathCurve2(GpPath *path, GDIPCONST GpPointF *points, INT count,
447 REAL tension)
449 INT i, len_pt = count*3-2;
450 GpPointF *pt;
451 REAL x1, x2, y1, y2;
452 GpStatus stat;
454 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
456 if(!path || !points || count <= 1)
457 return InvalidParameter;
459 pt = GdipAlloc(len_pt * sizeof(GpPointF));
460 if(!pt)
461 return OutOfMemory;
463 tension = tension * TENSION_CONST;
465 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
466 tension, &x1, &y1);
468 pt[0].X = points[0].X;
469 pt[0].Y = points[0].Y;
470 pt[1].X = x1;
471 pt[1].Y = y1;
473 for(i = 0; i < count-2; i++){
474 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
476 pt[3*i+2].X = x1;
477 pt[3*i+2].Y = y1;
478 pt[3*i+3].X = points[i+1].X;
479 pt[3*i+3].Y = points[i+1].Y;
480 pt[3*i+4].X = x2;
481 pt[3*i+4].Y = y2;
484 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
485 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
487 pt[len_pt-2].X = x1;
488 pt[len_pt-2].Y = y1;
489 pt[len_pt-1].X = points[count-1].X;
490 pt[len_pt-1].Y = points[count-1].Y;
492 stat = GdipAddPathBeziers(path, pt, len_pt);
494 GdipFree(pt);
496 return stat;
499 GpStatus WINGDIPAPI GdipAddPathCurve2I(GpPath *path, GDIPCONST GpPoint *points,
500 INT count, REAL tension)
502 GpPointF *ptf;
503 INT i;
504 GpStatus stat;
506 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
508 if(!path || !points || count <= 1)
509 return InvalidParameter;
511 ptf = GdipAlloc(sizeof(GpPointF)*count);
512 if(!ptf)
513 return OutOfMemory;
515 for(i = 0; i < count; i++){
516 ptf[i].X = (REAL)points[i].X;
517 ptf[i].Y = (REAL)points[i].Y;
520 stat = GdipAddPathCurve2(path, ptf, count, tension);
522 GdipFree(ptf);
524 return stat;
527 GpStatus WINGDIPAPI GdipAddPathCurve3(GpPath *path, GDIPCONST GpPointF *points,
528 INT count, INT offset, INT nseg, REAL tension)
530 TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path, points, count, offset, nseg, tension);
532 if(!path || !points || offset + 1 >= count || count - offset < nseg + 1)
533 return InvalidParameter;
535 return GdipAddPathCurve2(path, &points[offset], nseg + 1, tension);
538 GpStatus WINGDIPAPI GdipAddPathCurve3I(GpPath *path, GDIPCONST GpPoint *points,
539 INT count, INT offset, INT nseg, REAL tension)
541 TRACE("(%p, %p, %d, %d, %d, %.2f)\n", path, points, count, offset, nseg, tension);
543 if(!path || !points || offset + 1 >= count || count - offset < nseg + 1)
544 return InvalidParameter;
546 return GdipAddPathCurve2I(path, &points[offset], nseg + 1, tension);
549 GpStatus WINGDIPAPI GdipAddPathEllipse(GpPath *path, REAL x, REAL y, REAL width,
550 REAL height)
552 INT old_count, numpts;
554 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path, x, y, width, height);
556 if(!path)
557 return InvalidParameter;
559 if(!lengthen_path(path, MAX_ARC_PTS))
560 return OutOfMemory;
562 old_count = path->pathdata.Count;
563 if((numpts = arc2polybezier(&path->pathdata.Points[old_count], x, y, width,
564 height, 0.0, 360.0)) != MAX_ARC_PTS){
565 ERR("expected %d points but got %d\n", MAX_ARC_PTS, numpts);
566 return GenericError;
569 memset(&path->pathdata.Types[old_count + 1], PathPointTypeBezier,
570 MAX_ARC_PTS - 1);
572 /* An ellipse is an intrinsic figure (always is its own subpath). */
573 path->pathdata.Types[old_count] = PathPointTypeStart;
574 path->pathdata.Types[old_count + MAX_ARC_PTS - 1] |= PathPointTypeCloseSubpath;
575 path->newfigure = TRUE;
576 path->pathdata.Count += MAX_ARC_PTS;
578 return Ok;
581 GpStatus WINGDIPAPI GdipAddPathEllipseI(GpPath *path, INT x, INT y, INT width,
582 INT height)
584 TRACE("(%p, %d, %d, %d, %d)\n", path, x, y, width, height);
586 return GdipAddPathEllipse(path,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
589 GpStatus WINGDIPAPI GdipAddPathLine2(GpPath *path, GDIPCONST GpPointF *points,
590 INT count)
592 INT i, old_count;
594 TRACE("(%p, %p, %d)\n", path, points, count);
596 if(!path || !points)
597 return InvalidParameter;
599 if(!lengthen_path(path, count))
600 return OutOfMemory;
602 old_count = path->pathdata.Count;
604 for(i = 0; i < count; i++){
605 path->pathdata.Points[old_count + i].X = points[i].X;
606 path->pathdata.Points[old_count + i].Y = points[i].Y;
607 path->pathdata.Types[old_count + i] = PathPointTypeLine;
610 if(path->newfigure){
611 path->pathdata.Types[old_count] = PathPointTypeStart;
612 path->newfigure = FALSE;
615 path->pathdata.Count += count;
617 return Ok;
620 GpStatus WINGDIPAPI GdipAddPathLine2I(GpPath *path, GDIPCONST GpPoint *points, INT count)
622 GpPointF *pointsF;
623 INT i;
624 GpStatus stat;
626 TRACE("(%p, %p, %d)\n", path, points, count);
628 if(count <= 0)
629 return InvalidParameter;
631 pointsF = GdipAlloc(sizeof(GpPointF) * count);
632 if(!pointsF) return OutOfMemory;
634 for(i = 0;i < count; i++){
635 pointsF[i].X = (REAL)points[i].X;
636 pointsF[i].Y = (REAL)points[i].Y;
639 stat = GdipAddPathLine2(path, pointsF, count);
641 GdipFree(pointsF);
643 return stat;
646 GpStatus WINGDIPAPI GdipAddPathLine(GpPath *path, REAL x1, REAL y1, REAL x2, REAL y2)
648 INT old_count;
650 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path, x1, y1, x2, y2);
652 if(!path)
653 return InvalidParameter;
655 if(!lengthen_path(path, 2))
656 return OutOfMemory;
658 old_count = path->pathdata.Count;
660 path->pathdata.Points[old_count].X = x1;
661 path->pathdata.Points[old_count].Y = y1;
662 path->pathdata.Points[old_count + 1].X = x2;
663 path->pathdata.Points[old_count + 1].Y = y2;
665 path->pathdata.Types[old_count] =
666 (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
667 path->pathdata.Types[old_count + 1] = PathPointTypeLine;
669 path->newfigure = FALSE;
670 path->pathdata.Count += 2;
672 return Ok;
675 GpStatus WINGDIPAPI GdipAddPathLineI(GpPath *path, INT x1, INT y1, INT x2, INT y2)
677 TRACE("(%p, %d, %d, %d, %d)\n", path, x1, y1, x2, y2);
679 return GdipAddPathLine(path, (REAL)x1, (REAL)y1, (REAL)x2, (REAL)y2);
682 GpStatus WINGDIPAPI GdipAddPathPath(GpPath *path, GDIPCONST GpPath* addingPath,
683 BOOL connect)
685 INT old_count, count;
687 TRACE("(%p, %p, %d)\n", path, addingPath, connect);
689 if(!path || !addingPath)
690 return InvalidParameter;
692 old_count = path->pathdata.Count;
693 count = addingPath->pathdata.Count;
695 if(!lengthen_path(path, count))
696 return OutOfMemory;
698 memcpy(&path->pathdata.Points[old_count], addingPath->pathdata.Points,
699 count * sizeof(GpPointF));
700 memcpy(&path->pathdata.Types[old_count], addingPath->pathdata.Types, count);
702 if(path->newfigure || !connect)
703 path->pathdata.Types[old_count] = PathPointTypeStart;
704 else
705 path->pathdata.Types[old_count] = PathPointTypeLine;
707 path->newfigure = FALSE;
708 path->pathdata.Count += count;
710 return Ok;
713 GpStatus WINGDIPAPI GdipAddPathPie(GpPath *path, REAL x, REAL y, REAL width, REAL height,
714 REAL startAngle, REAL sweepAngle)
716 GpPointF *ptf;
717 GpStatus status;
718 INT i, count;
720 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
721 path, x, y, width, height, startAngle, sweepAngle);
723 if(!path)
724 return InvalidParameter;
726 /* on zero width/height only start point added */
727 if(width <= 1e-7 || height <= 1e-7){
728 if(!lengthen_path(path, 1))
729 return OutOfMemory;
730 path->pathdata.Points[0].X = x + width / 2.0;
731 path->pathdata.Points[0].Y = y + height / 2.0;
732 path->pathdata.Types[0] = PathPointTypeStart | PathPointTypeCloseSubpath;
733 path->pathdata.Count = 1;
734 return InvalidParameter;
737 count = arc2polybezier(NULL, x, y, width, height, startAngle, sweepAngle);
739 if(count == 0)
740 return Ok;
742 ptf = GdipAlloc(sizeof(GpPointF)*count);
743 if(!ptf)
744 return OutOfMemory;
746 arc2polybezier(ptf, x, y, width, height, startAngle, sweepAngle);
748 status = GdipAddPathLine(path, (width - x)/2, (height - y)/2, ptf[0].X, ptf[0].Y);
749 if(status != Ok){
750 GdipFree(ptf);
751 return status;
753 /* one spline is already added as a line endpoint */
754 if(!lengthen_path(path, count - 1)){
755 GdipFree(ptf);
756 return OutOfMemory;
759 memcpy(&(path->pathdata.Points[path->pathdata.Count]), &(ptf[1]),sizeof(GpPointF)*(count-1));
760 for(i = 0; i < count-1; i++)
761 path->pathdata.Types[path->pathdata.Count+i] = PathPointTypeBezier;
763 path->pathdata.Count += count-1;
765 GdipClosePathFigure(path);
767 GdipFree(ptf);
769 return status;
772 GpStatus WINGDIPAPI GdipAddPathPieI(GpPath *path, INT x, INT y, INT width, INT height,
773 REAL startAngle, REAL sweepAngle)
775 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
776 path, x, y, width, height, startAngle, sweepAngle);
778 return GdipAddPathPieI(path, (REAL)x, (REAL)y, (REAL)width, (REAL)height, startAngle, sweepAngle);
781 GpStatus WINGDIPAPI GdipAddPathPolygon(GpPath *path, GDIPCONST GpPointF *points, INT count)
783 INT old_count;
785 TRACE("(%p, %p, %d)\n", path, points, count);
787 if(!path || !points || count < 3)
788 return InvalidParameter;
790 if(!lengthen_path(path, count))
791 return OutOfMemory;
793 old_count = path->pathdata.Count;
795 memcpy(&path->pathdata.Points[old_count], points, count*sizeof(GpPointF));
796 memset(&path->pathdata.Types[old_count + 1], PathPointTypeLine, count - 1);
798 /* A polygon is an intrinsic figure */
799 path->pathdata.Types[old_count] = PathPointTypeStart;
800 path->pathdata.Types[old_count + count - 1] |= PathPointTypeCloseSubpath;
801 path->newfigure = TRUE;
802 path->pathdata.Count += count;
804 return Ok;
807 GpStatus WINGDIPAPI GdipAddPathPolygonI(GpPath *path, GDIPCONST GpPoint *points, INT count)
809 GpPointF *ptf;
810 GpStatus status;
811 INT i;
813 TRACE("(%p, %p, %d)\n", path, points, count);
815 if(!points || count < 3)
816 return InvalidParameter;
818 ptf = GdipAlloc(sizeof(GpPointF) * count);
819 if(!ptf)
820 return OutOfMemory;
822 for(i = 0; i < count; i++){
823 ptf[i].X = (REAL)points[i].X;
824 ptf[i].Y = (REAL)points[i].Y;
827 status = GdipAddPathPolygon(path, ptf, count);
829 GdipFree(ptf);
831 return status;
834 GpStatus WINGDIPAPI GdipClonePath(GpPath* path, GpPath **clone)
836 TRACE("(%p, %p)\n", path, clone);
838 if(!path || !clone)
839 return InvalidParameter;
841 *clone = GdipAlloc(sizeof(GpPath));
842 if(!*clone) return OutOfMemory;
844 **clone = *path;
846 (*clone)->pathdata.Points = GdipAlloc(path->datalen * sizeof(PointF));
847 (*clone)->pathdata.Types = GdipAlloc(path->datalen);
848 if(!(*clone)->pathdata.Points || !(*clone)->pathdata.Types){
849 GdipFree(*clone);
850 GdipFree((*clone)->pathdata.Points);
851 GdipFree((*clone)->pathdata.Types);
852 return OutOfMemory;
855 memcpy((*clone)->pathdata.Points, path->pathdata.Points,
856 path->datalen * sizeof(PointF));
857 memcpy((*clone)->pathdata.Types, path->pathdata.Types, path->datalen);
859 return Ok;
862 GpStatus WINGDIPAPI GdipClosePathFigure(GpPath* path)
864 TRACE("(%p)\n", path);
866 if(!path)
867 return InvalidParameter;
869 if(path->pathdata.Count > 0){
870 path->pathdata.Types[path->pathdata.Count - 1] |= PathPointTypeCloseSubpath;
871 path->newfigure = TRUE;
874 return Ok;
877 GpStatus WINGDIPAPI GdipClosePathFigures(GpPath* path)
879 INT i;
881 TRACE("(%p)\n", path);
883 if(!path)
884 return InvalidParameter;
886 for(i = 1; i < path->pathdata.Count; i++){
887 if(path->pathdata.Types[i] == PathPointTypeStart)
888 path->pathdata.Types[i-1] |= PathPointTypeCloseSubpath;
891 path->newfigure = TRUE;
893 return Ok;
896 GpStatus WINGDIPAPI GdipCreatePath(GpFillMode fill, GpPath **path)
898 TRACE("(%d, %p)\n", fill, path);
900 if(!path)
901 return InvalidParameter;
903 *path = GdipAlloc(sizeof(GpPath));
904 if(!*path) return OutOfMemory;
906 (*path)->fill = fill;
907 (*path)->newfigure = TRUE;
909 return Ok;
912 GpStatus WINGDIPAPI GdipCreatePath2(GDIPCONST GpPointF* points,
913 GDIPCONST BYTE* types, INT count, GpFillMode fill, GpPath **path)
915 TRACE("(%p, %p, %d, %d, %p)\n", points, types, count, fill, path);
917 if(!path)
918 return InvalidParameter;
920 *path = GdipAlloc(sizeof(GpPath));
921 if(!*path) return OutOfMemory;
923 (*path)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
924 (*path)->pathdata.Types = GdipAlloc(count);
926 if(!(*path)->pathdata.Points || !(*path)->pathdata.Types){
927 GdipFree((*path)->pathdata.Points);
928 GdipFree((*path)->pathdata.Types);
929 GdipFree(*path);
930 return OutOfMemory;
933 memcpy((*path)->pathdata.Points, points, count * sizeof(PointF));
934 memcpy((*path)->pathdata.Types, types, count);
935 (*path)->pathdata.Count = count;
936 (*path)->datalen = count;
938 (*path)->fill = fill;
939 (*path)->newfigure = TRUE;
941 return Ok;
944 GpStatus WINGDIPAPI GdipCreatePath2I(GDIPCONST GpPoint* points,
945 GDIPCONST BYTE* types, INT count, GpFillMode fill, GpPath **path)
947 GpPointF *ptF;
948 GpStatus ret;
949 INT i;
951 TRACE("(%p, %p, %d, %d, %p)\n", points, types, count, fill, path);
953 ptF = GdipAlloc(sizeof(GpPointF)*count);
955 for(i = 0;i < count; i++){
956 ptF[i].X = (REAL)points[i].X;
957 ptF[i].Y = (REAL)points[i].Y;
960 ret = GdipCreatePath2(ptF, types, count, fill, path);
962 GdipFree(ptF);
964 return ret;
967 GpStatus WINGDIPAPI GdipDeletePath(GpPath *path)
969 TRACE("(%p)\n", path);
971 if(!path)
972 return InvalidParameter;
974 GdipFree(path->pathdata.Points);
975 GdipFree(path->pathdata.Types);
976 GdipFree(path);
978 return Ok;
981 GpStatus WINGDIPAPI GdipFlattenPath(GpPath *path, GpMatrix* matrix, REAL flatness)
983 path_list_node_t *list, *node;
984 GpPointF pt;
985 INT i = 1;
986 INT startidx = 0;
988 TRACE("(%p, %p, %.2f)\n", path, matrix, flatness);
990 if(!path)
991 return InvalidParameter;
993 if(matrix){
994 WARN("transformation not supported yet!\n");
995 return NotImplemented;
998 if(path->pathdata.Count == 0)
999 return Ok;
1001 pt = path->pathdata.Points[0];
1002 if(!init_path_list(&list, pt.X, pt.Y))
1003 return OutOfMemory;
1005 node = list;
1007 while(i < path->pathdata.Count){
1009 BYTE type = path->pathdata.Types[i] & PathPointTypePathTypeMask;
1010 path_list_node_t *start;
1012 pt = path->pathdata.Points[i];
1014 /* save last start point index */
1015 if(type == PathPointTypeStart)
1016 startidx = i;
1018 /* always add line points and start points */
1019 if((type == PathPointTypeStart) || (type == PathPointTypeLine)){
1020 if(!add_path_list_node(node, pt.X, pt.Y, path->pathdata.Types[i]))
1021 goto memout;
1023 node = node->next;
1024 ++i;
1025 continue;
1028 /* Bezier curve always stored as 4 points */
1029 if((path->pathdata.Types[i-1] & PathPointTypePathTypeMask) != PathPointTypeStart){
1030 type = (path->pathdata.Types[i] & ~PathPointTypePathTypeMask) | PathPointTypeLine;
1031 if(!add_path_list_node(node, pt.X, pt.Y, type))
1032 goto memout;
1034 node = node->next;
1037 /* test for closed figure */
1038 if(path->pathdata.Types[i+1] & PathPointTypeCloseSubpath){
1039 pt = path->pathdata.Points[startidx];
1040 ++i;
1042 else
1044 i += 2;
1045 pt = path->pathdata.Points[i];
1048 start = node;
1049 /* add Bezier end point */
1050 type = (path->pathdata.Types[i] & ~PathPointTypePathTypeMask) | PathPointTypeLine;
1051 if(!add_path_list_node(node, pt.X, pt.Y, type))
1052 goto memout;
1053 node = node->next;
1055 /* flatten curve */
1056 if(!flatten_bezier(start, path->pathdata.Points[i-2].X, path->pathdata.Points[i-2].Y,
1057 path->pathdata.Points[i-1].X, path->pathdata.Points[i-1].Y,
1058 node, flatness))
1059 goto memout;
1061 ++i;
1062 }/* while */
1064 /* store path data back */
1065 i = path_list_count(list);
1066 if(!lengthen_path(path, i))
1067 goto memout;
1068 path->pathdata.Count = i;
1070 node = list;
1071 for(i = 0; i < path->pathdata.Count; i++){
1072 path->pathdata.Points[i] = node->pt;
1073 path->pathdata.Types[i] = node->type;
1074 node = node->next;
1077 free_path_list(list);
1078 return Ok;
1080 memout:
1081 free_path_list(list);
1082 return OutOfMemory;
1085 GpStatus WINGDIPAPI GdipGetPathData(GpPath *path, GpPathData* pathData)
1087 TRACE("(%p, %p)\n", path, pathData);
1089 if(!path || !pathData)
1090 return InvalidParameter;
1092 /* Only copy data. pathData allocation/freeing controlled by wrapper class.
1093 Assumed that pathData is enough wide to get all data - controlled by wrapper too. */
1094 memcpy(pathData->Points, path->pathdata.Points, sizeof(PointF) * pathData->Count);
1095 memcpy(pathData->Types , path->pathdata.Types , pathData->Count);
1097 return Ok;
1100 GpStatus WINGDIPAPI GdipGetPathFillMode(GpPath *path, GpFillMode *fillmode)
1102 TRACE("(%p, %p)\n", path, fillmode);
1104 if(!path || !fillmode)
1105 return InvalidParameter;
1107 *fillmode = path->fill;
1109 return Ok;
1112 GpStatus WINGDIPAPI GdipGetPathLastPoint(GpPath* path, GpPointF* lastPoint)
1114 INT count;
1116 TRACE("(%p, %p)\n", path, lastPoint);
1118 if(!path || !lastPoint)
1119 return InvalidParameter;
1121 count = path->pathdata.Count;
1122 if(count > 0)
1123 *lastPoint = path->pathdata.Points[count-1];
1125 return Ok;
1128 GpStatus WINGDIPAPI GdipGetPathPoints(GpPath *path, GpPointF* points, INT count)
1130 TRACE("(%p, %p, %d)\n", path, points, count);
1132 if(!path)
1133 return InvalidParameter;
1135 if(count < path->pathdata.Count)
1136 return InsufficientBuffer;
1138 memcpy(points, path->pathdata.Points, path->pathdata.Count * sizeof(GpPointF));
1140 return Ok;
1143 GpStatus WINGDIPAPI GdipGetPathPointsI(GpPath *path, GpPoint* points, INT count)
1145 GpStatus ret;
1146 GpPointF *ptf;
1147 INT i;
1149 TRACE("(%p, %p, %d)\n", path, points, count);
1151 if(count <= 0)
1152 return InvalidParameter;
1154 ptf = GdipAlloc(sizeof(GpPointF)*count);
1155 if(!ptf) return OutOfMemory;
1157 ret = GdipGetPathPoints(path,ptf,count);
1158 if(ret == Ok)
1159 for(i = 0;i < count;i++){
1160 points[i].X = roundr(ptf[i].X);
1161 points[i].Y = roundr(ptf[i].Y);
1163 GdipFree(ptf);
1165 return ret;
1168 GpStatus WINGDIPAPI GdipGetPathTypes(GpPath *path, BYTE* types, INT count)
1170 TRACE("(%p, %p, %d)\n", path, types, count);
1172 if(!path)
1173 return InvalidParameter;
1175 if(count < path->pathdata.Count)
1176 return InsufficientBuffer;
1178 memcpy(types, path->pathdata.Types, path->pathdata.Count);
1180 return Ok;
1183 /* Windows expands the bounding box to the maximum possible bounding box
1184 * for a given pen. For example, if a line join can extend past the point
1185 * it's joining by x units, the bounding box is extended by x units in every
1186 * direction (even though this is too conservative for most cases). */
1187 GpStatus WINGDIPAPI GdipGetPathWorldBounds(GpPath* path, GpRectF* bounds,
1188 GDIPCONST GpMatrix *matrix, GDIPCONST GpPen *pen)
1190 GpPointF * points, temp_pts[4];
1191 INT count, i;
1192 REAL path_width = 1.0, width, height, temp, low_x, low_y, high_x, high_y;
1194 TRACE("(%p, %p, %p, %p)\n", path, bounds, matrix, pen);
1196 /* Matrix and pen can be null. */
1197 if(!path || !bounds)
1198 return InvalidParameter;
1200 /* If path is empty just return. */
1201 count = path->pathdata.Count;
1202 if(count == 0){
1203 bounds->X = bounds->Y = bounds->Width = bounds->Height = 0.0;
1204 return Ok;
1207 points = path->pathdata.Points;
1209 low_x = high_x = points[0].X;
1210 low_y = high_y = points[0].Y;
1212 for(i = 1; i < count; i++){
1213 low_x = min(low_x, points[i].X);
1214 low_y = min(low_y, points[i].Y);
1215 high_x = max(high_x, points[i].X);
1216 high_y = max(high_y, points[i].Y);
1219 width = high_x - low_x;
1220 height = high_y - low_y;
1222 /* This looks unusual but it's the only way I can imitate windows. */
1223 if(matrix){
1224 temp_pts[0].X = low_x;
1225 temp_pts[0].Y = low_y;
1226 temp_pts[1].X = low_x;
1227 temp_pts[1].Y = high_y;
1228 temp_pts[2].X = high_x;
1229 temp_pts[2].Y = high_y;
1230 temp_pts[3].X = high_x;
1231 temp_pts[3].Y = low_y;
1233 GdipTransformMatrixPoints((GpMatrix*)matrix, temp_pts, 4);
1234 low_x = temp_pts[0].X;
1235 low_y = temp_pts[0].Y;
1237 for(i = 1; i < 4; i++){
1238 low_x = min(low_x, temp_pts[i].X);
1239 low_y = min(low_y, temp_pts[i].Y);
1242 temp = width;
1243 width = height * fabs(matrix->matrix[2]) + width * fabs(matrix->matrix[0]);
1244 height = height * fabs(matrix->matrix[3]) + temp * fabs(matrix->matrix[1]);
1247 if(pen){
1248 path_width = pen->width / 2.0;
1250 if(count > 2)
1251 path_width = max(path_width, pen->width * pen->miterlimit / 2.0);
1252 /* FIXME: this should probably also check for the startcap */
1253 if(pen->endcap & LineCapNoAnchor)
1254 path_width = max(path_width, pen->width * 2.2);
1256 low_x -= path_width;
1257 low_y -= path_width;
1258 width += 2.0 * path_width;
1259 height += 2.0 * path_width;
1262 bounds->X = low_x;
1263 bounds->Y = low_y;
1264 bounds->Width = width;
1265 bounds->Height = height;
1267 return Ok;
1270 GpStatus WINGDIPAPI GdipGetPathWorldBoundsI(GpPath* path, GpRect* bounds,
1271 GDIPCONST GpMatrix *matrix, GDIPCONST GpPen *pen)
1273 GpStatus ret;
1274 GpRectF boundsF;
1276 TRACE("(%p, %p, %p, %p)\n", path, bounds, matrix, pen);
1278 ret = GdipGetPathWorldBounds(path,&boundsF,matrix,pen);
1280 if(ret == Ok){
1281 bounds->X = roundr(boundsF.X);
1282 bounds->Y = roundr(boundsF.Y);
1283 bounds->Width = roundr(boundsF.Width);
1284 bounds->Height = roundr(boundsF.Height);
1287 return ret;
1290 GpStatus WINGDIPAPI GdipGetPointCount(GpPath *path, INT *count)
1292 TRACE("(%p, %p)\n", path, count);
1294 if(!path)
1295 return InvalidParameter;
1297 *count = path->pathdata.Count;
1299 return Ok;
1302 GpStatus WINGDIPAPI GdipReversePath(GpPath* path)
1304 INT i, count;
1305 INT start = 0; /* position in reversed path */
1306 GpPathData revpath;
1308 TRACE("(%p)\n", path);
1310 if(!path)
1311 return InvalidParameter;
1313 count = path->pathdata.Count;
1315 if(count == 0) return Ok;
1317 revpath.Points = GdipAlloc(sizeof(GpPointF)*count);
1318 revpath.Types = GdipAlloc(sizeof(BYTE)*count);
1319 revpath.Count = count;
1320 if(!revpath.Points || !revpath.Types){
1321 GdipFree(revpath.Points);
1322 GdipFree(revpath.Types);
1323 return OutOfMemory;
1326 for(i = 0; i < count; i++){
1328 /* find next start point */
1329 if(path->pathdata.Types[count-i-1] == PathPointTypeStart){
1330 INT j;
1331 for(j = start; j <= i; j++){
1332 revpath.Points[j] = path->pathdata.Points[count-j-1];
1333 revpath.Types[j] = path->pathdata.Types[count-j-1];
1335 /* mark start point */
1336 revpath.Types[start] = PathPointTypeStart;
1337 /* set 'figure' endpoint type */
1338 if(i-start > 1){
1339 revpath.Types[i] = path->pathdata.Types[count-start-1] & ~PathPointTypePathTypeMask;
1340 revpath.Types[i] |= revpath.Types[i-1];
1342 else
1343 revpath.Types[i] = path->pathdata.Types[start];
1345 start = i+1;
1349 memcpy(path->pathdata.Points, revpath.Points, sizeof(GpPointF)*count);
1350 memcpy(path->pathdata.Types, revpath.Types, sizeof(BYTE)*count);
1352 GdipFree(revpath.Points);
1353 GdipFree(revpath.Types);
1355 return Ok;
1358 GpStatus WINGDIPAPI GdipIsOutlineVisiblePathPointI(GpPath* path, INT x, INT y,
1359 GpPen *pen, GpGraphics *graphics, BOOL *result)
1361 TRACE("(%p, %d, %d, %p, %p, %p)\n", path, x, y, pen, graphics, result);
1363 return GdipIsOutlineVisiblePathPoint(path, x, y, pen, graphics, result);
1366 GpStatus WINGDIPAPI GdipIsOutlineVisiblePathPoint(GpPath* path, REAL x, REAL y,
1367 GpPen *pen, GpGraphics *graphics, BOOL *result)
1369 static int calls;
1371 if(!path || !pen)
1372 return InvalidParameter;
1374 if(!(calls++))
1375 FIXME("not implemented\n");
1377 return NotImplemented;
1380 GpStatus WINGDIPAPI GdipIsVisiblePathPointI(GpPath* path, INT x, INT y, GpGraphics *graphics, BOOL *result)
1382 TRACE("(%p, %d, %d, %p, %p)\n", path, x, y, graphics, result);
1384 return GdipIsVisiblePathPoint(path, x, y, graphics, result);
1387 GpStatus WINGDIPAPI GdipIsVisiblePathPoint(GpPath* path, REAL x, REAL y, GpGraphics *graphics, BOOL *result)
1389 static int calls;
1391 if(!path) return InvalidParameter;
1393 if(!(calls++))
1394 FIXME("not implemented\n");
1396 return NotImplemented;
1399 GpStatus WINGDIPAPI GdipStartPathFigure(GpPath *path)
1401 TRACE("(%p)\n", path);
1403 if(!path)
1404 return InvalidParameter;
1406 path->newfigure = TRUE;
1408 return Ok;
1411 GpStatus WINGDIPAPI GdipResetPath(GpPath *path)
1413 TRACE("(%p)\n", path);
1415 if(!path)
1416 return InvalidParameter;
1418 path->pathdata.Count = 0;
1419 path->newfigure = TRUE;
1420 path->fill = FillModeAlternate;
1422 return Ok;
1425 GpStatus WINGDIPAPI GdipSetPathFillMode(GpPath *path, GpFillMode fill)
1427 TRACE("(%p, %d)\n", path, fill);
1429 if(!path)
1430 return InvalidParameter;
1432 path->fill = fill;
1434 return Ok;
1437 GpStatus WINGDIPAPI GdipTransformPath(GpPath *path, GpMatrix *matrix)
1439 TRACE("(%p, %p)\n", path, matrix);
1441 if(!path)
1442 return InvalidParameter;
1444 if(path->pathdata.Count == 0)
1445 return Ok;
1447 return GdipTransformMatrixPoints(matrix, path->pathdata.Points,
1448 path->pathdata.Count);
1451 GpStatus WINGDIPAPI GdipAddPathRectangle(GpPath *path, REAL x, REAL y,
1452 REAL width, REAL height)
1454 GpPath *backup;
1455 GpPointF ptf[2];
1456 GpStatus retstat;
1457 BOOL old_new;
1459 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path, x, y, width, height);
1461 if(!path || width < 0.0 || height < 0.0)
1462 return InvalidParameter;
1464 /* make a backup copy of path data */
1465 if((retstat = GdipClonePath(path, &backup)) != Ok)
1466 return retstat;
1468 /* rectangle should start as new path */
1469 old_new = path->newfigure;
1470 path->newfigure = TRUE;
1471 if((retstat = GdipAddPathLine(path,x,y,x+width,y)) != Ok){
1472 path->newfigure = old_new;
1473 goto fail;
1476 ptf[0].X = x+width;
1477 ptf[0].Y = y+height;
1478 ptf[1].X = x;
1479 ptf[1].Y = y+height;
1481 if((retstat = GdipAddPathLine2(path, ptf, 2)) != Ok) goto fail;
1482 path->pathdata.Types[path->pathdata.Count-1] |= PathPointTypeCloseSubpath;
1484 /* free backup */
1485 GdipDeletePath(backup);
1486 return Ok;
1488 fail:
1489 /* reverting */
1490 GdipDeletePath(path);
1491 GdipClonePath(backup, &path);
1492 GdipDeletePath(backup);
1494 return retstat;
1497 GpStatus WINGDIPAPI GdipAddPathRectangleI(GpPath *path, INT x, INT y,
1498 INT width, INT height)
1500 TRACE("(%p, %d, %d, %d, %d)\n", path, x, y, width, height);
1502 return GdipAddPathRectangle(path,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
1505 GpStatus WINGDIPAPI GdipAddPathRectangles(GpPath *path, GDIPCONST GpRectF *rects, INT count)
1507 GpPath *backup;
1508 GpStatus retstat;
1509 INT i;
1511 TRACE("(%p, %p, %d)\n", path, rects, count);
1513 /* count == 0 - verified condition */
1514 if(!path || !rects || count == 0)
1515 return InvalidParameter;
1517 if(count < 0)
1518 return OutOfMemory;
1520 /* make a backup copy */
1521 if((retstat = GdipClonePath(path, &backup)) != Ok)
1522 return retstat;
1524 for(i = 0; i < count; i++){
1525 if((retstat = GdipAddPathRectangle(path,rects[i].X,rects[i].Y,rects[i].Width,rects[i].Height)) != Ok)
1526 goto fail;
1529 /* free backup */
1530 GdipDeletePath(backup);
1531 return Ok;
1533 fail:
1534 /* reverting */
1535 GdipDeletePath(path);
1536 GdipClonePath(backup, &path);
1537 GdipDeletePath(backup);
1539 return retstat;
1542 GpStatus WINGDIPAPI GdipAddPathRectanglesI(GpPath *path, GDIPCONST GpRect *rects, INT count)
1544 GpRectF *rectsF;
1545 GpStatus retstat;
1546 INT i;
1548 TRACE("(%p, %p, %d)\n", path, rects, count);
1550 if(!rects || count == 0)
1551 return InvalidParameter;
1553 if(count < 0)
1554 return OutOfMemory;
1556 rectsF = GdipAlloc(sizeof(GpRectF)*count);
1558 for(i = 0;i < count;i++){
1559 rectsF[i].X = (REAL)rects[i].X;
1560 rectsF[i].Y = (REAL)rects[i].Y;
1561 rectsF[i].Width = (REAL)rects[i].Width;
1562 rectsF[i].Height = (REAL)rects[i].Height;
1565 retstat = GdipAddPathRectangles(path, rectsF, count);
1566 GdipFree(rectsF);
1568 return retstat;
1571 GpStatus WINGDIPAPI GdipSetPathMarker(GpPath* path)
1573 INT count;
1575 TRACE("(%p)\n", path);
1577 if(!path)
1578 return InvalidParameter;
1580 count = path->pathdata.Count;
1582 /* set marker flag */
1583 if(count > 0)
1584 path->pathdata.Types[count-1] |= PathPointTypePathMarker;
1586 return Ok;
1589 GpStatus WINGDIPAPI GdipClearPathMarkers(GpPath* path)
1591 INT count;
1592 INT i;
1594 TRACE("(%p)\n", path);
1596 if(!path)
1597 return InvalidParameter;
1599 count = path->pathdata.Count;
1601 for(i = 0; i < count - 1; i++){
1602 path->pathdata.Types[i] &= ~PathPointTypePathMarker;
1605 return Ok;