[Gdiplus 15/15] Implement GdipGetRegionBounds

Adam Petaccia adam at tpetaccia.com
Wed Jul 9 02:34:14 CDT 2008


---
 dlls/gdiplus/region.c       |   39 ++++++++++++++++++++++++++++++++++++---
 dlls/gdiplus/tests/region.c |    6 ------
 2 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/dlls/gdiplus/region.c b/dlls/gdiplus/region.c
index c154352..20289d5 100644
--- a/dlls/gdiplus/region.c
+++ b/dlls/gdiplus/region.c
@@ -231,11 +231,44 @@ GpStatus WINGDIPAPI GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
     return NotImplemented;
 }
 
-GpStatus WINGDIPAPI GdipGetRegionBounds(GpRegion *region, GpGraphics *graphics, GpRectF *rect)
+GpStatus WINGDIPAPI GdipGetRegionBounds(GpRegion *region, GpGraphics *graphics,
+        GpRectF *rect)
 {
-    FIXME("(%p, %p, %p): stub\n", region, graphics, rect);
+    GpPointF *allPoints;
+    FLOAT mostLeft, mostRight, mostHigh, mostLow;
+    INT pointCount, i;
 
-    return NotImplemented;
+    if (!(region && graphics && rect))
+        return InvalidParameter;
+
+    TRACE("%p, %p, %p\n", region, graphics, rect);
+
+    GdipGetPointCount(&region->outline, &pointCount);
+    allPoints = GdipAlloc(sizeof(GpPointF) * pointCount);
+    if (!allPoints)
+        return OutOfMemory;
+    GdipGetPathPoints(&region->outline, allPoints, pointCount);
+
+    mostRight = mostLeft = allPoints[0].X;
+    mostHigh  = mostLow  = allPoints[0].Y;
+    for (i = 1; i < pointCount; i++)
+    {
+        if(allPoints[i].X < mostLeft)
+            mostLeft  = allPoints[i].X;
+        else if (allPoints[i].X > mostRight)
+            mostRight = allPoints[i].X;
+
+        if(allPoints[i].Y < mostLow)
+            mostLow   = allPoints[i].Y;
+        else if (allPoints[i].Y > mostHigh)
+            mostHigh  = allPoints[i].Y;
+    }
+    rect->X = mostLeft;
+    rect->Width = mostRight - mostLeft;
+    rect->Y = mostLow;
+    rect->Height = mostHigh - mostLow;
+
+    return Ok;
 }
 
 GpStatus WINGDIPAPI GdipGetRegionBoundsI(GpRegion *region, GpGraphics *graphics, GpRect *rect)
diff --git a/dlls/gdiplus/tests/region.c b/dlls/gdiplus/tests/region.c
index 1953a8d..8e11ce2 100644
--- a/dlls/gdiplus/tests/region.c
+++ b/dlls/gdiplus/tests/region.c
@@ -230,14 +230,11 @@ static void test_regionbounds(void)
 
     /* Clear the rect to make sure what we get isn't stale data */
     ZeroMemory(&rect, sizeof(RectF));
-todo_wine
-{
     stat = GdipGetRegionBounds(region, graphics, &rect);
     ok(rect.X == 5, "Expected 5 for X, got %f\n", rect.X);
     ok(rect.Y == 7, "Expected 7 for Y, got %f\n", rect.Y);
     ok(rect.Width == 10, "Expected a width of 10, got %f\n", rect.Width);
     ok(rect.Height == 20, "Expected a height of 20, got %f\n", rect.Height);
-}
     stat = GdipDeleteRegion(region);
     expect(Ok, stat);
 
@@ -251,15 +248,12 @@ todo_wine
     expect(Ok, stat);
     stat = GdipCreateRegionPath(path, &region);
     expect(Ok, stat);
-todo_wine
-{
     stat = GdipGetRegionBounds(region, graphics, &rect);
     expect(Ok, stat);
     ok(rect.X == 1, "Expected 0 for X, got %f\n", rect.X);
     ok(rect.Y == 1, "Expected 0 for Y, got %f\n", rect.Y);
     ok(rect.Width == 8, "Expected 0 for Width, got %f\n", rect.Width);
     ok(rect.Height == 3, "Expected 0 for Height, got %f\n", rect.Height);
-}
 
     GdipDeleteGraphics(graphics);
     GdipDeletePath(path);
-- 
1.5.4.3




More information about the wine-patches mailing list