gdiplus: GdipAddPathRectangle with tests

Nikolay Sivov bunglehead at gmail.com
Mon May 12 16:33:34 CDT 2008


Changelog:
    - GdipAddPathRectangle(I) with tests

---
 dlls/gdiplus/gdiplus.spec         |    4 +-
 dlls/gdiplus/graphicspath.c       |   50 +++++++++++++++++++++++++++++++++++++
 dlls/gdiplus/tests/graphicspath.c |   29 +++++++++++++++++++++
 include/gdiplusflat.h             |    2 +
 4 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/dlls/gdiplus/gdiplus.spec b/dlls/gdiplus/gdiplus.spec
index 6b088b1..f2eb2b3 100644
--- a/dlls/gdiplus/gdiplus.spec
+++ b/dlls/gdiplus/gdiplus.spec
@@ -25,8 +25,8 @@
 @ stub GdipAddPathPieI
 @ stub GdipAddPathPolygon
 @ stub GdipAddPathPolygonI
-@ stub GdipAddPathRectangle
-@ stub GdipAddPathRectangleI
+@ stdcall GdipAddPathRectangle(ptr long long long long)
+@ stdcall GdipAddPathRectangleI(ptr long long long long)
 @ stub GdipAddPathRectangles
 @ stub GdipAddPathRectanglesI
 @ stub GdipAddPathString
diff --git a/dlls/gdiplus/graphicspath.c b/dlls/gdiplus/graphicspath.c
index 84446aa..3c33244 100644
--- a/dlls/gdiplus/graphicspath.c
+++ b/dlls/gdiplus/graphicspath.c
@@ -708,3 +708,53 @@ GpStatus WINGDIPAPI GdipTransformPath(GpPath *path, GpMatrix *matrix)
     return GdipTransformMatrixPoints(matrix, path->pathdata.Points,
                                      path->pathdata.Count);
 }
+
+GpStatus WINGDIPAPI GdipAddPathRectangle(GpPath *path, REAL x, REAL y,
+    REAL width, REAL height)
+{
+    GpPath *backup;
+    GpPointF ptf[2];
+    GpStatus retstat;
+    BOOL old_new;
+
+    if(!path || width < 0.0 || height < 0.0)
+        return InvalidParameter;
+
+    /* make a backup copy of path data */
+    if((retstat = GdipClonePath(path, &backup)) != Ok)
+        return retstat;
+    
+    /* rectangle should start as new path */
+    old_new = path->newfigure;
+    path->newfigure = TRUE;
+    if((retstat = GdipAddPathLine(path,x,y,x+width,y)) != Ok){
+        path->newfigure = old_new;
+        goto fail;
+    }
+
+    ptf[0].X = x+width;
+    ptf[0].Y = y+height;
+    ptf[1].X = x;
+    ptf[1].Y = y+height;
+
+    if((retstat = GdipAddPathLine2(path,(GDIPCONST GpPointF*)&ptf,2)) != Ok)  goto fail;
+    path->pathdata.Types[path->pathdata.Count-1] |= PathPointTypeCloseSubpath;
+
+    /* free backup */
+    GdipDeletePath(backup);
+    return Ok;
+    
+fail:
+    /* reverting */
+    GdipDeletePath(path);
+    GdipClonePath(backup, &path);
+    GdipDeletePath(backup);
+
+    return retstat;
+}
+
+GpStatus WINGDIPAPI GdipAddPathRectangleI(GpPath *path, INT x, INT y,
+    INT width, INT height)
+{
+    return GdipAddPathRectangle(path,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
+}
diff --git a/dlls/gdiplus/tests/graphicspath.c b/dlls/gdiplus/tests/graphicspath.c
index 3860a2e..e797b44 100644
--- a/dlls/gdiplus/tests/graphicspath.c
+++ b/dlls/gdiplus/tests/graphicspath.c
@@ -545,6 +545,34 @@ static void test_linei(void)
     GdipDeletePath(path);
 }
 
+static path_test_t rect_path[] = {
+    {5.0, 5.0,       PathPointTypeStart, 0, 0}, /*0*/
+    {105.0, 5.0,     PathPointTypeLine,  0, 0}, /*1*/
+    {105.0, 55.0,    PathPointTypeLine,  0, 0}, /*2*/
+    {5.0, 55.0,      PathPointTypeLine | PathPointTypeCloseSubpath, 0, 0}, /*3*/
+
+    {100.0, 50.0,    PathPointTypeStart, 0, 0}, /*4*/
+    {220.0, 50.0,    PathPointTypeLine,  0, 0}, /*5*/
+    {220.0, 80.0,    PathPointTypeLine,  0, 0}, /*6*/
+    {100.0, 80.0,    PathPointTypeLine | PathPointTypeCloseSubpath, 0, 0}  /*7*/
+    };
+
+static void test_rect(void)
+{
+    GpStatus status;
+    GpPath *path;
+
+    GdipCreatePath(FillModeAlternate, &path);
+    status = GdipAddPathRectangle(path, 5.0, 5.0, 100.0, 50.0);
+    expect(Ok, status);
+    status = GdipAddPathRectangle(path, 100.0, 50.0, 120.0, 30.0);
+    expect(Ok, status);
+
+    ok_path(path, rect_path, sizeof(rect_path)/sizeof(path_test_t), FALSE);
+
+    GdipDeletePath(path);
+}
+
 START_TEST(graphicspath)
 {
     struct GdiplusStartupInput gdiplusStartupInput;
@@ -564,6 +592,7 @@ START_TEST(graphicspath)
     test_pathpath();
     test_ellipse();
     test_linei();
+    test_rect();
 
     GdiplusShutdown(gdiplusToken);
 }
diff --git a/include/gdiplusflat.h b/include/gdiplusflat.h
index 835b290..0d21c82 100644
--- a/include/gdiplusflat.h
+++ b/include/gdiplusflat.h
@@ -213,6 +213,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 GdipAddPathRectangle(GpPath*,REAL,REAL,REAL,REAL);
+GpStatus WINGDIPAPI GdipAddPathRectangleI(GpPath*,INT,INT,INT,INT);
 GpStatus WINGDIPAPI GdipClonePath(GpPath*,GpPath**);
 GpStatus WINGDIPAPI GdipClosePathFigure(GpPath*);
 GpStatus WINGDIPAPI GdipClosePathFigures(GpPath*);
-- 
1.4.4.4






More information about the wine-patches mailing list