Signed-off-by: Jeff Smith <whydoubt(a)gmail.com>
---
dlls/gdiplus/graphicspath.c | 41 ++++++++++++++++++++++++-------
dlls/gdiplus/tests/graphicspath.c | 34 +++++++++++++++++++++++++
2 files changed, 66 insertions(+), 9 deletions(-)
diff --git a/dlls/gdiplus/graphicspath.c b/dlls/gdiplus/graphicspath.c
index 4d5a73588f..6d2760bef4 100644
--- a/dlls/gdiplus/graphicspath.c
+++ b/dlls/gdiplus/graphicspath.c
@@ -166,6 +166,33 @@ static BOOL flatten_bezier(path_list_node_t *start, REAL x2, REAL y2, REAL x3, R
return TRUE;
}
+GpStatus extend_current_figure(GpPath *path, INT count, REAL x1, REAL y1, INT *old_count)
+{
+ *old_count = path->pathdata.Count;
+
+ if(path->newfigure ||
+ path->pathdata.Points[*old_count - 1].X != x1 ||
+ path->pathdata.Points[*old_count - 1].Y != y1)
+ {
+ if(!lengthen_path(path, count))
+ return OutOfMemory;
+
+ path->pathdata.Points[*old_count].X = x1;
+ path->pathdata.Points[*old_count].Y = y1;
+ path->pathdata.Types[*old_count] =
+ (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
+ }
+ else
+ {
+ if(!lengthen_path(path, count - 1))
+ return OutOfMemory;
+
+ (*old_count)--;
+ }
+
+ return Ok;
+}
+
/*******************************************************************************
* GdipAddPathArc [GDIPLUS.1]
*
@@ -244,6 +271,7 @@ GpStatus WINGDIPAPI GdipAddPathBezier(GpPath *path, REAL x1, REAL y1, REAL x2,
REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
{
INT old_count;
+ GpStatus status;
TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
path, x1, y1, x2, y2, x3, y3, x4, y4);
@@ -251,13 +279,10 @@ GpStatus WINGDIPAPI GdipAddPathBezier(GpPath *path, REAL x1, REAL y1, REAL x2,
if(!path)
return InvalidParameter;
- if(!lengthen_path(path, 4))
- return OutOfMemory;
-
- old_count = path->pathdata.Count;
+ status = extend_current_figure(path, 4, x1, y1, &old_count);
+ if(status != Ok)
+ return status;
- path->pathdata.Points[old_count].X = x1;
- path->pathdata.Points[old_count].Y = y1;
path->pathdata.Points[old_count + 1].X = x2;
path->pathdata.Points[old_count + 1].Y = y2;
path->pathdata.Points[old_count + 2].X = x3;
@@ -265,14 +290,12 @@ GpStatus WINGDIPAPI GdipAddPathBezier(GpPath *path, REAL x1, REAL y1, REAL x2,
path->pathdata.Points[old_count + 3].X = x4;
path->pathdata.Points[old_count + 3].Y = y4;
- path->pathdata.Types[old_count] =
- (path->newfigure ? PathPointTypeStart : PathPointTypeLine);
path->pathdata.Types[old_count + 1] = PathPointTypeBezier;
path->pathdata.Types[old_count + 2] = PathPointTypeBezier;
path->pathdata.Types[old_count + 3] = PathPointTypeBezier;
path->newfigure = FALSE;
- path->pathdata.Count += 4;
+ path->pathdata.Count = old_count + 4;
return Ok;
}
diff --git a/dlls/gdiplus/tests/graphicspath.c b/dlls/gdiplus/tests/graphicspath.c
index 7670a6c41f..d85cf68dfc 100644
--- a/dlls/gdiplus/tests/graphicspath.c
+++ b/dlls/gdiplus/tests/graphicspath.c
@@ -332,6 +332,39 @@ static void test_line2(void)
GdipDeletePath(path);
}
+static path_test_t bezier_path[] = {
+ {10.0, 10.0, PathPointTypeStart, 0, 0}, /*0*/
+ {20.0, 10.0, PathPointTypeBezier, 0, 0}, /*1*/
+ {20.0, 20.0, PathPointTypeBezier, 0, 0}, /*2*/
+ {30.0, 20.0, PathPointTypeBezier, 0, 0}, /*3*/
+ {40.0, 20.0, PathPointTypeBezier, 0, 0}, /*4*/
+ {40.0, 30.0, PathPointTypeBezier, 0, 0}, /*5*/
+ {50.0, 30.0, PathPointTypeBezier, 0, 0}, /*6*/
+ {50.0, 10.0, PathPointTypeLine, 0, 0}, /*7*/
+ {60.0, 10.0, PathPointTypeBezier, 0, 0}, /*8*/
+ {60.0, 20.0, PathPointTypeBezier, 0, 0}, /*9*/
+ {70.0, 20.0, PathPointTypeBezier, 0, 0} /*10*/
+ };
+
+static void test_bezier(void)
+{
+ GpStatus status;
+ GpPath* path;
+
+ GdipCreatePath(FillModeAlternate, &path);
+
+ status = GdipAddPathBezier(path, 10.0, 10.0, 20.0, 10.0, 20.0, 20.0, 30.0, 20.0);
+ expect(Ok, status);
+ status = GdipAddPathBezier(path, 30.0, 20.0, 40.0, 20.0, 40.0, 30.0, 50.0, 30.0);
+ expect(Ok, status);
+ status = GdipAddPathBezier(path, 50.0, 10.0, 60.0, 10.0, 60.0, 20.0, 70.0, 20.0);
+ expect(Ok, status);
+
+ ok_path(path, bezier_path, ARRAY_SIZE(bezier_path), FALSE);
+
+ GdipDeletePath(path);
+}
+
static path_test_t arc_path[] = {
{600.0, 450.0, PathPointTypeStart, 0, 0}, /*0*/
{600.0, 643.3, PathPointTypeBezier, 0, 0}, /*1*/
@@ -1784,6 +1817,7 @@ START_TEST(graphicspath)
test_getpathdata();
test_createpath2();
test_line2();
+ test_bezier();
test_arc();
test_worldbounds();
test_pathpath();
--
2.23.0