Nikolay Sivov : gdiplus: Implemented GdipGetRegionBounds/ GdipGetRegionBoundsI.

Alexandre Julliard julliard at winehq.org
Mon Feb 2 09:01:17 CST 2009


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

Author: Nikolay Sivov <bunglehead at gmail.com>
Date:   Fri Jan 30 23:56:01 2009 +0300

gdiplus: Implemented GdipGetRegionBounds/GdipGetRegionBoundsI.

---

 dlls/gdiplus/region.c       |   56 ++++++++++++++++++++++++++++++++++++---
 dlls/gdiplus/tests/region.c |   62 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 114 insertions(+), 4 deletions(-)

diff --git a/dlls/gdiplus/region.c b/dlls/gdiplus/region.c
index cc3b6cb..e42c5cd 100644
--- a/dlls/gdiplus/region.c
+++ b/dlls/gdiplus/region.c
@@ -634,18 +634,66 @@ GpStatus WINGDIPAPI GdipDeleteRegion(GpRegion *region)
     return Ok;
 }
 
+/*****************************************************************************
+ * GdipGetRegionBounds [GDIPLUS.@]
+ */
 GpStatus WINGDIPAPI GdipGetRegionBounds(GpRegion *region, GpGraphics *graphics, GpRectF *rect)
 {
-    FIXME("(%p, %p, %p): stub\n", region, graphics, rect);
+    HRGN hrgn;
+    RECT r;
+    GpStatus status;
 
-    return NotImplemented;
+    TRACE("(%p, %p, %p)\n", region, graphics, rect);
+
+    if(!region || !graphics || !rect)
+        return InvalidParameter;
+
+    status = GdipGetRegionHRgn(region, graphics, &hrgn);
+    if(status != Ok)
+        return status;
+
+    /* infinite */
+    if(!hrgn){
+        rect->X = rect->Y = -(REAL)(1 << 22);
+        rect->Width = rect->Height = (REAL)(1 << 23);
+        return Ok;
+    }
+
+    if(!GetRgnBox(hrgn, &r)){
+        DeleteObject(hrgn);
+        return GenericError;
+    }
+
+    rect->X = r.left;
+    rect->Y = r.top;
+    rect->Width  = r.right  - r.left;
+    rect->Height = r.bottom - r.top;
+
+    return Ok;
 }
 
+/*****************************************************************************
+ * GdipGetRegionBoundsI [GDIPLUS.@]
+ */
 GpStatus WINGDIPAPI GdipGetRegionBoundsI(GpRegion *region, GpGraphics *graphics, GpRect *rect)
 {
-    FIXME("(%p, %p, %p): stub\n", region, graphics, rect);
+    GpRectF rectf;
+    GpStatus status;
 
-    return NotImplemented;
+    TRACE("(%p, %p, %p)\n", region, graphics, rect);
+
+    if(!rect)
+        return InvalidParameter;
+
+    status = GdipGetRegionBounds(region, graphics, &rectf);
+    if(status == Ok){
+        rect->X = roundr(rectf.X);
+        rect->Y = roundr(rectf.X);
+        rect->Width  = roundr(rectf.Width);
+        rect->Height = roundr(rectf.Height);
+    }
+
+    return status;
 }
 
 static inline void write_dword(DWORD* location, INT* offset, const DWORD write)
diff --git a/dlls/gdiplus/tests/region.c b/dlls/gdiplus/tests/region.c
index 294fed7..689811c 100644
--- a/dlls/gdiplus/tests/region.c
+++ b/dlls/gdiplus/tests/region.c
@@ -1120,6 +1120,67 @@ static void test_translate(void)
     ReleaseDC(0, hdc);
 }
 
+static void test_getbounds(void)
+{
+    GpRegion *region;
+    GpGraphics *graphics;
+    GpStatus status;
+    GpRectF rectf;
+    HDC hdc = GetDC(0);
+
+    status = GdipCreateFromHDC(hdc, &graphics);
+    ok(status == Ok, "status %08x\n", status);
+    status = GdipCreateRegion(&region);
+    ok(status == Ok, "status %08x\n", status);
+
+    /* NULL */
+    status = GdipGetRegionBounds(NULL, NULL, NULL);
+    ok(status == InvalidParameter, "status %08x\n", status);
+    status = GdipGetRegionBounds(region, NULL, NULL);
+    ok(status == InvalidParameter, "status %08x\n", status);
+    status = GdipGetRegionBounds(region, graphics, NULL);
+    ok(status == InvalidParameter, "status %08x\n", status);
+    /* infinite */
+    rectf.X = rectf.Y = 0.0;
+    rectf.Height = rectf.Width = 100.0;
+    status = GdipGetRegionBounds(region, graphics, &rectf);
+    ok(status == Ok, "status %08x\n", status);
+    ok(rectf.X == -(REAL)(1 << 22), "Expected X = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.X);
+    ok(rectf.Y == -(REAL)(1 << 22), "Expected Y = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.Y);
+    ok(rectf.Width  == (REAL)(1 << 23), "Expected width = %.2f, got %.2f\n", (REAL)(1 << 23), rectf.Width);
+    ok(rectf.Height == (REAL)(1 << 23), "Expected height = %.2f, got %.2f\n",(REAL)(1 << 23), rectf.Height);
+    /* empty */
+    rectf.X = rectf.Y = 0.0;
+    rectf.Height = rectf.Width = 100.0;
+    status = GdipSetEmpty(region);
+    ok(status == Ok, "status %08x\n", status);
+    status = GdipGetRegionBounds(region, graphics, &rectf);
+    ok(status == Ok, "status %08x\n", status);
+    ok(rectf.X == 0.0, "Expected X = 0.0, got %.2f\n", rectf.X);
+    ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
+    ok(rectf.Width  == 0.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
+    ok(rectf.Height == 0.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
+    /* rect */
+    rectf.X = 10.0; rectf.Y = 0.0;
+    rectf.Width = rectf.Height = 100.0;
+    status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
+    ok(status == Ok, "status %08x\n", status);
+    rectf.X = rectf.Y = 0.0;
+    rectf.Height = rectf.Width = 0.0;
+    status = GdipGetRegionBounds(region, graphics, &rectf);
+    ok(status == Ok, "status %08x\n", status);
+    ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
+    ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
+    ok(rectf.Width  == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
+    ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
+
+    status = GdipDeleteRegion(region);
+    ok(status == Ok, "status %08x\n", status);
+    status = GdipDeleteGraphics(graphics);
+    ok(status == Ok, "status %08x\n", status);
+    ReleaseDC(0, hdc);
+}
+
 START_TEST(region)
 {
     struct GdiplusStartupInput gdiplusStartupInput;
@@ -1140,6 +1201,7 @@ START_TEST(region)
     test_gethrgn();
     test_isequal();
     test_translate();
+    test_getbounds();
 
     GdiplusShutdown(gdiplusToken);
 }




More information about the wine-cvs mailing list