gdiplus: Implemented GdipAddPathCurve2 with tests.
[wine/gsoc_dplay.git] / dlls / gdiplus / graphicspath.c
blobbf580b0775b3a4e5035f3bc48bb70a349d318898
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 GdipAddPathCurve2(GpPath *path, GDIPCONST GpPointF *points, INT count,
200 REAL tension)
202 INT i, len_pt = count*3-2;
203 GpPointF *pt;
204 REAL x1, x2, y1, y2;
205 GpStatus stat;
207 if(!path || !points || count <= 1)
208 return InvalidParameter;
210 pt = GdipAlloc(len_pt * sizeof(GpPointF));
211 if(!pt)
212 return OutOfMemory;
214 tension = tension * TENSION_CONST;
216 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
217 tension, &x1, &y1);
219 pt[0].X = points[0].X;
220 pt[0].Y = points[0].Y;
221 pt[1].X = x1;
222 pt[1].Y = y1;
224 for(i = 0; i < count-2; i++){
225 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
227 pt[3*i+2].X = x1;
228 pt[3*i+2].Y = y1;
229 pt[3*i+3].X = points[i+1].X;
230 pt[3*i+3].Y = points[i+1].Y;
231 pt[3*i+4].X = x2;
232 pt[3*i+4].Y = y2;
235 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
236 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
238 pt[len_pt-2].X = x1;
239 pt[len_pt-2].Y = y1;
240 pt[len_pt-1].X = points[count-1].X;
241 pt[len_pt-1].Y = points[count-1].Y;
243 stat = GdipAddPathBeziers(path, pt, len_pt);
245 GdipFree(pt);
247 return stat;
250 GpStatus WINGDIPAPI GdipAddPathEllipse(GpPath *path, REAL x, REAL y, REAL width,
251 REAL height)
253 INT old_count, numpts;
255 if(!path)
256 return InvalidParameter;
258 if(!lengthen_path(path, MAX_ARC_PTS))
259 return OutOfMemory;
261 old_count = path->pathdata.Count;
262 if((numpts = arc2polybezier(&path->pathdata.Points[old_count], x, y, width,
263 height, 0.0, 360.0)) != MAX_ARC_PTS){
264 ERR("expected %d points but got %d\n", MAX_ARC_PTS, numpts);
265 return GenericError;
268 memset(&path->pathdata.Types[old_count + 1], PathPointTypeBezier,
269 MAX_ARC_PTS - 1);
271 /* An ellipse is an intrinsic figure (always is its own subpath). */
272 path->pathdata.Types[old_count] = PathPointTypeStart;
273 path->pathdata.Types[old_count + MAX_ARC_PTS - 1] |= PathPointTypeCloseSubpath;
274 path->newfigure = TRUE;
275 path->pathdata.Count += MAX_ARC_PTS;
277 return Ok;
280 GpStatus WINGDIPAPI GdipAddPathEllipseI(GpPath *path, INT x, INT y, INT width,
281 INT height)
283 return GdipAddPathEllipse(path,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
286 GpStatus WINGDIPAPI GdipAddPathLine2(GpPath *path, GDIPCONST GpPointF *points,
287 INT count)
289 INT i, old_count;
291 if(!path || !points)
292 return InvalidParameter;
294 if(!lengthen_path(path, count))
295 return OutOfMemory;
297 old_count = path->pathdata.Count;
299 for(i = 0; i < count; i++){
300 path->pathdata.Points[old_count + i].X = points[i].X;
301 path->pathdata.Points[old_count + i].Y = points[i].Y;
302 path->pathdata.Types[old_count + i] = PathPointTypeLine;
305 if(path->newfigure){
306 path->pathdata.Types[old_count] = PathPointTypeStart;
307 path->newfigure = FALSE;
310 path->pathdata.Count += count;
312 return Ok;
315 GpStatus WINGDIPAPI GdipAddPathLine2I(GpPath *path, GDIPCONST GpPoint *points, INT count)
317 GpPointF *pointsF;
318 INT i;
319 GpStatus stat;
321 if(count <= 0)
322 return InvalidParameter;
324 pointsF = GdipAlloc(sizeof(GpPointF) * count);
325 if(!pointsF) return OutOfMemory;
327 for(i = 0;i < count; i++){
328 pointsF[i].X = (REAL)points[i].X;
329 pointsF[i].Y = (REAL)points[i].Y;
332 stat = GdipAddPathLine2(path, pointsF, count);
334 GdipFree(pointsF);
336 return stat;
339 GpStatus WINGDIPAPI GdipAddPathLine(GpPath *path, REAL x1, REAL y1, REAL x2, REAL y2)
341 INT old_count;
343 if(!path)
344 return InvalidParameter;
346 if(!lengthen_path(path, 2))
347 return OutOfMemory;
349 old_count = path->pathdata.Count;
351 path->pathdata.Points[old_count].X = x1;
352 path->pathdata.Points[old_count].Y = y1;
353 path->pathdata.Points[old_count + 1].X = x2;
354 path->pathdata.Points[old_count + 1].Y = y2;
356 path->pathdata.Types[old_count] =
357 (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
358 path->pathdata.Types[old_count + 1] = PathPointTypeLine;
360 path->newfigure = FALSE;
361 path->pathdata.Count += 2;
363 return Ok;
366 GpStatus WINGDIPAPI GdipAddPathLineI(GpPath *path, INT x1, INT y1, INT x2, INT y2)
368 return GdipAddPathLine(path, (REAL)x1, (REAL)y1, (REAL)x2, (REAL)y2);
371 GpStatus WINGDIPAPI GdipAddPathPath(GpPath *path, GDIPCONST GpPath* addingPath,
372 BOOL connect)
374 INT old_count, count;
376 if(!path || !addingPath)
377 return InvalidParameter;
379 old_count = path->pathdata.Count;
380 count = addingPath->pathdata.Count;
382 if(!lengthen_path(path, count))
383 return OutOfMemory;
385 memcpy(&path->pathdata.Points[old_count], addingPath->pathdata.Points,
386 count * sizeof(GpPointF));
387 memcpy(&path->pathdata.Types[old_count], addingPath->pathdata.Types, count);
389 if(path->newfigure || !connect)
390 path->pathdata.Types[old_count] = PathPointTypeStart;
391 else
392 path->pathdata.Types[old_count] = PathPointTypeLine;
394 path->newfigure = FALSE;
395 path->pathdata.Count += count;
397 return Ok;
400 GpStatus WINGDIPAPI GdipAddPathPolygon(GpPath *path, GDIPCONST GpPointF *points, INT count)
402 INT old_count;
404 if(!path || !points || count < 3)
405 return InvalidParameter;
407 if(!lengthen_path(path, count))
408 return OutOfMemory;
410 old_count = path->pathdata.Count;
412 memcpy(&path->pathdata.Points[old_count], points, count*sizeof(GpPointF));
413 memset(&path->pathdata.Types[old_count + 1], PathPointTypeLine, count - 1);
415 /* A polygon is an intrinsic figure */
416 path->pathdata.Types[old_count] = PathPointTypeStart;
417 path->pathdata.Types[old_count + count - 1] |= PathPointTypeCloseSubpath;
418 path->newfigure = TRUE;
419 path->pathdata.Count += count;
421 return Ok;
424 GpStatus WINGDIPAPI GdipAddPathPolygonI(GpPath *path, GDIPCONST GpPoint *points, INT count)
426 GpPointF *ptf;
427 GpStatus status;
428 INT i;
430 if(!points || count < 3)
431 return InvalidParameter;
433 ptf = GdipAlloc(sizeof(GpPointF) * count);
434 if(!ptf)
435 return OutOfMemory;
437 for(i = 0; i < count; i++){
438 ptf[i].X = (REAL)points[i].X;
439 ptf[i].Y = (REAL)points[i].Y;
442 status = GdipAddPathPolygon(path, ptf, count);
444 GdipFree(ptf);
446 return status;
449 GpStatus WINGDIPAPI GdipClonePath(GpPath* path, GpPath **clone)
451 if(!path || !clone)
452 return InvalidParameter;
454 *clone = GdipAlloc(sizeof(GpPath));
455 if(!*clone) return OutOfMemory;
457 **clone = *path;
459 (*clone)->pathdata.Points = GdipAlloc(path->datalen * sizeof(PointF));
460 (*clone)->pathdata.Types = GdipAlloc(path->datalen);
461 if(!(*clone)->pathdata.Points || !(*clone)->pathdata.Types){
462 GdipFree(*clone);
463 GdipFree((*clone)->pathdata.Points);
464 GdipFree((*clone)->pathdata.Types);
465 return OutOfMemory;
468 memcpy((*clone)->pathdata.Points, path->pathdata.Points,
469 path->datalen * sizeof(PointF));
470 memcpy((*clone)->pathdata.Types, path->pathdata.Types, path->datalen);
472 return Ok;
475 GpStatus WINGDIPAPI GdipClosePathFigure(GpPath* path)
477 if(!path)
478 return InvalidParameter;
480 if(path->pathdata.Count > 0){
481 path->pathdata.Types[path->pathdata.Count - 1] |= PathPointTypeCloseSubpath;
482 path->newfigure = TRUE;
485 return Ok;
488 GpStatus WINGDIPAPI GdipClosePathFigures(GpPath* path)
490 INT i;
492 if(!path)
493 return InvalidParameter;
495 for(i = 1; i < path->pathdata.Count; i++){
496 if(path->pathdata.Types[i] == PathPointTypeStart)
497 path->pathdata.Types[i-1] |= PathPointTypeCloseSubpath;
500 path->newfigure = TRUE;
502 return Ok;
505 GpStatus WINGDIPAPI GdipCreatePath(GpFillMode fill, GpPath **path)
507 if(!path)
508 return InvalidParameter;
510 *path = GdipAlloc(sizeof(GpPath));
511 if(!*path) return OutOfMemory;
513 (*path)->fill = fill;
514 (*path)->newfigure = TRUE;
516 return Ok;
519 GpStatus WINGDIPAPI GdipCreatePath2(GDIPCONST GpPointF* points,
520 GDIPCONST BYTE* types, INT count, GpFillMode fill, GpPath **path)
522 if(!path)
523 return InvalidParameter;
525 *path = GdipAlloc(sizeof(GpPath));
526 if(!*path) return OutOfMemory;
528 (*path)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
529 (*path)->pathdata.Types = GdipAlloc(count);
531 if(!(*path)->pathdata.Points || !(*path)->pathdata.Types){
532 GdipFree((*path)->pathdata.Points);
533 GdipFree((*path)->pathdata.Types);
534 GdipFree(*path);
535 return OutOfMemory;
538 memcpy((*path)->pathdata.Points, points, count * sizeof(PointF));
539 memcpy((*path)->pathdata.Types, types, count);
540 (*path)->pathdata.Count = count;
541 (*path)->datalen = count;
543 (*path)->fill = fill;
544 (*path)->newfigure = TRUE;
546 return Ok;
549 GpStatus WINGDIPAPI GdipCreatePath2I(GDIPCONST GpPoint* points,
550 GDIPCONST BYTE* types, INT count, GpFillMode fill, GpPath **path)
552 GpPointF *ptF;
553 GpStatus ret;
554 INT i;
556 ptF = GdipAlloc(sizeof(GpPointF)*count);
558 for(i = 0;i < count; i++){
559 ptF[i].X = (REAL)points[i].X;
560 ptF[i].Y = (REAL)points[i].Y;
563 ret = GdipCreatePath2(ptF, types, count, fill, path);
565 GdipFree(ptF);
567 return ret;
570 GpStatus WINGDIPAPI GdipDeletePath(GpPath *path)
572 if(!path)
573 return InvalidParameter;
575 GdipFree(path->pathdata.Points);
576 GdipFree(path->pathdata.Types);
577 GdipFree(path);
579 return Ok;
582 GpStatus WINGDIPAPI GdipGetPathData(GpPath *path, GpPathData* pathData)
584 if(!path || !pathData)
585 return InvalidParameter;
587 /* Only copy data. pathData allocation/freeing controlled by wrapper class.
588 Assumed that pathData is enough wide to get all data - controlled by wrapper too. */
589 memcpy(pathData->Points, path->pathdata.Points, sizeof(PointF) * pathData->Count);
590 memcpy(pathData->Types , path->pathdata.Types , pathData->Count);
592 return Ok;
595 GpStatus WINGDIPAPI GdipGetPathFillMode(GpPath *path, GpFillMode *fillmode)
597 if(!path || !fillmode)
598 return InvalidParameter;
600 *fillmode = path->fill;
602 return Ok;
605 GpStatus WINGDIPAPI GdipGetPathLastPoint(GpPath* path, GpPointF* lastPoint)
607 INT count;
609 if(!path || !lastPoint)
610 return InvalidParameter;
612 count = path->pathdata.Count;
613 if(count > 0)
614 *lastPoint = path->pathdata.Points[count-1];
616 return Ok;
619 GpStatus WINGDIPAPI GdipGetPathPoints(GpPath *path, GpPointF* points, INT count)
621 if(!path)
622 return InvalidParameter;
624 if(count < path->pathdata.Count)
625 return InsufficientBuffer;
627 memcpy(points, path->pathdata.Points, path->pathdata.Count * sizeof(GpPointF));
629 return Ok;
632 GpStatus WINGDIPAPI GdipGetPathPointsI(GpPath *path, GpPoint* points, INT count)
634 GpStatus ret;
635 GpPointF *ptf;
636 INT i;
638 if(count <= 0)
639 return InvalidParameter;
641 ptf = GdipAlloc(sizeof(GpPointF)*count);
642 if(!ptf) return OutOfMemory;
644 ret = GdipGetPathPoints(path,ptf,count);
645 if(ret == Ok)
646 for(i = 0;i < count;i++){
647 points[i].X = roundr(ptf[i].X);
648 points[i].Y = roundr(ptf[i].Y);
650 GdipFree(ptf);
652 return ret;
655 GpStatus WINGDIPAPI GdipGetPathTypes(GpPath *path, BYTE* types, INT count)
657 if(!path)
658 return InvalidParameter;
660 if(count < path->pathdata.Count)
661 return InsufficientBuffer;
663 memcpy(types, path->pathdata.Types, path->pathdata.Count);
665 return Ok;
668 /* Windows expands the bounding box to the maximum possible bounding box
669 * for a given pen. For example, if a line join can extend past the point
670 * it's joining by x units, the bounding box is extended by x units in every
671 * direction (even though this is too conservative for most cases). */
672 GpStatus WINGDIPAPI GdipGetPathWorldBounds(GpPath* path, GpRectF* bounds,
673 GDIPCONST GpMatrix *matrix, GDIPCONST GpPen *pen)
675 GpPointF * points, temp_pts[4];
676 INT count, i;
677 REAL path_width = 1.0, width, height, temp, low_x, low_y, high_x, high_y;
679 /* Matrix and pen can be null. */
680 if(!path || !bounds)
681 return InvalidParameter;
683 /* If path is empty just return. */
684 count = path->pathdata.Count;
685 if(count == 0){
686 bounds->X = bounds->Y = bounds->Width = bounds->Height = 0.0;
687 return Ok;
690 points = path->pathdata.Points;
692 low_x = high_x = points[0].X;
693 low_y = high_y = points[0].Y;
695 for(i = 1; i < count; i++){
696 low_x = min(low_x, points[i].X);
697 low_y = min(low_y, points[i].Y);
698 high_x = max(high_x, points[i].X);
699 high_y = max(high_y, points[i].Y);
702 width = high_x - low_x;
703 height = high_y - low_y;
705 /* This looks unusual but it's the only way I can imitate windows. */
706 if(matrix){
707 temp_pts[0].X = low_x;
708 temp_pts[0].Y = low_y;
709 temp_pts[1].X = low_x;
710 temp_pts[1].Y = high_y;
711 temp_pts[2].X = high_x;
712 temp_pts[2].Y = high_y;
713 temp_pts[3].X = high_x;
714 temp_pts[3].Y = low_y;
716 GdipTransformMatrixPoints((GpMatrix*)matrix, temp_pts, 4);
717 low_x = temp_pts[0].X;
718 low_y = temp_pts[0].Y;
720 for(i = 1; i < 4; i++){
721 low_x = min(low_x, temp_pts[i].X);
722 low_y = min(low_y, temp_pts[i].Y);
725 temp = width;
726 width = height * fabs(matrix->matrix[2]) + width * fabs(matrix->matrix[0]);
727 height = height * fabs(matrix->matrix[3]) + temp * fabs(matrix->matrix[1]);
730 if(pen){
731 path_width = pen->width / 2.0;
733 if(count > 2)
734 path_width = max(path_width, pen->width * pen->miterlimit / 2.0);
735 /* FIXME: this should probably also check for the startcap */
736 if(pen->endcap & LineCapNoAnchor)
737 path_width = max(path_width, pen->width * 2.2);
739 low_x -= path_width;
740 low_y -= path_width;
741 width += 2.0 * path_width;
742 height += 2.0 * path_width;
745 bounds->X = low_x;
746 bounds->Y = low_y;
747 bounds->Width = width;
748 bounds->Height = height;
750 return Ok;
753 GpStatus WINGDIPAPI GdipGetPathWorldBoundsI(GpPath* path, GpRect* bounds,
754 GDIPCONST GpMatrix *matrix, GDIPCONST GpPen *pen)
756 GpStatus ret;
757 GpRectF boundsF;
759 ret = GdipGetPathWorldBounds(path,&boundsF,matrix,pen);
761 if(ret == Ok){
762 bounds->X = roundr(boundsF.X);
763 bounds->Y = roundr(boundsF.Y);
764 bounds->Width = roundr(boundsF.Width);
765 bounds->Height = roundr(boundsF.Height);
768 return ret;
771 GpStatus WINGDIPAPI GdipGetPointCount(GpPath *path, INT *count)
773 if(!path)
774 return InvalidParameter;
776 *count = path->pathdata.Count;
778 return Ok;
781 GpStatus WINGDIPAPI GdipIsOutlineVisiblePathPointI(GpPath* path, INT x, INT y,
782 GpPen *pen, GpGraphics *graphics, BOOL *result)
784 return GdipIsOutlineVisiblePathPoint(path, x, y, pen, graphics, result);
787 GpStatus WINGDIPAPI GdipIsOutlineVisiblePathPoint(GpPath* path, REAL x, REAL y,
788 GpPen *pen, GpGraphics *graphics, BOOL *result)
790 static int calls;
792 if(!path || !pen)
793 return InvalidParameter;
795 if(!(calls++))
796 FIXME("not implemented\n");
798 return NotImplemented;
801 GpStatus WINGDIPAPI GdipIsVisiblePathPointI(GpPath* path, INT x, INT y, GpGraphics *graphics, BOOL *result)
803 return GdipIsVisiblePathPoint(path, x, y, graphics, result);
806 GpStatus WINGDIPAPI GdipIsVisiblePathPoint(GpPath* path, REAL x, REAL y, GpGraphics *graphics, BOOL *result)
808 static int calls;
810 if(!path) return InvalidParameter;
812 if(!(calls++))
813 FIXME("not implemented\n");
815 return NotImplemented;
818 GpStatus WINGDIPAPI GdipStartPathFigure(GpPath *path)
820 if(!path)
821 return InvalidParameter;
823 path->newfigure = TRUE;
825 return Ok;
828 GpStatus WINGDIPAPI GdipResetPath(GpPath *path)
830 if(!path)
831 return InvalidParameter;
833 path->pathdata.Count = 0;
834 path->newfigure = TRUE;
835 path->fill = FillModeAlternate;
837 return Ok;
840 GpStatus WINGDIPAPI GdipSetPathFillMode(GpPath *path, GpFillMode fill)
842 if(!path)
843 return InvalidParameter;
845 path->fill = fill;
847 return Ok;
850 GpStatus WINGDIPAPI GdipTransformPath(GpPath *path, GpMatrix *matrix)
852 if(!path)
853 return InvalidParameter;
855 if(path->pathdata.Count == 0)
856 return Ok;
858 return GdipTransformMatrixPoints(matrix, path->pathdata.Points,
859 path->pathdata.Count);
862 GpStatus WINGDIPAPI GdipAddPathRectangle(GpPath *path, REAL x, REAL y,
863 REAL width, REAL height)
865 GpPath *backup;
866 GpPointF ptf[2];
867 GpStatus retstat;
868 BOOL old_new;
870 if(!path || width < 0.0 || height < 0.0)
871 return InvalidParameter;
873 /* make a backup copy of path data */
874 if((retstat = GdipClonePath(path, &backup)) != Ok)
875 return retstat;
877 /* rectangle should start as new path */
878 old_new = path->newfigure;
879 path->newfigure = TRUE;
880 if((retstat = GdipAddPathLine(path,x,y,x+width,y)) != Ok){
881 path->newfigure = old_new;
882 goto fail;
885 ptf[0].X = x+width;
886 ptf[0].Y = y+height;
887 ptf[1].X = x;
888 ptf[1].Y = y+height;
890 if((retstat = GdipAddPathLine2(path, ptf, 2)) != Ok) goto fail;
891 path->pathdata.Types[path->pathdata.Count-1] |= PathPointTypeCloseSubpath;
893 /* free backup */
894 GdipDeletePath(backup);
895 return Ok;
897 fail:
898 /* reverting */
899 GdipDeletePath(path);
900 GdipClonePath(backup, &path);
901 GdipDeletePath(backup);
903 return retstat;
906 GpStatus WINGDIPAPI GdipAddPathRectangleI(GpPath *path, INT x, INT y,
907 INT width, INT height)
909 return GdipAddPathRectangle(path,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
912 GpStatus WINGDIPAPI GdipAddPathRectangles(GpPath *path, GDIPCONST GpRectF *rects, INT count)
914 GpPath *backup;
915 GpStatus retstat;
916 INT i;
918 /* count == 0 - verified condition */
919 if(!path || !rects || count == 0)
920 return InvalidParameter;
922 if(count < 0)
923 return OutOfMemory;
925 /* make a backup copy */
926 if((retstat = GdipClonePath(path, &backup)) != Ok)
927 return retstat;
929 for(i = 0; i < count; i++){
930 if((retstat = GdipAddPathRectangle(path,rects[i].X,rects[i].Y,rects[i].Width,rects[i].Height)) != Ok)
931 goto fail;
934 /* free backup */
935 GdipDeletePath(backup);
936 return Ok;
938 fail:
939 /* reverting */
940 GdipDeletePath(path);
941 GdipClonePath(backup, &path);
942 GdipDeletePath(backup);
944 return retstat;
947 GpStatus WINGDIPAPI GdipAddPathRectanglesI(GpPath *path, GDIPCONST GpRect *rects, INT count)
949 GpRectF *rectsF;
950 GpStatus retstat;
951 INT i;
953 if(!rects || count == 0)
954 return InvalidParameter;
956 if(count < 0)
957 return OutOfMemory;
959 rectsF = GdipAlloc(sizeof(GpRectF)*count);
961 for(i = 0;i < count;i++){
962 rectsF[i].X = (REAL)rects[i].X;
963 rectsF[i].Y = (REAL)rects[i].Y;
964 rectsF[i].Width = (REAL)rects[i].Width;
965 rectsF[i].Height = (REAL)rects[i].Height;
968 retstat = GdipAddPathRectangles(path, rectsF, count);
969 GdipFree(rectsF);
971 return retstat;
974 GpStatus WINGDIPAPI GdipSetPathMarker(GpPath* path)
976 INT count;
978 if(!path)
979 return InvalidParameter;
981 count = path->pathdata.Count;
983 /* set marker flag */
984 if(count > 0)
985 path->pathdata.Types[count-1] |= PathPointTypePathMarker;
987 return Ok;
990 GpStatus WINGDIPAPI GdipClearPathMarkers(GpPath* path)
992 INT count;
993 INT i;
995 if(!path)
996 return InvalidParameter;
998 count = path->pathdata.Count;
1000 for(i = 0; i < count - 1; i++){
1001 path->pathdata.Types[i] &= ~PathPointTypePathMarker;
1004 return Ok;