FORMATTING: apply consistent indentation, no code change
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Thu, 21 Feb 2008 02:40:23 +0000 (02:40 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Thu, 21 Feb 2008 02:40:23 +0000 (02:40 +0000)
svn path=/trunk/; revision=32441

reactos/subsystems/win32/win32k/objects/region.c

index 7a45643..29c64c8 100644 (file)
@@ -233,7 +233,8 @@ SOFTWARE.
  *     instead of using this structure to make use of
  *     register declarations.
  */
-typedef struct {
+typedef struct
+{
     INT minor_axis;    /* minor axis        */
     INT d;             /* decision variable */
     INT m, m1;         /* slope and slope+1 */
@@ -302,8 +303,9 @@ typedef struct {
 #define CLOCKWISE          1
 #define COUNTERCLOCKWISE  -1
 
-typedef struct _EdgeTableEntry {
-     INT ymax;           /* ycoord at which we exit this edge. */
+typedef struct _EdgeTableEntry
+{
+     INT ymax;             /* ycoord at which we exit this edge. */
      BRESINFO bres;        /* Bresenham info to run the edge     */
      struct _EdgeTableEntry *next;       /* next in the list     */
      struct _EdgeTableEntry *back;       /* for insertion sort   */
@@ -312,16 +314,18 @@ typedef struct _EdgeTableEntry {
 } EdgeTableEntry;
 
 
-typedef struct _ScanLineList{
-     INT scanline;            /* the scanline represented */
-     EdgeTableEntry *edgelist;  /* header node              */
+typedef struct _ScanLineList
+{
+     INT scanline;                /* the scanline represented */
+     EdgeTableEntry *edgelist;    /* header node              */
      struct _ScanLineList *next;  /* next in the list       */
 } ScanLineList;
 
 
-typedef struct {
-     INT ymax;               /* ymax for the polygon     */
-     INT ymin;               /* ymin for the polygon     */
+typedef struct
+{
+     INT ymax;                 /* ymax for the polygon     */
+     INT ymin;                 /* ymin for the polygon     */
      ScanLineList scanlines;   /* header node              */
 } EdgeTable;
 
@@ -333,7 +337,8 @@ typedef struct {
  */
 #define SLLSPERBLOCK 25
 
-typedef struct _ScanLineListBlock {
+typedef struct _ScanLineListBlock
+{
      ScanLineList SLLs[SLLSPERBLOCK];
      struct _ScanLineListBlock *next;
 } ScanLineListBlock;
@@ -401,26 +406,33 @@ typedef struct _ScanLineListBlock {
 /*
  *   Check to see if there is enough memory in the present region.
  */
-static __inline int xmemcheck(ROSRGNDATA *reg, PRECT *rect, PRECT *firstrect ) {
-       if ( (reg->rdh.nCount+1)*sizeof( RECT ) >= reg->rdh.nRgnSize ) {
-               PRECT temp;
-               DWORD NewSize = 2 * reg->rdh.nRgnSize;
-               if (NewSize < (reg->rdh.nCount + 1) * sizeof(RECT)) {
-                       NewSize = (reg->rdh.nCount + 1) * sizeof(RECT);
-               }
-               temp = ExAllocatePoolWithTag( PagedPool, NewSize, TAG_REGION);
-
-               if (temp == 0)
-                   return 0;
-
-                /* copy the rectangles */
-                COPY_RECTS(temp, *firstrect, reg->rdh.nCount);
-
-               reg->rdh.nRgnSize = NewSize;
-               if (*firstrect != &reg->rdh.rcBound)
-                   ExFreePool( *firstrect );
-               *firstrect = temp;
-               *rect = (*firstrect)+reg->rdh.nCount;
+static __inline int xmemcheck(ROSRGNDATA *reg, PRECT *rect, PRECT *firstrect)
+{
+    if ( (reg->rdh.nCount+1) * sizeof(RECT) >= reg->rdh.nRgnSize )
+    {
+        PRECT temp;
+        DWORD NewSize = 2 * reg->rdh.nRgnSize;
+        if (NewSize < (reg->rdh.nCount + 1) * sizeof(RECT))
+        {
+            NewSize = (reg->rdh.nCount + 1) * sizeof(RECT);
+        }
+        temp = ExAllocatePoolWithTag(PagedPool, NewSize, TAG_REGION);
+
+        if (temp == 0)
+        {
+            return 0;
+        }
+
+        /* Copy the rectangles */
+        COPY_RECTS(temp, *firstrect, reg->rdh.nCount);
+
+        reg->rdh.nRgnSize = NewSize;
+        if (*firstrect != &reg->rdh.rcBound)
+        {
+            ExFreePool(*firstrect);
+        }
+        *firstrect = temp;
+        *rect = (*firstrect)+reg->rdh.nCount;
     }
     return 1;
 }
@@ -437,7 +449,8 @@ typedef void (FASTCALL *nonOverlapProcp)(PROSRGNDATA, PRECT, PRECT, INT, INT);
 
 // used to allocate buffers for points and link the buffers together
 
-typedef struct _POINTBLOCK {
+typedef struct _POINTBLOCK
+{
   POINT pts[NUMPTSTOBUFFER];
   struct _POINTBLOCK *next;
 } POINTBLOCK;
@@ -450,67 +463,74 @@ typedef struct _POINTBLOCK {
 VOID FASTCALL
 IntDumpRegion(HRGN hRgn)
 {
-   ROSRGNDATA *Data;
-
-   Data = RGNDATA_LockRgn(hRgn);
-   if (Data == NULL)
-   {
-      DbgPrint("IntDumpRegion called with invalid region!\n");
-      return;
-   }
-
-   DbgPrint("IntDumpRegion(%x): %d,%d-%d,%d %d\n",
-      hRgn,
-      Data->rdh.rcBound.left,
-      Data->rdh.rcBound.top,
-      Data->rdh.rcBound.right,
-      Data->rdh.rcBound.bottom,
-      Data->rdh.iType);
-
-   RGNDATA_UnlockRgn(Data);
+    ROSRGNDATA *Data;
+
+    Data = RGNDATA_LockRgn(hRgn);
+    if (Data == NULL)
+    {
+        DbgPrint("IntDumpRegion called with invalid region!\n");
+        return;
+    }
+
+    DbgPrint("IntDumpRegion(%x): %d,%d-%d,%d %d\n",
+             hRgn,
+             Data->rdh.rcBound.left,
+             Data->rdh.rcBound.top,
+             Data->rdh.rcBound.right,
+             Data->rdh.rcBound.bottom,
+             Data->rdh.iType);
+
+    RGNDATA_UnlockRgn(Data);
 }
-#endif /* NDEBUG */
+#endif /* not NDEBUG */
 
-static BOOL FASTCALL REGION_CopyRegion(PROSRGNDATA dst, PROSRGNDATA src)
+static
+BOOL
+FASTCALL
+REGION_CopyRegion(
+    PROSRGNDATA dst,
+    PROSRGNDATA src
+)
 {
-  if(dst != src) //  don't want to copy to itself
-  {
-    if (dst->rdh.nRgnSize < src->rdh.nCount * sizeof(RECT))
-    {
-         PRECT temp;
-
-         temp = ExAllocatePoolWithTag(PagedPool, src->rdh.nCount * sizeof(RECT), TAG_REGION );
-         if( !temp )
-               return FALSE;
-
-         if( dst->Buffer && dst->Buffer != &dst->rdh.rcBound )
-               ExFreePool( dst->Buffer );      //free the old buffer
-         dst->Buffer = temp;
-      dst->rdh.nRgnSize = src->rdh.nCount * sizeof(RECT);  //size of region buffer
-    }
-    dst->rdh.nCount = src->rdh.nCount;                 //number of rectangles present in Buffer
-    dst->rdh.rcBound.left = src->rdh.rcBound.left;
-    dst->rdh.rcBound.top = src->rdh.rcBound.top;
-    dst->rdh.rcBound.right = src->rdh.rcBound.right;
-    dst->rdh.rcBound.bottom = src->rdh.rcBound.bottom;
-    dst->rdh.iType = src->rdh.iType;
-    COPY_RECTS(dst->Buffer, src->Buffer, src->rdh.nCount);
-  }
-  return TRUE;
+    if (dst != src) //  don't want to copy to itself
+    {
+        if (dst->rdh.nRgnSize < src->rdh.nCount * sizeof(RECT))
+        {
+            PRECT temp;
+
+            temp = ExAllocatePoolWithTag(PagedPool, src->rdh.nCount * sizeof(RECT), TAG_REGION );
+            if (!temp)
+                return FALSE;
+
+            if (dst->Buffer && dst->Buffer != &dst->rdh.rcBound)
+                ExFreePool(dst->Buffer);       //free the old buffer
+            dst->Buffer = temp;
+            dst->rdh.nRgnSize = src->rdh.nCount * sizeof(RECT);  //size of region buffer
+        }
+        dst->rdh.nCount = src->rdh.nCount;                 //number of rectangles present in Buffer
+        dst->rdh.rcBound.left = src->rdh.rcBound.left;
+        dst->rdh.rcBound.top = src->rdh.rcBound.top;
+        dst->rdh.rcBound.right = src->rdh.rcBound.right;
+        dst->rdh.rcBound.bottom = src->rdh.rcBound.bottom;
+        dst->rdh.iType = src->rdh.iType;
+        COPY_RECTS(dst->Buffer, src->Buffer, src->rdh.nCount);
+    }
+    return TRUE;
 }
 
-static void FASTCALL REGION_SetExtents (ROSRGNDATA *pReg)
+static void FASTCALL
+REGION_SetExtents(ROSRGNDATA *pReg)
 {
     RECT *pRect, *pRectEnd, *pExtents;
 
     if (pReg->rdh.nCount == 0)
     {
-               pReg->rdh.rcBound.left = 0;
-               pReg->rdh.rcBound.top = 0;
-               pReg->rdh.rcBound.right = 0;
-               pReg->rdh.rcBound.bottom = 0;
-               pReg->rdh.iType = NULLREGION;
-               return;
+        pReg->rdh.rcBound.left = 0;
+        pReg->rdh.rcBound.top = 0;
+        pReg->rdh.rcBound.right = 0;
+        pReg->rdh.rcBound.bottom = 0;
+        pReg->rdh.iType = NULLREGION;
+        return;
     }
 
     pExtents = &pReg->rdh.rcBound;
@@ -531,11 +551,11 @@ static void FASTCALL REGION_SetExtents (ROSRGNDATA *pReg)
 
     while (pRect <= pRectEnd)
     {
-               if (pRect->left < pExtents->left)
-                   pExtents->left = pRect->left;
-               if (pRect->right > pExtents->right)
-                   pExtents->right = pRect->right;
-               pRect++;
+        if (pRect->left < pExtents->left)
+            pExtents->left = pRect->left;
+        if (pRect->right > pExtents->right)
+            pExtents->right = pRect->right;
+        pRect++;
     }
     pReg->rdh.iType = (1 == pReg->rdh.nCount ? SIMPLEREGION : COMPLEXREGION);
 }
@@ -544,158 +564,167 @@ static void FASTCALL REGION_SetExtents (ROSRGNDATA *pReg)
 /***********************************************************************
  *           REGION_CropAndOffsetRegion
  */
-static BOOL FASTCALL REGION_CropAndOffsetRegion(const PPOINT off, const PRECT rect, PROSRGNDATA rgnSrc, PROSRGNDATA rgnDst)
+static BOOL FASTCALL
+REGION_CropAndOffsetRegion(
+    const PPOINT off,
+    const PRECT rect,
+    PROSRGNDATA rgnSrc,
+    PROSRGNDATA rgnDst
+)
 {
-  if(!rect) // just copy and offset
-  {
-    PRECT xrect;
-    if(rgnDst == rgnSrc)
+    if (!rect) // just copy and offset
     {
-      if(off->x || off->y)
-        xrect = (PRECT)rgnDst->Buffer;
-      else
-        return TRUE;
-    }
-    else{
-      xrect = ExAllocatePoolWithTag(PagedPool, rgnSrc->rdh.nCount * sizeof(RECT), TAG_REGION);
-         if( rgnDst->Buffer && rgnDst->Buffer != &rgnDst->rdh.rcBound )
-               ExFreePool( rgnDst->Buffer ); //free the old buffer. will be assigned to xrect below.
-       }
+        PRECT xrect;
+        if (rgnDst == rgnSrc)
+        {
+            if (off->x || off->y)
+                xrect = (PRECT)rgnDst->Buffer;
+            else
+                return TRUE;
+        }
+        else
+        {
+            xrect = ExAllocatePoolWithTag(PagedPool, rgnSrc->rdh.nCount * sizeof(RECT), TAG_REGION);
+            if (rgnDst->Buffer && rgnDst->Buffer != &rgnDst->rdh.rcBound)
+                ExFreePool(rgnDst->Buffer); //free the old buffer. will be assigned to xrect below.
+        }
 
-    if(xrect)
-    {
-      ULONG i;
+        if (xrect)
+        {
+            ULONG i;
 
-      if(rgnDst != rgnSrc)
-      {
-               *rgnDst = *rgnSrc;
-      }
+            if (rgnDst != rgnSrc)
+            {
+                *rgnDst = *rgnSrc;
+            }
 
-      if(off->x || off->y)
-      {
-        for(i = 0; i < rgnDst->rdh.nCount; i++)
-        {
-          xrect[i].left = ((PRECT)rgnSrc->Buffer + i)->left + off->x;
-          xrect[i].right = ((PRECT)rgnSrc->Buffer + i)->right + off->x;
-          xrect[i].top = ((PRECT)rgnSrc->Buffer + i)->top + off->y;
-          xrect[i].bottom = ((PRECT)rgnSrc->Buffer + i)->bottom + off->y;
-        }
-        rgnDst->rdh.rcBound.left   += off->x;
-        rgnDst->rdh.rcBound.right  += off->x;
-        rgnDst->rdh.rcBound.top    += off->y;
-        rgnDst->rdh.rcBound.bottom += off->y;
-      }
-      else
-      {
-        COPY_RECTS(xrect, rgnSrc->Buffer, rgnDst->rdh.nCount);
-      }
+            if (off->x || off->y)
+            {
+                for (i = 0; i < rgnDst->rdh.nCount; i++)
+                {
+                    xrect[i].left = ((PRECT)rgnSrc->Buffer + i)->left + off->x;
+                    xrect[i].right = ((PRECT)rgnSrc->Buffer + i)->right + off->x;
+                    xrect[i].top = ((PRECT)rgnSrc->Buffer + i)->top + off->y;
+                    xrect[i].bottom = ((PRECT)rgnSrc->Buffer + i)->bottom + off->y;
+                }
+                rgnDst->rdh.rcBound.left   += off->x;
+                rgnDst->rdh.rcBound.right  += off->x;
+                rgnDst->rdh.rcBound.top    += off->y;
+                rgnDst->rdh.rcBound.bottom += off->y;
+            }
+            else
+            {
+                COPY_RECTS(xrect, rgnSrc->Buffer, rgnDst->rdh.nCount);
+            }
 
-         rgnDst->Buffer = xrect;
-    } else
-      return FALSE;
-  }
-  else if ((rect->left >= rect->right) ||
-           (rect->top >= rect->bottom) ||
-            !EXTENTCHECK(rect, &rgnSrc->rdh.rcBound))
-  {
-       goto empty;
-  }
-  else // region box and clipping rect appear to intersect
-  {
-    PRECT lpr, rpr;
-    ULONG i, j, clipa, clipb;
-    INT left = rgnSrc->rdh.rcBound.right + off->x;
-    INT right = rgnSrc->rdh.rcBound.left + off->x;
+            rgnDst->Buffer = xrect;
+        }
+        else
+            return FALSE;
+    }
+    else if ((rect->left >= rect->right) ||
+             (rect->top >= rect->bottom) ||
+             !EXTENTCHECK(rect, &rgnSrc->rdh.rcBound))
+    {
+        goto empty;
+    }
+    else // region box and clipping rect appear to intersect
+    {
+        PRECT lpr, rpr;
+        ULONG i, j, clipa, clipb;
+        INT left = rgnSrc->rdh.rcBound.right + off->x;
+        INT right = rgnSrc->rdh.rcBound.left + off->x;
 
-    for(clipa = 0; ((PRECT)rgnSrc->Buffer + clipa)->bottom <= rect->top; clipa++)
-       //region and rect intersect so we stop before clipa > rgnSrc->rdh.nCount
-      ; // skip bands above the clipping rectangle
+        for (clipa = 0; ((PRECT)rgnSrc->Buffer + clipa)->bottom <= rect->top; clipa++)
+            //region and rect intersect so we stop before clipa > rgnSrc->rdh.nCount
+            ; // skip bands above the clipping rectangle
 
-    for(clipb = clipa; clipb < rgnSrc->rdh.nCount; clipb++)
-      if(((PRECT)rgnSrc->Buffer + clipb)->top >= rect->bottom)
-        break;    // and below it
+        for (clipb = clipa; clipb < rgnSrc->rdh.nCount; clipb++)
+            if (((PRECT)rgnSrc->Buffer + clipb)->top >= rect->bottom)
+                break;    // and below it
 
-    // clipa - index of the first rect in the first intersecting band
-    // clipb - index of the last rect in the last intersecting band
+        // clipa - index of the first rect in the first intersecting band
+        // clipb - index of the last rect in the last intersecting band
 
-    if((rgnDst != rgnSrc) && (rgnDst->rdh.nCount < (i = (clipb - clipa))))
-    {
-         PRECT temp;
-         temp = ExAllocatePoolWithTag( PagedPool, i * sizeof(RECT), TAG_REGION );
-      if(!temp)
-             return FALSE;
+        if ((rgnDst != rgnSrc) && (rgnDst->rdh.nCount < (i = (clipb - clipa))))
+        {
+            PRECT temp;
+            temp = ExAllocatePoolWithTag(PagedPool, i * sizeof(RECT), TAG_REGION);
+            if (!temp)
+                return FALSE;
 
-         if( rgnDst->Buffer && rgnDst->Buffer != &rgnDst->rdh.rcBound )
-               ExFreePool( rgnDst->Buffer ); //free the old buffer
-      rgnDst->Buffer = temp;
-      rgnDst->rdh.nCount = i;
-         rgnDst->rdh.nRgnSize = i * sizeof(RECT);
-    }
+            if (rgnDst->Buffer && rgnDst->Buffer != &rgnDst->rdh.rcBound)
+                ExFreePool(rgnDst->Buffer); //free the old buffer
+            rgnDst->Buffer = temp;
+            rgnDst->rdh.nCount = i;
+            rgnDst->rdh.nRgnSize = i * sizeof(RECT);
+        }
 
-    for(i = clipa, j = 0; i < clipb ; i++)
-    {
-      // i - src index, j - dst index, j is always <= i for obvious reasons
+        for (i = clipa, j = 0; i < clipb ; i++)
+        {
+            // i - src index, j - dst index, j is always <= i for obvious reasons
 
-      lpr = (PRECT)rgnSrc->Buffer + i;
+            lpr = (PRECT)rgnSrc->Buffer + i;
 
-      if(lpr->left < rect->right && lpr->right > rect->left)
-      {
-           rpr = (PRECT)rgnDst->Buffer + j;
+            if (lpr->left < rect->right && lpr->right > rect->left)
+            {
+                rpr = (PRECT)rgnDst->Buffer + j;
 
-        rpr->top = lpr->top + off->y;
-        rpr->bottom = lpr->bottom + off->y;
-        rpr->left = ((lpr->left > rect->left) ? lpr->left : rect->left) + off->x;
-        rpr->right = ((lpr->right < rect->right) ? lpr->right : rect->right) + off->x;
+                rpr->top = lpr->top + off->y;
+                rpr->bottom = lpr->bottom + off->y;
+                rpr->left = ((lpr->left > rect->left) ? lpr->left : rect->left) + off->x;
+                rpr->right = ((lpr->right < rect->right) ? lpr->right : rect->right) + off->x;
 
-        if(rpr->left < left) left = rpr->left;
-        if(rpr->right > right) right = rpr->right;
+                if (rpr->left < left) left = rpr->left;
+                if (rpr->right > right) right = rpr->right;
 
-        j++;
-      }
-    }
+                j++;
+            }
+        }
 
-    if(j == 0) goto empty;
+        if (j == 0) goto empty;
 
-    rgnDst->rdh.rcBound.left = left;
-    rgnDst->rdh.rcBound.right = right;
+        rgnDst->rdh.rcBound.left = left;
+        rgnDst->rdh.rcBound.right = right;
 
-    left = rect->top + off->y;
-    right = rect->bottom + off->y;
+        left = rect->top + off->y;
+        right = rect->bottom + off->y;
 
-    rgnDst->rdh.nCount = j--;
-    for(i = 0; i <= j; i++) // fixup top band
-      if((rgnDst->Buffer + i)->top < left)
-        (rgnDst->Buffer + i)->top = left;
-      else
-        break;
+        rgnDst->rdh.nCount = j--;
+        for (i = 0; i <= j; i++) // fixup top band
+            if ((rgnDst->Buffer + i)->top < left)
+                (rgnDst->Buffer + i)->top = left;
+            else
+                break;
 
-    for(i = j; i > 0; i--) // fixup bottom band
-      if(((PRECT)rgnDst->Buffer + i)->bottom > right)
-        ((PRECT)rgnDst->Buffer + i)->bottom = right;
-      else
-        break;
+        for (i = j; i > 0; i--) // fixup bottom band
+            if (((PRECT)rgnDst->Buffer + i)->bottom > right)
+                ((PRECT)rgnDst->Buffer + i)->bottom = right;
+            else
+                break;
 
-    rgnDst->rdh.rcBound.top = ((PRECT)rgnDst->Buffer)->top;
-    rgnDst->rdh.rcBound.bottom = ((PRECT)rgnDst->Buffer + j)->bottom;
+        rgnDst->rdh.rcBound.top = ((PRECT)rgnDst->Buffer)->top;
+        rgnDst->rdh.rcBound.bottom = ((PRECT)rgnDst->Buffer + j)->bottom;
 
-    rgnDst->rdh.iType = (j >= 1) ? COMPLEXREGION : SIMPLEREGION;
-  }
+        rgnDst->rdh.iType = (j >= 1) ? COMPLEXREGION : SIMPLEREGION;
+    }
 
-  return TRUE;
+    return TRUE;
 
 empty:
-       if(!rgnDst->Buffer)
-       {
-         rgnDst->Buffer = (PRECT)ExAllocatePoolWithTag(PagedPool, RGN_DEFAULT_RECTS * sizeof(RECT), TAG_REGION);
-         if(rgnDst->Buffer){
-           rgnDst->rdh.nCount = RGN_DEFAULT_RECTS;
-               rgnDst->rdh.nRgnSize = RGN_DEFAULT_RECTS * sizeof(RECT);
-         }
-         else
-           return FALSE;
-       }
-       EMPTY_REGION(rgnDst);
-       return TRUE;
+    if (!rgnDst->Buffer)
+    {
+        rgnDst->Buffer = (PRECT)ExAllocatePoolWithTag(PagedPool, RGN_DEFAULT_RECTS * sizeof(RECT), TAG_REGION);
+        if (rgnDst->Buffer)
+        {
+            rgnDst->rdh.nCount = RGN_DEFAULT_RECTS;
+            rgnDst->rdh.nRgnSize = RGN_DEFAULT_RECTS * sizeof(RECT);
+        }
+        else
+            return FALSE;
+    }
+    EMPTY_REGION(rgnDst);
+    return TRUE;
 }
 
 /*!
@@ -710,49 +739,58 @@ empty:
  *
  * \return     hDst if success, 0 otherwise.
  */
-HRGN FASTCALL REGION_CropRgn(HRGN hDst, HRGN hSrc, const PRECT lpRect, PPOINT lpPt)
+HRGN FASTCALL
+REGION_CropRgn(
+    HRGN hDst,
+    HRGN hSrc,
+    const PRECT lpRect,
+    PPOINT lpPt
+)
 {
-  PROSRGNDATA objSrc, rgnDst;
-  HRGN hRet = NULL;
-  POINT pt = { 0, 0 };
+    PROSRGNDATA objSrc, rgnDst;
+    HRGN hRet = NULL;
+    POINT pt = { 0, 0 };
 
-  if( !hDst )
+    if (!hDst)
     {
-      if( !( hDst = RGNDATA_AllocRgn(1) ) )
-       {
-         return 0;
-       }
+        if ( !(hDst = RGNDATA_AllocRgn(1)) )
+        {
+            return 0;
+        }
     }
 
-  rgnDst = RGNDATA_LockRgn(hDst);
-  if(rgnDst == NULL)
-  {
-    return NULL;
-  }
+    rgnDst = RGNDATA_LockRgn(hDst);
+    if (rgnDst == NULL)
+    {
+        return NULL;
+    }
 
-  objSrc = RGNDATA_LockRgn(hSrc);
-  if(objSrc == NULL)
-  {
-    RGNDATA_UnlockRgn(rgnDst);
-    return NULL;
-  }
-  if(!lpPt)
-       lpPt = &pt;
+    objSrc = RGNDATA_LockRgn(hSrc);
+    if (objSrc == NULL)
+    {
+        RGNDATA_UnlockRgn(rgnDst);
+        return NULL;
+    }
+    if (!lpPt)
+        lpPt = &pt;
 
-    if(REGION_CropAndOffsetRegion(lpPt, lpRect, objSrc, rgnDst) == FALSE)
-  { // ve failed cleanup and return
-       hRet = NULL;
+    if (REGION_CropAndOffsetRegion(lpPt, lpRect, objSrc, rgnDst) == FALSE)
+    {
+        // ve failed cleanup and return
+        hRet = NULL;
+    }
+    else  // ve are fine. unlock the correct pointer and return correct handle
+    {
+        hRet = hDst;
     }
-    else{ // ve are fine. unlock the correct pointer and return correct handle
-       hRet = hDst;
-  }
 
-  RGNDATA_UnlockRgn(objSrc);
-  RGNDATA_UnlockRgn(rgnDst);
+    RGNDATA_UnlockRgn(objSrc);
+    RGNDATA_UnlockRgn(rgnDst);
 
-  return hRet;
+    return hRet;
 }
 
+
 /*!
  *      Attempt to merge the rects in the current band with those in the
  *      previous one. Used only by REGION_RegionOp.
@@ -767,11 +805,13 @@ HRGN FASTCALL REGION_CropRgn(HRGN hDst, HRGN hSrc, const PRECT lpRect, PPOINT lp
  *          - pReg->numRects will be decreased.
  *
  */
-static INT FASTCALL REGION_Coalesce (
-            PROSRGNDATA pReg, /* Region to coalesce */
-            INT prevStart,  /* Index of start of previous band */
-            INT curStart    /* Index of start of current band */
-) {
+static INT FASTCALL
+REGION_Coalesce(
+    PROSRGNDATA pReg, /* Region to coalesce */
+    INT prevStart,  /* Index of start of previous band */
+    INT curStart    /* Index of start of current band */
+)
+{
     RECT *pPrevRect;          /* Current rect in previous band */
     RECT *pCurRect;           /* Current rect in current band */
     RECT *pRegEnd;            /* End of region */
@@ -791,97 +831,101 @@ static INT FASTCALL REGION_Coalesce (
     pCurRect = (PRECT)pReg->Buffer + curStart;
     bandtop = pCurRect->top;
     for (curNumRects = 0;
-        (pCurRect != pRegEnd) && (pCurRect->top == bandtop);
-        curNumRects++)
+            (pCurRect != pRegEnd) && (pCurRect->top == bandtop);
+            curNumRects++)
     {
-               pCurRect++;
+        pCurRect++;
     }
 
     if (pCurRect != pRegEnd)
     {
-               /*
-                * If more than one band was added, we have to find the start
-                * of the last band added so the next coalescing job can start
-                * at the right place... (given when multiple bands are added,
-                * this may be pointless -- see above).
-                */
-               pRegEnd--;
-               while ((pRegEnd-1)->top == pRegEnd->top)
-               {
-                   pRegEnd--;
-               }
-               curStart = pRegEnd - (PRECT)pReg->Buffer;
-               pRegEnd = (PRECT)pReg->Buffer + pReg->rdh.nCount;
-    }
-
-    if ((curNumRects == prevNumRects) && (curNumRects != 0)) {
-               pCurRect -= curNumRects;
-               /*
-                * The bands may only be coalesced if the bottom of the previous
-                * matches the top scanline of the current.
-                */
-               if (pPrevRect->bottom == pCurRect->top)
-               {
-                   /*
-                    * Make sure the bands have rects in the same places. This
-                    * assumes that rects have been added in such a way that they
-                    * cover the most area possible. I.e. two rects in a band must
-                    * have some horizontal space between them.
-                    */
-                   do
-                   {
-                               if ((pPrevRect->left != pCurRect->left) ||
-                                   (pPrevRect->right != pCurRect->right))
-                               {
-                                   /*
-                                    * The bands don't line up so they can't be coalesced.
-                                    */
-                                   return (curStart);
-                               }
-                               pPrevRect++;
-                               pCurRect++;
-                               prevNumRects -= 1;
-                   } while (prevNumRects != 0);
-
-                   pReg->rdh.nCount -= curNumRects;
-                   pCurRect -= curNumRects;
-                   pPrevRect -= curNumRects;
-
-                   /*
-                    * The bands may be merged, so set the bottom of each rect
-                    * in the previous band to that of the corresponding rect in
-                    * the current band.
-                    */
-                   do
-                   {
-                               pPrevRect->bottom = pCurRect->bottom;
-                               pPrevRect++;
-                               pCurRect++;
-                               curNumRects -= 1;
-                   } while (curNumRects != 0);
-
-                   /*
-                    * If only one band was added to the region, we have to backup
-                    * curStart to the start of the previous band.
-                    *
-                    * If more than one band was added to the region, copy the
-                    * other bands down. The assumption here is that the other bands
-                    * came from the same region as the current one and no further
-                    * coalescing can be done on them since it's all been done
-                    * already... curStart is already in the right place.
-                    */
-                   if (pCurRect == pRegEnd)
-                   {
-                               curStart = prevStart;
-                   }
-                   else
-                   {
-                               do
-                               {
-                                   *pPrevRect++ = *pCurRect++;
-                               } while (pCurRect != pRegEnd);
-                   }
-               }
+        /*
+         * If more than one band was added, we have to find the start
+         * of the last band added so the next coalescing job can start
+         * at the right place... (given when multiple bands are added,
+         * this may be pointless -- see above).
+         */
+        pRegEnd--;
+        while ((pRegEnd-1)->top == pRegEnd->top)
+        {
+            pRegEnd--;
+        }
+        curStart = pRegEnd - (PRECT)pReg->Buffer;
+        pRegEnd = (PRECT)pReg->Buffer + pReg->rdh.nCount;
+    }
+
+    if ((curNumRects == prevNumRects) && (curNumRects != 0))
+    {
+        pCurRect -= curNumRects;
+        /*
+         * The bands may only be coalesced if the bottom of the previous
+         * matches the top scanline of the current.
+         */
+        if (pPrevRect->bottom == pCurRect->top)
+        {
+            /*
+             * Make sure the bands have rects in the same places. This
+             * assumes that rects have been added in such a way that they
+             * cover the most area possible. I.e. two rects in a band must
+             * have some horizontal space between them.
+             */
+            do
+            {
+                if ((pPrevRect->left != pCurRect->left) ||
+                        (pPrevRect->right != pCurRect->right))
+                {
+                    /*
+                     * The bands don't line up so they can't be coalesced.
+                     */
+                    return (curStart);
+                }
+                pPrevRect++;
+                pCurRect++;
+                prevNumRects -= 1;
+            }
+            while (prevNumRects != 0);
+
+            pReg->rdh.nCount -= curNumRects;
+            pCurRect -= curNumRects;
+            pPrevRect -= curNumRects;
+
+            /*
+             * The bands may be merged, so set the bottom of each rect
+             * in the previous band to that of the corresponding rect in
+             * the current band.
+             */
+            do
+            {
+                pPrevRect->bottom = pCurRect->bottom;
+                pPrevRect++;
+                pCurRect++;
+                curNumRects -= 1;
+            }
+            while (curNumRects != 0);
+
+            /*
+             * If only one band was added to the region, we have to backup
+             * curStart to the start of the previous band.
+             *
+             * If more than one band was added to the region, copy the
+             * other bands down. The assumption here is that the other bands
+             * came from the same region as the current one and no further
+             * coalescing can be done on them since it's all been done
+             * already... curStart is already in the right place.
+             */
+            if (pCurRect == pRegEnd)
+            {
+                curStart = prevStart;
+            }
+            else
+            {
+                do
+                {
+                    *pPrevRect++ = *pCurRect++;
+                }
+                while (pCurRect != pRegEnd);
+            }
+        }
     }
     return (curStart);
 }
@@ -910,13 +954,13 @@ static INT FASTCALL REGION_Coalesce (
  */
 static void FASTCALL
 REGION_RegionOp(
-       ROSRGNDATA *newReg, /* Place to store result */
-       ROSRGNDATA *reg1,   /* First region in operation */
-       ROSRGNDATA *reg2,   /* 2nd region in operation */
-       overlapProcp overlapFunc,     /* Function to call for over-lapping bands */
-       nonOverlapProcp nonOverlap1Func, /* Function to call for non-overlapping bands in region 1 */
-       nonOverlapProcp nonOverlap2Func  /* Function to call for non-overlapping bands in region 2 */
-       )
+    ROSRGNDATA *newReg, /* Place to store result */
+    ROSRGNDATA *reg1,   /* First region in operation */
+    ROSRGNDATA *reg2,   /* 2nd region in operation */
+    overlapProcp overlapFunc,     /* Function to call for over-lapping bands */
+    nonOverlapProcp nonOverlap1Func, /* Function to call for non-overlapping bands in region 1 */
+    nonOverlapProcp nonOverlap2Func  /* Function to call for non-overlapping bands in region 2 */
+)
 {
     RECT *r1;                         /* Pointer into first region */
     RECT *r2;                         /* Pointer into 2d region */
@@ -964,10 +1008,10 @@ REGION_RegionOp(
      */
     newReg->rdh.nRgnSize = max(reg1->rdh.nCount,reg2->rdh.nCount) * 2 * sizeof(RECT);
 
-    if (! (newReg->Buffer = ExAllocatePoolWithTag( PagedPool, newReg->rdh.nRgnSize, TAG_REGION )))
+    if (! (newReg->Buffer = ExAllocatePoolWithTag(PagedPool, newReg->rdh.nRgnSize, TAG_REGION)))
     {
-               newReg->rdh.nRgnSize = 0;
-               return;
+        newReg->rdh.nRgnSize = 0;
+        return;
     }
 
     /*
@@ -984,9 +1028,9 @@ REGION_RegionOp(
      * the top of the rectangles of both regions and ybot clips the bottoms.
      */
     if (reg1->rdh.rcBound.top < reg2->rdh.rcBound.top)
-               ybot = reg1->rdh.rcBound.top;
+        ybot = reg1->rdh.rcBound.top;
     else
-               ybot = reg2->rdh.rcBound.top;
+        ybot = reg2->rdh.rcBound.top;
 
     /*
      * prevBand serves to mark the start of the previous band so rectangles
@@ -1001,104 +1045,105 @@ REGION_RegionOp(
 
     do
     {
-               curBand = newReg->rdh.nCount;
-
-               /*
-                * This algorithm proceeds one source-band (as opposed to a
-                * destination band, which is determined by where the two regions
-                * intersect) at a time. r1BandEnd and r2BandEnd serve to mark the
-                * rectangle after the last one in the current band for their
-                * respective regions.
-                */
-               r1BandEnd = r1;
-               while ((r1BandEnd != r1End) && (r1BandEnd->top == r1->top))
-               {
-                   r1BandEnd++;
-               }
-
-               r2BandEnd = r2;
-               while ((r2BandEnd != r2End) && (r2BandEnd->top == r2->top))
-               {
-                   r2BandEnd++;
-               }
-
-               /*
-                * First handle the band that doesn't intersect, if any.
-                *
-                * Note that attention is restricted to one band in the
-                * non-intersecting region at once, so if a region has n
-                * bands between the current position and the next place it overlaps
-                * the other, this entire loop will be passed through n times.
-                */
-               if (r1->top < r2->top)
-               {
-                   top = max(r1->top,ybot);
-                   bot = min(r1->bottom,r2->top);
-
-                   if ((top != bot) && (nonOverlap1Func != NULL))
-                   {
-                               (* nonOverlap1Func) (newReg, r1, r1BandEnd, top, bot);
-                   }
-
-                   ytop = r2->top;
-               }
-               else if (r2->top < r1->top)
-               {
-                   top = max(r2->top,ybot);
-                   bot = min(r2->bottom,r1->top);
-
-                   if ((top != bot) && (nonOverlap2Func != NULL))
-                   {
-                               (* nonOverlap2Func) (newReg, r2, r2BandEnd, top, bot);
-                   }
-
-                   ytop = r1->top;
-               }
-               else
-               {
-                   ytop = r1->top;
-               }
-
-               /*
-                * If any rectangles got added to the region, try and coalesce them
-                * with rectangles from the previous band. Note we could just do
-                * this test in miCoalesce, but some machines incur a not
-                * inconsiderable cost for function calls, so...
-                */
-               if (newReg->rdh.nCount != curBand)
-               {
-                   prevBand = REGION_Coalesce (newReg, prevBand, curBand);
-               }
-
-               /*
-                * Now see if we've hit an intersecting band. The two bands only
-                * intersect if ybot > ytop
-                */
-               ybot = min(r1->bottom, r2->bottom);
-               curBand = newReg->rdh.nCount;
-               if (ybot > ytop)
-               {
-                   (* overlapFunc) (newReg, r1, r1BandEnd, r2, r2BandEnd, ytop, ybot);
-               }
-
-               if (newReg->rdh.nCount != curBand)
-               {
-                   prevBand = REGION_Coalesce (newReg, prevBand, curBand);
-               }
-
-               /*
-                * If we've finished with a band (bottom == ybot) we skip forward
-                * in the region to the next band.
-                */
-               if (r1->bottom == ybot)
-               {
-                   r1 = r1BandEnd;
-               }
-               if (r2->bottom == ybot)
-               {
-                   r2 = r2BandEnd;
-               }
-    } while ((r1 != r1End) && (r2 != r2End));
+        curBand = newReg->rdh.nCount;
+
+        /*
+         * This algorithm proceeds one source-band (as opposed to a
+         * destination band, which is determined by where the two regions
+         * intersect) at a time. r1BandEnd and r2BandEnd serve to mark the
+         * rectangle after the last one in the current band for their
+         * respective regions.
+         */
+        r1BandEnd = r1;
+        while ((r1BandEnd != r1End) && (r1BandEnd->top == r1->top))
+        {
+            r1BandEnd++;
+        }
+
+        r2BandEnd = r2;
+        while ((r2BandEnd != r2End) && (r2BandEnd->top == r2->top))
+        {
+            r2BandEnd++;
+        }
+
+        /*
+         * First handle the band that doesn't intersect, if any.
+         *
+         * Note that attention is restricted to one band in the
+         * non-intersecting region at once, so if a region has n
+         * bands between the current position and the next place it overlaps
+         * the other, this entire loop will be passed through n times.
+         */
+        if (r1->top < r2->top)
+        {
+            top = max(r1->top,ybot);
+            bot = min(r1->bottom,r2->top);
+
+            if ((top != bot) && (nonOverlap1Func != NULL))
+            {
+                (* nonOverlap1Func) (newReg, r1, r1BandEnd, top, bot);
+            }
+
+            ytop = r2->top;
+        }
+        else if (r2->top < r1->top)
+        {
+            top = max(r2->top,ybot);
+            bot = min(r2->bottom,r1->top);
+
+            if ((top != bot) && (nonOverlap2Func != NULL))
+            {
+                (* nonOverlap2Func) (newReg, r2, r2BandEnd, top, bot);
+            }
+
+            ytop = r1->top;
+        }
+        else
+        {
+            ytop = r1->top;
+        }
+
+        /*
+         * If any rectangles got added to the region, try and coalesce them
+         * with rectangles from the previous band. Note we could just do
+         * this test in miCoalesce, but some machines incur a not
+         * inconsiderable cost for function calls, so...
+         */
+        if (newReg->rdh.nCount != curBand)
+        {
+            prevBand = REGION_Coalesce (newReg, prevBand, curBand);
+        }
+
+        /*
+         * Now see if we've hit an intersecting band. The two bands only
+         * intersect if ybot > ytop
+         */
+        ybot = min(r1->bottom, r2->bottom);
+        curBand = newReg->rdh.nCount;
+        if (ybot > ytop)
+        {
+            (* overlapFunc) (newReg, r1, r1BandEnd, r2, r2BandEnd, ytop, ybot);
+        }
+
+        if (newReg->rdh.nCount != curBand)
+        {
+            prevBand = REGION_Coalesce (newReg, prevBand, curBand);
+        }
+
+        /*
+         * If we've finished with a band (bottom == ybot) we skip forward
+         * in the region to the next band.
+         */
+        if (r1->bottom == ybot)
+        {
+            r1 = r1BandEnd;
+        }
+        if (r2->bottom == ybot)
+        {
+            r2 = r2BandEnd;
+        }
+    }
+    while ((r1 != r1End) && (r2 != r2End));
 
     /*
      * Deal with whichever region still has rectangles left.
@@ -1106,39 +1151,41 @@ REGION_RegionOp(
     curBand = newReg->rdh.nCount;
     if (r1 != r1End)
     {
-               if (nonOverlap1Func != NULL)
-               {
-                   do
-                   {
-                               r1BandEnd = r1;
-                               while ((r1BandEnd < r1End) && (r1BandEnd->top == r1->top))
-                               {
-                                   r1BandEnd++;
-                               }
-                               (* nonOverlap1Func) (newReg, r1, r1BandEnd,
-                                                    max(r1->top,ybot), r1->bottom);
-                               r1 = r1BandEnd;
-                   } while (r1 != r1End);
-               }
+        if (nonOverlap1Func != NULL)
+        {
+            do
+            {
+                r1BandEnd = r1;
+                while ((r1BandEnd < r1End) && (r1BandEnd->top == r1->top))
+                {
+                    r1BandEnd++;
+                }
+                (* nonOverlap1Func) (newReg, r1, r1BandEnd,
+                                     max(r1->top,ybot), r1->bottom);
+                r1 = r1BandEnd;
+            }
+            while (r1 != r1End);
+        }
     }
     else if ((r2 != r2End) && (nonOverlap2Func != NULL))
     {
-               do
-               {
-                   r2BandEnd = r2;
-                   while ((r2BandEnd < r2End) && (r2BandEnd->top == r2->top))
-                   {
-                        r2BandEnd++;
-                   }
-                   (* nonOverlap2Func) (newReg, r2, r2BandEnd,
-                                       max(r2->top,ybot), r2->bottom);
-                   r2 = r2BandEnd;
-               } while (r2 != r2End);
+        do
+        {
+            r2BandEnd = r2;
+            while ((r2BandEnd < r2End) && (r2BandEnd->top == r2->top))
+            {
+                r2BandEnd++;
+            }
+            (* nonOverlap2Func) (newReg, r2, r2BandEnd,
+                                 max(r2->top,ybot), r2->bottom);
+            r2 = r2BandEnd;
+        }
+        while (r2 != r2End);
     }
 
     if (newReg->rdh.nCount != curBand)
     {
-               (void) REGION_Coalesce (newReg, prevBand, curBand);
+        (void) REGION_Coalesce (newReg, prevBand, curBand);
     }
 
     /*
@@ -1151,41 +1198,42 @@ REGION_RegionOp(
      */
     if ((2 * newReg->rdh.nCount*sizeof(RECT) < newReg->rdh.nRgnSize && (newReg->rdh.nCount > 2)))
     {
-               if (REGION_NOT_EMPTY(newReg))
-               {
-                   RECT *prev_rects = (PRECT)newReg->Buffer;
-                   newReg->Buffer = ExAllocatePoolWithTag( PagedPool, newReg->rdh.nCount*sizeof(RECT), TAG_REGION );
-
-                   if (! newReg->Buffer)
-                               newReg->Buffer = prev_rects;
-                       else{
-                               newReg->rdh.nRgnSize = newReg->rdh.nCount*sizeof(RECT);
-                               COPY_RECTS(newReg->Buffer, prev_rects, newReg->rdh.nCount);
-                               if (prev_rects != &newReg->rdh.rcBound)
-                                       ExFreePool( prev_rects );
-                       }
-               }
-               else
-               {
-                   /*
-                    * No point in doing the extra work involved in an Xrealloc if
-                    * the region is empty
-                    */
-                   newReg->rdh.nRgnSize = sizeof(RECT);
-                   if (newReg->Buffer != &newReg->rdh.rcBound)
-                       ExFreePool( newReg->Buffer );
-                   newReg->Buffer = ExAllocatePoolWithTag( PagedPool, sizeof(RECT), TAG_REGION );
-                       ASSERT( newReg->Buffer );
-               }
-    }
-
-       if( newReg->rdh.nCount == 0 )
-               newReg->rdh.iType = NULLREGION;
-       else
-               newReg->rdh.iType = (newReg->rdh.nCount > 1)? COMPLEXREGION : SIMPLEREGION;
-
-       if (oldRects != &newReg->rdh.rcBound)
-               ExFreePool( oldRects );
+        if (REGION_NOT_EMPTY(newReg))
+        {
+            RECT *prev_rects = (PRECT)newReg->Buffer;
+            newReg->Buffer = ExAllocatePoolWithTag(PagedPool, newReg->rdh.nCount*sizeof(RECT), TAG_REGION);
+
+            if (! newReg->Buffer)
+                newReg->Buffer = prev_rects;
+            else
+            {
+                newReg->rdh.nRgnSize = newReg->rdh.nCount*sizeof(RECT);
+                COPY_RECTS(newReg->Buffer, prev_rects, newReg->rdh.nCount);
+                if (prev_rects != &newReg->rdh.rcBound)
+                    ExFreePool(prev_rects);
+            }
+        }
+        else
+        {
+            /*
+             * No point in doing the extra work involved in an Xrealloc if
+             * the region is empty
+             */
+            newReg->rdh.nRgnSize = sizeof(RECT);
+            if (newReg->Buffer != &newReg->rdh.rcBound)
+                ExFreePool(newReg->Buffer);
+            newReg->Buffer = ExAllocatePoolWithTag(PagedPool, sizeof(RECT), TAG_REGION);
+            ASSERT(newReg->Buffer);
+        }
+    }
+
+    if (newReg->rdh.nCount == 0)
+        newReg->rdh.iType = NULLREGION;
+    else
+        newReg->rdh.iType = (newReg->rdh.nCount > 1)? COMPLEXREGION : SIMPLEREGION;
+
+    if (oldRects != &newReg->rdh.rcBound)
+        ExFreePool(oldRects);
     return;
 }
 
@@ -1205,15 +1253,15 @@ REGION_RegionOp(
  *
  */
 static void FASTCALL
-REGION_IntersectO (
-       PROSRGNDATA pReg,
-       PRECT       r1,
-       PRECT       r1End,
-       PRECT       r2,
-       PRECT       r2End,
-       INT         top,
-       INT         bottom
-       )
+REGION_IntersectO(
+    PROSRGNDATA pReg,
+    PRECT       r1,
+    PRECT       r1End,
+    PRECT       r2,
+    PRECT       r2End,
+    INT         top,
+    INT         bottom
+)
 {
     INT       left, right;
     RECT      *pNextRect;
@@ -1222,45 +1270,45 @@ REGION_IntersectO (
 
     while ((r1 != r1End) && (r2 != r2End))
     {
-               left = max(r1->left, r2->left);
-               right = min(r1->right, r2->right);
-
-               /*
-                * If there's any overlap between the two rectangles, add that
-                * overlap to the new region.
-                * There's no need to check for subsumption because the only way
-                * such a need could arise is if some region has two rectangles
-                * right next to each other. Since that should never happen...
-                */
-               if (left < right)
-               {
-                   MEMCHECK(pReg, pNextRect, pReg->Buffer);
-                   pNextRect->left = left;
-                   pNextRect->top = top;
-                   pNextRect->right = right;
-                   pNextRect->bottom = bottom;
-                   pReg->rdh.nCount += 1;
-                   pNextRect++;
-               }
-
-               /*
-                * Need to advance the pointers. Shift the one that extends
-                * to the right the least, since the other still has a chance to
-                * overlap with that region's next rectangle, if you see what I mean.
-                */
-               if (r1->right < r2->right)
-               {
-                   r1++;
-               }
-               else if (r2->right < r1->right)
-               {
-                   r2++;
-               }
-               else
-               {
-                   r1++;
-                   r2++;
-               }
+        left = max(r1->left, r2->left);
+        right =        min(r1->right, r2->right);
+
+        /*
+         * If there's any overlap between the two rectangles, add that
+         * overlap to the new region.
+         * There's no need to check for subsumption because the only way
+         * such a need could arise is if some region has two rectangles
+         * right next to each other. Since that should never happen...
+         */
+        if (left < right)
+        {
+            MEMCHECK(pReg, pNextRect, pReg->Buffer);
+            pNextRect->left = left;
+            pNextRect->top = top;
+            pNextRect->right = right;
+            pNextRect->bottom = bottom;
+            pReg->rdh.nCount += 1;
+            pNextRect++;
+        }
+
+        /*
+         * Need to advance the pointers. Shift the one that extends
+         * to the right the least, since the other still has a chance to
+         * overlap with that region's next rectangle, if you see what I mean.
+         */
+        if (r1->right < r2->right)
+        {
+            r1++;
+        }
+        else if (r2->right < r1->right)
+        {
+            r2++;
+        }
+        else
+        {
+            r1++;
+            r2++;
+        }
     }
     return;
 }
@@ -1268,16 +1316,20 @@ REGION_IntersectO (
 /***********************************************************************
  *          REGION_IntersectRegion
  */
-static void FASTCALL REGION_IntersectRegion(ROSRGNDATA *newReg, ROSRGNDATA *reg1,
-                                  ROSRGNDATA *reg2)
+static void FASTCALL
+REGION_IntersectRegion(
+    ROSRGNDATA *newReg,
+    ROSRGNDATA *reg1,
+    ROSRGNDATA *reg2
+)
 {
-  /* check for trivial reject */
-  if ( (!(reg1->rdh.nCount)) || (!(reg2->rdh.nCount))  ||
-    (!EXTENTCHECK(&reg1->rdh.rcBound, &reg2->rdh.rcBound)))
-    newReg->rdh.nCount = 0;
-  else
-    REGION_RegionOp (newReg, reg1, reg2,
-      REGION_IntersectO, NULL, NULL);
+    /* check for trivial reject */
+    if ( (!(reg1->rdh.nCount)) || (!(reg2->rdh.nCount))  ||
+         (!EXTENTCHECK(&reg1->rdh.rcBound, &reg2->rdh.rcBound)) )
+        newReg->rdh.nCount = 0;
+    else
+        REGION_RegionOp (newReg, reg1, reg2,
+                         REGION_IntersectO, NULL, NULL);
 
     /*
      * Can't alter newReg's extents before we call miRegionOp because
@@ -1309,12 +1361,12 @@ static void FASTCALL REGION_IntersectRegion(ROSRGNDATA *newReg, ROSRGNDATA *reg1
  */
 static void FASTCALL
 REGION_UnionNonO (
-       PROSRGNDATA pReg,
-       PRECT       r,
-       PRECT       rEnd,
-       INT         top,
-       INT         bottom
-       )
+    PROSRGNDATA pReg,
+    PRECT       r,
+    PRECT       rEnd,
+    INT         top,
+    INT         bottom
+)
 {
     RECT *pNextRect;
 
@@ -1322,14 +1374,14 @@ REGION_UnionNonO (
 
     while (r != rEnd)
     {
-               MEMCHECK(pReg, pNextRect, pReg->Buffer);
-               pNextRect->left = r->left;
-               pNextRect->top = top;
-               pNextRect->right = r->right;
-               pNextRect->bottom = bottom;
-               pReg->rdh.nCount += 1;
-               pNextRect++;
-               r++;
+        MEMCHECK(pReg, pNextRect, pReg->Buffer);
+        pNextRect->left = r->left;
+        pNextRect->top = top;
+        pNextRect->right = r->right;
+        pNextRect->bottom = bottom;
+        pReg->rdh.nCount += 1;
+        pNextRect++;
+        r++;
     }
     return;
 }
@@ -1348,14 +1400,14 @@ REGION_UnionNonO (
  */
 static void FASTCALL
 REGION_UnionO (
-       PROSRGNDATA pReg,
-       PRECT       r1,
-       PRECT       r1End,
-       PRECT       r2,
-       PRECT       r2End,
-       INT         top,
-       INT         bottom
-       )
+    PROSRGNDATA pReg,
+    PRECT       r1,
+    PRECT       r1End,
+    PRECT       r2,
+    PRECT       r2End,
+    INT         top,
+    INT         bottom
+)
 {
     RECT *pNextRect;
 
@@ -1386,104 +1438,109 @@ REGION_UnionO (
 
     while ((r1 != r1End) && (r2 != r2End))
     {
-               if (r1->left < r2->left)
-               {
-                   MERGERECT(r1);
-               }
-               else
-               {
-                   MERGERECT(r2);
-               }
+        if (r1->left < r2->left)
+        {
+            MERGERECT(r1);
+        }
+        else
+        {
+            MERGERECT(r2);
+        }
     }
 
     if (r1 != r1End)
     {
-               do
-               {
-                   MERGERECT(r1);
-               } while (r1 != r1End);
+        do
+        {
+            MERGERECT(r1);
+        }
+        while (r1 != r1End);
     }
     else while (r2 != r2End)
-    {
-               MERGERECT(r2);
-    }
+        {
+            MERGERECT(r2);
+        }
     return;
 }
 
 /***********************************************************************
  *          REGION_UnionRegion
  */
-static void FASTCALL REGION_UnionRegion(ROSRGNDATA *newReg, ROSRGNDATA *reg1,
-                              ROSRGNDATA *reg2)
+static void FASTCALL
+REGION_UnionRegion(
+    ROSRGNDATA *newReg,
+    ROSRGNDATA *reg1,
+    ROSRGNDATA *reg2
+)
 {
-  /*  checks all the simple cases */
+    /*  checks all the simple cases */
 
-  /*
-   * Region 1 and 2 are the same or region 1 is empty
-   */
-  if (reg1 == reg2 || 0 == reg1->rdh.nCount ||
-      reg1->rdh.rcBound.right <= reg1->rdh.rcBound.left ||
-      reg1->rdh.rcBound.bottom <= reg1->rdh.rcBound.top)
+    /*
+     * Region 1 and 2 are the same or region 1 is empty
+     */
+    if (reg1 == reg2 || 0 == reg1->rdh.nCount ||
+            reg1->rdh.rcBound.right <= reg1->rdh.rcBound.left ||
+            reg1->rdh.rcBound.bottom <= reg1->rdh.rcBound.top)
     {
-      if (newReg != reg2)
-       {
-         REGION_CopyRegion(newReg, reg2);
-       }
-      return;
+        if (newReg != reg2)
+        {
+            REGION_CopyRegion(newReg, reg2);
+        }
+        return;
     }
 
     /*
      * if nothing to union (region 2 empty)
      */
-  if (0 == reg2->rdh.nCount ||
-      reg2->rdh.rcBound.right <= reg2->rdh.rcBound.left ||
-      reg2->rdh.rcBound.bottom <= reg2->rdh.rcBound.top)
-    {
-      if (newReg != reg1)
-       {
-         REGION_CopyRegion(newReg, reg1);
-       }
-      return;
-    }
-
-  /*
-   * Region 1 completely subsumes region 2
-   */
-  if (1 == reg1->rdh.nCount &&
-      reg1->rdh.rcBound.left <= reg2->rdh.rcBound.left &&
-      reg1->rdh.rcBound.top <= reg2->rdh.rcBound.top &&
-      reg2->rdh.rcBound.right <= reg1->rdh.rcBound.right &&
-      reg2->rdh.rcBound.bottom <= reg1->rdh.rcBound.bottom)
-    {
-      if (newReg != reg1)
-       {
-         REGION_CopyRegion(newReg, reg1);
-       }
-      return;
-    }
-
-  /*
-   * Region 2 completely subsumes region 1
-   */
-  if (1 == reg2->rdh.nCount &&
-      reg2->rdh.rcBound.left <= reg1->rdh.rcBound.left &&
-      reg2->rdh.rcBound.top <= reg1->rdh.rcBound.top &&
-      reg1->rdh.rcBound.right <= reg2->rdh.rcBound.right &&
-      reg1->rdh.rcBound.bottom <= reg2->rdh.rcBound.bottom)
-    {
-      if (newReg != reg2)
-       {
-         REGION_CopyRegion(newReg, reg2);
-       }
-      return;
-    }
-
-  REGION_RegionOp ( newReg, reg1, reg2, REGION_UnionO,
-                 REGION_UnionNonO, REGION_UnionNonO );
-  newReg->rdh.rcBound.left = min(reg1->rdh.rcBound.left, reg2->rdh.rcBound.left);
-  newReg->rdh.rcBound.top = min(reg1->rdh.rcBound.top, reg2->rdh.rcBound.top);
-  newReg->rdh.rcBound.right = max(reg1->rdh.rcBound.right, reg2->rdh.rcBound.right);
-  newReg->rdh.rcBound.bottom = max(reg1->rdh.rcBound.bottom, reg2->rdh.rcBound.bottom);
+    if (0 == reg2->rdh.nCount ||
+            reg2->rdh.rcBound.right <= reg2->rdh.rcBound.left ||
+            reg2->rdh.rcBound.bottom <= reg2->rdh.rcBound.top)
+    {
+        if (newReg != reg1)
+        {
+            REGION_CopyRegion(newReg, reg1);
+        }
+        return;
+    }
+
+    /*
+     * Region 1 completely subsumes region 2
+     */
+    if (1 == reg1->rdh.nCount &&
+            reg1->rdh.rcBound.left <= reg2->rdh.rcBound.left &&
+            reg1->rdh.rcBound.top <= reg2->rdh.rcBound.top &&
+            reg2->rdh.rcBound.right <= reg1->rdh.rcBound.right &&
+            reg2->rdh.rcBound.bottom <= reg1->rdh.rcBound.bottom)
+    {
+        if (newReg != reg1)
+        {
+            REGION_CopyRegion(newReg, reg1);
+        }
+        return;
+    }
+
+    /*
+     * Region 2 completely subsumes region 1
+     */
+    if (1 == reg2->rdh.nCount &&
+            reg2->rdh.rcBound.left <= reg1->rdh.rcBound.left &&
+            reg2->rdh.rcBound.top <= reg1->rdh.rcBound.top &&
+            reg1->rdh.rcBound.right <= reg2->rdh.rcBound.right &&
+            reg1->rdh.rcBound.bottom <= reg2->rdh.rcBound.bottom)
+    {
+        if (newReg != reg2)
+        {
+            REGION_CopyRegion(newReg, reg2);
+        }
+        return;
+    }
+
+    REGION_RegionOp (newReg, reg1, reg2, REGION_UnionO,
+                     REGION_UnionNonO, REGION_UnionNonO);
+    newReg->rdh.rcBound.left = min(reg1->rdh.rcBound.left, reg2->rdh.rcBound.left);
+    newReg->rdh.rcBound.top = min(reg1->rdh.rcBound.top, reg2->rdh.rcBound.top);
+    newReg->rdh.rcBound.right = max(reg1->rdh.rcBound.right, reg2->rdh.rcBound.right);
+    newReg->rdh.rcBound.bottom = max(reg1->rdh.rcBound.bottom, reg2->rdh.rcBound.bottom);
 }
 
 /***********************************************************************
@@ -1502,13 +1559,13 @@ static void FASTCALL REGION_UnionRegion(ROSRGNDATA *newReg, ROSRGNDATA *reg1,
  *
  */
 static void FASTCALL
-REGION_SubtractNonO1 (
-       PROSRGNDATA pReg,
-       PRECT       r,
-       PRECT       rEnd,
-       INT         top,
-       INT         bottom
-       )
+REGION_SubtractNonO1(
+    PROSRGNDATA pReg,
+    PRECT       r,
+    PRECT       rEnd,
+    INT         top,
+    INT         bottom
+)
 {
     RECT *pNextRect;
 
@@ -1516,14 +1573,14 @@ REGION_SubtractNonO1 (
 
     while (r != rEnd)
     {
-               MEMCHECK(pReg, pNextRect, pReg->Buffer);
-               pNextRect->left = r->left;
-               pNextRect->top = top;
-               pNextRect->right = r->right;
-               pNextRect->bottom = bottom;
-               pReg->rdh.nCount += 1;
-               pNextRect++;
-               r++;
+        MEMCHECK(pReg, pNextRect, pReg->Buffer);
+        pNextRect->left = r->left;
+        pNextRect->top = top;
+        pNextRect->right = r->right;
+        pNextRect->bottom = bottom;
+        pReg->rdh.nCount += 1;
+        pNextRect++;
+        r++;
     }
     return;
 }
@@ -1541,15 +1598,15 @@ REGION_SubtractNonO1 (
  *
  */
 static void FASTCALL
-REGION_SubtractO (
-       PROSRGNDATA pReg,
-       PRECT       r1,
-       PRECT       r1End,
-       PRECT       r2,
-       PRECT       r2End,
-       INT         top,
-       INT         bottom
-       )
+REGION_SubtractO(
+    PROSRGNDATA pReg,
+    PRECT       r1,
+    PRECT       r1End,
+    PRECT       r2,
+    PRECT       r2End,
+    INT         top,
+    INT         bottom
+)
 {
     RECT *pNextRect;
     INT left;
@@ -1559,87 +1616,87 @@ REGION_SubtractO (
 
     while ((r1 != r1End) && (r2 != r2End))
     {
-               if (r2->right <= left)
-               {
-                   /*
-                    * Subtrahend missed the boat: go to next subtrahend.
-                    */
-                   r2++;
-               }
-               else if (r2->left <= left)
-               {
-                   /*
-                    * Subtrahend preceeds minuend: nuke left edge of minuend.
-                    */
-                   left = r2->right;
-                   if (left >= r1->right)
-                   {
-                       /*
-                        * Minuend completely covered: advance to next minuend and
-                        * reset left fence to edge of new minuend.
-                        */
-                       r1++;
-                       if (r1 != r1End)
-                           left = r1->left;
-                   }
-                   else
-                   {
-                       /*
-                        * Subtrahend now used up since it doesn't extend beyond
-                        * minuend
-                        */
-                       r2++;
-                   }
-               }
-               else if (r2->left < r1->right)
-               {
-                   /*
-                    * Left part of subtrahend covers part of minuend: add uncovered
-                    * part of minuend to region and skip to next subtrahend.
-                    */
-                   MEMCHECK(pReg, pNextRect, pReg->Buffer);
-                   pNextRect->left = left;
-                   pNextRect->top = top;
-                   pNextRect->right = r2->left;
-                   pNextRect->bottom = bottom;
-                   pReg->rdh.nCount += 1;
-                   pNextRect++;
-                   left = r2->right;
-                   if (left >= r1->right)
-                   {
-                       /*
-                        * Minuend used up: advance to new...
-                        */
-                       r1++;
-                       if (r1 != r1End)
-                           left = r1->left;
-                   }
-                   else
-                   {
-                       /*
-                        * Subtrahend used up
-                        */
-                       r2++;
-                   }
-               }
-               else
-               {
-                   /*
-                    * Minuend used up: add any remaining piece before advancing.
-                    */
-                   if (r1->right > left)
-                   {
-                               MEMCHECK(pReg, pNextRect, pReg->Buffer);
-                               pNextRect->left = left;
-                               pNextRect->top = top;
-                               pNextRect->right = r1->right;
-                               pNextRect->bottom = bottom;
-                               pReg->rdh.nCount += 1;
-                               pNextRect++;
-                   }
-                   r1++;
-                   left = r1->left;
-               }
+        if (r2->right <= left)
+        {
+            /*
+             * Subtrahend missed the boat: go to next subtrahend.
+             */
+            r2++;
+        }
+        else if (r2->left <= left)
+        {
+            /*
+             * Subtrahend preceeds minuend: nuke left edge of minuend.
+             */
+            left = r2->right;
+            if (left >= r1->right)
+            {
+                /*
+                 * Minuend completely covered: advance to next minuend and
+                 * reset left fence to edge of new minuend.
+                 */
+                r1++;
+                if (r1 != r1End)
+                    left = r1->left;
+            }
+            else
+            {
+                /*
+                 * Subtrahend now used up since it doesn't extend beyond
+                 * minuend
+                 */
+                r2++;
+            }
+        }
+        else if (r2->left < r1->right)
+        {
+            /*
+             * Left part of subtrahend covers part of minuend: add uncovered
+             * part of minuend to region and skip to next subtrahend.
+             */
+            MEMCHECK(pReg, pNextRect, pReg->Buffer);
+            pNextRect->left = left;
+            pNextRect->top = top;
+            pNextRect->right = r2->left;
+            pNextRect->bottom = bottom;
+            pReg->rdh.nCount += 1;
+            pNextRect++;
+            left = r2->right;
+            if (left >= r1->right)
+            {
+                /*
+                 * Minuend used up: advance to new...
+                 */
+                r1++;
+                if (r1 != r1End)
+                    left = r1->left;
+            }
+            else
+            {
+                /*
+                 * Subtrahend used up
+                 */
+                r2++;
+            }
+        }
+        else
+        {
+            /*
+             * Minuend used up: add any remaining piece before advancing.
+             */
+            if (r1->right > left)
+            {
+                MEMCHECK(pReg, pNextRect, pReg->Buffer);
+                pNextRect->left = left;
+                pNextRect->top = top;
+                pNextRect->right = r1->right;
+                pNextRect->bottom = bottom;
+                pReg->rdh.nCount += 1;
+                pNextRect++;
+            }
+            r1++;
+            left = r1->left;
+        }
     }
 
     /*
@@ -1647,18 +1704,18 @@ REGION_SubtractO (
      */
     while (r1 != r1End)
     {
-               MEMCHECK(pReg, pNextRect, pReg->Buffer);
-               pNextRect->left = left;
-               pNextRect->top = top;
-               pNextRect->right = r1->right;
-               pNextRect->bottom = bottom;
-               pReg->rdh.nCount += 1;
-               pNextRect++;
-               r1++;
-               if (r1 != r1End)
-               {
-                   left = r1->left;
-               }
+        MEMCHECK(pReg, pNextRect, pReg->Buffer);
+        pNextRect->left = left;
+        pNextRect->top = top;
+        pNextRect->right = r1->right;
+        pNextRect->bottom = bottom;
+        pReg->rdh.nCount += 1;
+        pNextRect++;
+        r1++;
+        if (r1 != r1End)
+        {
+            left = r1->left;
+        }
     }
     return;
 }
@@ -1674,19 +1731,23 @@ REGION_SubtractO (
  *      regD is overwritten.
  *
  */
-static void FASTCALL REGION_SubtractRegion(ROSRGNDATA *regD, ROSRGNDATA *regM,
-                                                      ROSRGNDATA *regS )
+static void FASTCALL
+REGION_SubtractRegion(
+    ROSRGNDATA *regD,
+    ROSRGNDATA *regM,
+    ROSRGNDATA *regS
+)
 {
-   /* check for trivial reject */
+    /* check for trivial reject */
     if ( (!(regM->rdh.nCount)) || (!(regS->rdh.nCount))  ||
-               (!EXTENTCHECK(&regM->rdh.rcBound, &regS->rdh.rcBound)) )
+         (!EXTENTCHECK(&regM->rdh.rcBound, &regS->rdh.rcBound)) )
     {
-               REGION_CopyRegion(regD, regM);
-               return;
+        REGION_CopyRegion(regD, regM);
+        return;
     }
 
     REGION_RegionOp (regD, regM, regS, REGION_SubtractO,
-               REGION_SubtractNonO1, NULL);
+                     REGION_SubtractNonO1, NULL);
 
     /*
      * Can't alter newReg's extents before we call miRegionOp because
@@ -1701,61 +1762,76 @@ static void FASTCALL REGION_SubtractRegion(ROSRGNDATA *regD, ROSRGNDATA *regM,
 /***********************************************************************
  *          REGION_XorRegion
  */
-static void FASTCALL REGION_XorRegion(ROSRGNDATA *dr, ROSRGNDATA *sra,
-                                                       ROSRGNDATA *srb)
+static void FASTCALL
+REGION_XorRegion(
+    ROSRGNDATA *dr,
+    ROSRGNDATA *sra,
+    ROSRGNDATA *srb
+)
 {
-  HRGN htra, htrb;
-  ROSRGNDATA *tra, *trb;
+    HRGN htra, htrb;
+    ROSRGNDATA *tra, *trb;
 
-  if(!(htra = RGNDATA_AllocRgn(sra->rdh.nCount + 1)))
-    return;
-  if(!(htrb = RGNDATA_AllocRgn(srb->rdh.nCount + 1)))
-  {
-    NtGdiDeleteObject( htra );
-    return;
-  }
-  tra = RGNDATA_LockRgn( htra );
-  if(!tra ){
-    NtGdiDeleteObject( htra );
-    NtGdiDeleteObject( htrb );
-    return;
-  }
+    if (!(htra = RGNDATA_AllocRgn(sra->rdh.nCount + 1)))
+        return;
+    if (!(htrb = RGNDATA_AllocRgn(srb->rdh.nCount + 1)))
+    {
+        NtGdiDeleteObject(htra);
+        return;
+    }
+    tra = RGNDATA_LockRgn(htra);
+    if (!tra )
+    {
+        NtGdiDeleteObject(htra);
+        NtGdiDeleteObject(htrb);
+        return;
+    }
 
-  trb = RGNDATA_LockRgn( htrb );
-  if( !trb ){
-    RGNDATA_UnlockRgn( tra );
-    NtGdiDeleteObject( htra );
-    NtGdiDeleteObject( htrb );
-    return;
-  }
+    trb = RGNDATA_LockRgn(htrb);
+    if (!trb)
+    {
+        RGNDATA_UnlockRgn(tra);
+        NtGdiDeleteObject(htra);
+        NtGdiDeleteObject(htrb);
+        return;
+    }
 
-  REGION_SubtractRegion(tra,sra,srb);
-  REGION_SubtractRegion(trb,srb,sra);
-  REGION_UnionRegion(dr,tra,trb);
-  RGNDATA_UnlockRgn( tra );
-  RGNDATA_UnlockRgn( trb );
+    REGION_SubtractRegion(tra, sra, srb);
+    REGION_SubtractRegion(trb, srb, sra);
+    REGION_UnionRegion(dr, tra, trb);
+    RGNDATA_UnlockRgn(tra);
+    RGNDATA_UnlockRgn(trb);
 
-  NtGdiDeleteObject( htra );
-  NtGdiDeleteObject( htrb );
-  return;
+    NtGdiDeleteObject(htra);
+    NtGdiDeleteObject(htrb);
+    return;
 }
 
 
 /*!
  * Adds a rectangle to a REGION
  */
-void FASTCALL REGION_UnionRectWithRegion(const RECT *rect, ROSRGNDATA *rgn)
+void FASTCALL
+REGION_UnionRectWithRegion(
+    const RECT *rect,
+    ROSRGNDATA *rgn
+)
 {
     ROSRGNDATA region;
 
     region.Buffer = &region.rdh.rcBound;
     region.rdh.nCount = 1;
-    region.rdh.nRgnSize = sizeof( RECT );
+    region.rdh.nRgnSize = sizeof(RECT);
     region.rdh.rcBound = *rect;
     REGION_UnionRegion(rgn, rgn, &region);
 }
 
-BOOL FASTCALL REGION_CreateSimpleFrameRgn(PROSRGNDATA rgn, INT x, INT y)
+BOOL FASTCALL
+REGION_CreateSimpleFrameRgn(
+    PROSRGNDATA rgn,
+    INT x,
+    INT y
+)
 {
     RECT rc[4];
     PRECT prc;
@@ -1765,7 +1841,7 @@ BOOL FASTCALL REGION_CreateSimpleFrameRgn(PROSRGNDATA rgn, INT x, INT y)
         prc = rc;
 
         if (rgn->rdh.rcBound.bottom - rgn->rdh.rcBound.top > y * 2 &&
-            rgn->rdh.rcBound.right - rgn->rdh.rcBound.left > x * 2)
+                rgn->rdh.rcBound.right - rgn->rdh.rcBound.left > x * 2)
         {
             if (y != 0)
             {
@@ -1812,7 +1888,7 @@ BOOL FASTCALL REGION_CreateSimpleFrameRgn(PROSRGNDATA rgn, INT x, INT y)
             rgn->rdh.nCount = (DWORD)(prc - rc);
             ASSERT(rgn->rdh.nCount > 1);
             rgn->rdh.nRgnSize = rgn->rdh.nCount * sizeof(RECT);
-            rgn->Buffer = ExAllocatePoolWithTag( PagedPool, rgn->rdh.nRgnSize, TAG_REGION);
+            rgn->Buffer = ExAllocatePoolWithTag(PagedPool, rgn->rdh.nRgnSize, TAG_REGION);
             if (!rgn->Buffer)
             {
                 rgn->rdh.nRgnSize = 0;
@@ -1826,348 +1902,385 @@ BOOL FASTCALL REGION_CreateSimpleFrameRgn(PROSRGNDATA rgn, INT x, INT y)
     return TRUE;
 }
 
-BOOL FASTCALL REGION_CreateFrameRgn(HRGN hDest, HRGN hSrc, INT x, INT y)
+BOOL FASTCALL
+REGION_CreateFrameRgn(
+    HRGN hDest,
+    HRGN hSrc,
+    INT x,
+    INT y
+)
 {
-   PROSRGNDATA srcObj, destObj;
-   PRECT rc;
-   ULONG i;
-
-   if (!(srcObj = (PROSRGNDATA)RGNDATA_LockRgn(hSrc)))
-   {
-      return FALSE;
-   }
-   if (!REGION_NOT_EMPTY(srcObj))
-   {
-      RGNDATA_UnlockRgn(srcObj);
-      return FALSE;
-   }
-   if (!(destObj = (PROSRGNDATA)RGNDATA_LockRgn(hDest)))
-   {
-      RGNDATA_UnlockRgn(srcObj);
-      return FALSE;
-   }
-
-   EMPTY_REGION(destObj);
-   if (!REGION_CopyRegion(destObj, srcObj))
-   {
-      RGNDATA_UnlockRgn(destObj);
-      RGNDATA_UnlockRgn(srcObj);
-      return FALSE;
-   }
-
-   if (srcObj->rdh.iType == SIMPLEREGION)
-   {
-       if (!REGION_CreateSimpleFrameRgn(destObj, x, y))
-       {
-           EMPTY_REGION(destObj);
-           RGNDATA_UnlockRgn(destObj);
-           RGNDATA_UnlockRgn(srcObj);
-           return FALSE;
-       }
-   }
-   else
-   {
-       /* Original region moved to right */
-       rc = (PRECT)srcObj->Buffer;
-       for (i = 0; i < srcObj->rdh.nCount; i++)
-       {
-          rc->left += x;
-          rc->right += x;
-          rc++;
-       }
-       REGION_IntersectRegion(destObj, destObj, srcObj);
-
-       /* Original region moved to left */
-       rc = (PRECT)srcObj->Buffer;
-       for (i = 0; i < srcObj->rdh.nCount; i++)
-       {
-          rc->left -= 2 * x;
-          rc->right -= 2 * x;
-          rc++;
-       }
-       REGION_IntersectRegion(destObj, destObj, srcObj);
-
-       /* Original region moved down */
-       rc = (PRECT)srcObj->Buffer;
-       for (i = 0; i < srcObj->rdh.nCount; i++)
-       {
-          rc->left += x;
-          rc->right += x;
-          rc->top += y;
-          rc->bottom += y;
-          rc++;
-       }
-       REGION_IntersectRegion(destObj, destObj, srcObj);
-
-       /* Original region moved up */
-       rc = (PRECT)srcObj->Buffer;
-       for (i = 0; i < srcObj->rdh.nCount; i++)
-       {
-          rc->top -= 2 * y;
-          rc->bottom -= 2 * y;
-          rc++;
-       }
-       REGION_IntersectRegion(destObj, destObj, srcObj);
-
-       /* Restore the original region */
-       rc = (PRECT)srcObj->Buffer;
-       for (i = 0; i < srcObj->rdh.nCount; i++)
-       {
-          rc->top += y;
-          rc->bottom += y;
-          rc++;
-       }
-       REGION_SubtractRegion(destObj, srcObj, destObj);
-   }
-
-   RGNDATA_UnlockRgn(destObj);
-   RGNDATA_UnlockRgn(srcObj);
-   return TRUE;
+    PROSRGNDATA srcObj, destObj;
+    PRECT rc;
+    ULONG i;
+
+    if (!(srcObj = (PROSRGNDATA)RGNDATA_LockRgn(hSrc)))
+    {
+        return FALSE;
+    }
+    if (!REGION_NOT_EMPTY(srcObj))
+    {
+        RGNDATA_UnlockRgn(srcObj);
+        return FALSE;
+    }
+    if (!(destObj = (PROSRGNDATA)RGNDATA_LockRgn(hDest)))
+    {
+        RGNDATA_UnlockRgn(srcObj);
+        return FALSE;
+    }
+
+    EMPTY_REGION(destObj);
+    if (!REGION_CopyRegion(destObj, srcObj))
+    {
+        RGNDATA_UnlockRgn(destObj);
+        RGNDATA_UnlockRgn(srcObj);
+        return FALSE;
+    }
+
+    if (srcObj->rdh.iType == SIMPLEREGION)
+    {
+        if (!REGION_CreateSimpleFrameRgn(destObj, x, y))
+        {
+            EMPTY_REGION(destObj);
+            RGNDATA_UnlockRgn(destObj);
+            RGNDATA_UnlockRgn(srcObj);
+            return FALSE;
+        }
+    }
+    else
+    {
+        /* Original region moved to right */
+        rc = (PRECT)srcObj->Buffer;
+        for (i = 0; i < srcObj->rdh.nCount; i++)
+        {
+            rc->left += x;
+            rc->right += x;
+            rc++;
+        }
+        REGION_IntersectRegion(destObj, destObj, srcObj);
+
+        /* Original region moved to left */
+        rc = (PRECT)srcObj->Buffer;
+        for (i = 0; i < srcObj->rdh.nCount; i++)
+        {
+            rc->left -= 2 * x;
+            rc->right -= 2 * x;
+            rc++;
+        }
+        REGION_IntersectRegion(destObj, destObj, srcObj);
+
+        /* Original region moved down */
+        rc = (PRECT)srcObj->Buffer;
+        for (i = 0; i < srcObj->rdh.nCount; i++)
+        {
+            rc->left += x;
+            rc->right += x;
+            rc->top += y;
+            rc->bottom += y;
+            rc++;
+        }
+        REGION_IntersectRegion(destObj, destObj, srcObj);
+
+        /* Original region moved up */
+        rc = (PRECT)srcObj->Buffer;
+        for (i = 0; i < srcObj->rdh.nCount; i++)
+        {
+            rc->top -= 2 * y;
+            rc->bottom -= 2 * y;
+            rc++;
+        }
+        REGION_IntersectRegion(destObj, destObj, srcObj);
+
+        /* Restore the original region */
+        rc = (PRECT)srcObj->Buffer;
+        for (i = 0; i < srcObj->rdh.nCount; i++)
+        {
+            rc->top += y;
+            rc->bottom += y;
+            rc++;
+        }
+        REGION_SubtractRegion(destObj, srcObj, destObj);
+    }
+
+    RGNDATA_UnlockRgn(destObj);
+    RGNDATA_UnlockRgn(srcObj);
+    return TRUE;
 }
 
 
-BOOL FASTCALL REGION_LPTODP(HDC hdc, HRGN hDest, HRGN hSrc)
+BOOL FASTCALL
+REGION_LPTODP(
+    HDC hdc,
+    HRGN hDest,
+    HRGN hSrc)
 {
-  RECT *pCurRect, *pEndRect;
-  PROSRGNDATA srcObj = NULL;
-  PROSRGNDATA destObj = NULL;
-
-  DC * dc = DC_LockDc(hdc);
-  RECT tmpRect;
-  BOOL ret = FALSE;
-  PDC_ATTR Dc_Attr;
-  
-  if(!dc)
-    return ret;
-  Dc_Attr = dc->pDc_Attr;
-  if(!Dc_Attr) Dc_Attr = &dc->Dc_Attr;
-  
-  if(Dc_Attr->iMapMode == MM_TEXT) // Requires only a translation
-  {
-    if(NtGdiCombineRgn(hDest, hSrc, 0, RGN_COPY) == ERROR)
-      goto done;
-
-    NtGdiOffsetRgn(hDest, Dc_Attr->ptlViewportOrg.x - Dc_Attr->ptlWindowOrg.x,
-                                       Dc_Attr->ptlViewportOrg.y - Dc_Attr->ptlWindowOrg.y);
-    ret = TRUE;
-    goto done;
-  }
+    RECT *pCurRect, *pEndRect;
+    PROSRGNDATA srcObj = NULL;
+    PROSRGNDATA destObj = NULL;
+
+    DC * dc = DC_LockDc(hdc);
+    RECT tmpRect;
+    BOOL ret = FALSE;
+    PDC_ATTR Dc_Attr;
+
+    if (!dc)
+        return ret;
+    Dc_Attr = dc->pDc_Attr;
+    if (!Dc_Attr) Dc_Attr = &dc->Dc_Attr;
+
+    if (Dc_Attr->iMapMode == MM_TEXT) // Requires only a translation
+    {
+        if (NtGdiCombineRgn(hDest, hSrc, 0, RGN_COPY) == ERROR)
+            goto done;
+
+        NtGdiOffsetRgn(hDest, Dc_Attr->ptlViewportOrg.x - Dc_Attr->ptlWindowOrg.x,
+                       Dc_Attr->ptlViewportOrg.y - Dc_Attr->ptlWindowOrg.y);
+        ret = TRUE;
+        goto done;
+    }
 
-  if(!( srcObj = (PROSRGNDATA) RGNDATA_LockRgn( hSrc ) ))
+    if ( !(srcObj = (PROSRGNDATA) RGNDATA_LockRgn(hSrc)) )
         goto done;
-  if(!( destObj = (PROSRGNDATA) RGNDATA_LockRgn( hDest ) ))
-  {
-    RGNDATA_UnlockRgn( srcObj );
-    goto done;
-  }
-  EMPTY_REGION(destObj);
-
-  pEndRect = (PRECT)srcObj->Buffer + srcObj->rdh.nCount;
-  for(pCurRect = (PRECT)srcObj->Buffer; pCurRect < pEndRect; pCurRect++)
-  {
-    tmpRect = *pCurRect;
-    tmpRect.left = XLPTODP(Dc_Attr, tmpRect.left);
-    tmpRect.top = YLPTODP(Dc_Attr, tmpRect.top);
-    tmpRect.right = XLPTODP(Dc_Attr, tmpRect.right);
-    tmpRect.bottom = YLPTODP(Dc_Attr, tmpRect.bottom);
-
-    if(tmpRect.left > tmpRect.right)
-      { INT tmp = tmpRect.left; tmpRect.left = tmpRect.right; tmpRect.right = tmp; }
-    if(tmpRect.top > tmpRect.bottom)
-      { INT tmp = tmpRect.top; tmpRect.top = tmpRect.bottom; tmpRect.bottom = tmp; }
-
-    REGION_UnionRectWithRegion(&tmpRect, destObj);
-  }
-  ret = TRUE;
-
-  RGNDATA_UnlockRgn( srcObj );
-  RGNDATA_UnlockRgn( destObj );
+    if ( !(destObj = (PROSRGNDATA) RGNDATA_LockRgn(hDest)) )
+    {
+        RGNDATA_UnlockRgn(srcObj);
+        goto done;
+    }
+    EMPTY_REGION(destObj);
+
+    pEndRect = (PRECT)srcObj->Buffer + srcObj->rdh.nCount;
+    for (pCurRect = (PRECT)srcObj->Buffer; pCurRect < pEndRect; pCurRect++)
+    {
+        tmpRect = *pCurRect;
+        tmpRect.left = XLPTODP(Dc_Attr, tmpRect.left);
+        tmpRect.top = YLPTODP(Dc_Attr, tmpRect.top);
+        tmpRect.right = XLPTODP(Dc_Attr, tmpRect.right);
+        tmpRect.bottom = YLPTODP(Dc_Attr, tmpRect.bottom);
+
+        if (tmpRect.left > tmpRect.right)
+        {
+            INT tmp = tmpRect.left;
+            tmpRect.left = tmpRect.right;
+            tmpRect.right = tmp;
+        }
+        if (tmpRect.top > tmpRect.bottom)
+        {
+            INT tmp = tmpRect.top;
+            tmpRect.top = tmpRect.bottom;
+            tmpRect.bottom = tmp;
+        }
+
+        REGION_UnionRectWithRegion(&tmpRect, destObj);
+    }
+    ret = TRUE;
+
+    RGNDATA_UnlockRgn(srcObj);
+    RGNDATA_UnlockRgn(destObj);
 
 done:
-  DC_UnlockDc( dc );
-  return ret;
+    DC_UnlockDc(dc);
+    return ret;
 }
 
-HRGN FASTCALL RGNDATA_AllocRgn(INT n)
+HRGN FASTCALL
+RGNDATA_AllocRgn(INT n)
 {
-  HRGN hReg;
-  PROSRGNDATA pReg;
+    HRGN hReg;
+    PROSRGNDATA pReg;
 
-  if ((hReg = (HRGN) GDIOBJ_AllocObj(GdiHandleTable, GDI_OBJECT_TYPE_REGION)))
+    if ((hReg = (HRGN) GDIOBJ_AllocObj(GdiHandleTable, GDI_OBJECT_TYPE_REGION)))
     {
-      if (NULL != (pReg = RGNDATA_LockRgn(hReg)))
+        if (NULL != (pReg = RGNDATA_LockRgn(hReg)))
         {
-          if (1 == n)
+            if (1 == n)
             {
-              /* Testing shows that > 95% of all regions have only 1 rect.
-                 Including that here saves us from having to do another
-                 allocation */
-              pReg->Buffer = &pReg->rdh.rcBound;
+                /* Testing shows that > 95% of all regions have only 1 rect.
+                   Including that here saves us from having to do another
+                   allocation */
+                pReg->Buffer = &pReg->rdh.rcBound;
             }
-          else
+            else
             {
-              pReg->Buffer = ExAllocatePoolWithTag(PagedPool, n * sizeof(RECT), TAG_REGION);
+                pReg->Buffer = ExAllocatePoolWithTag(PagedPool, n * sizeof(RECT), TAG_REGION);
             }
-          if (NULL != pReg->Buffer)
+            if (NULL != pReg->Buffer)
             {
-              EMPTY_REGION(pReg);
-              pReg->rdh.dwSize = sizeof(RGNDATAHEADER);
-              pReg->rdh.nCount = n;
-              pReg->rdh.nRgnSize = n*sizeof(RECT);
+                EMPTY_REGION(pReg);
+                pReg->rdh.dwSize = sizeof(RGNDATAHEADER);
+                pReg->rdh.nCount = n;
+                pReg->rdh.nRgnSize = n*sizeof(RECT);
 
-              RGNDATA_UnlockRgn(pReg);
+                RGNDATA_UnlockRgn(pReg);
 
-              return hReg;
+                return hReg;
             }
         }
-      else
+        else
         {
-          RGNDATA_FreeRgn(hReg);
+            RGNDATA_FreeRgn(hReg);
         }
     }
 
-  return NULL;
+    return NULL;
 }
 
 BOOL INTERNAL_CALL
 RGNDATA_Cleanup(PVOID ObjectBody)
 {
-  PROSRGNDATA pRgn = (PROSRGNDATA)ObjectBody;
-  if(pRgn->Buffer && pRgn->Buffer != &pRgn->rdh.rcBound)
-    ExFreePool(pRgn->Buffer);
-  return TRUE;
+    PROSRGNDATA pRgn = (PROSRGNDATA)ObjectBody;
+    if (pRgn->Buffer && pRgn->Buffer != &pRgn->rdh.rcBound)
+        ExFreePool(pRgn->Buffer);
+    return TRUE;
 }
 
 // NtGdi Exported Functions
 INT
 STDCALL
 NtGdiCombineRgn(HRGN  hDest,
-                    HRGN  hSrc1,
-                    HRGN  hSrc2,
-                    INT  CombineMode)
+                HRGN  hSrc1,
+                HRGN  hSrc2,
+                INT  CombineMode)
 {
-  INT result = ERROR;
-  PROSRGNDATA destRgn, src1Rgn, src2Rgn;
-
-  destRgn = RGNDATA_LockRgn(hDest);
-  if( destRgn )
-    {
-      src1Rgn = RGNDATA_LockRgn(hSrc1);
-      if( src1Rgn )
-         {
-           if (CombineMode == RGN_COPY)
-             {
-               if( !REGION_CopyRegion(destRgn, src1Rgn) )
-                 return ERROR;
-               result = destRgn->rdh.iType;
-             }
-           else
-           {
-              src2Rgn = RGNDATA_LockRgn(hSrc2);
-              if( src2Rgn )
-               {
-                 switch (CombineMode)
-                   {
-                     case RGN_AND:
-                       REGION_IntersectRegion(destRgn, src1Rgn, src2Rgn);
-                       break;
-                     case RGN_OR:
-                       REGION_UnionRegion(destRgn, src1Rgn, src2Rgn);
-                       break;
-                     case RGN_XOR:
-                       REGION_XorRegion(destRgn, src1Rgn, src2Rgn);
-                       break;
-                     case RGN_DIFF:
-                       REGION_SubtractRegion(destRgn, src1Rgn, src2Rgn);
-                       break;
-                   }
-                 RGNDATA_UnlockRgn(src2Rgn);
-                 result = destRgn->rdh.iType;
-               }
-               else if(hSrc2 == NULL)
+    INT result = ERROR;
+    PROSRGNDATA destRgn, src1Rgn, src2Rgn;
+
+    destRgn = RGNDATA_LockRgn(hDest);
+    if (destRgn)
+    {
+        src1Rgn = RGNDATA_LockRgn(hSrc1);
+        if (src1Rgn)
+        {
+            if (CombineMode == RGN_COPY)
+            {
+                if ( !REGION_CopyRegion(destRgn, src1Rgn) )
+                    return ERROR;
+                result = destRgn->rdh.iType;
+            }
+            else
+            {
+                src2Rgn = RGNDATA_LockRgn(hSrc2);
+                if (src2Rgn)
+                {
+                    switch (CombineMode)
+                    {
+                    case RGN_AND:
+                        REGION_IntersectRegion(destRgn, src1Rgn, src2Rgn);
+                        break;
+                    case RGN_OR:
+                        REGION_UnionRegion(destRgn, src1Rgn, src2Rgn);
+                        break;
+                    case RGN_XOR:
+                        REGION_XorRegion(destRgn, src1Rgn, src2Rgn);
+                        break;
+                    case RGN_DIFF:
+                        REGION_SubtractRegion(destRgn, src1Rgn, src2Rgn);
+                        break;
+                    }
+                    RGNDATA_UnlockRgn(src2Rgn);
+                    result = destRgn->rdh.iType;
+                }
+                else if (hSrc2 == NULL)
                 {
-                  DPRINT1("NtGdiCombineRgn requires hSrc2 != NULL for combine mode %d!\n", CombineMode);
+                    DPRINT1("NtGdiCombineRgn requires hSrc2 != NULL for combine mode %d!\n", CombineMode);
                 }
-           }
+            }
 
             RGNDATA_UnlockRgn(src1Rgn);
-         }
+        }
 
-      RGNDATA_UnlockRgn(destRgn);
+        RGNDATA_UnlockRgn(destRgn);
     }
-  else
+    else
     {
-      DPRINT("NtGdiCombineRgn: hDest unavailable\n");
-      result = ERROR;
+        DPRINT("NtGdiCombineRgn: hDest unavailable\n");
+        result = ERROR;
     }
 
-  return result;
+    return result;
 }
 
 HRGN
 STDCALL
-NtGdiCreateEllipticRgn(INT Left,
-                       INT Top,
-                       INT Right,
-                       INT Bottom)
+NtGdiCreateEllipticRgn(
+    INT Left,
+    INT Top,
+    INT Right,
+    INT Bottom
+)
 {
-   return NtGdiCreateRoundRectRgn(Left, Top, Right, Bottom,
-      Right - Left, Bottom - Top);
+    return NtGdiCreateRoundRectRgn(Left, Top, Right, Bottom,
+                                   Right - Left, Bottom - Top);
 }
 
 HRGN STDCALL
 NtGdiCreateRectRgn(INT LeftRect, INT TopRect, INT RightRect, INT BottomRect)
 {
-   HRGN hRgn;
-
-   /* Allocate region data structure with space for 1 RECT */
-   if ((hRgn = RGNDATA_AllocRgn(1)))
-   {
-      if (NtGdiSetRectRgn(hRgn, LeftRect, TopRect, RightRect, BottomRect))
-         return hRgn;
-      NtGdiDeleteObject(hRgn);
-   }
-
-   SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
-   return NULL;
+    HRGN hRgn;
+
+    /* Allocate region data structure with space for 1 RECT */
+    if ((hRgn = RGNDATA_AllocRgn(1)))
+    {
+        if (NtGdiSetRectRgn(hRgn, LeftRect, TopRect, RightRect, BottomRect))
+            return hRgn;
+        NtGdiDeleteObject(hRgn);
+    }
+
+    SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
+    return NULL;
 }
 
 HRGN
 STDCALL
-NtGdiCreateRoundRectRgn(INT left, INT top, INT right, INT bottom,
-   INT ellipse_width, INT ellipse_height)
+NtGdiCreateRoundRectRgn(
+    INT left,
+    INT top,
+    INT right,
+    INT bottom,
+    INT ellipse_width,
+    INT ellipse_height
+)
 {
     PROSRGNDATA obj;
     HRGN hrgn;
     int asq, bsq, d, xd, yd;
     RECT rect;
 
-      /* Make the dimensions sensible */
+    /* Make the dimensions sensible */
 
-    if (left > right) { INT tmp = left; left = right; right = tmp; }
-    if (top > bottom) { INT tmp = top; top = bottom; bottom = tmp; }
+    if (left > right)
+    {
+        INT tmp = left;
+        left = right;
+        right = tmp;
+    }
+    if (top > bottom)
+    {
+        INT tmp = top;
+        top = bottom;
+        bottom = tmp;
+    }
 
     ellipse_width = abs(ellipse_width);
     ellipse_height = abs(ellipse_height);
 
-      /* Check parameters */
+    /* Check parameters */
 
     if (ellipse_width > right-left) ellipse_width = right-left;
     if (ellipse_height > bottom-top) ellipse_height = bottom-top;
 
-      /* Check if we can do a normal rectangle instead */
+    /* Check if we can do a normal rectangle instead */
 
     if ((ellipse_width < 2) || (ellipse_height < 2))
-        return NtGdiCreateRectRgn( left, top, right, bottom );
+        return NtGdiCreateRectRgn(left, top, right, bottom);
 
-      /* Create region */
+    /* Create region */
 
     d = (ellipse_height < 128) ? ((3 * ellipse_height) >> 2) : 64;
     if (!(hrgn = RGNDATA_AllocRgn(d))) return 0;
     if (!(obj = RGNDATA_LockRgn(hrgn))) return 0;
 
-      /* Ellipse algorithm, based on an article by K. Porter */
-      /* in DDJ Graphics Programming Column, 8/89 */
+    /* Ellipse algorithm, based on an article by K. Porter */
+    /* in DDJ Graphics Programming Column, 8/89 */
 
     asq = ellipse_width * ellipse_width / 4;        /* a^2 */
     bsq = ellipse_height * ellipse_height / 4;      /* b^2 */
@@ -2178,263 +2291,282 @@ NtGdiCreateRoundRectRgn(INT left, INT top, INT right, INT bottom,
     rect.left   = left + ellipse_width / 2;
     rect.right  = right - ellipse_width / 2;
 
-      /* Loop to draw first half of quadrant */
+    /* Loop to draw first half of quadrant */
 
     while (xd < yd)
     {
-       if (d > 0)  /* if nearest pixel is toward the center */
-       {
-             /* move toward center */
-           rect.top = top++;
-           rect.bottom = rect.top + 1;
-           UnsafeIntUnionRectWithRgn( obj, &rect );
-           rect.top = --bottom;
-           rect.bottom = rect.top + 1;
-           UnsafeIntUnionRectWithRgn( obj, &rect );
-           yd -= 2*asq;
-           d  -= yd;
-       }
-       rect.left--;        /* next horiz point */
-       rect.right++;
-       xd += 2*bsq;
-       d  += bsq + xd;
-    }
-      /* Loop to draw second half of quadrant */
+        if (d > 0)  /* if nearest pixel is toward the center */
+        {
+            /* move toward center */
+            rect.top = top++;
+            rect.bottom = rect.top + 1;
+            UnsafeIntUnionRectWithRgn(obj, &rect);
+            rect.top = --bottom;
+            rect.bottom = rect.top + 1;
+            UnsafeIntUnionRectWithRgn(obj, &rect);
+            yd -= 2*asq;
+            d  -= yd;
+        }
+        rect.left--;        /* next horiz point */
+        rect.right++;
+        xd += 2*bsq;
+        d  += bsq + xd;
+    }
+    /* Loop to draw second half of quadrant */
 
     d += (3 * (asq-bsq) / 2 - (xd+yd)) / 2;
     while (yd >= 0)
     {
-         /* next vertical point */
-       rect.top = top++;
-       rect.bottom = rect.top + 1;
-       UnsafeIntUnionRectWithRgn( obj, &rect );
-       rect.top = --bottom;
-       rect.bottom = rect.top + 1;
-       UnsafeIntUnionRectWithRgn( obj, &rect );
-       if (d < 0)   /* if nearest pixel is outside ellipse */
-       {
-           rect.left--;     /* move away from center */
-           rect.right++;
-           xd += 2*bsq;
-           d  += xd;
-       }
-       yd -= 2*asq;
-       d  += asq - yd;
-    }
-      /* Add the inside rectangle */
+        /* next vertical point */
+        rect.top = top++;
+        rect.bottom = rect.top + 1;
+        UnsafeIntUnionRectWithRgn(obj, &rect);
+        rect.top = --bottom;
+        rect.bottom = rect.top + 1;
+        UnsafeIntUnionRectWithRgn(obj, &rect);
+        if (d < 0)   /* if nearest pixel is outside ellipse */
+        {
+            rect.left--;     /* move away from center */
+            rect.right++;
+            xd += 2*bsq;
+            d  += xd;
+        }
+        yd -= 2*asq;
+        d  += asq - yd;
+    }
+    /* Add the inside rectangle */
+
+    if (top <= bottom)
+    {
+        rect.top = top;
+        rect.bottom = bottom;
+        UnsafeIntUnionRectWithRgn(obj, &rect);
+    }
+    RGNDATA_UnlockRgn(obj);
+    return hrgn;
+}
+
+BOOL
+STDCALL
+NtGdiEqualRgn(
+    HRGN  hSrcRgn1,
+    HRGN  hSrcRgn2
+)
+{
+    PROSRGNDATA rgn1, rgn2;
+    PRECT tRect1, tRect2;
+    ULONG i;
+    BOOL bRet = FALSE;
+
+    if ( !(rgn1 = RGNDATA_LockRgn(hSrcRgn1)) )
+        return ERROR;
+
+    if ( !(rgn2 = RGNDATA_LockRgn(hSrcRgn2)) )
+    {
+        RGNDATA_UnlockRgn(rgn1);
+        return ERROR;
+    }
+
+    if (rgn1->rdh.nCount != rgn2->rdh.nCount ||
+            rgn1->rdh.nCount == 0 ||
+            rgn1->rdh.rcBound.left   != rgn2->rdh.rcBound.left ||
+            rgn1->rdh.rcBound.right  != rgn2->rdh.rcBound.right ||
+            rgn1->rdh.rcBound.top    != rgn2->rdh.rcBound.top ||
+            rgn1->rdh.rcBound.bottom != rgn2->rdh.rcBound.bottom)
+        goto exit;
+
+    tRect1 = (PRECT)rgn1->Buffer;
+    tRect2 = (PRECT)rgn2->Buffer;
+
+    if (!tRect1 || !tRect2)
+        goto exit;
+
+    for (i=0; i < rgn1->rdh.nCount; i++)
+    {
+        if (tRect1[i].left   != tRect2[i].left ||
+                tRect1[i].right  != tRect2[i].right ||
+                tRect1[i].top    != tRect2[i].top ||
+                tRect1[i].bottom != tRect2[i].bottom)
+            goto exit;
+    }
+    bRet = TRUE;
+
+exit:
+    RGNDATA_UnlockRgn(rgn1);
+    RGNDATA_UnlockRgn(rgn2);
+    return bRet;
+}
+
+HRGN
+STDCALL
+NtGdiExtCreateRegion(
+    OPTIONAL LPXFORM Xform,
+    DWORD Count,
+    LPRGNDATA RgnData
+)
+{
+    HRGN hRgn;
+    PROSRGNDATA Region;
+    DWORD nCount = 0;
+    NTSTATUS Status = STATUS_SUCCESS;
+
+    if (Count < FIELD_OFFSET(RGNDATA, Buffer))
+    {
+        SetLastWin32Error(ERROR_INVALID_PARAMETER);
+        return NULL;
+    }
+
+    _SEH_TRY
+    {
+        ProbeForRead(RgnData, Count, 1);
+        nCount = RgnData->rdh.nCount;
+        if ((Count - FIELD_OFFSET(RGNDATA, Buffer)) / sizeof(RECT) < nCount)
+        {
+            Status = STATUS_INVALID_PARAMETER;
+            _SEH_LEAVE;
+        }
+    }
+    _SEH_HANDLE
+    {
+        Status = _SEH_GetExceptionCode();
+    }
+    _SEH_END;
+    if (!NT_SUCCESS(Status))
+    {
+        SetLastNtError(Status);
+        return NULL;
+    }
+
+    hRgn = RGNDATA_AllocRgn(nCount);
+    if (hRgn == NULL)
+    {
+        SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
+        return NULL;
+    }
 
-    if (top <= bottom)
+    Region = RGNDATA_LockRgn(hRgn);
+    if (Region == NULL)
     {
-       rect.top = top;
-       rect.bottom = bottom;
-       UnsafeIntUnionRectWithRgn( obj, &rect );
+        SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
+        return FALSE;
     }
-    RGNDATA_UnlockRgn( obj );
-    return hrgn;
-}
 
-BOOL
-STDCALL
-NtGdiEqualRgn(HRGN  hSrcRgn1,
-                   HRGN  hSrcRgn2)
-{
-  PROSRGNDATA rgn1, rgn2;
-  PRECT tRect1, tRect2;
-  ULONG i;
-  BOOL bRet = FALSE;
-
-  if( !(rgn1 = RGNDATA_LockRgn(hSrcRgn1)))
-       return ERROR;
-
-  if( !(rgn2 = RGNDATA_LockRgn(hSrcRgn2))){
-       RGNDATA_UnlockRgn( rgn1 );
-       return ERROR;
-  }
-
-  if(rgn1->rdh.nCount != rgn2->rdh.nCount ||
-       rgn1->rdh.nCount == 0 ||
-       rgn1->rdh.rcBound.left   != rgn2->rdh.rcBound.left ||
-       rgn1->rdh.rcBound.right  != rgn2->rdh.rcBound.right ||
-       rgn1->rdh.rcBound.top    != rgn2->rdh.rcBound.top ||
-       rgn1->rdh.rcBound.bottom != rgn2->rdh.rcBound.bottom)
-       goto exit;
-
-  tRect1 = (PRECT)rgn1->Buffer;
-  tRect2 = (PRECT)rgn2->Buffer;
-
-  if( !tRect1 || !tRect2 )
-       goto exit;
-
-  for(i=0; i < rgn1->rdh.nCount; i++)
-  {
-    if(tRect1[i].left   != tRect2[i].left ||
-               tRect1[i].right  != tRect2[i].right ||
-               tRect1[i].top    != tRect2[i].top ||
-               tRect1[i].bottom != tRect2[i].bottom)
-          goto exit;
-  }
-  bRet = TRUE;
+    _SEH_TRY
+    {
+        RtlCopyMemory(&Region->rdh,
+        RgnData,
+        FIELD_OFFSET(RGNDATA, Buffer));
+        RtlCopyMemory(Region->Buffer,
+                      RgnData->Buffer,
+                      Count - FIELD_OFFSET(RGNDATA, Buffer));
+    }
+    _SEH_HANDLE
+    {
+        Status = _SEH_GetExceptionCode();
+    }
+    _SEH_END;
+    if (!NT_SUCCESS(Status))
+    {
+        SetLastWin32Error(ERROR_INVALID_PARAMETER);
+        RGNDATA_UnlockRgn(Region);
+        NtGdiDeleteObject(hRgn);
+        return NULL;
+    }
 
-exit:
-  RGNDATA_UnlockRgn( rgn1 );
-  RGNDATA_UnlockRgn( rgn2 );
-  return bRet;
-}
+    RGNDATA_UnlockRgn(Region);
 
-HRGN
-STDCALL
-NtGdiExtCreateRegion(OPTIONAL LPXFORM Xform,
-                          DWORD Count,
-                          LPRGNDATA RgnData)
-{
-   HRGN hRgn;
-   PROSRGNDATA Region;
-   DWORD nCount = 0;
-   NTSTATUS Status = STATUS_SUCCESS;
-
-   if (Count < FIELD_OFFSET(RGNDATA, Buffer))
-   {
-      SetLastWin32Error(ERROR_INVALID_PARAMETER);
-      return NULL;
-   }
-
-   _SEH_TRY
-   {
-     ProbeForRead(RgnData,
-                  Count,
-                  1);
-     nCount = RgnData->rdh.nCount;
-     if((Count - FIELD_OFFSET(RGNDATA, Buffer)) / sizeof(RECT) < nCount)
-     {
-       Status = STATUS_INVALID_PARAMETER;
-       _SEH_LEAVE;
-     }
-   }
-   _SEH_HANDLE
-   {
-     Status = _SEH_GetExceptionCode();
-   }
-   _SEH_END;
-   if (!NT_SUCCESS(Status))
-   {
-      SetLastNtError(Status);
-      return NULL;
-   }
-
-   hRgn = RGNDATA_AllocRgn(nCount);
-   if (hRgn == NULL)
-   {
-      SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
-      return NULL;
-   }
-
-   Region = RGNDATA_LockRgn(hRgn);
-   if (Region == NULL)
-   {
-      SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
-      return FALSE;
-   }
-
-   _SEH_TRY
-   {
-     RtlCopyMemory(&Region->rdh,
-                   RgnData,
-                   FIELD_OFFSET(RGNDATA, Buffer));
-     RtlCopyMemory(Region->Buffer,
-                   RgnData->Buffer,
-                   Count - FIELD_OFFSET(RGNDATA, Buffer));
-   }
-   _SEH_HANDLE
-   {
-     Status = _SEH_GetExceptionCode();
-   }
-   _SEH_END;
-   if (!NT_SUCCESS(Status))
-   {
-      SetLastWin32Error(ERROR_INVALID_PARAMETER);
-      RGNDATA_UnlockRgn(Region);
-      NtGdiDeleteObject(hRgn);
-      return NULL;
-   }
-
-   RGNDATA_UnlockRgn(Region);
-
-   return hRgn;
+    return hRgn;
 }
 
 BOOL
 STDCALL
-NtGdiFillRgn(HDC hDC, HRGN hRgn, HBRUSH hBrush)
+NtGdiFillRgn(
+    HDC hDC,
+    HRGN hRgn,
+    HBRUSH hBrush
+)
 {
-  HBRUSH oldhBrush;
-  PROSRGNDATA rgn;
-  PRECT r;
+    HBRUSH oldhBrush;
+    PROSRGNDATA rgn;
+    PRECT r;
 
-  if (NULL == (rgn = RGNDATA_LockRgn(hRgn)))
+    if (NULL == (rgn = RGNDATA_LockRgn(hRgn)))
     {
-      return FALSE;
+        return FALSE;
     }
 
-  if (NULL == (oldhBrush = NtGdiSelectBrush(hDC, hBrush)))
+    if (NULL == (oldhBrush = NtGdiSelectBrush(hDC, hBrush)))
     {
-      RGNDATA_UnlockRgn(rgn);
-      return FALSE;
+        RGNDATA_UnlockRgn(rgn);
+        return FALSE;
     }
 
-  for (r = rgn->Buffer; r < rgn->Buffer + rgn->rdh.nCount; r++)
+    for (r = rgn->Buffer; r < rgn->Buffer + rgn->rdh.nCount; r++)
     {
-      NtGdiPatBlt(hDC, r->left, r->top, r->right - r->left, r->bottom - r->top, PATCOPY);
+        NtGdiPatBlt(hDC, r->left, r->top, r->right - r->left, r->bottom - r->top, PATCOPY);
     }
 
-  RGNDATA_UnlockRgn( rgn );
-  NtGdiSelectBrush(hDC, oldhBrush);
+    RGNDATA_UnlockRgn(rgn);
+    NtGdiSelectBrush(hDC, oldhBrush);
 
-  return TRUE;
+    return TRUE;
 }
 
 BOOL
 STDCALL
-NtGdiFrameRgn(HDC hDC, HRGN  hRgn, HBRUSH  hBrush, INT  Width, INT  Height)
+NtGdiFrameRgn(
+    HDC hDC,
+    HRGN hRgn,
+    HBRUSH hBrush,
+    INT Width,
+    INT Height
+)
 {
-  HRGN FrameRgn;
-  BOOL Ret;
+    HRGN FrameRgn;
+    BOOL Ret;
 
-  if(!(FrameRgn = NtGdiCreateRectRgn(0, 0, 0, 0)))
-  {
-    return FALSE;
-  }
-  if(!REGION_CreateFrameRgn(FrameRgn, hRgn, Width, Height))
-  {
-    NtGdiDeleteObject(FrameRgn);
-    return FALSE;
-  }
+    if (!(FrameRgn = NtGdiCreateRectRgn(0, 0, 0, 0)))
+    {
+        return FALSE;
+    }
+    if (!REGION_CreateFrameRgn(FrameRgn, hRgn, Width, Height))
+    {
+        NtGdiDeleteObject(FrameRgn);
+        return FALSE;
+    }
 
-  Ret = NtGdiFillRgn(hDC, FrameRgn, hBrush);
+    Ret = NtGdiFillRgn(hDC, FrameRgn, hBrush);
 
-  NtGdiDeleteObject(FrameRgn);
-  return Ret;
+    NtGdiDeleteObject(FrameRgn);
+    return Ret;
 }
 
 INT FASTCALL
-UnsafeIntGetRgnBox(PROSRGNDATA  Rgn,
-                   LPRECT  pRect)
+UnsafeIntGetRgnBox(
+    PROSRGNDATA Rgn,
+    LPRECT pRect
+)
 {
-  DWORD ret;
+    DWORD ret;
 
-  if (Rgn)
+    if (Rgn)
     {
-      *pRect = Rgn->rdh.rcBound;
-      ret = Rgn->rdh.iType;
+        *pRect = Rgn->rdh.rcBound;
+        ret = Rgn->rdh.iType;
 
-      return ret;
+        return ret;
     }
-  return 0; //if invalid region return zero
+    return 0; //if invalid region return zero
 }
 
 
 /* See wine, msdn, osr and  Feng Yuan - Windows Graphics Programming Win32 Gdi And Directdraw */
 INT STDCALL
-NtGdiGetRandomRgn(HDC hDC, HRGN hDest, INT iCode)
+NtGdiGetRandomRgn(
+    HDC hDC,
+    HRGN hDest,
+    INT iCode
+)
 {
     INT ret = 0;
     PDC pDC;
@@ -2450,39 +2582,39 @@ NtGdiGetRandomRgn(HDC hDC, HRGN hDest, INT iCode)
 
     switch (iCode)
     {
-        case 1:
+    case 1:
+        hSrc = pDC->w.hClipRgn;
+        break;
+    case 2:
+        //hSrc = dc->hMetaRgn;
+        DPRINT1("hMetaRgn not implemented\n");
+        DC_UnlockDc(pDC);
+        return -1;
+        break;
+    case 3:
+        DPRINT1("hMetaRgn not implemented\n");
+        //hSrc = dc->hMetaClipRgn;
+        if (!hSrc)
+        {
             hSrc = pDC->w.hClipRgn;
-            break;
-        case 2:
-            //hSrc = dc->hMetaRgn;
-            DPRINT1("hMetaRgn not implemented\n");
-            DC_UnlockDc(pDC);
-            return -1;
-            break;
-        case 3:
-            DPRINT1("hMetaRgn not implemented\n");
-            //hSrc = dc->hMetaClipRgn;
-            if(!hSrc)
-            {
-                hSrc = pDC->w.hClipRgn;
-            }
-            //if(!hSrc) rgn = dc->hMetaRgn;
-            break;
-        case 4:
-            hSrc = pDC->w.hVisRgn;
-            break;
-        default:
-            hSrc = 0;
+        }
+        //if (!hSrc) rgn = dc->hMetaRgn;
+        break;
+    case 4:
+        hSrc = pDC->w.hVisRgn;
+        break;
+    default:
+        hSrc = 0;
     }
     if (hSrc)
     {
-        if(NtGdiCombineRgn(hDest, hSrc, 0, RGN_COPY) == ERROR)
+        if (NtGdiCombineRgn(hDest, hSrc, 0, RGN_COPY) == ERROR)
         {
-               ret = -1;
+            ret = -1;
         }
         else
         {
-               ret = 1;
+            ret = 1;
         }
     }
     if (iCode == SYSRGN)
@@ -2497,377 +2629,411 @@ NtGdiGetRandomRgn(HDC hDC, HRGN hDest, INT iCode)
 }
 
 INT STDCALL
-IntGdiGetRgnBox(HRGN hRgn,
-                LPRECT pRect)
+IntGdiGetRgnBox(
+    HRGN hRgn,
+    LPRECT pRect
+)
 {
-  PROSRGNDATA Rgn;
-  DWORD ret;
+    PROSRGNDATA Rgn;
+    DWORD ret;
 
-  if (!(Rgn = RGNDATA_LockRgn(hRgn)))
-  {
-    return ERROR;
-  }
+    if (!(Rgn = RGNDATA_LockRgn(hRgn)))
+    {
+        return ERROR;
+    }
 
-  ret = UnsafeIntGetRgnBox(Rgn, pRect);
-  RGNDATA_UnlockRgn(Rgn);
+    ret = UnsafeIntGetRgnBox(Rgn, pRect);
+    RGNDATA_UnlockRgn(Rgn);
 
-  return ret;
+    return ret;
 }
 
 
 INT STDCALL
-NtGdiGetRgnBox(HRGN  hRgn,
-             LPRECT  pRect)
+NtGdiGetRgnBox(
+    HRGN hRgn,
+    LPRECT pRect
+)
 {
-  PROSRGNDATA  Rgn;
-  RECT SafeRect;
-  DWORD ret;
-  NTSTATUS Status = STATUS_SUCCESS;
+    PROSRGNDATA  Rgn;
+    RECT SafeRect;
+    DWORD ret;
+    NTSTATUS Status = STATUS_SUCCESS;
 
-  if (!(Rgn = RGNDATA_LockRgn(hRgn)))
+    if (!(Rgn = RGNDATA_LockRgn(hRgn)))
     {
-      return ERROR;
+        return ERROR;
     }
 
-  ret = UnsafeIntGetRgnBox(Rgn, &SafeRect);
-  RGNDATA_UnlockRgn(Rgn);
-  if (ERROR == ret)
+    ret = UnsafeIntGetRgnBox(Rgn, &SafeRect);
+    RGNDATA_UnlockRgn(Rgn);
+    if (ERROR == ret)
     {
-      return ret;
+        return ret;
     }
 
-  _SEH_TRY
-  {
-    ProbeForWrite(pRect,
-                  sizeof(RECT),
-                  1);
-    *pRect = SafeRect;
-  }
-  _SEH_HANDLE
-  {
-    Status = _SEH_GetExceptionCode();
-  }
-  _SEH_END;
-  if (!NT_SUCCESS(Status))
+    _SEH_TRY
+    {
+        ProbeForWrite(pRect, sizeof(RECT), 1);
+        *pRect = SafeRect;
+    }
+    _SEH_HANDLE
+    {
+        Status = _SEH_GetExceptionCode();
+    }
+    _SEH_END;
+    if (!NT_SUCCESS(Status))
     {
-      return ERROR;
+        return ERROR;
     }
 
-  return ret;
+    return ret;
 }
 
 BOOL
 STDCALL
-NtGdiInvertRgn(HDC  hDC,
-                    HRGN  hRgn)
+NtGdiInvertRgn(
+    HDC hDC,
+    HRGN hRgn
+)
 {
-  PROSRGNDATA RgnData;
-  ULONG i;
-  PRECT rc;
-
-  if(!(RgnData = RGNDATA_LockRgn(hRgn)))
-  {
-    SetLastWin32Error(ERROR_INVALID_HANDLE);
-    return FALSE;
-  }
+    PROSRGNDATA RgnData;
+    ULONG i;
+    PRECT rc;
 
-  rc = (PRECT)RgnData->Buffer;
-  for(i = 0; i < RgnData->rdh.nCount; i++)
-  {
+    if (!(RgnData = RGNDATA_LockRgn(hRgn)))
+    {
+        SetLastWin32Error(ERROR_INVALID_HANDLE);
+        return FALSE;
+    }
 
-    if(!NtGdiPatBlt(hDC, rc->left, rc->top, rc->right - rc->left, rc->bottom - rc->top, DSTINVERT))
+    rc = (PRECT)RgnData->Buffer;
+    for (i = 0; i < RgnData->rdh.nCount; i++)
     {
-      RGNDATA_UnlockRgn(RgnData);
-      return FALSE;
+
+        if (!NtGdiPatBlt(hDC, rc->left, rc->top, rc->right - rc->left, rc->bottom - rc->top, DSTINVERT))
+        {
+            RGNDATA_UnlockRgn(RgnData);
+            return FALSE;
+        }
+        rc++;
     }
-    rc++;
-  }
 
-  RGNDATA_UnlockRgn(RgnData);
-  return TRUE;
+    RGNDATA_UnlockRgn(RgnData);
+    return TRUE;
 }
 
 INT
 STDCALL
-NtGdiOffsetRgn(HRGN  hRgn,
-                   INT  XOffset,
-                   INT  YOffset)
+NtGdiOffsetRgn(
+    HRGN hRgn,
+    INT XOffset,
+    INT YOffset
+)
 {
-  PROSRGNDATA rgn = RGNDATA_LockRgn(hRgn);
-  INT ret;
+    PROSRGNDATA rgn = RGNDATA_LockRgn(hRgn);
+    INT ret;
 
-  DPRINT("NtGdiOffsetRgn: hRgn %d Xoffs %d Yoffs %d rgn %x\n", hRgn, XOffset, YOffset, rgn );
+    DPRINT("NtGdiOffsetRgn: hRgn %d Xoffs %d Yoffs %d rgn %x\n", hRgn, XOffset, YOffset, rgn );
 
-  if( !rgn ){
+    if (!rgn)
+    {
         DPRINT("NtGdiOffsetRgn: hRgn error\n");
         return ERROR;
-  }
-
-  if(XOffset || YOffset) {
-    int nbox = rgn->rdh.nCount;
-    PRECT pbox = (PRECT)rgn->Buffer;
-
-    if(nbox && pbox) {
-      while(nbox--) {
-        pbox->left += XOffset;
-        pbox->right += XOffset;
-        pbox->top += YOffset;
-        pbox->bottom += YOffset;
-        pbox++;
-      }
-      if (rgn->Buffer != &rgn->rdh.rcBound)
-      {
-        rgn->rdh.rcBound.left += XOffset;
-        rgn->rdh.rcBound.right += XOffset;
-        rgn->rdh.rcBound.top += YOffset;
-        rgn->rdh.rcBound.bottom += YOffset;
-      }
     }
-  }
-  ret = rgn->rdh.iType;
-  RGNDATA_UnlockRgn( rgn );
-  return ret;
+
+    if (XOffset || YOffset)
+    {
+        int nbox = rgn->rdh.nCount;
+        PRECT pbox = (PRECT)rgn->Buffer;
+
+        if (nbox && pbox)
+        {
+            while (nbox--)
+            {
+                pbox->left += XOffset;
+                pbox->right += XOffset;
+                pbox->top += YOffset;
+                pbox->bottom += YOffset;
+                pbox++;
+            }
+            if (rgn->Buffer != &rgn->rdh.rcBound)
+            {
+                rgn->rdh.rcBound.left += XOffset;
+                rgn->rdh.rcBound.right += XOffset;
+                rgn->rdh.rcBound.top += YOffset;
+                rgn->rdh.rcBound.bottom += YOffset;
+            }
+        }
+    }
+    ret = rgn->rdh.iType;
+    RGNDATA_UnlockRgn(rgn);
+    return ret;
 }
 
 BOOL
 FASTCALL
-IntGdiPaintRgn(PDC dc, HRGN  hRgn)
+IntGdiPaintRgn(
+    PDC dc,
+    HRGN hRgn
+)
 {
-  //RECT box;
-  HRGN tmpVisRgn; //, prevVisRgn;
-  PROSRGNDATA visrgn;
-  CLIPOBJ* ClipRegion;
-  BOOL bRet = FALSE;
-  PGDIBRUSHOBJ pBrush;
-  GDIBRUSHINST BrushInst;
-  POINTL BrushOrigin;
-  BITMAPOBJ *BitmapObj;
-  PDC_ATTR Dc_Attr;
-  
-  if( !dc )
-    return FALSE;
-  Dc_Attr = dc->pDc_Attr;
-  if(!Dc_Attr) Dc_Attr = &dc->Dc_Attr;
-  
-  if(!(tmpVisRgn = NtGdiCreateRectRgn(0, 0, 0, 0)))
-  {
-    DC_UnlockDc( dc );
-    return FALSE;
-  }
-
-/* ei enable later
-  // Transform region into device co-ords
-  if(!REGION_LPTODP(hDC, tmpVisRgn, hRgn) || NtGdiOffsetRgn(tmpVisRgn, dc->w.DCOrgX, dc->w.DCOrgY) == ERROR)
-  {
-    NtGdiDeleteObject( tmpVisRgn );
-    DC_UnlockDc( dc );
-    return FALSE;
-  }
-*/
-  /* enable when clipping is implemented
-  NtGdiCombineRgn(tmpVisRgn, tmpVisRgn, dc->w.hGCClipRgn, RGN_AND);
-  */
-
-  //visrgn = RGNDATA_LockRgn(tmpVisRgn);
-  visrgn = RGNDATA_LockRgn(hRgn);
-  if (visrgn == NULL)
-  {
-    NtGdiDeleteObject( tmpVisRgn );
-    DC_UnlockDc( dc );
-    return FALSE;
-  }
-
-  ClipRegion = IntEngCreateClipRegion(visrgn->rdh.nCount,
-                                      (PRECTL)visrgn->Buffer,
-                                      (PRECTL)&visrgn->rdh.rcBound );
-  ASSERT( ClipRegion );
-  pBrush = BRUSHOBJ_LockBrush(Dc_Attr->hbrush);
-  ASSERT(pBrush);
-  IntGdiInitBrushInstance(&BrushInst, pBrush, dc->XlateBrush);
-
-  BrushOrigin.x = Dc_Attr->ptlBrushOrigin.x;
-  BrushOrigin.y = Dc_Attr->ptlBrushOrigin.y;
-  BitmapObj = BITMAPOBJ_LockBitmap(dc->w.hBitmap);
-  /* FIXME - Handle BitmapObj == NULL !!!! */
-
-  bRet = IntEngPaint(&BitmapObj->SurfObj,
-                     ClipRegion,
-                     &BrushInst.BrushObject,
-                     &BrushOrigin,
-                     0xFFFF);//FIXME:don't know what to put here
-
-  BITMAPOBJ_UnlockBitmap(BitmapObj);
-  BRUSHOBJ_UnlockBrush(pBrush);
-  RGNDATA_UnlockRgn( visrgn );
-  NtGdiDeleteObject( tmpVisRgn );
-
-  // Fill the region
-  return TRUE;
+    //RECT box;
+    HRGN tmpVisRgn; //, prevVisRgn;
+    PROSRGNDATA visrgn;
+    CLIPOBJ* ClipRegion;
+    BOOL bRet = FALSE;
+    PGDIBRUSHOBJ pBrush;
+    GDIBRUSHINST BrushInst;
+    POINTL BrushOrigin;
+    BITMAPOBJ *BitmapObj;
+    PDC_ATTR Dc_Attr;
+
+    if (!dc)
+        return FALSE;
+    Dc_Attr = dc->pDc_Attr;
+    if (!Dc_Attr) Dc_Attr = &dc->Dc_Attr;
+
+    if (!(tmpVisRgn = NtGdiCreateRectRgn(0, 0, 0, 0)))
+    {
+        DC_UnlockDc(dc);
+        return FALSE;
+    }
+
+    /* ei enable later
+      // Transform region into device co-ords
+      if (!REGION_LPTODP(hDC, tmpVisRgn, hRgn) || NtGdiOffsetRgn(tmpVisRgn, dc->w.DCOrgX, dc->w.DCOrgY) == ERROR)
+      {
+        NtGdiDeleteObject(tmpVisRgn);
+        DC_UnlockDc(dc);
+        return FALSE;
+      }
+    */
+    /* enable when clipping is implemented
+    NtGdiCombineRgn(tmpVisRgn, tmpVisRgn, dc->w.hGCClipRgn, RGN_AND);
+    */
+
+    //visrgn = RGNDATA_LockRgn(tmpVisRgn);
+    visrgn = RGNDATA_LockRgn(hRgn);
+    if (visrgn == NULL)
+    {
+        NtGdiDeleteObject(tmpVisRgn);
+        DC_UnlockDc(dc);
+        return FALSE;
+    }
+
+    ClipRegion = IntEngCreateClipRegion(visrgn->rdh.nCount,
+                                        (PRECTL)visrgn->Buffer,
+                                        (PRECTL)&visrgn->rdh.rcBound );
+    ASSERT(ClipRegion);
+    pBrush = BRUSHOBJ_LockBrush(Dc_Attr->hbrush);
+    ASSERT(pBrush);
+    IntGdiInitBrushInstance(&BrushInst, pBrush, dc->XlateBrush);
+
+    BrushOrigin.x = Dc_Attr->ptlBrushOrigin.x;
+    BrushOrigin.y = Dc_Attr->ptlBrushOrigin.y;
+    BitmapObj = BITMAPOBJ_LockBitmap(dc->w.hBitmap);
+    /* FIXME - Handle BitmapObj == NULL !!!! */
+
+    bRet = IntEngPaint(&BitmapObj->SurfObj,
+                       ClipRegion,
+                       &BrushInst.BrushObject,
+                       &BrushOrigin,
+                       0xFFFF);//FIXME:don't know what to put here
+
+    BITMAPOBJ_UnlockBitmap(BitmapObj);
+    BRUSHOBJ_UnlockBrush(pBrush);
+    RGNDATA_UnlockRgn(visrgn);
+    NtGdiDeleteObject(tmpVisRgn);
+
+    // Fill the region
+    return TRUE;
 }
 
 BOOL
 STDCALL
-NtGdiPtInRegion(HRGN  hRgn,
-                     INT  X,
-                     INT  Y)
+NtGdiPtInRegion(
+    HRGN hRgn,
+    INT X,
+    INT Y
+)
 {
-  PROSRGNDATA rgn;
-  ULONG i;
-  PRECT r;
-
-  if(!(rgn = RGNDATA_LockRgn(hRgn) ) )
-         return FALSE;
-
-  if(rgn->rdh.nCount > 0 && INRECT(rgn->rdh.rcBound, X, Y)){
-    r = (PRECT) rgn->Buffer;
-    for(i = 0; i < rgn->rdh.nCount; i++) {
-      if(INRECT(*r, X, Y)){
-       RGNDATA_UnlockRgn(rgn);
-       return TRUE;
-      }
-      r++;
+    PROSRGNDATA rgn;
+    ULONG i;
+    PRECT r;
+
+    if (!(rgn = RGNDATA_LockRgn(hRgn) ) )
+        return FALSE;
+
+    if (rgn->rdh.nCount > 0 && INRECT(rgn->rdh.rcBound, X, Y))
+    {
+        r = (PRECT) rgn->Buffer;
+        for (i = 0; i < rgn->rdh.nCount; i++)
+        {
+            if (INRECT(*r, X, Y))
+            {
+                RGNDATA_UnlockRgn(rgn);
+                return TRUE;
+            }
+            r++;
+        }
     }
-  }
-  RGNDATA_UnlockRgn(rgn);
-  return FALSE;
+    RGNDATA_UnlockRgn(rgn);
+    return FALSE;
 }
 
 BOOL
 FASTCALL
-UnsafeIntRectInRegion(PROSRGNDATA Rgn,
-                      CONST LPRECT rc)
+UnsafeIntRectInRegion(
+    PROSRGNDATA Rgn,
+    CONST LPRECT rc
+)
 {
-  PRECT pCurRect, pRectEnd;
+    PRECT pCurRect, pRectEnd;
 
-  // this is (just) a useful optimization
-  if((Rgn->rdh.nCount > 0) && EXTENTCHECK(&Rgn->rdh.rcBound, rc))
-  {
-    for (pCurRect = (PRECT)Rgn->Buffer, pRectEnd = pCurRect + Rgn->rdh.nCount; pCurRect < pRectEnd; pCurRect++)
+    // this is (just) a useful optimization
+    if ((Rgn->rdh.nCount > 0) && EXTENTCHECK(&Rgn->rdh.rcBound, rc))
     {
-      if (pCurRect->bottom <= rc->top) continue; // not far enough down yet
-      if (pCurRect->top >= rc->bottom) break;    // too far down
-      if (pCurRect->right <= rc->left) continue; // not far enough over yet
-      if (pCurRect->left >= rc->right) continue;
+        for (pCurRect = (PRECT)Rgn->Buffer, pRectEnd = pCurRect + Rgn->rdh.nCount; pCurRect < pRectEnd; pCurRect++)
+        {
+            if (pCurRect->bottom <= rc->top) continue; // not far enough down yet
+            if (pCurRect->top >= rc->bottom) break;    // too far down
+            if (pCurRect->right <= rc->left) continue; // not far enough over yet
+            if (pCurRect->left >= rc->right) continue;
 
-      return TRUE;
+            return TRUE;
+        }
     }
-  }
-  return FALSE;
+    return FALSE;
 }
 
 BOOL
 STDCALL
-NtGdiRectInRegion(HRGN  hRgn,
-                  LPRECT  unsaferc)
+NtGdiRectInRegion(
+    HRGN  hRgn,
+    LPRECT unsaferc
+)
 {
-  PROSRGNDATA Rgn;
-  RECT rc = {0};
-  BOOL Ret;
-  NTSTATUS Status = STATUS_SUCCESS;
-
-  if(!(Rgn = RGNDATA_LockRgn(hRgn)))
-  {
-    return ERROR;
-  }
-
-  _SEH_TRY
-  {
-    ProbeForRead(unsaferc,
-                 sizeof(RECT),
-                 1);
-    rc = *unsaferc;
-  }
-  _SEH_HANDLE
-  {
-    Status = _SEH_GetExceptionCode();
-  }
-  _SEH_END;
-
-  if (!NT_SUCCESS(Status))
-    {
-      RGNDATA_UnlockRgn(Rgn);
-      SetLastNtError(Status);
-      DPRINT1("NtGdiRectInRegion: bogus rc\n");
-      return ERROR;
-    }
-
-  Ret = UnsafeIntRectInRegion(Rgn, &rc);
-  RGNDATA_UnlockRgn(Rgn);
-  return Ret;
+    PROSRGNDATA Rgn;
+    RECT rc = {0};
+    BOOL Ret;
+    NTSTATUS Status = STATUS_SUCCESS;
+
+    if (!(Rgn = RGNDATA_LockRgn(hRgn)))
+    {
+        return ERROR;
+    }
+
+    _SEH_TRY
+    {
+        ProbeForRead(unsaferc, sizeof(RECT), 1);
+        rc = *unsaferc;
+    }
+    _SEH_HANDLE
+    {
+        Status = _SEH_GetExceptionCode();
+    }
+    _SEH_END;
+
+    if (!NT_SUCCESS(Status))
+    {
+        RGNDATA_UnlockRgn(Rgn);
+        SetLastNtError(Status);
+        DPRINT1("NtGdiRectInRegion: bogus rc\n");
+        return ERROR;
+    }
+
+    Ret = UnsafeIntRectInRegion(Rgn, &rc);
+    RGNDATA_UnlockRgn(Rgn);
+    return Ret;
 }
 
 BOOL
 STDCALL
-NtGdiSetRectRgn(HRGN  hRgn,
-                     INT  LeftRect,
-                     INT  TopRect,
-                     INT  RightRect,
-                     INT  BottomRect)
+NtGdiSetRectRgn(
+    HRGN hRgn,
+    INT LeftRect,
+    INT TopRect,
+    INT RightRect,
+    INT BottomRect
+)
 {
-  PROSRGNDATA rgn;
-  PRECT firstRect;
+    PROSRGNDATA rgn;
+    PRECT firstRect;
 
 
 
-  if( !( rgn = RGNDATA_LockRgn(hRgn) ) )
-         return 0; //per documentation
+    if ( !(rgn = RGNDATA_LockRgn(hRgn)) )
+        return 0; //per documentation
 
-  if (LeftRect > RightRect) { INT tmp = LeftRect; LeftRect = RightRect; RightRect = tmp; }
-  if (TopRect > BottomRect) { INT tmp = TopRect; TopRect = BottomRect; BottomRect = tmp; }
+    if (LeftRect > RightRect)
+    {
+        INT tmp = LeftRect;
+        LeftRect = RightRect;
+        RightRect = tmp;
+    }
+    if (TopRect > BottomRect)
+    {
+        INT tmp = TopRect;
+        TopRect = BottomRect;
+        BottomRect = tmp;
+    }
 
-  if((LeftRect != RightRect) && (TopRect != BottomRect))
-  {
-    firstRect = (PRECT)rgn->Buffer;
-       ASSERT( firstRect );
-       firstRect->left = rgn->rdh.rcBound.left = LeftRect;
-    firstRect->top = rgn->rdh.rcBound.top = TopRect;
-    firstRect->right = rgn->rdh.rcBound.right = RightRect;
-    firstRect->bottom = rgn->rdh.rcBound.bottom = BottomRect;
-    rgn->rdh.nCount = 1;
-    rgn->rdh.iType = SIMPLEREGION;
-  } else
-    EMPTY_REGION(rgn);
+    if ((LeftRect != RightRect) && (TopRect != BottomRect))
+    {
+        firstRect = (PRECT)rgn->Buffer;
+        ASSERT(firstRect);
+        firstRect->left = rgn->rdh.rcBound.left = LeftRect;
+        firstRect->top = rgn->rdh.rcBound.top = TopRect;
+        firstRect->right = rgn->rdh.rcBound.right = RightRect;
+        firstRect->bottom = rgn->rdh.rcBound.bottom = BottomRect;
+        rgn->rdh.nCount = 1;
+        rgn->rdh.iType = SIMPLEREGION;
+    }
+    else
+        EMPTY_REGION(rgn);
 
-  RGNDATA_UnlockRgn( rgn );
-  return TRUE;
+    RGNDATA_UnlockRgn(rgn);
+    return TRUE;
 }
 
 HRGN STDCALL
-NtGdiUnionRectWithRgn(HRGN hDest, CONST PRECT UnsafeRect)
+NtGdiUnionRectWithRgn(
+    HRGN hDest,
+    CONST PRECT UnsafeRect
+)
 {
     RECT SafeRect = {0};
-  PROSRGNDATA Rgn;
-  NTSTATUS Status = STATUS_SUCCESS;
-
-  if(!(Rgn = (PROSRGNDATA)RGNDATA_LockRgn(hDest)))
-  {
-     SetLastWin32Error(ERROR_INVALID_HANDLE);
-     return NULL;
-  }
-
-  _SEH_TRY
-  {
-    ProbeForRead(UnsafeRect,
-                 sizeof(RECT),
-                 1);
-    SafeRect = *UnsafeRect;
-  }
-  _SEH_HANDLE
-  {
-    Status = _SEH_GetExceptionCode();
-  }
-  _SEH_END;
-
-  if (! NT_SUCCESS(Status))
-    {
-      RGNDATA_UnlockRgn(Rgn);
-      SetLastNtError(Status);
-      return NULL;
-    }
-
-  UnsafeIntUnionRectWithRgn(Rgn, &SafeRect);
-  RGNDATA_UnlockRgn(Rgn);
-  return hDest;
+    PROSRGNDATA Rgn;
+    NTSTATUS Status = STATUS_SUCCESS;
+
+    if (!(Rgn = (PROSRGNDATA)RGNDATA_LockRgn(hDest)))
+    {
+        SetLastWin32Error(ERROR_INVALID_HANDLE);
+        return NULL;
+    }
+
+    _SEH_TRY
+    {
+        ProbeForRead(UnsafeRect, sizeof(RECT), 1);
+        SafeRect = *UnsafeRect;
+    }
+    _SEH_HANDLE
+    {
+        Status = _SEH_GetExceptionCode();
+    }
+    _SEH_END;
+
+    if (! NT_SUCCESS(Status))
+    {
+        RGNDATA_UnlockRgn(Rgn);
+        SetLastNtError(Status);
+        return NULL;
+    }
+
+    UnsafeIntUnionRectWithRgn(Rgn, &SafeRect);
+    RGNDATA_UnlockRgn(Rgn);
+    return hDest;
 }
 
 /*!
@@ -2880,51 +3046,54 @@ NtGdiUnionRectWithRgn(HRGN hDest, CONST PRECT UnsafeRect)
  *
  * If the function fails, the return value is zero."
  */
-DWORD STDCALL NtGdiGetRegionData(HRGN hrgn, DWORD count, LPRGNDATA rgndata)
+DWORD STDCALL
+NtGdiGetRegionData(
+    HRGN hrgn,
+    DWORD count,
+    LPRGNDATA rgndata
+)
 {
     DWORD size;
-    PROSRGNDATA obj = RGNDATA_LockRgn( hrgn );
+    PROSRGNDATA obj = RGNDATA_LockRgn(hrgn);
     NTSTATUS Status = STATUS_SUCCESS;
 
-    if(!obj)
-               return 0;
+    if (!obj)
+        return 0;
 
     size = obj->rdh.nCount * sizeof(RECT);
-    if(count < (size + sizeof(RGNDATAHEADER)) || rgndata == NULL)
+    if (count < (size + sizeof(RGNDATAHEADER)) || rgndata == NULL)
     {
-        RGNDATA_UnlockRgn( obj );
-               if (rgndata) /* buffer is too small, signal it by return 0 */
-                   return 0;
-               else            /* user requested buffer size with rgndata NULL */
-                   return size + sizeof(RGNDATAHEADER);
+        RGNDATA_UnlockRgn(obj);
+        if (rgndata) /* buffer is too small, signal it by return 0 */
+            return 0;
+        else           /* user requested buffer size with rgndata NULL */
+            return size + sizeof(RGNDATAHEADER);
     }
 
     _SEH_TRY
     {
-      ProbeForWrite(rgndata,
-                    count,
-                    1);
-      RtlCopyMemory(rgndata,
-                    obj,
-                    sizeof(RGNDATAHEADER));
-      RtlCopyMemory((PVOID)((ULONG_PTR)rgndata + (ULONG_PTR)sizeof(RGNDATAHEADER)),
-                    obj->Buffer,
-                    size);
+        ProbeForWrite(rgndata, count, 1);
+        RtlCopyMemory(rgndata,
+                      obj,
+                      sizeof(RGNDATAHEADER));
+        RtlCopyMemory((PVOID)((ULONG_PTR)rgndata + (ULONG_PTR)sizeof(RGNDATAHEADER)),
+                      obj->Buffer,
+                      size);
     }
     _SEH_HANDLE
     {
-      Status = _SEH_GetExceptionCode();
+        Status = _SEH_GetExceptionCode();
     }
     _SEH_END;
 
-    if(!NT_SUCCESS(Status))
+    if (!NT_SUCCESS(Status))
     {
-      SetLastNtError(Status);
-      RGNDATA_UnlockRgn( obj );
-      return 0;
+        SetLastNtError(Status);
+        RGNDATA_UnlockRgn(obj);
+        return 0;
     }
 
-    RGNDATA_UnlockRgn( obj );
+    RGNDATA_UnlockRgn(obj);
     return size + sizeof(RGNDATAHEADER);
 }
 
@@ -2938,9 +3107,14 @@ DWORD STDCALL NtGdiGetRegionData(HRGN hrgn, DWORD count, LPRGNDATA rgndata)
  *     bucket.  Finally, we can insert it.
  *
  */
-static void FASTCALL REGION_InsertEdgeInET(EdgeTable *ET, EdgeTableEntry *ETE,
-                INT scanline, ScanLineListBlock **SLLBlock, INT *iSLLBlock)
-
+static void FASTCALL
+REGION_InsertEdgeInET(
+    EdgeTable *ET,
+    EdgeTableEntry *ETE,
+    INT scanline,
+    ScanLineListBlock **SLLBlock,
+    INT *iSLLBlock
+)
 {
     EdgeTableEntry *start, *prev;
     ScanLineList *pSLL, *pPrevSLL;
@@ -2964,13 +3138,13 @@ static void FASTCALL REGION_InsertEdgeInET(EdgeTable *ET, EdgeTableEntry *ETE,
     {
         if (*iSLLBlock > SLLSPERBLOCK-1)
         {
-            tmpSLLBlock = ExAllocatePoolWithTag( PagedPool, sizeof(ScanLineListBlock), TAG_REGION);
-           if(!tmpSLLBlock)
-           {
-               DPRINT1("REGION_InsertEdgeInETL(): Can't alloc SLLB\n");
-               /* FIXME - free resources? */
-               return;
-           }
+            tmpSLLBlock = ExAllocatePoolWithTag(PagedPool, sizeof(ScanLineListBlock), TAG_REGION);
+            if (!tmpSLLBlock)
+            {
+                DPRINT1("REGION_InsertEdgeInETL(): Can't alloc SLLB\n");
+                /* FIXME - free resources? */
+                return;
+            }
             (*SLLBlock)->next = tmpSLLBlock;
             tmpSLLBlock->next = (ScanLineListBlock *)NULL;
             *SLLBlock = tmpSLLBlock;
@@ -3010,7 +3184,11 @@ static void FASTCALL REGION_InsertEdgeInET(EdgeTable *ET, EdgeTableEntry *ETE,
  *     leaving them sorted by smaller x coordinate.
  *
  */
-static void FASTCALL REGION_loadAET(EdgeTableEntry *AET, EdgeTableEntry *ETEs)
+static void FASTCALL
+REGION_loadAET(
+    EdgeTableEntry *AET,
+    EdgeTableEntry *ETEs
+)
 {
     EdgeTableEntry *pPrevAET;
     EdgeTableEntry *tmp;
@@ -3056,7 +3234,8 @@ static void FASTCALL REGION_loadAET(EdgeTableEntry *AET, EdgeTableEntry *ETEs)
  *         V------------------->       V---> ...
  *
  */
-static void FASTCALL REGION_computeWAET(EdgeTableEntry *AET)
+static void FASTCALL
+REGION_computeWAET(EdgeTableEntry *AET)
 {
     register EdgeTableEntry *pWETE;
     register int inside = 1;
@@ -3072,8 +3251,8 @@ static void FASTCALL REGION_computeWAET(EdgeTableEntry *AET)
         else
             isInside--;
 
-        if ((!inside && !isInside) ||
-            ( inside &&  isInside))
+        if ( (!inside && !isInside) ||
+             ( inside &&  isInside) )
         {
             pWETE->nextWETE = AET;
             pWETE = AET;
@@ -3092,7 +3271,8 @@ static void FASTCALL REGION_computeWAET(EdgeTableEntry *AET)
  *     Edge Table.
  *
  */
-static BOOL FASTCALL REGION_InsertionSort(EdgeTableEntry *AET)
+static BOOL FASTCALL
+REGION_InsertionSort(EdgeTableEntry *AET)
 {
     EdgeTableEntry *pETEchase;
     EdgeTableEntry *pETEinsert;
@@ -3129,14 +3309,15 @@ static BOOL FASTCALL REGION_InsertionSort(EdgeTableEntry *AET)
  *
  *     Clean up our act.
  */
-static void FASTCALL REGION_FreeStorage(ScanLineListBlock *pSLLBlock)
+static void FASTCALL
+REGION_FreeStorage(ScanLineListBlock *pSLLBlock)
 {
     ScanLineListBlock   *tmpSLLBlock;
 
     while (pSLLBlock)
     {
         tmpSLLBlock = pSLLBlock->next;
-        ExFreePool( pSLLBlock );
+        ExFreePool(pSLLBlock);
         pSLLBlock = tmpSLLBlock;
     }
 }
@@ -3147,8 +3328,12 @@ static void FASTCALL REGION_FreeStorage(ScanLineListBlock *pSLLBlock)
  *
  *     Create an array of rectangles from a list of points.
  */
-static int FASTCALL REGION_PtsToRegion(int numFullPtBlocks, int iCurPtBlock,
-                      POINTBLOCK *FirstPtBlock, ROSRGNDATA *reg)
+static int FASTCALL
+REGION_PtsToRegion(
+    int numFullPtBlocks,
+    int iCurPtBlock,
+    POINTBLOCK *FirstPtBlock,
+    ROSRGNDATA *reg)
 {
     RECT *rects;
     POINT *pts;
@@ -3161,15 +3346,15 @@ static int FASTCALL REGION_PtsToRegion(int numFullPtBlocks, int iCurPtBlock,
 
     numRects = ((numFullPtBlocks * NUMPTSTOBUFFER) + iCurPtBlock) >> 1;
 
-    if(!(temp = ExAllocatePoolWithTag(PagedPool, numRects * sizeof(RECT), TAG_REGION)))
+    if (!(temp = ExAllocatePoolWithTag(PagedPool, numRects * sizeof(RECT), TAG_REGION)))
     {
-      return 0;
+        return 0;
     }
-    if(reg->Buffer != NULL)
+    if (reg->Buffer != NULL)
     {
-      COPY_RECTS(temp, reg->Buffer, reg->rdh.nCount);
-      if(reg->Buffer != &reg->rdh.rcBound)
-        ExFreePool(reg->Buffer);
+        COPY_RECTS(temp, reg->Buffer, reg->rdh.nCount);
+        if (reg->Buffer != &reg->rdh.rcBound)
+            ExFreePool(reg->Buffer);
     }
     reg->Buffer = temp;
 
@@ -3179,41 +3364,49 @@ static int FASTCALL REGION_PtsToRegion(int numFullPtBlocks, int iCurPtBlock,
     numRects = 0;
     extents->left = LARGE_COORDINATE,  extents->right = SMALL_COORDINATE;
 
-    for ( ; numFullPtBlocks >= 0; numFullPtBlocks--) {
-       /* the loop uses 2 points per iteration */
-       i = NUMPTSTOBUFFER >> 1;
-       if (!numFullPtBlocks)
-           i = iCurPtBlock >> 1;
-       for (pts = CurPtBlock->pts; i--; pts += 2) {
-           if (pts->x == pts[1].x)
-               continue;
-           if (numRects && pts->x == rects->left && pts->y == rects->bottom &&
-               pts[1].x == rects->right &&
-               (numRects == 1 || rects[-1].top != rects->top) &&
-               (i && pts[2].y > pts[1].y)) {
-               rects->bottom = pts[1].y + 1;
-               continue;
-           }
-           numRects++;
-           rects++;
-           rects->left = pts->x;  rects->top = pts->y;
-           rects->right = pts[1].x;  rects->bottom = pts[1].y + 1;
-           if (rects->left < extents->left)
-               extents->left = rects->left;
-           if (rects->right > extents->right)
-               extents->right = rects->right;
-        }
-       CurPtBlock = CurPtBlock->next;
-    }
-
-    if (numRects) {
-       extents->top = reg->Buffer->top;
-       extents->bottom = rects->bottom;
-    } else {
-       extents->left = 0;
-       extents->top = 0;
-       extents->right = 0;
-       extents->bottom = 0;
+    for ( ; numFullPtBlocks >= 0; numFullPtBlocks--)
+    {
+        /* the loop uses 2 points per iteration */
+        i = NUMPTSTOBUFFER >> 1;
+        if (!numFullPtBlocks)
+            i = iCurPtBlock >> 1;
+        for (pts = CurPtBlock->pts; i--; pts += 2)
+        {
+            if (pts->x == pts[1].x)
+                continue;
+            if (numRects && pts->x == rects->left && pts->y == rects->bottom &&
+                    pts[1].x == rects->right &&
+                    (numRects == 1 || rects[-1].top != rects->top) &&
+                    (i && pts[2].y > pts[1].y))
+            {
+                rects->bottom = pts[1].y + 1;
+                continue;
+            }
+            numRects++;
+            rects++;
+            rects->left = pts->x;
+            rects->top = pts->y;
+            rects->right = pts[1].x;
+            rects->bottom = pts[1].y + 1;
+            if (rects->left < extents->left)
+                extents->left = rects->left;
+            if (rects->right > extents->right)
+                extents->right = rects->right;
+        }
+        CurPtBlock = CurPtBlock->next;
+    }
+
+    if (numRects)
+    {
+        extents->top = reg->Buffer->top;
+        extents->bottom = rects->bottom;
+    }
+    else
+    {
+        extents->left = 0;
+        extents->top = 0;
+        extents->right = 0;
+        extents->bottom = 0;
     }
     reg->rdh.nCount = numRects;
 
@@ -3244,9 +3437,16 @@ static int FASTCALL REGION_PtsToRegion(int numFullPtBlocks, int iCurPtBlock,
  *     which an edge is initially entered.
  *
  */
-static void FASTCALL REGION_CreateETandAET(const INT *Count, INT nbpolygons,
-            const POINT *pts, EdgeTable *ET, EdgeTableEntry *AET,
-            EdgeTableEntry *pETEs, ScanLineListBlock *pSLLBlock)
+static void FASTCALL
+REGION_CreateETandAET(
+    const INT *Count,
+    INT nbpolygons,
+    const POINT *pts,
+    EdgeTable *ET,
+    EdgeTableEntry *AET,
+    EdgeTableEntry *pETEs,
+    ScanLineListBlock *pSLLBlock
+)
 {
     const POINT *top, *bottom;
     const POINT *PrevPt, *CurrPt, *EndPt;
@@ -3272,72 +3472,74 @@ static void FASTCALL REGION_CreateETandAET(const INT *Count, INT nbpolygons,
     pSLLBlock->next = (ScanLineListBlock *)NULL;
 
     EndPt = pts - 1;
-    for(poly = 0; poly < nbpolygons; poly++)
+    for (poly = 0; poly < nbpolygons; poly++)
     {
         count = Count[poly];
         EndPt += count;
-        if(count < 2)
-           continue;
+        if (count < 2)
+            continue;
 
-       PrevPt = EndPt;
-
-    /*
-     *  for each vertex in the array of points.
-     *  In this loop we are dealing with two vertices at
-     *  a time -- these make up one edge of the polygon.
-     */
-       while (count--)
-       {
-           CurrPt = pts++;
+        PrevPt = EndPt;
 
         /*
-         *  find out which point is above and which is below.
+         *  for each vertex in the array of points.
+         *  In this loop we are dealing with two vertices at
+         *  a time -- these make up one edge of the polygon.
          */
-           if (PrevPt->y > CurrPt->y)
-           {
-               bottom = PrevPt, top = CurrPt;
-               pETEs->ClockWise = 0;
-           }
-           else
-           {
-               bottom = CurrPt, top = PrevPt;
-               pETEs->ClockWise = 1;
-           }
+        while (count--)
+        {
+            CurrPt = pts++;
 
-        /*
-         * don't add horizontal edges to the Edge table.
-         */
-           if (bottom->y != top->y)
-           {
-               pETEs->ymax = bottom->y-1;
-                               /* -1 so we don't get last scanline */
+            /*
+             *  find out which point is above and which is below.
+             */
+            if (PrevPt->y > CurrPt->y)
+            {
+                bottom = PrevPt, top = CurrPt;
+                pETEs->ClockWise = 0;
+            }
+            else
+            {
+                bottom = CurrPt, top = PrevPt;
+                pETEs->ClockWise = 1;
+            }
 
             /*
-             *  initialize integer edge algorithm
+             * don't add horizontal edges to the Edge table.
              */
-               dy = bottom->y - top->y;
-               BRESINITPGONSTRUCT(dy, top->x, bottom->x, pETEs->bres);
+            if (bottom->y != top->y)
+            {
+                pETEs->ymax = bottom->y-1;
+                /* -1 so we don't get last scanline */
+
+                /*
+                 *  initialize integer edge algorithm
+                 */
+                dy = bottom->y - top->y;
+                BRESINITPGONSTRUCT(dy, top->x, bottom->x, pETEs->bres);
 
-               REGION_InsertEdgeInET(ET, pETEs, top->y, &pSLLBlock,
-                                                               &iSLLBlock);
+                REGION_InsertEdgeInET(ET, pETEs, top->y, &pSLLBlock,
+                                      &iSLLBlock);
 
-               if (PrevPt->y > ET->ymax)
-                 ET->ymax = PrevPt->y;
-               if (PrevPt->y < ET->ymin)
-                 ET->ymin = PrevPt->y;
-               pETEs++;
-           }
+                if (PrevPt->y > ET->ymax)
+                    ET->ymax = PrevPt->y;
+                if (PrevPt->y < ET->ymin)
+                    ET->ymin = PrevPt->y;
+                pETEs++;
+            }
 
-           PrevPt = CurrPt;
-       }
+            PrevPt = CurrPt;
+        }
     }
 }
 
 HRGN FASTCALL
-IntCreatePolyPolgonRgn(POINT *Pts,
-                       INT *Count,
-                      INT nbpolygons,
-                       INT mode)
+IntCreatePolyPolgonRgn(
+    POINT *Pts,
+    INT *Count,
+    INT nbpolygons,
+    INT mode
+)
 {
     HRGN hrgn;
     ROSRGNDATA *region;
@@ -3358,55 +3560,58 @@ IntCreatePolyPolgonRgn(POINT *Pts,
     int numFullPtBlocks = 0;
     INT poly, total;
 
-    if(!(hrgn = RGNDATA_AllocRgn(nbpolygons)))
+    if (!(hrgn = RGNDATA_AllocRgn(nbpolygons)))
         return 0;
-    if(!(region = RGNDATA_LockRgn(hrgn)))
+    if (!(region = RGNDATA_LockRgn(hrgn)))
     {
-      NtGdiDeleteObject(hrgn);
-      return 0;
+        NtGdiDeleteObject(hrgn);
+        return 0;
     }
 
     /* special case a rectangle */
 
     if (((nbpolygons == 1) && ((*Count == 4) ||
-       ((*Count == 5) && (Pts[4].x == Pts[0].x) && (Pts[4].y == Pts[0].y)))) &&
-       (((Pts[0].y == Pts[1].y) &&
-         (Pts[1].x == Pts[2].x) &&
-         (Pts[2].y == Pts[3].y) &&
-         (Pts[3].x == Pts[0].x)) ||
-        ((Pts[0].x == Pts[1].x) &&
-         (Pts[1].y == Pts[2].y) &&
-         (Pts[2].x == Pts[3].x) &&
-         (Pts[3].y == Pts[0].y))))
-    {
-        RGNDATA_UnlockRgn( region );
-       NtGdiSetRectRgn( hrgn, min(Pts[0].x, Pts[2].x), min(Pts[0].y, Pts[2].y),
-                           max(Pts[0].x, Pts[2].x), max(Pts[0].y, Pts[2].y) );
-       return hrgn;
-    }
-
-    for(poly = total = 0; poly < nbpolygons; poly++)
+                               ((*Count == 5) && (Pts[4].x == Pts[0].x) && (Pts[4].y == Pts[0].y)))) &&
+            (((Pts[0].y == Pts[1].y) &&
+              (Pts[1].x == Pts[2].x) &&
+              (Pts[2].y == Pts[3].y) &&
+              (Pts[3].x == Pts[0].x)) ||
+             ((Pts[0].x == Pts[1].x) &&
+              (Pts[1].y == Pts[2].y) &&
+              (Pts[2].x == Pts[3].x) &&
+              (Pts[3].y == Pts[0].y))))
+    {
+        RGNDATA_UnlockRgn(region);
+        NtGdiSetRectRgn(hrgn, min(Pts[0].x, Pts[2].x), min(Pts[0].y, Pts[2].y),
+                        max(Pts[0].x, Pts[2].x), max(Pts[0].y, Pts[2].y));
+        return hrgn;
+    }
+
+    for (poly = total = 0; poly < nbpolygons; poly++)
         total += Count[poly];
-    if (! (pETEs = ExAllocatePoolWithTag( PagedPool, sizeof(EdgeTableEntry) * total, TAG_REGION )))
+    if (! (pETEs = ExAllocatePoolWithTag(PagedPool, sizeof(EdgeTableEntry) * total, TAG_REGION)) )
     {
-        NtGdiDeleteObject( hrgn );
-       return 0;
+        NtGdiDeleteObject(hrgn);
+        return 0;
     }
     pts = FirstPtBlock.pts;
     REGION_CreateETandAET(Count, nbpolygons, Pts, &ET, &AET, pETEs, &SLLBlock);
     pSLL = ET.scanlines.next;
     curPtBlock = &FirstPtBlock;
 
-    if (mode != WINDING) {
+    if (mode != WINDING)
+    {
         /*
          *  for each scanline
          */
-        for (y = ET.ymin; y < ET.ymax; y++) {
+        for (y = ET.ymin; y < ET.ymax; y++)
+        {
             /*
              *  Add a new edge to the active edge table when we
              *  get to the next edge.
              */
-            if (pSLL != NULL && y == pSLL->scanline) {
+            if (pSLL != NULL && y == pSLL->scanline)
+            {
                 REGION_loadAET(&AET, pSLL->edgelist);
                 pSLL = pSLL->next;
             }
@@ -3416,20 +3621,23 @@ IntCreatePolyPolgonRgn(POINT *Pts,
             /*
              *  for each active edge
              */
-            while (pAET) {
+            while (pAET)
+            {
                 pts->x = pAET->bres.minor_axis,  pts->y = y;
                 pts++, iPts++;
 
                 /*
                  *  send out the buffer
                  */
-                if (iPts == NUMPTSTOBUFFER) {
-                    tmpPtBlock = ExAllocatePoolWithTag( PagedPool, sizeof(POINTBLOCK), TAG_REGION);
-                   if(!tmpPtBlock) {
-                       DPRINT1("Can't alloc tPB\n");
-                       ExFreePool(pETEs);
-                       return 0;
-                   }
+                if (iPts == NUMPTSTOBUFFER)
+                {
+                    tmpPtBlock = ExAllocatePoolWithTag(PagedPool, sizeof(POINTBLOCK), TAG_REGION);
+                    if (!tmpPtBlock)
+                    {
+                        DPRINT1("Can't alloc tPB\n");
+                        ExFreePool(pETEs);
+                        return 0;
+                    }
                     curPtBlock->next = tmpPtBlock;
                     curPtBlock = tmpPtBlock;
                     pts = curPtBlock->pts;
@@ -3441,16 +3649,19 @@ IntCreatePolyPolgonRgn(POINT *Pts,
             REGION_InsertionSort(&AET);
         }
     }
-    else {
+    else
+    {
         /*
          *  for each scanline
          */
-        for (y = ET.ymin; y < ET.ymax; y++) {
+        for (y = ET.ymin; y < ET.ymax; y++)
+        {
             /*
              *  Add a new edge to the active edge table when we
              *  get to the next edge.
              */
-            if (pSLL != NULL && y == pSLL->scanline) {
+            if (pSLL != NULL && y == pSLL->scanline)
+            {
                 REGION_loadAET(&AET, pSLL->edgelist);
                 REGION_computeWAET(&AET);
                 pSLL = pSLL->next;
@@ -3462,31 +3673,36 @@ IntCreatePolyPolgonRgn(POINT *Pts,
             /*
              *  for each active edge
              */
-            while (pAET) {
+            while (pAET)
+            {
                 /*
                  *  add to the buffer only those edges that
                  *  are in the Winding active edge table.
                  */
-                if (pWETE == pAET) {
+                if (pWETE == pAET)
+                {
                     pts->x = pAET->bres.minor_axis,  pts->y = y;
                     pts++, iPts++;
 
                     /*
                      *  send out the buffer
                      */
-                    if (iPts == NUMPTSTOBUFFER) {
-                        tmpPtBlock = ExAllocatePoolWithTag( PagedPool,
-                                              sizeof(POINTBLOCK), TAG_REGION );
-                       if(!tmpPtBlock) {
-                           DPRINT1("Can't alloc tPB\n");
-                           ExFreePool(pETEs);
-                           NtGdiDeleteObject( hrgn );
-                           return 0;
-                       }
+                    if (iPts == NUMPTSTOBUFFER)
+                    {
+                        tmpPtBlock = ExAllocatePoolWithTag(PagedPool,
+                                                           sizeof(POINTBLOCK), TAG_REGION);
+                        if (!tmpPtBlock)
+                        {
+                            DPRINT1("Can't alloc tPB\n");
+                            ExFreePool(pETEs);
+                            NtGdiDeleteObject(hrgn);
+                            return 0;
+                        }
                         curPtBlock->next = tmpPtBlock;
                         curPtBlock = tmpPtBlock;
                         pts = curPtBlock->pts;
-                        numFullPtBlocks++;    iPts = 0;
+                        numFullPtBlocks++;
+                        iPts = 0;
                     }
                     pWETE = pWETE->nextWETE;
                 }
@@ -3497,7 +3713,8 @@ IntCreatePolyPolgonRgn(POINT *Pts,
              *  recompute the winding active edge table if
              *  we just resorted or have exited an edge.
              */
-            if (REGION_InsertionSort(&AET) || fixWAET) {
+            if (REGION_InsertionSort(&AET) || fixWAET)
+            {
                 REGION_computeWAET(&AET);
                 fixWAET = FALSE;
             }
@@ -3506,153 +3723,150 @@ IntCreatePolyPolgonRgn(POINT *Pts,
     REGION_FreeStorage(SLLBlock.next);
     REGION_PtsToRegion(numFullPtBlocks, iPts, &FirstPtBlock, region);
 
-    for (curPtBlock = FirstPtBlock.next; --numFullPtBlocks >= 0;) {
-       tmpPtBlock = curPtBlock->next;
-       ExFreePool( curPtBlock );
-       curPtBlock = tmpPtBlock;
+    for (curPtBlock = FirstPtBlock.next; --numFullPtBlocks >= 0;)
+    {
+        tmpPtBlock = curPtBlock->next;
+        ExFreePool(curPtBlock);
+        curPtBlock = tmpPtBlock;
     }
-    ExFreePool( pETEs );
-    RGNDATA_UnlockRgn( region );
+    ExFreePool(pETEs);
+    RGNDATA_UnlockRgn(region);
     return hrgn;
 }
 
 
 HRGN
 FASTCALL
-GdiCreatePolyPolygonRgn(CONST PPOINT  pt,
-                          CONST PINT  PolyCounts,
-                          INT  Count,
-                          INT  PolyFillMode)
+GdiCreatePolyPolygonRgn(
+    CONST PPOINT pt,
+    CONST PINT  PolyCounts,
+    INT  Count,
+    INT  PolyFillMode
+)
 {
-   POINT *Safept;
-   INT *SafePolyCounts;
-   INT nPoints, nEmpty, nInvalid, i;
-   HRGN hRgn;
-   NTSTATUS Status = STATUS_SUCCESS;
-
-   if (pt == NULL || PolyCounts == NULL || Count == 0 ||
-       (PolyFillMode != WINDING && PolyFillMode != ALTERNATE))
-   {
-      /* Windows doesn't set a last error here */
-      return (HRGN)0;
-   }
-
-   _SEH_TRY
-   {
-      ProbeForRead(PolyCounts,
-                   Count * sizeof(INT),
-                   1);
-      /* just probe one point for now, we don't know the length of the array yet */
-      ProbeForRead(pt,
-                   sizeof(POINT),
-                   1);
-   }
-   _SEH_HANDLE
-   {
-      Status = _SEH_GetExceptionCode();
-   }
-   _SEH_END;
-
-   if (!NT_SUCCESS(Status))
-   {
-      SetLastNtError(Status);
-      return (HRGN)0;
-   }
-
-   if (!(SafePolyCounts = ExAllocatePoolWithTag(PagedPool, Count * sizeof(INT), TAG_REGION)))
-   {
-      SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
-      return (HRGN)0;
-   }
-
-   _SEH_TRY
-   {
-      /* pointers were already probed! */
-      RtlCopyMemory(SafePolyCounts,
-                    PolyCounts,
-                    Count * sizeof(INT));
-   }
-   _SEH_HANDLE
-   {
-      Status = _SEH_GetExceptionCode();
-   }
-   _SEH_END;
-
-   if (!NT_SUCCESS(Status))
-   {
-      ExFreePool(SafePolyCounts);
-      SetLastNtError(Status);
-      return (HRGN)0;
-   }
-
-   /* validate poligons */
-   nPoints = 0;
-   nEmpty = 0;
-   nInvalid = 0;
-   for (i = 0; i < Count; i++)
-   {
-      if (SafePolyCounts[i] == 0)
-      {
-         nEmpty++;
-      }
-      if (SafePolyCounts[i] == 1)
-      {
-         nInvalid++;
-      }
-      nPoints += SafePolyCounts[i];
-   }
-
-   if (nEmpty == Count)
-   {
-      /* if all polygon counts are zero, return without setting a last error code. */
-      ExFreePool(SafePolyCounts);
-      return (HRGN)0;
-   }
-   if (nInvalid != 0)
-   {
-     /* if at least one poly count is 1, fail */
-     ExFreePool(SafePolyCounts);
-     SetLastWin32Error(ERROR_INVALID_PARAMETER);
-     return (HRGN)0;
-   }
-
-   /* copy points */
-   if (!(Safept = ExAllocatePoolWithTag(PagedPool, nPoints * sizeof(POINT), TAG_REGION)))
-   {
-      ExFreePool(SafePolyCounts);
-      SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
-      return (HRGN)0;
-   }
-
-   _SEH_TRY
-   {
-      ProbeForRead(pt,
-                   nPoints * sizeof(POINT),
-                   1);
-      /* pointers were already probed! */
-      RtlCopyMemory(Safept,
-                    pt,
-                    nPoints * sizeof(POINT));
-   }
-   _SEH_HANDLE
-   {
-      Status = _SEH_GetExceptionCode();
-   }
-   _SEH_END;
-   if (!NT_SUCCESS(Status))
-   {
-      ExFreePool(Safept);
-      ExFreePool(SafePolyCounts);
-      SetLastNtError(Status);
-      return (HRGN)0;
-   }
-
-   /* now we're ready to calculate the region safely */
-   hRgn = IntCreatePolyPolgonRgn(Safept, SafePolyCounts, Count, PolyFillMode);
-
-   ExFreePool(Safept);
-   ExFreePool(SafePolyCounts);
-   return hRgn;
+    POINT *Safept;
+    INT *SafePolyCounts;
+    INT nPoints, nEmpty, nInvalid, i;
+    HRGN hRgn;
+    NTSTATUS Status = STATUS_SUCCESS;
+
+    if (pt == NULL || PolyCounts == NULL || Count == 0 ||
+            (PolyFillMode != WINDING && PolyFillMode != ALTERNATE))
+    {
+        /* Windows doesn't set a last error here */
+        return (HRGN)0;
+    }
+
+    _SEH_TRY
+    {
+        ProbeForRead(PolyCounts, Count * sizeof(INT), 1);
+        /* just probe one point for now, we don't know the length of the array yet */
+        ProbeForRead(pt, sizeof(POINT), 1);
+    }
+    _SEH_HANDLE
+    {
+        Status = _SEH_GetExceptionCode();
+    }
+    _SEH_END;
+
+    if (!NT_SUCCESS(Status))
+    {
+        SetLastNtError(Status);
+        return (HRGN)0;
+    }
+
+    if (!(SafePolyCounts = ExAllocatePoolWithTag(PagedPool, Count * sizeof(INT), TAG_REGION)))
+    {
+        SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
+        return (HRGN)0;
+    }
+
+    _SEH_TRY
+    {
+        /* pointers were already probed! */
+        RtlCopyMemory(SafePolyCounts,
+        PolyCounts,
+        Count * sizeof(INT));
+    }
+    _SEH_HANDLE
+    {
+        Status = _SEH_GetExceptionCode();
+    }
+    _SEH_END;
+
+    if (!NT_SUCCESS(Status))
+    {
+        ExFreePool(SafePolyCounts);
+        SetLastNtError(Status);
+        return (HRGN)0;
+    }
+
+    /* validate poligons */
+    nPoints = 0;
+    nEmpty = 0;
+    nInvalid = 0;
+    for (i = 0; i < Count; i++)
+    {
+        if (SafePolyCounts[i] == 0)
+        {
+            nEmpty++;
+        }
+        if (SafePolyCounts[i] == 1)
+        {
+            nInvalid++;
+        }
+        nPoints += SafePolyCounts[i];
+    }
+
+    if (nEmpty == Count)
+    {
+        /* if all polygon counts are zero, return without setting a last error code. */
+        ExFreePool(SafePolyCounts);
+        return (HRGN)0;
+    }
+    if (nInvalid != 0)
+    {
+        /* if at least one poly count is 1, fail */
+        ExFreePool(SafePolyCounts);
+        SetLastWin32Error(ERROR_INVALID_PARAMETER);
+        return (HRGN)0;
+    }
+
+    /* copy points */
+    if (!(Safept = ExAllocatePoolWithTag(PagedPool, nPoints * sizeof(POINT), TAG_REGION)))
+    {
+        ExFreePool(SafePolyCounts);
+        SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
+        return (HRGN)0;
+    }
+
+    _SEH_TRY
+    {
+        ProbeForRead(pt, nPoints * sizeof(POINT), 1);
+        /* pointers were already probed! */
+        RtlCopyMemory(Safept,
+                      pt,
+                      nPoints * sizeof(POINT));
+    }
+    _SEH_HANDLE
+    {
+        Status = _SEH_GetExceptionCode();
+    }
+    _SEH_END;
+    if (!NT_SUCCESS(Status))
+    {
+        ExFreePool(Safept);
+        ExFreePool(SafePolyCounts);
+        SetLastNtError(Status);
+        return (HRGN)0;
+    }
+
+    /* now we're ready to calculate the region safely */
+    hRgn = IntCreatePolyPolgonRgn(Safept, SafePolyCounts, Count, PolyFillMode);
+
+    ExFreePool(Safept);
+    ExFreePool(SafePolyCounts);
+    return hRgn;
 }
 
 /* EOF */