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 GpStatus WINGDIPAPI GdipAddPathArc(GpPath *path, REAL x1, REAL y1, REAL x2,
37 REAL y2, REAL startAngle, REAL sweepAngle)
39 INT count, old_count, i;
41 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
42 path, x1, y1, x2, y2, startAngle, sweepAngle);
45 return InvalidParameter;
47 count = arc2polybezier(NULL, x1, y1, x2, y2, startAngle, sweepAngle);
51 if(!lengthen_path(path, count))
54 old_count = path->pathdata.Count;
55 arc2polybezier(&path->pathdata.Points[old_count], x1, y1, x2, y2,
56 startAngle, sweepAngle);
58 for(i = 0; i < count; i++){
59 path->pathdata.Types[old_count + i] = PathPointTypeBezier;
62 path->pathdata.Types[old_count] =
63 (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
64 path->newfigure = FALSE;
65 path->pathdata.Count += count;
70 GpStatus WINGDIPAPI GdipAddPathArcI(GpPath *path, INT x1, INT y1, INT x2,
71 INT y2, REAL startAngle, REAL sweepAngle)
73 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
74 path, x1, y1, x2, y2, startAngle, sweepAngle);
76 return GdipAddPathArc(path,(REAL)x1,(REAL)y1,(REAL)x2,(REAL)y2,startAngle,sweepAngle);
79 GpStatus WINGDIPAPI GdipAddPathBezier(GpPath *path, REAL x1, REAL y1, REAL x2,
80 REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
84 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
85 path, x1, y1, x2, y2, x3, y3, x4, y4);
88 return InvalidParameter;
90 if(!lengthen_path(path, 4))
93 old_count = path->pathdata.Count;
95 path->pathdata.Points[old_count].X = x1;
96 path->pathdata.Points[old_count].Y = y1;
97 path->pathdata.Points[old_count + 1].X = x2;
98 path->pathdata.Points[old_count + 1].Y = y2;
99 path->pathdata.Points[old_count + 2].X = x3;
100 path->pathdata.Points[old_count + 2].Y = y3;
101 path->pathdata.Points[old_count + 3].X = x4;
102 path->pathdata.Points[old_count + 3].Y = y4;
104 path->pathdata.Types[old_count] =
105 (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
106 path->pathdata.Types[old_count + 1] = PathPointTypeBezier;
107 path->pathdata.Types[old_count + 2] = PathPointTypeBezier;
108 path->pathdata.Types[old_count + 3] = PathPointTypeBezier;
110 path->newfigure = FALSE;
111 path->pathdata.Count += 4;
116 GpStatus WINGDIPAPI GdipAddPathBezierI(GpPath *path, INT x1, INT y1, INT x2,
117 INT y2, INT x3, INT y3, INT x4, INT y4)
119 TRACE("(%p, %d, %d, %d, %d, %d, %d, %d, %d)\n",
120 path, x1, y1, x2, y2, x3, y3, x4, y4);
122 return GdipAddPathBezier(path,(REAL)x1,(REAL)y1,(REAL)x2,(REAL)y2,(REAL)x3,(REAL)y3,
126 GpStatus WINGDIPAPI GdipAddPathBeziers(GpPath *path, GDIPCONST GpPointF *points,
131 TRACE("(%p, %p, %d)\n", path, points, count);
133 if(!path || !points || ((count - 1) % 3))
134 return InvalidParameter;
136 if(!lengthen_path(path, count))
139 old_count = path->pathdata.Count;
141 for(i = 0; i < count; i++){
142 path->pathdata.Points[old_count + i].X = points[i].X;
143 path->pathdata.Points[old_count + i].Y = points[i].Y;
144 path->pathdata.Types[old_count + i] = PathPointTypeBezier;
147 path->pathdata.Types[old_count] =
148 (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
149 path->newfigure = FALSE;
150 path->pathdata.Count += count;
155 GpStatus WINGDIPAPI GdipAddPathBeziersI(GpPath *path, GDIPCONST GpPoint *points,
162 TRACE("(%p, %p, %d)\n", path, points, count);
164 if(!points || ((count - 1) % 3))
165 return InvalidParameter;
167 ptsF = GdipAlloc(sizeof(GpPointF) * count);
171 for(i = 0; i < count; i++){
172 ptsF[i].X = (REAL)points[i].X;
173 ptsF[i].Y = (REAL)points[i].Y;
176 ret = GdipAddPathBeziers(path, ptsF, count);
182 GpStatus WINGDIPAPI GdipAddPathClosedCurve(GpPath *path, GDIPCONST GpPointF *points,
185 TRACE("(%p, %p, %d)\n", path, points, count);
187 return GdipAddPathClosedCurve2(path, points, count, 1.0);
190 GpStatus WINGDIPAPI GdipAddPathClosedCurveI(GpPath *path, GDIPCONST GpPoint *points,
193 TRACE("(%p, %p, %d)\n", path, points, count);
195 return GdipAddPathClosedCurve2I(path, points, count, 1.0);
198 GpStatus WINGDIPAPI GdipAddPathClosedCurve2(GpPath *path, GDIPCONST GpPointF *points,
199 INT count, REAL tension)
201 INT i, len_pt = (count + 1)*3-2;
207 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
209 if(!path || !points || count <= 1)
210 return InvalidParameter;
212 pt = GdipAlloc(len_pt * sizeof(GpPointF));
213 pts = GdipAlloc((count + 1)*sizeof(GpPointF));
220 /* copy source points to extend with the last one */
221 memcpy(pts, points, sizeof(GpPointF)*count);
224 tension = tension * TENSION_CONST;
226 for(i = 0; i < count-1; i++){
227 calc_curve_bezier(&(pts[i]), tension, &x1, &y1, &x2, &y2);
231 pt[3*i+3].X = pts[i+1].X;
232 pt[3*i+3].Y = pts[i+1].Y;
237 /* points [len_pt-2] and [0] are calculated
238 separetely to connect splines properly */
239 pts[0] = points[count-1];
240 pts[1] = points[0]; /* equals to start and end of a resulting path */
243 calc_curve_bezier(pts, tension, &x1, &y1, &x2, &y2);
251 pt[len_pt-1].X = pt[0].X;
252 pt[len_pt-1].Y = pt[0].Y;
254 stat = GdipAddPathBeziers(path, pt, len_pt);
258 INT count = path->pathdata.Count;
259 path->pathdata.Types[count - 1] |= PathPointTypeCloseSubpath;
260 path->newfigure = TRUE;
269 GpStatus WINGDIPAPI GdipAddPathClosedCurve2I(GpPath *path, GDIPCONST GpPoint *points,
270 INT count, REAL tension)
276 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
278 if(!path || !points || count <= 1)
279 return InvalidParameter;
281 ptf = GdipAlloc(sizeof(GpPointF)*count);
285 for(i = 0; i < count; i++){
286 ptf[i].X = (REAL)points[i].X;
287 ptf[i].Y = (REAL)points[i].Y;
290 stat = GdipAddPathClosedCurve2(path, ptf, count, tension);
297 GpStatus WINGDIPAPI GdipAddPathCurve(GpPath *path, GDIPCONST GpPointF *points, INT count)
299 TRACE("(%p, %p, %d)\n", path, points, count);
301 if(!path || !points || count <= 1)
302 return InvalidParameter;
304 return GdipAddPathCurve2(path, points, count, 1.0);
307 GpStatus WINGDIPAPI GdipAddPathCurveI(GpPath *path, GDIPCONST GpPoint *points, INT count)
309 TRACE("(%p, %p, %d)\n", path, points, count);
311 if(!path || !points || count <= 1)
312 return InvalidParameter;
314 return GdipAddPathCurve2I(path, points, count, 1.0);
317 GpStatus WINGDIPAPI GdipAddPathCurve2(GpPath *path, GDIPCONST GpPointF *points, INT count,
320 INT i, len_pt = count*3-2;
325 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
327 if(!path || !points || count <= 1)
328 return InvalidParameter;
330 pt = GdipAlloc(len_pt * sizeof(GpPointF));
334 tension = tension * TENSION_CONST;
336 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
339 pt[0].X = points[0].X;
340 pt[0].Y = points[0].Y;
344 for(i = 0; i < count-2; i++){
345 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
349 pt[3*i+3].X = points[i+1].X;
350 pt[3*i+3].Y = points[i+1].Y;
355 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
356 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
360 pt[len_pt-1].X = points[count-1].X;
361 pt[len_pt-1].Y = points[count-1].Y;
363 stat = GdipAddPathBeziers(path, pt, len_pt);
370 GpStatus WINGDIPAPI GdipAddPathCurve2I(GpPath *path, GDIPCONST GpPoint *points,
371 INT count, REAL tension)
377 TRACE("(%p, %p, %d, %.2f)\n", path, points, count, tension);
379 if(!path || !points || count <= 1)
380 return InvalidParameter;
382 ptf = GdipAlloc(sizeof(GpPointF)*count);
386 for(i = 0; i < count; i++){
387 ptf[i].X = (REAL)points[i].X;
388 ptf[i].Y = (REAL)points[i].Y;
391 stat = GdipAddPathCurve2(path, ptf, count, tension);
398 GpStatus WINGDIPAPI GdipAddPathEllipse(GpPath *path, REAL x, REAL y, REAL width,
401 INT old_count, numpts;
403 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path, x, y, width, height);
406 return InvalidParameter;
408 if(!lengthen_path(path, MAX_ARC_PTS))
411 old_count = path->pathdata.Count;
412 if((numpts = arc2polybezier(&path->pathdata.Points[old_count], x, y, width,
413 height, 0.0, 360.0)) != MAX_ARC_PTS){
414 ERR("expected %d points but got %d\n", MAX_ARC_PTS, numpts);
418 memset(&path->pathdata.Types[old_count + 1], PathPointTypeBezier,
421 /* An ellipse is an intrinsic figure (always is its own subpath). */
422 path->pathdata.Types[old_count] = PathPointTypeStart;
423 path->pathdata.Types[old_count + MAX_ARC_PTS - 1] |= PathPointTypeCloseSubpath;
424 path->newfigure = TRUE;
425 path->pathdata.Count += MAX_ARC_PTS;
430 GpStatus WINGDIPAPI GdipAddPathEllipseI(GpPath *path, INT x, INT y, INT width,
433 TRACE("(%p, %d, %d, %d, %d)\n", path, x, y, width, height);
435 return GdipAddPathEllipse(path,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
438 GpStatus WINGDIPAPI GdipAddPathLine2(GpPath *path, GDIPCONST GpPointF *points,
443 TRACE("(%p, %p, %d)\n", path, points, count);
446 return InvalidParameter;
448 if(!lengthen_path(path, count))
451 old_count = path->pathdata.Count;
453 for(i = 0; i < count; i++){
454 path->pathdata.Points[old_count + i].X = points[i].X;
455 path->pathdata.Points[old_count + i].Y = points[i].Y;
456 path->pathdata.Types[old_count + i] = PathPointTypeLine;
460 path->pathdata.Types[old_count] = PathPointTypeStart;
461 path->newfigure = FALSE;
464 path->pathdata.Count += count;
469 GpStatus WINGDIPAPI GdipAddPathLine2I(GpPath *path, GDIPCONST GpPoint *points, INT count)
475 TRACE("(%p, %p, %d)\n", path, points, count);
478 return InvalidParameter;
480 pointsF = GdipAlloc(sizeof(GpPointF) * count);
481 if(!pointsF) return OutOfMemory;
483 for(i = 0;i < count; i++){
484 pointsF[i].X = (REAL)points[i].X;
485 pointsF[i].Y = (REAL)points[i].Y;
488 stat = GdipAddPathLine2(path, pointsF, count);
495 GpStatus WINGDIPAPI GdipAddPathLine(GpPath *path, REAL x1, REAL y1, REAL x2, REAL y2)
499 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path, x1, y1, x2, y2);
502 return InvalidParameter;
504 if(!lengthen_path(path, 2))
507 old_count = path->pathdata.Count;
509 path->pathdata.Points[old_count].X = x1;
510 path->pathdata.Points[old_count].Y = y1;
511 path->pathdata.Points[old_count + 1].X = x2;
512 path->pathdata.Points[old_count + 1].Y = y2;
514 path->pathdata.Types[old_count] =
515 (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
516 path->pathdata.Types[old_count + 1] = PathPointTypeLine;
518 path->newfigure = FALSE;
519 path->pathdata.Count += 2;
524 GpStatus WINGDIPAPI GdipAddPathLineI(GpPath *path, INT x1, INT y1, INT x2, INT y2)
526 TRACE("(%p, %d, %d, %d, %d)\n", path, x1, y1, x2, y2);
528 return GdipAddPathLine(path, (REAL)x1, (REAL)y1, (REAL)x2, (REAL)y2);
531 GpStatus WINGDIPAPI GdipAddPathPath(GpPath *path, GDIPCONST GpPath* addingPath,
534 INT old_count, count;
536 TRACE("(%p, %p, %d)\n", path, addingPath, connect);
538 if(!path || !addingPath)
539 return InvalidParameter;
541 old_count = path->pathdata.Count;
542 count = addingPath->pathdata.Count;
544 if(!lengthen_path(path, count))
547 memcpy(&path->pathdata.Points[old_count], addingPath->pathdata.Points,
548 count * sizeof(GpPointF));
549 memcpy(&path->pathdata.Types[old_count], addingPath->pathdata.Types, count);
551 if(path->newfigure || !connect)
552 path->pathdata.Types[old_count] = PathPointTypeStart;
554 path->pathdata.Types[old_count] = PathPointTypeLine;
556 path->newfigure = FALSE;
557 path->pathdata.Count += count;
562 GpStatus WINGDIPAPI GdipAddPathPie(GpPath *path, REAL x, REAL y, REAL width, REAL height,
563 REAL startAngle, REAL sweepAngle)
569 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
570 path, x, y, width, height, startAngle, sweepAngle);
573 return InvalidParameter;
575 count = arc2polybezier(NULL, x, y, width, height, startAngle, sweepAngle);
580 ptf = GdipAlloc(sizeof(GpPointF)*count);
584 arc2polybezier(ptf, x, y, width, height, startAngle, sweepAngle);
586 status = GdipAddPathLine(path, (width - x)/2, (height - y)/2, ptf[0].X, ptf[0].Y);
591 /* one spline is already added as a line endpoint */
592 if(!lengthen_path(path, count - 1)){
597 memcpy(&(path->pathdata.Points[path->pathdata.Count]), &(ptf[1]),sizeof(GpPointF)*(count-1));
598 for(i = 0; i < count-1; i++)
599 path->pathdata.Types[path->pathdata.Count+i] = PathPointTypeBezier;
601 path->pathdata.Count += count-1;
603 GdipClosePathFigure(path);
610 GpStatus WINGDIPAPI GdipAddPathPieI(GpPath *path, INT x, INT y, INT width, INT height,
611 REAL startAngle, REAL sweepAngle)
613 TRACE("(%p, %d, %d, %d, %d, %.2f, %.2f)\n",
614 path, x, y, width, height, startAngle, sweepAngle);
616 return GdipAddPathPieI(path, (REAL)x, (REAL)y, (REAL)width, (REAL)height, startAngle, sweepAngle);
619 GpStatus WINGDIPAPI GdipAddPathPolygon(GpPath *path, GDIPCONST GpPointF *points, INT count)
623 TRACE("(%p, %p, %d)\n", path, points, count);
625 if(!path || !points || count < 3)
626 return InvalidParameter;
628 if(!lengthen_path(path, count))
631 old_count = path->pathdata.Count;
633 memcpy(&path->pathdata.Points[old_count], points, count*sizeof(GpPointF));
634 memset(&path->pathdata.Types[old_count + 1], PathPointTypeLine, count - 1);
636 /* A polygon is an intrinsic figure */
637 path->pathdata.Types[old_count] = PathPointTypeStart;
638 path->pathdata.Types[old_count + count - 1] |= PathPointTypeCloseSubpath;
639 path->newfigure = TRUE;
640 path->pathdata.Count += count;
645 GpStatus WINGDIPAPI GdipAddPathPolygonI(GpPath *path, GDIPCONST GpPoint *points, INT count)
651 TRACE("(%p, %p, %d)\n", path, points, count);
653 if(!points || count < 3)
654 return InvalidParameter;
656 ptf = GdipAlloc(sizeof(GpPointF) * count);
660 for(i = 0; i < count; i++){
661 ptf[i].X = (REAL)points[i].X;
662 ptf[i].Y = (REAL)points[i].Y;
665 status = GdipAddPathPolygon(path, ptf, count);
672 GpStatus WINGDIPAPI GdipClonePath(GpPath* path, GpPath **clone)
674 TRACE("(%p, %p)\n", path, clone);
677 return InvalidParameter;
679 *clone = GdipAlloc(sizeof(GpPath));
680 if(!*clone) return OutOfMemory;
684 (*clone)->pathdata.Points = GdipAlloc(path->datalen * sizeof(PointF));
685 (*clone)->pathdata.Types = GdipAlloc(path->datalen);
686 if(!(*clone)->pathdata.Points || !(*clone)->pathdata.Types){
688 GdipFree((*clone)->pathdata.Points);
689 GdipFree((*clone)->pathdata.Types);
693 memcpy((*clone)->pathdata.Points, path->pathdata.Points,
694 path->datalen * sizeof(PointF));
695 memcpy((*clone)->pathdata.Types, path->pathdata.Types, path->datalen);
700 GpStatus WINGDIPAPI GdipClosePathFigure(GpPath* path)
702 TRACE("(%p)\n", path);
705 return InvalidParameter;
707 if(path->pathdata.Count > 0){
708 path->pathdata.Types[path->pathdata.Count - 1] |= PathPointTypeCloseSubpath;
709 path->newfigure = TRUE;
715 GpStatus WINGDIPAPI GdipClosePathFigures(GpPath* path)
719 TRACE("(%p)\n", path);
722 return InvalidParameter;
724 for(i = 1; i < path->pathdata.Count; i++){
725 if(path->pathdata.Types[i] == PathPointTypeStart)
726 path->pathdata.Types[i-1] |= PathPointTypeCloseSubpath;
729 path->newfigure = TRUE;
734 GpStatus WINGDIPAPI GdipCreatePath(GpFillMode fill, GpPath **path)
736 TRACE("(%d, %p)\n", fill, path);
739 return InvalidParameter;
741 *path = GdipAlloc(sizeof(GpPath));
742 if(!*path) return OutOfMemory;
744 (*path)->fill = fill;
745 (*path)->newfigure = TRUE;
750 GpStatus WINGDIPAPI GdipCreatePath2(GDIPCONST GpPointF* points,
751 GDIPCONST BYTE* types, INT count, GpFillMode fill, GpPath **path)
753 TRACE("(%p, %p, %d, %d, %p)\n", points, types, count, fill, path);
756 return InvalidParameter;
758 *path = GdipAlloc(sizeof(GpPath));
759 if(!*path) return OutOfMemory;
761 (*path)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
762 (*path)->pathdata.Types = GdipAlloc(count);
764 if(!(*path)->pathdata.Points || !(*path)->pathdata.Types){
765 GdipFree((*path)->pathdata.Points);
766 GdipFree((*path)->pathdata.Types);
771 memcpy((*path)->pathdata.Points, points, count * sizeof(PointF));
772 memcpy((*path)->pathdata.Types, types, count);
773 (*path)->pathdata.Count = count;
774 (*path)->datalen = count;
776 (*path)->fill = fill;
777 (*path)->newfigure = TRUE;
782 GpStatus WINGDIPAPI GdipCreatePath2I(GDIPCONST GpPoint* points,
783 GDIPCONST BYTE* types, INT count, GpFillMode fill, GpPath **path)
789 TRACE("(%p, %p, %d, %d, %p)\n", points, types, count, fill, path);
791 ptF = GdipAlloc(sizeof(GpPointF)*count);
793 for(i = 0;i < count; i++){
794 ptF[i].X = (REAL)points[i].X;
795 ptF[i].Y = (REAL)points[i].Y;
798 ret = GdipCreatePath2(ptF, types, count, fill, path);
805 GpStatus WINGDIPAPI GdipDeletePath(GpPath *path)
807 TRACE("(%p)\n", path);
810 return InvalidParameter;
812 GdipFree(path->pathdata.Points);
813 GdipFree(path->pathdata.Types);
819 GpStatus WINGDIPAPI GdipFlattenPath(GpPath *path, GpMatrix* matrix, REAL flatness)
824 return InvalidParameter;
827 FIXME("not implemented\n");
829 return NotImplemented;
832 GpStatus WINGDIPAPI GdipGetPathData(GpPath *path, GpPathData* pathData)
834 TRACE("(%p, %p)\n", path, pathData);
836 if(!path || !pathData)
837 return InvalidParameter;
839 /* Only copy data. pathData allocation/freeing controlled by wrapper class.
840 Assumed that pathData is enough wide to get all data - controlled by wrapper too. */
841 memcpy(pathData->Points, path->pathdata.Points, sizeof(PointF) * pathData->Count);
842 memcpy(pathData->Types , path->pathdata.Types , pathData->Count);
847 GpStatus WINGDIPAPI GdipGetPathFillMode(GpPath *path, GpFillMode *fillmode)
849 TRACE("(%p, %p)\n", path, fillmode);
851 if(!path || !fillmode)
852 return InvalidParameter;
854 *fillmode = path->fill;
859 GpStatus WINGDIPAPI GdipGetPathLastPoint(GpPath* path, GpPointF* lastPoint)
863 TRACE("(%p, %p)\n", path, lastPoint);
865 if(!path || !lastPoint)
866 return InvalidParameter;
868 count = path->pathdata.Count;
870 *lastPoint = path->pathdata.Points[count-1];
875 GpStatus WINGDIPAPI GdipGetPathPoints(GpPath *path, GpPointF* points, INT count)
877 TRACE("(%p, %p, %d)\n", path, points, count);
880 return InvalidParameter;
882 if(count < path->pathdata.Count)
883 return InsufficientBuffer;
885 memcpy(points, path->pathdata.Points, path->pathdata.Count * sizeof(GpPointF));
890 GpStatus WINGDIPAPI GdipGetPathPointsI(GpPath *path, GpPoint* points, INT count)
896 TRACE("(%p, %p, %d)\n", path, points, count);
899 return InvalidParameter;
901 ptf = GdipAlloc(sizeof(GpPointF)*count);
902 if(!ptf) return OutOfMemory;
904 ret = GdipGetPathPoints(path,ptf,count);
906 for(i = 0;i < count;i++){
907 points[i].X = roundr(ptf[i].X);
908 points[i].Y = roundr(ptf[i].Y);
915 GpStatus WINGDIPAPI GdipGetPathTypes(GpPath *path, BYTE* types, INT count)
917 TRACE("(%p, %p, %d)\n", path, types, count);
920 return InvalidParameter;
922 if(count < path->pathdata.Count)
923 return InsufficientBuffer;
925 memcpy(types, path->pathdata.Types, path->pathdata.Count);
930 /* Windows expands the bounding box to the maximum possible bounding box
931 * for a given pen. For example, if a line join can extend past the point
932 * it's joining by x units, the bounding box is extended by x units in every
933 * direction (even though this is too conservative for most cases). */
934 GpStatus WINGDIPAPI GdipGetPathWorldBounds(GpPath* path, GpRectF* bounds,
935 GDIPCONST GpMatrix *matrix, GDIPCONST GpPen *pen)
937 GpPointF * points, temp_pts[4];
939 REAL path_width = 1.0, width, height, temp, low_x, low_y, high_x, high_y;
941 TRACE("(%p, %p, %p, %p)\n", path, bounds, matrix, pen);
943 /* Matrix and pen can be null. */
945 return InvalidParameter;
947 /* If path is empty just return. */
948 count = path->pathdata.Count;
950 bounds->X = bounds->Y = bounds->Width = bounds->Height = 0.0;
954 points = path->pathdata.Points;
956 low_x = high_x = points[0].X;
957 low_y = high_y = points[0].Y;
959 for(i = 1; i < count; i++){
960 low_x = min(low_x, points[i].X);
961 low_y = min(low_y, points[i].Y);
962 high_x = max(high_x, points[i].X);
963 high_y = max(high_y, points[i].Y);
966 width = high_x - low_x;
967 height = high_y - low_y;
969 /* This looks unusual but it's the only way I can imitate windows. */
971 temp_pts[0].X = low_x;
972 temp_pts[0].Y = low_y;
973 temp_pts[1].X = low_x;
974 temp_pts[1].Y = high_y;
975 temp_pts[2].X = high_x;
976 temp_pts[2].Y = high_y;
977 temp_pts[3].X = high_x;
978 temp_pts[3].Y = low_y;
980 GdipTransformMatrixPoints((GpMatrix*)matrix, temp_pts, 4);
981 low_x = temp_pts[0].X;
982 low_y = temp_pts[0].Y;
984 for(i = 1; i < 4; i++){
985 low_x = min(low_x, temp_pts[i].X);
986 low_y = min(low_y, temp_pts[i].Y);
990 width = height * fabs(matrix->matrix[2]) + width * fabs(matrix->matrix[0]);
991 height = height * fabs(matrix->matrix[3]) + temp * fabs(matrix->matrix[1]);
995 path_width = pen->width / 2.0;
998 path_width = max(path_width, pen->width * pen->miterlimit / 2.0);
999 /* FIXME: this should probably also check for the startcap */
1000 if(pen->endcap & LineCapNoAnchor)
1001 path_width = max(path_width, pen->width * 2.2);
1003 low_x -= path_width;
1004 low_y -= path_width;
1005 width += 2.0 * path_width;
1006 height += 2.0 * path_width;
1011 bounds->Width = width;
1012 bounds->Height = height;
1017 GpStatus WINGDIPAPI GdipGetPathWorldBoundsI(GpPath* path, GpRect* bounds,
1018 GDIPCONST GpMatrix *matrix, GDIPCONST GpPen *pen)
1023 TRACE("(%p, %p, %p, %p)\n", path, bounds, matrix, pen);
1025 ret = GdipGetPathWorldBounds(path,&boundsF,matrix,pen);
1028 bounds->X = roundr(boundsF.X);
1029 bounds->Y = roundr(boundsF.Y);
1030 bounds->Width = roundr(boundsF.Width);
1031 bounds->Height = roundr(boundsF.Height);
1037 GpStatus WINGDIPAPI GdipGetPointCount(GpPath *path, INT *count)
1039 TRACE("(%p, %p)\n", path, count);
1042 return InvalidParameter;
1044 *count = path->pathdata.Count;
1049 GpStatus WINGDIPAPI GdipReversePath(GpPath* path)
1052 INT start = 0; /* position in reversed path */
1055 TRACE("(%p)\n", path);
1058 return InvalidParameter;
1060 count = path->pathdata.Count;
1062 if(count == 0) return Ok;
1064 revpath.Points = GdipAlloc(sizeof(GpPointF)*count);
1065 revpath.Types = GdipAlloc(sizeof(BYTE)*count);
1066 revpath.Count = count;
1067 if(!revpath.Points || !revpath.Types){
1068 GdipFree(revpath.Points);
1069 GdipFree(revpath.Types);
1073 for(i = 0; i < count; i++){
1075 /* find next start point */
1076 if(path->pathdata.Types[count-i-1] == PathPointTypeStart){
1078 for(j = start; j <= i; j++){
1079 revpath.Points[j] = path->pathdata.Points[count-j-1];
1080 revpath.Types[j] = path->pathdata.Types[count-j-1];
1082 /* mark start point */
1083 revpath.Types[start] = PathPointTypeStart;
1084 /* set 'figure' endpoint type */
1086 revpath.Types[i] = path->pathdata.Types[count-start-1] & ~PathPointTypePathTypeMask;
1087 revpath.Types[i] |= revpath.Types[i-1];
1090 revpath.Types[i] = path->pathdata.Types[start];
1096 memcpy(path->pathdata.Points, revpath.Points, sizeof(GpPointF)*count);
1097 memcpy(path->pathdata.Types, revpath.Types, sizeof(BYTE)*count);
1099 GdipFree(revpath.Points);
1100 GdipFree(revpath.Types);
1105 GpStatus WINGDIPAPI GdipIsOutlineVisiblePathPointI(GpPath* path, INT x, INT y,
1106 GpPen *pen, GpGraphics *graphics, BOOL *result)
1108 TRACE("(%p, %d, %d, %p, %p, %p)\n", path, x, y, pen, graphics, result);
1110 return GdipIsOutlineVisiblePathPoint(path, x, y, pen, graphics, result);
1113 GpStatus WINGDIPAPI GdipIsOutlineVisiblePathPoint(GpPath* path, REAL x, REAL y,
1114 GpPen *pen, GpGraphics *graphics, BOOL *result)
1119 return InvalidParameter;
1122 FIXME("not implemented\n");
1124 return NotImplemented;
1127 GpStatus WINGDIPAPI GdipIsVisiblePathPointI(GpPath* path, INT x, INT y, GpGraphics *graphics, BOOL *result)
1129 TRACE("(%p, %d, %d, %p, %p)\n", path, x, y, graphics, result);
1131 return GdipIsVisiblePathPoint(path, x, y, graphics, result);
1134 GpStatus WINGDIPAPI GdipIsVisiblePathPoint(GpPath* path, REAL x, REAL y, GpGraphics *graphics, BOOL *result)
1138 if(!path) return InvalidParameter;
1141 FIXME("not implemented\n");
1143 return NotImplemented;
1146 GpStatus WINGDIPAPI GdipStartPathFigure(GpPath *path)
1148 TRACE("(%p)\n", path);
1151 return InvalidParameter;
1153 path->newfigure = TRUE;
1158 GpStatus WINGDIPAPI GdipResetPath(GpPath *path)
1160 TRACE("(%p)\n", path);
1163 return InvalidParameter;
1165 path->pathdata.Count = 0;
1166 path->newfigure = TRUE;
1167 path->fill = FillModeAlternate;
1172 GpStatus WINGDIPAPI GdipSetPathFillMode(GpPath *path, GpFillMode fill)
1174 TRACE("(%p, %d)\n", path, fill);
1177 return InvalidParameter;
1184 GpStatus WINGDIPAPI GdipTransformPath(GpPath *path, GpMatrix *matrix)
1186 TRACE("(%p, %p)\n", path, matrix);
1189 return InvalidParameter;
1191 if(path->pathdata.Count == 0)
1194 return GdipTransformMatrixPoints(matrix, path->pathdata.Points,
1195 path->pathdata.Count);
1198 GpStatus WINGDIPAPI GdipAddPathRectangle(GpPath *path, REAL x, REAL y,
1199 REAL width, REAL height)
1206 TRACE("(%p, %.2f, %.2f, %.2f, %.2f)\n", path, x, y, width, height);
1208 if(!path || width < 0.0 || height < 0.0)
1209 return InvalidParameter;
1211 /* make a backup copy of path data */
1212 if((retstat = GdipClonePath(path, &backup)) != Ok)
1215 /* rectangle should start as new path */
1216 old_new = path->newfigure;
1217 path->newfigure = TRUE;
1218 if((retstat = GdipAddPathLine(path,x,y,x+width,y)) != Ok){
1219 path->newfigure = old_new;
1224 ptf[0].Y = y+height;
1226 ptf[1].Y = y+height;
1228 if((retstat = GdipAddPathLine2(path, ptf, 2)) != Ok) goto fail;
1229 path->pathdata.Types[path->pathdata.Count-1] |= PathPointTypeCloseSubpath;
1232 GdipDeletePath(backup);
1237 GdipDeletePath(path);
1238 GdipClonePath(backup, &path);
1239 GdipDeletePath(backup);
1244 GpStatus WINGDIPAPI GdipAddPathRectangleI(GpPath *path, INT x, INT y,
1245 INT width, INT height)
1247 TRACE("(%p, %d, %d, %d, %d)\n", path, x, y, width, height);
1249 return GdipAddPathRectangle(path,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
1252 GpStatus WINGDIPAPI GdipAddPathRectangles(GpPath *path, GDIPCONST GpRectF *rects, INT count)
1258 TRACE("(%p, %p, %d)\n", path, rects, count);
1260 /* count == 0 - verified condition */
1261 if(!path || !rects || count == 0)
1262 return InvalidParameter;
1267 /* make a backup copy */
1268 if((retstat = GdipClonePath(path, &backup)) != Ok)
1271 for(i = 0; i < count; i++){
1272 if((retstat = GdipAddPathRectangle(path,rects[i].X,rects[i].Y,rects[i].Width,rects[i].Height)) != Ok)
1277 GdipDeletePath(backup);
1282 GdipDeletePath(path);
1283 GdipClonePath(backup, &path);
1284 GdipDeletePath(backup);
1289 GpStatus WINGDIPAPI GdipAddPathRectanglesI(GpPath *path, GDIPCONST GpRect *rects, INT count)
1295 TRACE("(%p, %p, %d)\n", path, rects, count);
1297 if(!rects || count == 0)
1298 return InvalidParameter;
1303 rectsF = GdipAlloc(sizeof(GpRectF)*count);
1305 for(i = 0;i < count;i++){
1306 rectsF[i].X = (REAL)rects[i].X;
1307 rectsF[i].Y = (REAL)rects[i].Y;
1308 rectsF[i].Width = (REAL)rects[i].Width;
1309 rectsF[i].Height = (REAL)rects[i].Height;
1312 retstat = GdipAddPathRectangles(path, rectsF, count);
1318 GpStatus WINGDIPAPI GdipSetPathMarker(GpPath* path)
1322 TRACE("(%p)\n", path);
1325 return InvalidParameter;
1327 count = path->pathdata.Count;
1329 /* set marker flag */
1331 path->pathdata.Types[count-1] |= PathPointTypePathMarker;
1336 GpStatus WINGDIPAPI GdipClearPathMarkers(GpPath* path)
1341 TRACE("(%p)\n", path);
1344 return InvalidParameter;
1346 count = path->pathdata.Count;
1348 for(i = 0; i < count - 1; i++){
1349 path->pathdata.Types[i] &= ~PathPointTypePathMarker;