Nikolay Sivov : gdiplus: Implementation of GdipAddPathPolygon with tests.

Alexandre Julliard julliard at winehq.org
Thu Jun 26 14:51:05 CDT 2008


Module: wine
Branch: master
Commit: 629761acde13283e0dfc6c42cab3e91e11fbbd88
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=629761acde13283e0dfc6c42cab3e91e11fbbd88

Author: Nikolay Sivov <bunglehead at gmail.com>
Date:   Thu Jun 26 18:07:04 2008 +0400

gdiplus: Implementation of GdipAddPathPolygon with tests.

---

 dlls/gdiplus/gdiplus.spec         |    4 +-
 dlls/gdiplus/graphicspath.c       |   49 +++++++++++++++++++++++++++++++++++++
 dlls/gdiplus/tests/graphicspath.c |   47 +++++++++++++++++++++++++++++++++++
 include/gdiplusflat.h             |    2 +
 4 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/dlls/gdiplus/gdiplus.spec b/dlls/gdiplus/gdiplus.spec
index 57e0de6..264127d 100644
--- a/dlls/gdiplus/gdiplus.spec
+++ b/dlls/gdiplus/gdiplus.spec
@@ -23,8 +23,8 @@
 @ stdcall GdipAddPathPath(ptr ptr long)
 @ stub GdipAddPathPie
 @ stub GdipAddPathPieI
-@ stub GdipAddPathPolygon
-@ stub GdipAddPathPolygonI
+@ stdcall GdipAddPathPolygon(ptr ptr long)
+@ stdcall GdipAddPathPolygonI(ptr ptr long)
 @ stdcall GdipAddPathRectangle(ptr long long long long)
 @ stdcall GdipAddPathRectangleI(ptr long long long long)
 @ stdcall GdipAddPathRectangles(ptr ptr long)
diff --git a/dlls/gdiplus/graphicspath.c b/dlls/gdiplus/graphicspath.c
index c474e99..1da6866 100644
--- a/dlls/gdiplus/graphicspath.c
+++ b/dlls/gdiplus/graphicspath.c
@@ -346,6 +346,55 @@ GpStatus WINGDIPAPI GdipAddPathPath(GpPath *path, GDIPCONST GpPath* addingPath,
     return Ok;
 }
 
+GpStatus WINGDIPAPI GdipAddPathPolygon(GpPath *path, GDIPCONST GpPointF *points, INT count)
+{
+    INT old_count;
+
+    if(!path || !points || count < 3)
+        return InvalidParameter;
+
+    if(!lengthen_path(path, count))
+        return OutOfMemory;
+
+    old_count = path->pathdata.Count;
+
+    memcpy(&path->pathdata.Points[old_count], points, count*sizeof(GpPointF));
+    memset(&path->pathdata.Types[old_count + 1], PathPointTypeLine, count - 1);
+
+    /* A polygon is an intrinsic figure */
+    path->pathdata.Types[old_count] = PathPointTypeStart;
+    path->pathdata.Types[old_count + count - 1] |= PathPointTypeCloseSubpath;
+    path->newfigure = TRUE;
+    path->pathdata.Count += count;
+
+    return Ok;
+}
+
+GpStatus WINGDIPAPI GdipAddPathPolygonI(GpPath *path, GDIPCONST GpPoint *points, INT count)
+{
+    GpPointF *ptf;
+    GpStatus status;
+    INT i;
+
+    if(!points || count < 3)
+        return InvalidParameter;
+
+    ptf = GdipAlloc(sizeof(GpPointF) * count);
+    if(!ptf)
+        return OutOfMemory;
+
+    for(i = 0; i < count; i++){
+        ptf[i].X = (REAL)points[i].X;
+        ptf[i].Y = (REAL)points[i].Y;
+    }
+
+    status = GdipAddPathPolygon(path, ptf, count);
+
+    GdipFree(ptf);
+
+    return status;
+}
+
 GpStatus WINGDIPAPI GdipClonePath(GpPath* path, GpPath **clone)
 {
     if(!path || !clone)
diff --git a/dlls/gdiplus/tests/graphicspath.c b/dlls/gdiplus/tests/graphicspath.c
index 262a527..9f65898 100644
--- a/dlls/gdiplus/tests/graphicspath.c
+++ b/dlls/gdiplus/tests/graphicspath.c
@@ -575,6 +575,52 @@ static void test_linei(void)
     GdipDeletePath(path);
 }
 
