Commit 8be642c4 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

gdiplus: Implemented GdipAddPathClosedCurve2 with tests.

parent 6492f07f
......@@ -4,7 +4,7 @@
@ stdcall GdipAddPathBezierI(ptr long long long long long long long long)
@ stdcall GdipAddPathBeziers(ptr ptr long)
@ stdcall GdipAddPathBeziersI(ptr ptr long)
@ stub GdipAddPathClosedCurve2
@ stdcall GdipAddPathClosedCurve2(ptr ptr long long)
@ stub GdipAddPathClosedCurve2I
@ stub GdipAddPathClosedCurve
@ stub GdipAddPathClosedCurveI
......
......@@ -196,6 +196,75 @@ GpStatus WINGDIPAPI GdipAddPathBeziersI(GpPath *path, GDIPCONST GpPoint *points,
return ret;
}
GpStatus WINGDIPAPI GdipAddPathClosedCurve2(GpPath *path, GDIPCONST GpPointF *points,
INT count, REAL tension)
{
INT i, len_pt = (count + 1)*3-2;
GpPointF *pt;
GpPointF *pts;
REAL x1, x2, y1, y2;
GpStatus stat;
if(!path || !points || count <= 1)
return InvalidParameter;
pt = GdipAlloc(len_pt * sizeof(GpPointF));
pts = GdipAlloc((count + 1)*sizeof(GpPointF));
if(!pt || !pts){
GdipFree(pt);
GdipFree(pts);
return OutOfMemory;
}
/* copy source points to extend with the last one */
memcpy(pts, points, sizeof(GpPointF)*count);
pts[count] = pts[0];
tension = tension * TENSION_CONST;
for(i = 0; i < count-1; i++){
calc_curve_bezier(&(pts[i]), tension, &x1, &y1, &x2, &y2);
pt[3*i+2].X = x1;
pt[3*i+2].Y = y1;
pt[3*i+3].X = pts[i+1].X;
pt[3*i+3].Y = pts[i+1].Y;
pt[3*i+4].X = x2;
pt[3*i+4].Y = y2;
}
/* points [len_pt-2] and [0] are calculated
separetely to connect splines properly */
pts[0] = points[count-1];
pts[1] = points[0]; /* equals to start and end of a resulting path */
pts[2] = points[1];
calc_curve_bezier(pts, tension, &x1, &y1, &x2, &y2);
pt[len_pt-2].X = x1;
pt[len_pt-2].Y = y1;
pt[0].X = pts[1].X;
pt[0].Y = pts[1].Y;
pt[1].X = x2;
pt[1].Y = y2;
/* close path */
pt[len_pt-1].X = pt[0].X;
pt[len_pt-1].Y = pt[0].Y;
stat = GdipAddPathBeziers(path, pt, len_pt);
/* close figure */
if(stat == Ok){
INT count = path->pathdata.Count;
path->pathdata.Types[count - 1] |= PathPointTypeCloseSubpath;
path->newfigure = TRUE;
}
GdipFree(pts);
GdipFree(pt);
return stat;
}
GpStatus WINGDIPAPI GdipAddPathCurve(GpPath *path, GDIPCONST GpPointF *points, INT count)
{
if(!path || !points || count <= 1)
......
......@@ -764,6 +764,55 @@ static void test_addcurve(void)
GdipDeletePath(path);
}
static path_test_t addclosedcurve_path[] = {
{0.0, 0.0, PathPointTypeStart, 0, 0}, /*0*/
{-6.7, 0.0, PathPointTypeBezier, 0, 0}, /*1*/
{6.7, 3.3, PathPointTypeBezier, 0, 0}, /*2*/
{10.0, 10.0, PathPointTypeBezier, 0, 0}, /*3*/
{13.3, 16.7, PathPointTypeBezier, 0, 0}, /*4*/
{3.3, 20.0, PathPointTypeBezier, 0, 0}, /*5*/
{10.0, 20.0, PathPointTypeBezier, 0, 0}, /*6*/
{16.7, 20.0, PathPointTypeBezier, 0, 0}, /*7*/
{33.3, 16.7, PathPointTypeBezier, 0, 0}, /*8*/
{30.0, 10.0, PathPointTypeBezier, 0, 0}, /*9*/
{26.7, 3.3, PathPointTypeBezier, 0, 0}, /*10*/
{6.7, 0.0, PathPointTypeBezier, 0, 0}, /*11*/
{0.0, 0.0, PathPointTypeBezier | PathPointTypeCloseSubpath, 0, 0} /*12*/
};
static void test_addclosedcurve(void)
{
GpStatus status;
GpPath *path;
GpPointF points[4];
points[0].X = 0.0;
points[0].Y = 0.0;
points[1].X = 10.0;
points[1].Y = 10.0;
points[2].X = 10.0;
points[2].Y = 20.0;
points[3].X = 30.0;
points[3].Y = 10.0;
GdipCreatePath(FillModeAlternate, &path);
/* NULL args */
status = GdipAddPathClosedCurve2(NULL, NULL, 0, 0.0);
expect(InvalidParameter, status);
status = GdipAddPathClosedCurve2(path, NULL, 0, 0.0);
expect(InvalidParameter, status);
status = GdipAddPathClosedCurve2(path, points, -1, 0.0);
expect(InvalidParameter, status);
status = GdipAddPathClosedCurve2(path, points, 1, 1.0);
expect(InvalidParameter, status);
/* add to empty path */
status = GdipAddPathClosedCurve2(path, points, 4, 1.0);
expect(Ok, status);
ok_path(path, addclosedcurve_path, sizeof(addclosedcurve_path)/sizeof(path_test_t), FALSE);
GdipDeletePath(path);
}
START_TEST(graphicspath)
{
struct GdiplusStartupInput gdiplusStartupInput;
......@@ -788,6 +837,7 @@ START_TEST(graphicspath)
test_polygon();
test_lastpoint();
test_addcurve();
test_addclosedcurve();
GdiplusShutdown(gdiplusToken);
}
......@@ -246,6 +246,7 @@ GpStatus WINGDIPAPI GdipAddPathBezier(GpPath*,REAL,REAL,REAL,REAL,REAL,REAL,REAL
GpStatus WINGDIPAPI GdipAddPathBezierI(GpPath*,INT,INT,INT,INT,INT,INT,INT,INT);
GpStatus WINGDIPAPI GdipAddPathBeziers(GpPath*,GDIPCONST GpPointF*,INT);
GpStatus WINGDIPAPI GdipAddPathBeziersI(GpPath*,GDIPCONST GpPoint*,INT);
GpStatus WINGDIPAPI GdipAddPathClosedCurve2(GpPath*,GDIPCONST GpPointF*,INT,REAL);
GpStatus WINGDIPAPI GdipAddPathCurve(GpPath*,GDIPCONST GpPointF*,INT);
GpStatus WINGDIPAPI GdipAddPathCurveI(GpPath*,GDIPCONST GpPoint*,INT);
GpStatus WINGDIPAPI GdipAddPathCurve2(GpPath*,GDIPCONST GpPointF*,INT,REAL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment