gdiplus: Implementation of GdipAddPathPolygon with tests.

oldstable
Nikolay Sivov 2008-06-26 18:07:04 +04:00 committed by Alexandre Julliard
parent 3ef22e56f2
commit 629761acde
4 changed files with 100 additions and 2 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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);
}

View File

@ -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);