+static path_test_t poly_path[] = {
+    {5.00, 5.00, PathPointTypeStart, 0, 0},   /*1*/
+    {6.00, 8.00, PathPointTypeLine, 0, 0},    /*2*/
+    {0.00,  0.00,  PathPointTypeStart, 0, 0}, /*3*/
+    {10.00, 10.00, PathPointTypeLine, 0, 0},  /*4*/
+    {10.00, 20.00, PathPointTypeLine, 0, 0},  /*5*/
+    {30.00, 10.00, PathPointTypeLine, 0, 0},  /*6*/
+    {20.00, 0.00, PathPointTypeLine | PathPointTypeCloseSubpath, 0, 0}, /*7*/
+    };
+
+static void test_polygon(void)
+{
+    GpStatus status;
+    GpPath *path;
+    GpPointF points[5];
+
+    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;
+    points[4].X = 20.0;
+    points[4].Y = 0.0;
+
+    /* NULL args */
+    status = GdipAddPathPolygon(NULL, points, 5);
+    expect(InvalidParameter, status);
+    status = GdipAddPathPolygon(path, NULL, 5);
+    expect(InvalidParameter, status);
+    /* Polygon should have 3 points at least */
+    status = GdipAddPathPolygon(path, points, 2);
+    expect(InvalidParameter, status);
+
+    GdipCreatePath(FillModeAlternate, &path);
+    /* to test how it prolongs not empty path */
+    status = GdipAddPathLine(path, 5.0, 5.0, 6.0, 8.0);
+    expect(Ok, status);
+    status = GdipAddPathPolygon(path, points, 5);
+    expect(Ok, status);
+    /* check resulting path */
+    ok_path(path, poly_path, sizeof(poly_path)/sizeof(path_test_t), FALSE);
+}
+
 static path_test_t rect_path[] = {
     {5.0, 5.0,       PathPointTypeStart, 0, 0}, /*0*/
     {105.0, 5.0,     PathPointTypeLine,  0, 0}, /*1*/
@@ -643,6 +689,7 @@ START_TEST(graphicspath)
     test_ellipse();
     test_linei();
     test_rect();
+    test_polygon();
 
     GdiplusShutdown(gdiplusToken);
 }
diff --git a/include/gdiplusflat.h b/include/gdiplusflat.h
index c20efdc..3891f0f 100644
--- a/include/gdiplusflat.h
+++ b/include/gdiplusflat.h
@@ -215,6 +215,8 @@ GpStatus WINGDIPAPI GdipAddPathLine2(GpPath*,GDIPCONST GpPointF*,INT);
 GpStatus WINGDIPAPI GdipAddPathLine2I(GpPath*,GDIPCONST GpPoint*,INT);
 GpStatus WINGDIPAPI GdipAddPathLineI(GpPath*,INT,INT,INT,INT);
 GpStatus WINGDIPAPI GdipAddPathPath(GpPath*,GDIPCONST GpPath*,BOOL);
+GpStatus WINGDIPAPI GdipAddPathPolygon(GpPath*,GDIPCONST GpPointF*,INT);
+GpStatus WINGDIPAPI GdipAddPathPolygonI(GpPath*,GDIPCONST GpPoint*,INT);
 GpStatus WINGDIPAPI GdipAddPathRectangle(GpPath*,REAL,REAL,REAL,REAL);
 GpStatus WINGDIPAPI GdipAddPathRectangleI(GpPath*,INT,INT,INT,INT);
 GpStatus WINGDIPAPI GdipAddPathRectangles(GpPath*,GDIPCONST GpRectF*,INT);




More information about the wine-cvs mailing list