regedit: Interpret REG_DWORD as unsigned in editor.
[wine/gsoc_dplay.git] / dlls / gdiplus / graphicspath.c
blob24f25e1ebf242d610a6fc2084e8b70bbad3db01c
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 /* 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);
49 return FALSE;
52 /* reallocation, double size of arrays */
53 else if(path->datalen - path->pathdata.Count < len){
54 while(path->datalen - path->pathdata.Count < len)
55 path->datalen *= 2;
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;
66 return TRUE;
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;
74 if(!path)
75 return InvalidParameter;
77 count = arc2polybezier(NULL, x1, y1, x2, y2, startAngle, sweepAngle);
79 if(count == 0)
80 return Ok;
81 if(!lengthen_path(path, count))
82 return OutOfMemory;
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;
97 return Ok;
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)
109 INT old_count;
111 if(!path)
112 return InvalidParameter;
114 if(!lengthen_path(path, 4))
115 return OutOfMemory;
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;
137 return Ok;
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,
144 (REAL)x4,(REAL)y4);
147 GpStatus WINGDIPAPI GdipAddPathBeziers(GpPath *path, GDIPCONST GpPointF *points,
148 INT count)
150 INT i, old_count;
152 if(!path || !points || ((count - 1) % 3))
153 return InvalidParameter;
155 if(!lengthen_path(path, count))
156 return OutOfMemory;
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;
171 return Ok;
174 GpStatus WINGDIPAPI GdipAddPathBeziersI(GpPath *path, GDIPCONST GpPoint *points,
175 INT count)
177 GpPointF *ptsF;
178 GpStatus ret;
179 INT i;
181 if(!points || ((count - 1) % 3))
182 return InvalidParameter;
184 ptsF = GdipAlloc(sizeof(GpPointF) * count);
185 if(!ptsF)
186 return OutOfMemory;
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);
194 GdipFree(ptsF);
196 return ret;
199 GpStatus WINGDIPAPI GdipAddPathEllipse(GpPath *path, REAL x, REAL y, REAL width,
200 REAL height)
202 INT old_count, numpts;
204 if(!path)
205 return InvalidParameter;
207 if(!lengthen_path(path, MAX_ARC_PTS))
208 return OutOfMemory;
210 old_count = path->pathdata.Count;
211 if((numpts = arc2polybezier(&path->pathdata.Points[old_count], x, y, width,
212 height, 0.0, 360.0)) != MAX_ARC_PTS){
213 ERR("expected %d points but got %d\n", MAX_ARC_PTS, numpts);
214 return GenericError;
217 memset(&path->pathdata.Types[old_count + 1], PathPointTypeBezier,
218 MAX_ARC_PTS - 1);
220 /* An ellipse is an intrinsic figure (always is its own subpath). */
221 path->pathdata.Types[old_count] = PathPointTypeStart;
222 path->pathdata.Types[old_count + MAX_ARC_PTS - 1] |= PathPointTypeCloseSubpath;
223 path->newfigure = TRUE;
224 path->pathdata.Count += MAX_ARC_PTS;
226 return Ok;
229 GpStatus WINGDIPAPI GdipAddPathEllipseI(GpPath *path, INT x, INT y, INT width,
230 INT height)
232 return GdipAddPathEllipse(path,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
235 GpStatus WINGDIPAPI GdipAddPathLine2(GpPath *path, GDIPCONST GpPointF *points,
236 INT count)
238 INT i, old_count;
240 if(!path || !points)
241 return InvalidParameter;
243 if(!lengthen_path(path, count))
244 return OutOfMemory;
246 old_count = path->pathdata.Count;
248 for(i = 0; i < count; i++){
249 path->pathdata.Points[old_count + i].X = points[i].X;
250 path->pathdata.Points[old_count + i].Y = points[i].Y;
251 path->pathdata.Types[old_count + i] = PathPointTypeLine;
254 if(path->newfigure){
255 path->pathdata.Types[old_count] = PathPointTypeStart;
256 path->newfigure = FALSE;
259 path->pathdata.Count += count;
261 return Ok;
264 GpStatus WINGDIPAPI GdipAddPathLine2I(GpPath *path, GDIPCONST GpPoint *points, INT count)
266 GpPointF *pointsF;
267 INT i;
268 GpStatus stat;
270 if(count <= 0)
271 return InvalidParameter;
273 pointsF = GdipAlloc(sizeof(GpPointF) * count);
274 if(!pointsF) return OutOfMemory;
276 for(i = 0;i < count; i++){
277 pointsF[i].X = (REAL)points[i].X;
278 pointsF[i].Y = (REAL)points[i].Y;
281 stat = GdipAddPathLine2(path, pointsF, count);
283 GdipFree(pointsF);
285 return stat;
288 GpStatus WINGDIPAPI GdipAddPathLine(GpPath *path, REAL x1, REAL y1, REAL x2, REAL y2)
290 INT old_count;
292 if(!path)
293 return InvalidParameter;
295 if(!lengthen_path(path, 2))
296 return OutOfMemory;
298 old_count = path->pathdata.Count;
300 path->pathdata.Points[old_count].X = x1;
301 path->pathdata.Points[old_count].Y = y1;
302 path->pathdata.Points[old_count + 1].X = x2;
303 path->pathdata.Points[old_count + 1].Y = y2;
305 path->pathdata.Types[old_count] =
306 (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
307 path->pathdata.Types[old_count + 1] = PathPointTypeLine;
309 path->newfigure = FALSE;
310 path->pathdata.Count += 2;
312 return Ok;
315 GpStatus WINGDIPAPI GdipAddPathLineI(GpPath *path, INT x1, INT y1, INT x2, INT y2)
317 return GdipAddPathLine(path, (REAL)x1, (REAL)y1, (REAL)x2, (REAL)y2);
320 GpStatus WINGDIPAPI GdipAddPathPath(GpPath *path, GDIPCONST GpPath* addingPath,
321 BOOL connect)
323 INT old_count, count;
325 if(!path || !addingPath)
326 return InvalidParameter;
328 old_count = path->pathdata.Count;
329 count = addingPath->pathdata.Count;
331 if(!lengthen_path(path, count))
332 return OutOfMemory;
334 memcpy(&path->pathdata.Points[old_count], addingPath->pathdata.Points,
335 count * sizeof(GpPointF));
336 memcpy(&path->pathdata.Types[old_count], addingPath->pathdata.Types, count);
338 if(path->newfigure || !connect)
339 path->pathdata.Types[old_count] = PathPointTypeStart;
340 else
341 path->pathdata.Types[old_count] = PathPointTypeLine;
343 path->newfigure = FALSE;
344 path->pathdata.Count += count;
346 return Ok;
349 GpStatus WINGDIPAPI GdipClonePath(GpPath* path, GpPath **clone)
351 if(!path || !clone)
352 return InvalidParameter;
354 *clone = GdipAlloc(sizeof(GpPath));
355 if(!*clone) return OutOfMemory;
357 **clone = *path;
359 (*clone)->pathdata.Points = GdipAlloc(path->datalen * sizeof(PointF));
360 (*clone)->pathdata.Types = GdipAlloc(path->datalen);
361 if(!(*clone)->pathdata.Points || !(*clone)->pathdata.Types){
362 GdipFree(*clone);
363 GdipFree((*clone)->pathdata.Points);
364 GdipFree((*clone)->pathdata.Types);
365 return OutOfMemory;
368 memcpy((*clone)->pathdata.Points, path->pathdata.Points,
369 path->datalen * sizeof(PointF));
370 memcpy((*clone)->pathdata.Types, path->pathdata.Types, path->datalen);
372 return Ok;
375 GpStatus WINGDIPAPI GdipClosePathFigure(GpPath* path)
377 if(!path)
378 return InvalidParameter;
380 if(path->pathdata.Count > 0){
381 path->pathdata.Types[path->pathdata.Count - 1] |= PathPointTypeCloseSubpath;
382 path->newfigure = TRUE;
385 return Ok;
388 GpStatus WINGDIPAPI GdipClosePathFigures(GpPath* path)
390 INT i;
392 if(!path)
393 return InvalidParameter;
395 for(i = 1; i < path->pathdata.Count; i++){
396 if(path->pathdata.Types[i] == PathPointTypeStart)
397 path->pathdata.Types[i-1] |= PathPointTypeCloseSubpath;
400 path->newfigure = TRUE;
402 return Ok;
405 GpStatus WINGDIPAPI GdipCreatePath(GpFillMode fill, GpPath **path)
407 if(!path)
408 return InvalidParameter;
410 *path = GdipAlloc(sizeof(GpPath));
411 if(!*path) return OutOfMemory;
413 (*path)->fill = fill;
414 (*path)->newfigure = TRUE;
416 return Ok;
419 GpStatus WINGDIPAPI GdipCreatePath2(GDIPCONST GpPointF* points,
420 GDIPCONST BYTE* types, INT count, GpFillMode fill, GpPath **path)
422 if(!path)
423 return InvalidParameter;
425 *path = GdipAlloc(sizeof(GpPath));
426 if(!*path) return OutOfMemory;
428 (*path)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
429 (*path)->pathdata.Types = GdipAlloc(count);
431 if(!(*path)->pathdata.Points || !(*path)->pathdata.Types){
432 GdipFree((*path)->pathdata.Points);
433 GdipFree((*path)->pathdata.Types);
434 GdipFree(*path);
435 return OutOfMemory;
438 memcpy((*path)->pathdata.Points, points, count * sizeof(PointF));
439 memcpy((*path)->pathdata.Types, types, count);
440 (*path)->pathdata.Count = count;
441 (*path)->datalen = count;
443 (*path)->fill = fill;
444 (*path)->newfigure = TRUE;
446 return Ok;
449 GpStatus WINGDIPAPI GdipCreatePath2I(GDIPCONST GpPoint* points,
450 GDIPCONST BYTE* types, INT count, GpFillMode fill, GpPath **path)
452 GpPointF *ptF;
453 GpStatus ret;
454 INT i;
456 ptF = GdipAlloc(sizeof(GpPointF)*count);
458 for(i = 0;i < count; i++){
459 ptF[i].X = (REAL)points[i].X;
460 ptF[i].Y = (REAL)points[i].Y;
463 ret = GdipCreatePath2(ptF, types, count, fill, path);
465 GdipFree(ptF);
467 return ret;
470 GpStatus WINGDIPAPI GdipDeletePath(GpPath *path)
472 if(!path)
473 return InvalidParameter;
475 GdipFree(path->pathdata.Points);
476 GdipFree(path->pathdata.Types);
477 GdipFree(path);
479 return Ok;
482 GpStatus WINGDIPAPI GdipGetPathData(GpPath *path, GpPathData* pathData)
484 if(!path || !pathData)
485 return InvalidParameter;
487 pathData->Count = path->pathdata.Count;
489 pathData->Points = GdipAlloc(sizeof(PointF) * pathData->Count);
490 if(!pathData->Points)
491 return OutOfMemory;
493 pathData->Types = GdipAlloc(pathData->Count);
494 if(!pathData->Points)
495 return OutOfMemory;
497 /* copy data */
498 memcpy(pathData->Points, path->pathdata.Points, sizeof(PointF) * pathData->Count);
499 memcpy(pathData->Types , path->pathdata.Types , pathData->Count);
501 return Ok;
504 GpStatus WINGDIPAPI GdipGetPathFillMode(GpPath *path, GpFillMode *fillmode)
506 if(!path || !fillmode)
507 return InvalidParameter;
509 *fillmode = path->fill;
511 return Ok;
514 GpStatus WINGDIPAPI GdipGetPathPoints(GpPath *path, GpPointF* points, INT count)
516 if(!path)
517 return InvalidParameter;
519 if(count < path->pathdata.Count)
520 return InsufficientBuffer;
522 memcpy(points, path->pathdata.Points, path->pathdata.Count * sizeof(GpPointF));
524 return Ok;
527 GpStatus WINGDIPAPI GdipGetPathPointsI(GpPath *path, GpPoint* points, INT count)
529 GpStatus ret;
530 GpPointF *ptf;
531 INT i;
533 if(count <= 0)
534 return InvalidParameter;
536 ptf = GdipAlloc(sizeof(GpPointF)*count);
537 if(!ptf) return OutOfMemory;
539 ret = GdipGetPathPoints(path,ptf,count);
540 if(ret == Ok)
541 for(i = 0;i < count;i++){
542 points[i].X = roundr(ptf[i].X);
543 points[i].Y = roundr(ptf[i].Y);
545 GdipFree(ptf);
547 return ret;
550 GpStatus WINGDIPAPI GdipGetPathTypes(GpPath *path, BYTE* types, INT count)
552 if(!path)
553 return InvalidParameter;
555 if(count < path->pathdata.Count)
556 return InsufficientBuffer;
558 memcpy(types, path->pathdata.Types, path->pathdata.Count);
560 return Ok;
563 /* Windows expands the bounding box to the maximum possible bounding box
564 * for a given pen. For example, if a line join can extend past the point
565 * it's joining by x units, the bounding box is extended by x units in every
566 * direction (even though this is too conservative for most cases). */
567 GpStatus WINGDIPAPI GdipGetPathWorldBounds(GpPath* path, GpRectF* bounds,
568 GDIPCONST GpMatrix *matrix, GDIPCONST GpPen *pen)
570 GpPointF * points, temp_pts[4];
571 INT count, i;
572 REAL path_width = 1.0, width, height, temp, low_x, low_y, high_x, high_y;
574 /* Matrix and pen can be null. */
575 if(!path || !bounds)
576 return InvalidParameter;
578 /* If path is empty just return. */
579 count = path->pathdata.Count;
580 if(count == 0){
581 bounds->X = bounds->Y = bounds->Width = bounds->Height = 0.0;
582 return Ok;
585 points = path->pathdata.Points;
587 low_x = high_x = points[0].X;
588 low_y = high_y = points[0].Y;
590 for(i = 1; i < count; i++){
591 low_x = min(low_x, points[i].X);
592 low_y = min(low_y, points[i].Y);
593 high_x = max(high_x, points[i].X);
594 high_y = max(high_y, points[i].Y);
597 width = high_x - low_x;
598 height = high_y - low_y;
600 /* This looks unusual but it's the only way I can imitate windows. */
601 if(matrix){
602 temp_pts[0].X = low_x;
603 temp_pts[0].Y = low_y;
604 temp_pts[1].X = low_x;
605 temp_pts[1].Y = high_y;
606 temp_pts[2].X = high_x;
607 temp_pts[2].Y = high_y;
608 temp_pts[3].X = high_x;
609 temp_pts[3].Y = low_y;
611 GdipTransformMatrixPoints((GpMatrix*)matrix, temp_pts, 4);
612 low_x = temp_pts[0].X;
613 low_y = temp_pts[0].Y;
615 for(i = 1; i < 4; i++){
616 low_x = min(low_x, temp_pts[i].X);
617 low_y = min(low_y, temp_pts[i].Y);
620 temp = width;
621 width = height * fabs(matrix->matrix[2]) + width * fabs(matrix->matrix[0]);
622 height = height * fabs(matrix->matrix[3]) + temp * fabs(matrix->matrix[1]);
625 if(pen){
626 path_width = pen->width / 2.0;
628 if(count > 2)
629 path_width = max(path_width, pen->width * pen->miterlimit / 2.0);
630 /* FIXME: this should probably also check for the startcap */
631 if(pen->endcap & LineCapNoAnchor)
632 path_width = max(path_width, pen->width * 2.2);
634 low_x -= path_width;
635 low_y -= path_width;
636 width += 2.0 * path_width;
637 height += 2.0 * path_width;
640 bounds->X = low_x;
641 bounds->Y = low_y;
642 bounds->Width = width;
643 bounds->Height = height;
645 return Ok;
648 GpStatus WINGDIPAPI GdipGetPathWorldBoundsI(GpPath* path, GpRect* bounds,
649 GDIPCONST GpMatrix *matrix, GDIPCONST GpPen *pen)
651 GpStatus ret;
652 GpRectF boundsF;
654 ret = GdipGetPathWorldBounds(path,&boundsF,matrix,pen);
656 if(ret == Ok){
657 bounds->X = roundr(boundsF.X);
658 bounds->Y = roundr(boundsF.Y);
659 bounds->Width = roundr(boundsF.Width);
660 bounds->Height = roundr(boundsF.Height);
663 return ret;
666 GpStatus WINGDIPAPI GdipGetPointCount(GpPath *path, INT *count)
668 if(!path)
669 return InvalidParameter;
671 *count = path->pathdata.Count;
673 return Ok;
676 GpStatus WINGDIPAPI GdipIsOutlineVisiblePathPointI(GpPath* path, INT x, INT y,
677 GpPen *pen, GpGraphics *graphics, BOOL *result)
679 static int calls;
681 if(!path || !pen)
682 return InvalidParameter;
684 if(!(calls++))
685 FIXME("not implemented\n");
687 return NotImplemented;
690 GpStatus WINGDIPAPI GdipStartPathFigure(GpPath *path)
692 if(!path)
693 return InvalidParameter;
695 path->newfigure = TRUE;
697 return Ok;
700 GpStatus WINGDIPAPI GdipResetPath(GpPath *path)
702 if(!path)
703 return InvalidParameter;
705 path->pathdata.Count = 0;
706 path->newfigure = TRUE;
707 path->fill = FillModeAlternate;
709 return Ok;
712 GpStatus WINGDIPAPI GdipSetPathFillMode(GpPath *path, GpFillMode fill)
714 if(!path)
715 return InvalidParameter;
717 path->fill = fill;
719 return Ok;
722 GpStatus WINGDIPAPI GdipTransformPath(GpPath *path, GpMatrix *matrix)
724 if(!path)
725 return InvalidParameter;
727 if(path->pathdata.Count == 0)
728 return Ok;
730 return GdipTransformMatrixPoints(matrix, path->pathdata.Points,
731 path->pathdata.Count);
734 GpStatus WINGDIPAPI GdipAddPathRectangle(GpPath *path, REAL x, REAL y,
735 REAL width, REAL height)
737 GpPath *backup;
738 GpPointF ptf[2];
739 GpStatus retstat;
740 BOOL old_new;
742 if(!path || width < 0.0 || height < 0.0)
743 return InvalidParameter;
745 /* make a backup copy of path data */
746 if((retstat = GdipClonePath(path, &backup)) != Ok)
747 return retstat;
749 /* rectangle should start as new path */
750 old_new = path->newfigure;
751 path->newfigure = TRUE;
752 if((retstat = GdipAddPathLine(path,x,y,x+width,y)) != Ok){
753 path->newfigure = old_new;
754 goto fail;
757 ptf[0].X = x+width;
758 ptf[0].Y = y+height;
759 ptf[1].X = x;
760 ptf[1].Y = y+height;
762 if((retstat = GdipAddPathLine2(path,(GDIPCONST GpPointF*)&ptf,2)) != Ok) goto fail;
763 path->pathdata.Types[path->pathdata.Count-1] |= PathPointTypeCloseSubpath;
765 /* free backup */
766 GdipDeletePath(backup);
767 return Ok;
769 fail:
770 /* reverting */
771 GdipDeletePath(path);
772 GdipClonePath(backup, &path);
773 GdipDeletePath(backup);
775 return retstat;
778 GpStatus WINGDIPAPI GdipAddPathRectangleI(GpPath *path, INT x, INT y,
779 INT width, INT height)
781 return GdipAddPathRectangle(path,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
784 GpStatus WINGDIPAPI GdipAddPathRectangles(GpPath *path, GDIPCONST GpRectF *rects, INT count)
786 GpPath *backup;
787 GpStatus retstat;
788 INT i;
790 /* count == 0 - verified condition */
791 if(!path || !rects || count == 0)
792 return InvalidParameter;
794 if(count < 0)
795 return OutOfMemory;
797 /* make a backup copy */
798 if((retstat = GdipClonePath(path, &backup)) != Ok)
799 return retstat;
801 for(i = 0; i < count; i++){
802 if((retstat = GdipAddPathRectangle(path,rects[i].X,rects[i].Y,rects[i].Width,rects[i].Height)) != Ok)
803 goto fail;
806 /* free backup */
807 GdipDeletePath(backup);
808 return Ok;
810 fail:
811 /* reverting */
812 GdipDeletePath(path);
813 GdipClonePath(backup, &path);
814 GdipDeletePath(backup);
816 return retstat;
819 GpStatus WINGDIPAPI GdipAddPathRectanglesI(GpPath *path, GDIPCONST GpRect *rects, INT count)
821 GpRectF *rectsF;
822 GpStatus retstat;
823 INT i;
825 if(!rects || count == 0)
826 return InvalidParameter;
828 if(count < 0)
829 return OutOfMemory;
831 rectsF = GdipAlloc(sizeof(GpRectF)*count);
833 for(i = 0;i < count;i++){
834 rectsF[i].X = (REAL)rects[i].X;
835 rectsF[i].Y = (REAL)rects[i].Y;
836 rectsF[i].Width = (REAL)rects[i].Width;
837 rectsF[i].Height = (REAL)rects[i].Height;
840 retstat = GdipAddPathRectangles(path, rectsF, count);
841 GdipFree(rectsF);
843 return retstat;