2005-09-26 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / System.Drawing / System.Drawing / Graphics.cs
old mode 100755 (executable)
new mode 100644 (file)
index 3e1ae40..42b107c
@@ -1,18 +1,41 @@
 //
 // System.Drawing.Graphics.cs
 //
-// (C) 2003 Ximian, Inc.  http://www.ximian.com
-//
 // Authors:
 //     Gonzalo Paniagua Javier (gonzalo@ximian.com) (stubbed out)
 //      Alexandre Pigolkine(pigolkine@gmx.de)
-//             Jordi Mas i Hernandez (jordi@ximian.com)
+//     Jordi Mas i Hernandez (jordi@ximian.com)
+//
+// Copyright (C) 2003 Ximian, Inc. (http://www.ximian.com)
+//
+// Copyright (C) 2004-2005 Novell, Inc. (http://www.novell.com)
 //
-using System;
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System.Drawing.Drawing2D;
 using System.Drawing.Imaging;
 using System.Drawing.Text;
+using System.ComponentModel;
 using System.Runtime.InteropServices;
+using System.Security.Permissions;
 using System.Text;
 
 namespace System.Drawing
@@ -21,48 +44,54 @@ namespace System.Drawing
        public sealed class Graphics : MarshalByRefObject, IDisposable
        {
                internal IntPtr nativeObject = IntPtr.Zero;
-               internal static float defDpiX = 0;
-               internal static float defDpiY = 0;
-               
+               private bool disposed = false;
+               private static float defDpiX = 0;
+               private static float defDpiY = 0;
+
+               [ComVisible(false)]
                public delegate bool EnumerateMetafileProc (EmfPlusRecordType recordType,
                                                            int flags,
                                                            int dataSize,
                                                            IntPtr data,
                                                            PlayRecordCallback callbackData);
                
-               public delegate bool DrawImageAbort (IntPtr callbackData);              
-               
+               [ComVisible (false)]
+               public delegate bool DrawImageAbort (IntPtr callbackData);
+
                private Graphics (IntPtr nativeGraphics)
                {
-                       if (nativeGraphics == IntPtr.Zero)
-                               Console.WriteLine ("Here: " + Environment.StackTrace);
                        nativeObject = nativeGraphics;
                }
-               
+
+               ~Graphics ()
+               {
+                       Dispose ();                     
+               }               
+
                static internal float systemDpiX {
-                       get {                                   
-                                       if (defDpiX==0) {
-                                               Bitmap bmp = new Bitmap(1,1);
-                                               Graphics g = Graphics.FromImage(bmp);   
-                                               defDpiX = g.DpiX;
-                                       }
-                                       return defDpiX;
+                       get {
+                               if (defDpiX == 0) {
+                                       Bitmap bmp = new Bitmap (1, 1);
+                                       Graphics g = Graphics.FromImage (bmp);
+                                       defDpiX = g.DpiX;
+                               }
+                               return defDpiX;
                        }
                }
 
                static internal float systemDpiY {
                        get {
-                                       if (defDpiY==0) {
-                                               Bitmap bmp = new Bitmap(1,1);
-                                               Graphics g = Graphics.FromImage(bmp);   
-                                               defDpiY = g.DpiY;
-                                       }
-                                       return defDpiY;
+                               if (defDpiY == 0) {
+                                       Bitmap bmp = new Bitmap (1, 1);
+                                       Graphics g = Graphics.FromImage (bmp);
+                                       defDpiY = g.DpiY;
+                               }
+                               return defDpiY;
                        }
                }
-               
+
                internal IntPtr NativeObject {
-                       get{
+                       get {
                                return nativeObject;
                        }
 
@@ -81,40 +110,51 @@ namespace System.Drawing
                public GraphicsContainer BeginContainer ()
                {
                        int state;
+                       Status status;
+                       status = GDIPlus.GdipBeginContainer2 (nativeObject, out state);
+                       GDIPlus.CheckStatus (status);
 
-                        GDIPlus.GdipBeginContainer2 (nativeObject, out state);
-               
                         return new GraphicsContainer(state);
                }
                
                public GraphicsContainer BeginContainer (Rectangle dstrect, Rectangle srcrect, GraphicsUnit unit)
                {
                        int state;
+                       Status status;
+                       status = GDIPlus.GdipBeginContainerI (nativeObject, dstrect, srcrect, unit, out state);
+                       GDIPlus.CheckStatus (status);
 
-                        GDIPlus.GdipBeginContainerI (nativeObject, dstrect, srcrect, unit, out state);         
-               
-                        return new GraphicsContainer (state);
+                       return new GraphicsContainer (state);
                }
 
                
                public GraphicsContainer BeginContainer (RectangleF dstrect, RectangleF srcrect, GraphicsUnit unit)
                {
                        int state;
+                       Status status;
+                       status = GDIPlus.GdipBeginContainer (nativeObject, dstrect, srcrect, unit, out state);
+                       GDIPlus.CheckStatus (status);
 
-                        GDIPlus.GdipBeginContainer (nativeObject, dstrect, srcrect, unit, out state);          
-               
-                        return new GraphicsContainer (state);
+                       return new GraphicsContainer (state);
                }
 
                
                public void Clear (Color color)
-               {                       
-                       GDIPlus.GdipGraphicsClear(nativeObject, color.ToArgb());                        
+               {
+                       Status status;
+                       status = GDIPlus.GdipGraphicsClear (nativeObject, color.ToArgb ());
+                       GDIPlus.CheckStatus (status);
                }
 
-               [MonoTODO]
                public void Dispose ()
                {
+                       Status status;
+                       if (! disposed) {
+                               status = GDIPlus.GdipDeleteGraphics (nativeObject);
+                               nativeObject = IntPtr.Zero;
+                               GDIPlus.CheckStatus (status);
+                               disposed = true;                                
+                       }
                }
 
                
@@ -132,40 +172,53 @@ namespace System.Drawing
                
                public void DrawArc (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
                {
-                       GDIPlus.GdipDrawArc (nativeObject, pen.nativeObject,
-                                        x, y, width, height, startAngle, sweepAngle);                        
+                       Status status;
+                       status = GDIPlus.GdipDrawArc (nativeObject, pen.nativeObject,
+                                        x, y, width, height, startAngle, sweepAngle);
+                       GDIPlus.CheckStatus (status);
                }
 
-               public void DrawArc (Pen pen, int x, int y, int width, int height, float startAngle, float sweepAngle)
-               {                       
-                       GDIPlus.GdipDrawArcI (nativeObject, pen.nativeObject,
-                                        x, y, width, height, startAngle, sweepAngle);
-                                                    
+               // Microsoft documentation states that the signature for this member should be
+               // public void DrawArc( Pen pen,  int x,  int y,  int width,  int height,   int startAngle,
+               // int sweepAngle. However, GdipDrawArcI uses also float for the startAngle and sweepAngle params
+               public void DrawArc (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
+               {
+                       Status status;
+                       status = GDIPlus.GdipDrawArcI (nativeObject, pen.nativeObject,
+                                               x, y, width, height, startAngle, sweepAngle);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawBezier (Pen pen, PointF pt1, PointF pt2, PointF pt3, PointF pt4)
                {
-                       GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject, 
-                                        pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);                                     
-                       
+                       Status status;
+                       status = GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject,
+                                                       pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X,
+                                                       pt3.Y, pt4.X, pt4.Y);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawBezier (Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)
                {
-                       GDIPlus.GdipDrawBezierI (nativeObject, pen.nativeObject, 
-                                        pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);                                        
-               
+                       Status status;
+                       status = GDIPlus.GdipDrawBezierI (nativeObject, pen.nativeObject,
+                                                       pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X,
+                                                       pt3.Y, pt4.X, pt4.Y);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawBezier (Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
                {
-                       GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject, x1, y1, x2, y2, x3, y3, x4, y4);
+                       Status status;
+                       status = GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject, x1,
+                                                       y1, x2, y2, x3, y3, x4, y4);
+                       GDIPlus.CheckStatus (status);
                }
 
-                [MonoTODO]
                public void DrawBeziers (Pen pen, Point [] points)
                {
                         int length = points.Length;
+                       Status status;
 
                         if (length < 3)
                                 return;
@@ -176,16 +229,18 @@ namespace System.Drawing
                                 Point p3 = points [i + 2];
                                 Point p4 = points [i + 3];
 
-                                GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject,
+                                status = GDIPlus.GdipDrawBezier (nativeObject, 
+                                                       pen.nativeObject,
                                                         p1.X, p1.Y, p2.X, p2.Y, 
                                                         p3.X, p3.Y, p4.X, p4.Y);
+                               GDIPlus.CheckStatus (status);
                         }
                }
 
-                [MonoTODO]
                public void DrawBeziers (Pen pen, PointF [] points)
                {
                        int length = points.Length;
+                       Status status;
 
                         if (length < 3)
                                 return;
@@ -196,74 +251,98 @@ namespace System.Drawing
                                 PointF p3 = points [i + 2];
                                 PointF p4 = points [i + 3];
 
-                                GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject,
+                                status = GDIPlus.GdipDrawBezier (nativeObject, 
+                                                       pen.nativeObject,
                                                         p1.X, p1.Y, p2.X, p2.Y, 
                                                         p3.X, p3.Y, p4.X, p4.Y);
+                               GDIPlus.CheckStatus (status);
                         }
                }
 
                
                public void DrawClosedCurve (Pen pen, PointF [] points)
                {
-                       GDIPlus.GdipDrawClosedCurve (nativeObject, pen.nativeObject, points, points.Length);
+                       Status status;
+                       status = GDIPlus.GdipDrawClosedCurve (nativeObject, pen.nativeObject, points, points.Length);
+                       GDIPlus.CheckStatus (status);
                }
                
                public void DrawClosedCurve (Pen pen, Point [] points)
                {
-                       GDIPlus.GdipDrawClosedCurveI (nativeObject, pen.nativeObject, points, points.Length);                   
+                       Status status;
+                       status = GDIPlus.GdipDrawClosedCurveI (nativeObject, pen.nativeObject, points, points.Length);
+                       GDIPlus.CheckStatus (status);
                }
                        
                public void DrawClosedCurve (Pen pen, Point [] points, float tension, FillMode fillmode)
                {
-                       GDIPlus.GdipDrawClosedCurve2I (nativeObject, pen.nativeObject, points, points.Length, tension); 
+                       Status status;
+                       status = GDIPlus.GdipDrawClosedCurve2I (nativeObject, pen.nativeObject, points, points.Length, tension);
+                       GDIPlus.CheckStatus (status);
                }
                
                public void DrawClosedCurve (Pen pen, PointF [] points, float tension, FillMode fillmode)
                {
-                       GDIPlus.GdipDrawClosedCurve2 (nativeObject, pen.nativeObject, points, points.Length, tension);
+                       Status status;
+                       status = GDIPlus.GdipDrawClosedCurve2 (nativeObject, pen.nativeObject, points, points.Length, tension);
+                       GDIPlus.CheckStatus (status);
                }
                
                public void DrawCurve (Pen pen, Point [] points)
                {
-                       GDIPlus.GdipDrawCurveI (nativeObject, pen.nativeObject, points, points.Length);                 
+                       Status status;
+                       status = GDIPlus.GdipDrawCurveI (nativeObject, pen.nativeObject, points, points.Length);
+                       GDIPlus.CheckStatus (status);
                }
                
                public void DrawCurve (Pen pen, PointF [] points)
                {
-                       GDIPlus.GdipDrawCurve (nativeObject, pen.nativeObject, points, points.Length);                          
-                       
+                       Status status;
+                       status = GDIPlus.GdipDrawCurve (nativeObject, pen.nativeObject, points, points.Length);
+                       GDIPlus.CheckStatus (status);
                }
                
                public void DrawCurve (Pen pen, PointF [] points, float tension)
-               {                       
-                       GDIPlus.GdipDrawCurve2 (nativeObject, pen.nativeObject, points, points.Length, tension);                
-                       
+               {
+                       Status status;
+                       status = GDIPlus.GdipDrawCurve2 (nativeObject, pen.nativeObject, points, points.Length, tension);
+                       GDIPlus.CheckStatus (status);
                }
                
                public void DrawCurve (Pen pen, Point [] points, float tension)
                {
-                       GDIPlus.GdipDrawCurve2I (nativeObject, pen.nativeObject, points, points.Length, tension);               
-                       
+                       Status status;
+                       status = GDIPlus.GdipDrawCurve2I (nativeObject, pen.nativeObject, points, points.Length, tension);              
+                       GDIPlus.CheckStatus (status);
                }
                
                
                public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments)
                {
-                       GDIPlus.GdipDrawCurve3 (nativeObject, pen.nativeObject, points, points.Length,
-                               offset, numberOfSegments, 0.5f);
+                       Status status;
+                       status = GDIPlus.GdipDrawCurve3 (nativeObject, pen.nativeObject,
+                                                       points, points.Length, offset,
+                                                       numberOfSegments, 0.5f);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawCurve (Pen pen, Point [] points, int offset, int numberOfSegments, float tension)
                {
-                       GDIPlus.GdipDrawCurve3I (nativeObject, pen.nativeObject, points, points.Length,
-                                        offset, numberOfSegments, tension);
+                       Status status;
+                       status = GDIPlus.GdipDrawCurve3I (nativeObject, pen.nativeObject,
+                                                       points, points.Length, offset,
+                                                       numberOfSegments, tension);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments, float tension)
                {
-                       GDIPlus.GdipDrawCurve3 (nativeObject, pen.nativeObject, points, points.Length, 
-                                        offset, numberOfSegments, tension);
+                       Status status;
+                       status = GDIPlus.GdipDrawCurve3 (nativeObject, pen.nativeObject,
+                                                       points, points.Length, offset,
+                                                       numberOfSegments, tension);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawEllipse (Pen pen, Rectangle rect)
@@ -278,48 +357,53 @@ namespace System.Drawing
 
                public void DrawEllipse (Pen pen, int x, int y, int width, int height)
                {
-                       GDIPlus.GdipDrawEllipseI (nativeObject, pen.nativeObject, x, y, width, height);
+                       Status status;
+                       status = GDIPlus.GdipDrawEllipseI (nativeObject, pen.nativeObject, x, y, width, height);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawEllipse (Pen pen, float x, float y, float width, float height)
                {
-                       GDIPlus.GdipDrawEllipse (nativeObject, pen.nativeObject, x, y, width, height); 
+                       Status status = GDIPlus.GdipDrawEllipse (nativeObject, pen.nativeObject, x, y, width, height);
+                       GDIPlus.CheckStatus (status);
                }
 
-               [MonoTODO]
                public void DrawIcon (Icon icon, Rectangle targetRect)
                {
-                       throw new NotImplementedException ();
+                       Image img = icon.ToBitmap ();
+                       DrawImage (img, targetRect);
                }
 
-               [MonoTODO]
                public void DrawIcon (Icon icon, int x, int y)
                {
-                       throw new NotImplementedException ();
+                       Image img = icon.ToBitmap ();
+                       DrawImage (img, x, y);
                }
 
-               [MonoTODO]
                public void DrawIconUnstretched (Icon icon, Rectangle targetRect)
                {
-                       throw new NotImplementedException ();
+                       Image img = icon.ToBitmap ();
+                       DrawImageUnscaled (img, targetRect);
                }
                
                public void DrawImage (Image image, RectangleF rect)
                {
-                       GDIPlus.GdipDrawImageRect(nativeObject, image.NativeObject, rect.X, rect.Y,
-                           rect.Width, rect.Height);
+                       Status status = GDIPlus.GdipDrawImageRect(nativeObject, image.NativeObject, rect.X, rect.Y, rect.Width, rect.Height);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void DrawImage (Image image, PointF point)
                {
-                       GDIPlus.GdipDrawImage (nativeObject, image.NativeObject, point.X, point.Y);                     
+                       Status status = GDIPlus.GdipDrawImage (nativeObject, image.NativeObject, point.X, point.Y);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void DrawImage (Image image, Point [] destPoints)
                {
-                       GDIPlus.GdipDrawImagePointsI (nativeObject, image.NativeObject, destPoints, destPoints.Length);
+                       Status status = GDIPlus.GdipDrawImagePointsI (nativeObject, image.NativeObject, destPoints, destPoints.Length);
+                       GDIPlus.CheckStatus (status);
                }
 
                
@@ -331,279 +415,305 @@ namespace System.Drawing
                
                public void DrawImage (Image image, Rectangle rect)
                {
-                       DrawImage(image, rect.X, rect.Y, rect.Width, rect.Height);
+                       DrawImage (image, rect.X, rect.Y, rect.Width, rect.Height);
                }
 
                
                public void DrawImage (Image image, PointF [] destPoints)
                {
-                       GDIPlus.GdipDrawImagePoints (nativeObject, image.NativeObject, destPoints, destPoints.Length);
+                       Status status = GDIPlus.GdipDrawImagePoints (nativeObject, image.NativeObject, destPoints, destPoints.Length);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void DrawImage (Image image, int x, int y)
                {
-                       GDIPlus.GdipDrawImageI (nativeObject, image.NativeObject, x, y);
+                       Status status = GDIPlus.GdipDrawImageI (nativeObject, image.NativeObject, x, y);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void DrawImage (Image image, float x, float y)
                {
-                       GDIPlus.GdipDrawImage (nativeObject, image.NativeObject, x, y);
+                       Status status = GDIPlus.GdipDrawImage (nativeObject, image.NativeObject, x, y);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void DrawImage (Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit)
                {
-                       GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,                                                            
+                       Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
                                destRect.X, destRect.Y, destRect.Width, destRect.Height,
                                srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
                                srcUnit, IntPtr.Zero, null, IntPtr.Zero);
+                       GDIPlus.CheckStatus (status);
                }
                
                public void DrawImage (Image image, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit)
                {                       
-                       GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,                                                            
+                       Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
                                destRect.X, destRect.Y, destRect.Width, destRect.Height,
                                srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
                                srcUnit, IntPtr.Zero, null, IntPtr.Zero);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit)
                {
-                       GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
-                               destPoints, destPoints.Length , srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
-                               srcUnit, IntPtr.Zero, null, IntPtr.Zero);
-                
+                       Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
+                               destPoints, destPoints.Length , srcRect.X, srcRect.Y, 
+                               srcRect.Width, srcRect.Height, srcUnit, IntPtr.Zero, 
+                               null, IntPtr.Zero);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit)
                {
                        
-                       GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
-                               destPoints, destPoints.Length , srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
-                               srcUnit, IntPtr.Zero, null, IntPtr.Zero);
+                       Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
+                               destPoints, destPoints.Length , srcRect.X, srcRect.Y, 
+                               srcRect.Width, srcRect.Height, srcUnit, IntPtr.Zero, 
+                               null, IntPtr.Zero);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, 
                                 ImageAttributes imageAttr)
                {
-                       GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
-                               destPoints, destPoints.Length , srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
-                               srcUnit, imageAttr.NativeObject , null, IntPtr.Zero);
+                       Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
+                               destPoints, destPoints.Length , srcRect.X, srcRect.Y,
+                               srcRect.Width, srcRect.Height, srcUnit,
+                               imageAttr.NativeObject, null, IntPtr.Zero);
+                       GDIPlus.CheckStatus (status);
                }
                
                public void DrawImage (Image image, float x, float y, float width, float height)
                {
-                       GDIPlus.GdipDrawImageRect(nativeObject, image.NativeObject, x, y,
+                       Status status = GDIPlus.GdipDrawImageRect(nativeObject, image.NativeObject, x, y,
                            width, height);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, 
                                 ImageAttributes imageAttr)
                {
-                       GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
-                               destPoints, destPoints.Length , srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
-                               srcUnit, imageAttr.NativeObject, null, IntPtr.Zero);
+                       Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
+                               destPoints, destPoints.Length , srcRect.X, srcRect.Y,
+                               srcRect.Width, srcRect.Height, srcUnit, 
+                               imageAttr.NativeObject, null, IntPtr.Zero);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void DrawImage (Image image, int x, int y, Rectangle srcRect, GraphicsUnit srcUnit)
                {                       
-                       GDIPlus.GdipDrawImagePointRectI(nativeObject, image.NativeObject, x, y,
-                                srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, srcUnit);
+                       Status status = GDIPlus.GdipDrawImagePointRectI(nativeObject, image.NativeObject, x, y, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, srcUnit);
+                       GDIPlus.CheckStatus (status);
                }
                
                public void DrawImage (Image image, int x, int y, int width, int height)
                {
-                       GDIPlus.GdipDrawImageRectI (nativeObject, image.nativeObject, x, y, width, height);
+                       Status status = GDIPlus.GdipDrawImageRectI (nativeObject, image.nativeObject, x, y, width, height);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawImage (Image image, float x, float y, RectangleF srcRect, GraphicsUnit srcUnit)
                {                       
-                       GDIPlus.GdipDrawImagePointRect(nativeObject,    image.nativeObject, x, y, srcRect.X, srcRect.Y, 
-                               srcRect.Width, srcRect.Height, srcUnit);                                                                                
+                       Status status = GDIPlus.GdipDrawImagePointRect (nativeObject, image.nativeObject, x, y, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, srcUnit);
+                       GDIPlus.CheckStatus (status);
                }
 
                
-               public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, 
-                                ImageAttributes imageAttr, DrawImageAbort callback)
+               public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
                {
-                       GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
-                               destPoints, destPoints.Length , srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
-                               srcUnit, imageAttr.NativeObject, callback, IntPtr.Zero);
+                       Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
+                               destPoints, destPoints.Length , srcRect.X, srcRect.Y,
+                               srcRect.Width, srcRect.Height, srcUnit, 
+                               imageAttr.NativeObject, callback, IntPtr.Zero);
+                       GDIPlus.CheckStatus (status);
                }
 
                
-               public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, 
-                                ImageAttributes imageAttr, DrawImageAbort callback)
+               public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
                {
                        
-                       GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
-                               destPoints, destPoints.Length , srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
-                               srcUnit, imageAttr.NativeObject, callback, IntPtr.Zero);
+                       Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
+                               destPoints, destPoints.Length , srcRect.X, srcRect.Y,
+                               srcRect.Width, srcRect.Height, srcUnit, 
+                               imageAttr.NativeObject, callback, IntPtr.Zero);
+                       GDIPlus.CheckStatus (status);
                }
 
                
-               public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, 
-                                ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
+               public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
                {
-                       GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
-                               destPoints, destPoints.Length , srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
-                               srcUnit, imageAttr.NativeObject, callback, (IntPtr) callbackData);
+
+                       Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
+                               destPoints, destPoints.Length , srcRect.X, srcRect.Y, 
+                               srcRect.Width, srcRect.Height, srcUnit, 
+                               imageAttr.NativeObject, callback, (IntPtr) callbackData);
+                       GDIPlus.CheckStatus (status);
                }
 
                
-               public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, 
-                                GraphicsUnit srcUnit)
+               public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit)
                {
-                       GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
+                       Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
                                        srcX, srcY, srcWidth, srcHeight, srcUnit, IntPtr.Zero, 
-                                       null, IntPtr.Zero);                                                             
+                                       null, IntPtr.Zero);
+                       GDIPlus.CheckStatus (status);                                   
                }
                
-               public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, 
-                                ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
+               public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
                {
-                       GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
-                               destPoints, destPoints.Length , srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
-                               srcUnit, imageAttr.NativeObject, callback, (IntPtr) callbackData);
+                       Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
+                               destPoints, destPoints.Length , srcRect.X, srcRect.Y,
+                               srcRect.Width, srcRect.Height, srcUnit, 
+                               imageAttr.NativeObject, callback, (IntPtr) callbackData);
+                       GDIPlus.CheckStatus (status);
                }
 
                
-               public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, 
-                                GraphicsUnit srcUnit)
+               public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit)
                {
-                       GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
+                       Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
                                        srcX, srcY, srcWidth, srcHeight, srcUnit, IntPtr.Zero, 
-                                       null, IntPtr.Zero);                                                             
+                                       null, IntPtr.Zero);
+                       GDIPlus.CheckStatus (status);
                }
 
                
-               public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, 
-                                GraphicsUnit srcUnit, ImageAttributes imageAttrs)
+               public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs)
                {
-                       GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
+                       Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
-                                       srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttrs.NativeObject, 
-                                       null, IntPtr.Zero);                                     
-                       
+                                       srcX, srcY, srcWidth, srcHeight, srcUnit,
+                               imageAttrs.NativeObject, null, IntPtr.Zero);
+                       GDIPlus.CheckStatus (status);
                }
                
-               public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, 
-                                GraphicsUnit srcUnit, ImageAttributes imageAttr)
+               public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr)
                {                       
-                       GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject, 
-                                        destRect.X, destRect.Y, destRect.Width, destRect.Height,
-                                        srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttr.NativeObject, 
-                                        null, IntPtr.Zero);
+                       Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject, 
+                                        destRect.X, destRect.Y, destRect.Width, 
+                                       destRect.Height, srcX, srcY, srcWidth, srcHeight,
+                                       srcUnit, imageAttr.NativeObject, null, IntPtr.Zero);
+                       GDIPlus.CheckStatus (status);
                }
                
-               public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight,
-                                GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
+               public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
                {
-                       GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject, 
-                                        destRect.X, destRect.Y, destRect.Width, destRect.Height,
-                                        srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttr.NativeObject, 
-                                        callback, IntPtr.Zero);
+                       Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject, 
+                                        destRect.X, destRect.Y, destRect.Width, 
+                                       destRect.Height, srcX, srcY, srcWidth, srcHeight,
+                                       srcUnit, imageAttr.NativeObject, callback,
+                                       IntPtr.Zero);
+                       GDIPlus.CheckStatus (status);
                }
                
-               public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight,
-                                GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
+               public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
                {
-                       GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject, 
-                                        destRect.X, destRect.Y, destRect.Width, destRect.Height,
-                                        srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttr.NativeObject, 
-                                        callback, IntPtr.Zero);
+                       Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject, 
+                                        destRect.X, destRect.Y, destRect.Width, 
+                                       destRect.Height, srcX, srcY, srcWidth, srcHeight,
+                                       srcUnit, imageAttr.NativeObject, 
+                                       callback, IntPtr.Zero);
+                       GDIPlus.CheckStatus (status);
                }
 
                
-               public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight,
-                                GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
+               public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
                {
-                       GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject, 
+                       Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject, 
                                destRect.X, destRect.Y, destRect.Width, destRect.Height,
-                               srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttr.NativeObject, 
-                               callback, callbackData);
+                               srcX, srcY, srcWidth, srcHeight, srcUnit, 
+                               imageAttr.NativeObject, callback, callbackData);
+                       GDIPlus.CheckStatus (status);
                }
 
                
-               public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, 
-                                GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
+               public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
                {
-                       GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject, 
+                       Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject, 
                                        destRect.X, destRect.Y, destRect.Width, destRect.Height,
-                               srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttr.NativeObject, 
-                               callback, callbackData);
+                               srcX, srcY, srcWidth, srcHeight, srcUnit,
+                               imageAttr.NativeObject, callback, callbackData);
+                       GDIPlus.CheckStatus (status);
                }               
                
                public void DrawImageUnscaled (Image image, Point point)
                {
-                       DrawImage(image, point.X, point.Y);
+                       DrawImageUnscaled (image, point.X, point.Y);
                }
                
                public void DrawImageUnscaled (Image image, Rectangle rect)
                {
-                       DrawImage(image, rect.X, rect.Y, rect.Width, rect.Height);
+                       DrawImageUnscaled (image, rect.X, rect.Y, rect.Width, rect.Height);
                }
                
                public void DrawImageUnscaled (Image image, int x, int y)
                {
-                       DrawImage(image, x, y);
+                       DrawImage (image, x, y, image.Width, image.Height);
                }
 
                public void DrawImageUnscaled (Image image, int x, int y, int width, int height)
                {
-                       DrawImage(image, x, y, width, height);
+                       Image tmpImg = new Bitmap (width, height);
+                       Graphics g = FromImage (tmpImg);
+                       g.DrawImage (image, 0, 0, image.Width, image.Height);
+                       this.DrawImage (tmpImg, x, y, width, height);
+                       tmpImg.Dispose ();
+                       g.Dispose ();
                }
 
                public void DrawLine (Pen pen, PointF pt1, PointF pt2)
                {
-                        GDIPlus.GdipDrawLine (
-                                nativeObject, pen.nativeObject,
-                                pt1.X, pt1.Y,
-                                pt2.X, pt2.Y);                             
-                               
+                        Status status = GDIPlus.GdipDrawLine (nativeObject, pen.nativeObject,
+                                               pt1.X, pt1.Y, pt2.X, pt2.Y);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawLine (Pen pen, Point pt1, Point pt2)
                {
-                        GDIPlus.GdipDrawLineI (
-                                nativeObject, pen.nativeObject,
-                                pt1.X, pt1.Y,
-                                pt2.X, pt2.Y);                           
+                        Status status = GDIPlus.GdipDrawLineI (nativeObject, pen.nativeObject,
+                                               pt1.X, pt1.Y, pt2.X, pt2.Y);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawLine (Pen pen, int x1, int y1, int x2, int y2)
                {
-                       GDIPlus.GdipDrawLineI (nativeObject, pen.nativeObject, x1, y1, x2, y2);                 
+                       Status status = GDIPlus.GdipDrawLineI (nativeObject, pen.nativeObject, x1, y1, x2, y2);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawLine (Pen pen, float x1, float y1, float x2, float y2)
                {
-                       GDIPlus.GdipDrawLine (nativeObject, pen.nativeObject, x1, y1, x2, y2);  
+                       Status status = GDIPlus.GdipDrawLine (nativeObject, pen.nativeObject, x1, y1, x2, y2);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawLines (Pen pen, PointF [] points)
                {
-                       GDIPlus.GdipDrawLines (nativeObject, pen.nativeObject, points, points.Length);  
+                       Status status = GDIPlus.GdipDrawLines (nativeObject, pen.nativeObject, points, points.Length);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawLines (Pen pen, Point [] points)
                {
-                       GDIPlus.GdipDrawLinesI (nativeObject, pen.nativeObject, points, points.Length);                 
+                       Status status = GDIPlus.GdipDrawLinesI (nativeObject, pen.nativeObject, points, points.Length);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawPath (Pen pen, GraphicsPath path)
                {
-                       GDIPlus.GdipDrawPath (nativeObject, pen.nativeObject, path.nativePath);
+                       Status status = GDIPlus.GdipDrawPath (nativeObject, pen.nativeObject, path.nativePath);
+                       GDIPlus.CheckStatus (status);
                }
                
                public void DrawPie (Pen pen, Rectangle rect, float startAngle, float sweepAngle)
@@ -618,25 +728,32 @@ namespace System.Drawing
                
                public void DrawPie (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
                {
-                       GDIPlus.GdipDrawPie (nativeObject, pen.nativeObject, x, y, width, height, startAngle, sweepAngle);
+                       Status status = GDIPlus.GdipDrawPie (nativeObject, pen.nativeObject, x, y, width, height, startAngle, sweepAngle);
+                       GDIPlus.CheckStatus (status);
                }
                
-               public void DrawPie (Pen pen, int x, int y, int width, int height, float startAngle, float sweepAngle)
+               // Microsoft documentation states that the signature for this member should be
+               // public void DrawPie(Pen pen, int x,  int y,  int width,   int height,   int startAngle
+               // int sweepAngle. However, GdipDrawPieI uses also float for the startAngle and sweepAngle params
+               public void DrawPie (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
                {
-                       GDIPlus.GdipDrawPieI (nativeObject, pen.nativeObject, x, y, width, height, startAngle, sweepAngle);
+                       Status status = GDIPlus.GdipDrawPieI (nativeObject, pen.nativeObject, x, y, width, height, startAngle, sweepAngle);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawPolygon (Pen pen, Point [] points)
                {
-                       GDIPlus.GdipDrawPolygonI (nativeObject, pen.nativeObject, points, points.Length);
+                       Status status = GDIPlus.GdipDrawPolygonI (nativeObject, pen.nativeObject, points, points.Length);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawPolygon (Pen pen, PointF [] points)
                {
-                       GDIPlus.GdipDrawPolygon (nativeObject, pen.nativeObject, points, points.Length);
+                       Status status = GDIPlus.GdipDrawPolygon (nativeObject, pen.nativeObject, points, points.Length);
+                       GDIPlus.CheckStatus (status);
                }
 
-               public void DrawRectangle (Pen pen, RectangleF rect)
+               internal void DrawRectangle (Pen pen, RectangleF rect)
                {
                        DrawRectangle (pen, rect.Left, rect.Top, rect.Width, rect.Height);
                }
@@ -648,70 +765,70 @@ namespace System.Drawing
 
                public void DrawRectangle (Pen pen, float x, float y, float width, float height)
                {
-                       GDIPlus.GdipDrawRectangle (nativeObject, pen.nativeObject, x, y, width, height);
+                       Status status = GDIPlus.GdipDrawRectangle (nativeObject, pen.nativeObject, x, y, width, height);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawRectangle (Pen pen, int x, int y, int width, int height)
                {
-                       GDIPlus.GdipDrawRectangleI (nativeObject, pen.nativeObject, x, y, width, height);
+                       Status status = GDIPlus.GdipDrawRectangleI (nativeObject, pen.nativeObject, x, y, width, height);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawRectangles (Pen pen, RectangleF [] rects)
                {
-                       foreach (RectangleF rc in rects)
-                               DrawRectangle (pen, rc.Left, rc.Top, rc.Width, rc.Height);
+                       Status status = GDIPlus.GdipDrawRectangles (nativeObject, pen.nativeObject, rects, rects.Length);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void DrawRectangles (Pen pen, Rectangle [] rects)
                {
-                       foreach (RectangleF rc in rects)
-                               DrawRectangle(pen, rc.Left, rc.Top, rc.Width, rc.Height);
+                       Status status = GDIPlus.GdipDrawRectanglesI (nativeObject, pen.nativeObject, rects, rects.Length);
+                       GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle)
-               {                       
-                       GDIPlus.GdipDrawString (nativeObject, s, s.Length, font.NativeObject, ref layoutRectangle, IntPtr.Zero, brush.nativeObject);                     
+               {
+                       DrawString (s, font, brush, layoutRectangle, null);
                }
-               
+
                public void DrawString (string s, Font font, Brush brush, PointF point)
                {
-                       RectangleF rc = new RectangleF (point.X, point.Y, 0, 0);
-                       GDIPlus.GdipDrawString (nativeObject, s, s.Length, font.NativeObject, ref rc, IntPtr.Zero, brush.nativeObject);
+                       DrawString (s, font, brush, new RectangleF (point.X, point.Y, 0, 0), null);
                }
-               
+
                public void DrawString (string s, Font font, Brush brush, PointF point, StringFormat format)
                {
-                       RectangleF rc = new RectangleF (point.X, point.Y, 0, 0);
-                       GDIPlus.GdipDrawString (nativeObject, s, s.Length, font.NativeObject, ref rc, format.NativeObject, brush.nativeObject);
-               }
-               
-               public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
-               {
-                       GDIPlus.GdipDrawString (nativeObject, s, s.Length, font.NativeObject, ref layoutRectangle, 
-                               format.NativeObject, brush.nativeObject);
+                       DrawString(s, font, brush, new RectangleF(point.X, point.Y, 0, 0), format);
                }
 
                public void DrawString (string s, Font font, Brush brush, float x, float y)
                {
-                       RectangleF rc = new RectangleF (x, y, 0, 0);
-                       
-                       GDIPlus.GdipDrawString (nativeObject, s, s.Length, font.NativeObject, 
-                               ref rc, IntPtr.Zero, brush.nativeObject);                       
+                       DrawString (s, font, brush, new RectangleF (x, y, 0, 0), null);
                }
 
                public void DrawString (string s, Font font, Brush brush, float x, float y, StringFormat format)
                {
-                       RectangleF rc = new RectangleF (x, y, 0, 0);
+                       DrawString (s, font, brush, new RectangleF(x, y, 0, 0), format);
+               }
+
+               public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
+               {
+                       if (font == null)
+                               throw new ArgumentNullException ("font");
+                       if (brush == null)
+                               throw new ArgumentNullException ("brush");
+                       if (s == null || s.Length == 0)
+                               return;
 
-                       GDIPlus.GdipDrawString (nativeObject, s, s.Length, font.NativeObject,
-                               ref rc, format.NativeObject, brush.nativeObject);
+                       Status status = GDIPlus.GdipDrawString (nativeObject, s, s.Length, font.NativeObject, ref layoutRectangle, format != null ? format.NativeObject : IntPtr.Zero, brush.nativeObject);
+                       GDIPlus.CheckStatus (status);
                }
 
-               
                public void EndContainer (GraphicsContainer container)
                {
-                       GDIPlus.GdipEndContainer(nativeObject, container.NativeObject);
+                       Status status = GDIPlus.GdipEndContainer(nativeObject, container.NativeObject);
+                       GDIPlus.CheckStatus (status);
                }
 
                [MonoTODO]
@@ -932,25 +1049,28 @@ namespace System.Drawing
        
                public void ExcludeClip (Rectangle rect)
                {
-                       GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Exclude);    
+                       Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Exclude);
+                       GDIPlus.CheckStatus (status);
                }
 
-               [MonoTODO]
                public void ExcludeClip (Region region)
                {
-                       throw new NotImplementedException ();
+                       Status status = GDIPlus.GdipSetClipRegion (nativeObject, region.NativeObject, CombineMode.Exclude);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void FillClosedCurve (Brush brush, PointF [] points)
                {
-                      GDIPlus.GdipFillClosedCurve (nativeObject, brush.NativeObject, points, points.Length);
+                      Status status = GDIPlus.GdipFillClosedCurve (nativeObject, brush.NativeObject, points, points.Length);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void FillClosedCurve (Brush brush, Point [] points)
                {
-                       GDIPlus.GdipFillClosedCurveI (nativeObject, brush.NativeObject, points, points.Length);
+                       Status status = GDIPlus.GdipFillClosedCurveI (nativeObject, brush.NativeObject, points, points.Length);
+                       GDIPlus.CheckStatus (status);
                }
 
                
@@ -966,12 +1086,14 @@ namespace System.Drawing
 
                public void FillClosedCurve (Brush brush, PointF [] points, FillMode fillmode, float tension)
                {
-                       GDIPlus.GdipFillClosedCurve2 (nativeObject, brush.NativeObject, points, points.Length, tension, fillmode);
+                       Status status = GDIPlus.GdipFillClosedCurve2 (nativeObject, brush.NativeObject, points, points.Length, tension, fillmode);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void FillClosedCurve (Brush brush, Point [] points, FillMode fillmode, float tension)
                {
-                       GDIPlus.GdipFillClosedCurve2I (nativeObject, brush.NativeObject, points, points.Length, tension, fillmode);
+                       Status status = GDIPlus.GdipFillClosedCurve2I (nativeObject, brush.NativeObject, points, points.Length, tension, fillmode);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void FillEllipse (Brush brush, Rectangle rect)
@@ -986,53 +1108,62 @@ namespace System.Drawing
 
                public void FillEllipse (Brush brush, float x, float y, float width, float height)
                {
-                        GDIPlus.GdipFillEllipse (nativeObject, brush.nativeObject, x, y, width, height);
+                        Status status = GDIPlus.GdipFillEllipse (nativeObject, brush.nativeObject, x, y, width, height);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void FillEllipse (Brush brush, int x, int y, int width, int height)
                {
-                       GDIPlus.GdipFillEllipseI (nativeObject, brush.nativeObject, x, y, width, height);
+                       Status status = GDIPlus.GdipFillEllipseI (nativeObject, brush.nativeObject, x, y, width, height);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void FillPath (Brush brush, GraphicsPath path)
                {
-                       GDIPlus.GdipFillPath (nativeObject, brush.NativeObject,  path.NativeObject);
+                       Status status = GDIPlus.GdipFillPath (nativeObject, brush.NativeObject,  path.NativeObject);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void FillPie (Brush brush, Rectangle rect, float startAngle, float sweepAngle)
                {
-                       GDIPlus.GdipFillPie (nativeObject, brush.NativeObject, rect.X, rect.Y, rect.Width, rect.Height,
-                                        startAngle, sweepAngle);
+                       Status status = GDIPlus.GdipFillPie (nativeObject, brush.NativeObject, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void FillPie (Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle)
                {
-                       GDIPlus.GdipFillPieI (nativeObject, brush.NativeObject, x, y, width, height, startAngle, sweepAngle);
+                       Status status = GDIPlus.GdipFillPieI (nativeObject, brush.NativeObject, x, y, width, height, startAngle, sweepAngle);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void FillPie (Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle)
                {
-                       GDIPlus.GdipFillPie (nativeObject, brush.NativeObject, x, y, width, height, startAngle, sweepAngle);
+                       Status status = GDIPlus.GdipFillPie (nativeObject, brush.NativeObject, x, y, width, height, startAngle, sweepAngle);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void FillPolygon (Brush brush, PointF [] points)
                {
-                       GDIPlus.GdipFillPolygon2 (nativeObject, brush.nativeObject, points, points.Length);
+                       Status status = GDIPlus.GdipFillPolygon2 (nativeObject, brush.nativeObject, points, points.Length);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void FillPolygon (Brush brush, Point [] points)
                {
-                       GDIPlus.GdipFillPolygon2I (nativeObject, brush.nativeObject, points, points.Length);
+                       Status status = GDIPlus.GdipFillPolygon2I (nativeObject, brush.nativeObject, points, points.Length);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void FillPolygon (Brush brush, Point [] points, FillMode fillMode)
                {
-                       GDIPlus.GdipFillPolygonI (nativeObject, brush.nativeObject, points, points.Length, fillMode);
+                       Status status = GDIPlus.GdipFillPolygonI (nativeObject, brush.nativeObject, points, points.Length, fillMode);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void FillPolygon (Brush brush, PointF [] points, FillMode fillMode)
                {
-                       GDIPlus.GdipFillPolygon (nativeObject, brush.nativeObject, points, points.Length, fillMode);
+                       Status status = GDIPlus.GdipFillPolygon (nativeObject, brush.nativeObject, points, points.Length, fillMode);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void FillRectangle (Brush brush, RectangleF rect)
@@ -1047,106 +1178,158 @@ namespace System.Drawing
 
                public void FillRectangle (Brush brush, int x, int y, int width, int height)
                {
-                       GDIPlus.GdipFillRectangle (nativeObject, brush.nativeObject, (float)x, (float)y, (float)width, (float)height);
+                       Status status = GDIPlus.GdipFillRectangleI (nativeObject, brush.nativeObject, x, y, width, height);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void FillRectangle (Brush brush, float x, float y, float width, float height)
                {
-                       GDIPlus.GdipFillRectangle (nativeObject, brush.nativeObject, x, y, width, height);
+                       Status status = GDIPlus.GdipFillRectangle (nativeObject, brush.nativeObject, x, y, width, height);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void FillRectangles (Brush brush, Rectangle [] rects)
                {
-                        foreach (Rectangle rc in rects)
-                                FillRectangle(brush, rc);
+                       Status status = GDIPlus.GdipFillRectanglesI (nativeObject, brush.nativeObject, rects, rects.Length);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void FillRectangles (Brush brush, RectangleF [] rects)
                {
-                       foreach (RectangleF rc in rects)
-                                FillRectangle(brush, rc);
+                       Status status = GDIPlus.GdipFillRectangles (nativeObject, brush.nativeObject, rects, rects.Length);
+                       GDIPlus.CheckStatus (status);
                }
 
-               [MonoTODO]
+               
                public void FillRegion (Brush brush, Region region)
                {
-                       throw new NotImplementedException ();
+                       Status status = GDIPlus.GdipFillRegion (nativeObject, brush.NativeObject, region.NativeObject);                  
+                        GDIPlus.CheckStatus(status);
                }
 
-               [MonoTODO]
+               
                public void Flush ()
                {
                        Flush (FlushIntention.Flush);
                }
 
-               [MonoTODO]
+               
                public void Flush (FlushIntention intention)
                {
-                       throw new NotImplementedException ();
+                       Status status = GDIPlus.GdipFlush (nativeObject, intention);
+                        GDIPlus.CheckStatus (status);                    
+                       if (GDIPlus.UseQuartzDrawable || GDIPlus.UseCocoaDrawable)
+                               Carbon.CGContextSynchronize (GDIPlus.Display);
                }
 
-               
+               [EditorBrowsable (EditorBrowsableState.Advanced)]               
                public static Graphics FromHdc (IntPtr hdc)
                {
-                       int graphics;
-                       if (GDIPlus.GdipCreateFromHDC (hdc, out graphics) != Status.Ok){
-                               Console.WriteLine ("Graphics.FromHdc: the HDC is an invalid handle");
-                               return null;
-                       }
-                           
-                       Graphics result = new Graphics ((IntPtr) graphics);
-                       return result;
+                       IntPtr graphics;
+                       Status status = GDIPlus.GdipCreateFromHDC (hdc, out graphics);
+                       GDIPlus.CheckStatus (status);
+                       return new Graphics (graphics);
                }
 
                [MonoTODO]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public static Graphics FromHdc (IntPtr hdc, IntPtr hdevice)
                {
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
                public static Graphics FromHdcInternal (IntPtr hdc)
                {
-                       throw new NotImplementedException ();
+                       GDIPlus.Display = hdc;
+                       return null;
                }
-               
+
+               [EditorBrowsable (EditorBrowsableState.Advanced)]               
                public static Graphics FromHwnd (IntPtr hwnd)
                {
                        IntPtr graphics;
-                       
-                       GDIPlus.GdipCreateFromHWND (hwnd, out graphics);                        
-                       
-                       return new Graphics (graphics); 
-               }
 
-               [MonoTODO]
+                       if (GDIPlus.UseCocoaDrawable) {
+                               CarbonContext cgContext = Carbon.GetCGContextForNSView (hwnd);
+                               GDIPlus.GdipCreateFromQuartz_macosx (cgContext.ctx, cgContext.width, cgContext.height, out graphics);
+                               
+                               GDIPlus.Display = cgContext.ctx;
+                               return new Graphics (graphics);
+                       }
+                       if (GDIPlus.UseQuartzDrawable) {
+                               CarbonContext cgContext = Carbon.GetCGContextForView (hwnd);
+                               GDIPlus.GdipCreateFromQuartz_macosx (cgContext.ctx, cgContext.width, cgContext.height, out graphics);
+                               
+                               GDIPlus.Display = cgContext.ctx;
+                               return new Graphics (graphics);
+                       }
+                       if (GDIPlus.UseX11Drawable) {
+                               if (GDIPlus.Display == IntPtr.Zero) {
+                                       GDIPlus.Display = GDIPlus.XOpenDisplay (IntPtr.Zero);
+                               }
+
+                               return FromXDrawable (hwnd, GDIPlus.Display);
+
+                       }
+
+                       Status status = GDIPlus.GdipCreateFromHWND (hwnd, out graphics);
+                       GDIPlus.CheckStatus (status);
+
+                       return new Graphics (graphics);
+               }
+               
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
                public static Graphics FromHwndInternal (IntPtr hwnd)
                {
-                       throw new NotImplementedException ();
+                       return FromHwnd (hwnd);
                }
 
-               [MonoTODO]
                public static Graphics FromImage (Image image)
                {
-                       if (image == null) throw new ArgumentException ();
-                       int graphics;
-                       GDIPlus.GdipGetImageGraphicsContext (image.nativeObject, out graphics);
-                       Graphics result = new Graphics ((IntPtr) graphics);
+                       IntPtr graphics;
+
+                       if (image == null) 
+                               throw new ArgumentNullException ();
+
+                       Status status = GDIPlus.GdipGetImageGraphicsContext (image.nativeObject, out graphics);
+                       GDIPlus.CheckStatus (status);
+                       Graphics result = new Graphics (graphics);
+                               
+                       // check for Unix platforms - see FAQ for more details
+                       // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
+                       int platform = (int) Environment.OSVersion.Platform;
+                       if ((platform == 4) || (platform == 128)) {
+                               Rectangle rect  = new Rectangle (0,0, image.Width, image.Height);
+                               GDIPlus.GdipSetVisibleClip_linux (result.NativeObject, ref rect);
+                       }
+                               
                        return result;
                }
 
+               internal static Graphics FromXDrawable (IntPtr drawable, IntPtr display)
+               {
+                       IntPtr graphics;
+
+                       Status s = GDIPlus.GdipCreateFromXDrawable_linux (drawable, display, out graphics);
+                       GDIPlus.CheckStatus (s);
+                       return new Graphics (graphics);
+               }
+
                [MonoTODO]
                public static IntPtr GetHalftonePalette ()
                {
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public IntPtr GetHdc ()
                {
-                       int hdc;
-                       GDIPlus.GdipGetDC (nativeObject, out hdc);
-                       return (IntPtr) hdc;
+                       IntPtr hdc;
+                       GDIPlus.CheckStatus (GDIPlus.GdipGetDC (this.nativeObject, out hdc));
+                       return hdc;
                }
 
                
@@ -1154,31 +1337,37 @@ namespace System.Drawing
                {
                        int argb;
                        
-                       GDIPlus.GdipGetNearestColor (nativeObject, out argb);                   
+                       Status status = GDIPlus.GdipGetNearestColor (nativeObject, out argb);
+                       GDIPlus.CheckStatus (status);
+
                        return Color.FromArgb (argb);
                }
 
-               [MonoTODO]
+               
                public void IntersectClip (Region region)
                {
-                       throw new NotImplementedException ();
+                       Status status = GDIPlus.GdipSetClipRegion (nativeObject, region.NativeObject, CombineMode.Intersect);
+                       GDIPlus.CheckStatus (status);
                }
                
                public void IntersectClip (RectangleF rect)
                {
-                       GDIPlus.GdipSetClipRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Intersect);
+                       Status status = GDIPlus.GdipSetClipRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Intersect);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void IntersectClip (Rectangle rect)
                {                       
-                       GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Intersect);
+                       Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Intersect);
+                       GDIPlus.CheckStatus (status);
                }
 
                public bool IsVisible (Point point)
                {
                        bool isVisible = false;
 
-                       GDIPlus.GdipIsVisiblePointI (nativeObject, point.X, point.Y, out isVisible);
+                       Status status = GDIPlus.GdipIsVisiblePointI (nativeObject, point.X, point.Y, out isVisible);
+                       GDIPlus.CheckStatus (status);
 
                         return isVisible;
                }
@@ -1188,7 +1377,8 @@ namespace System.Drawing
                {
                        bool isVisible = false;
 
-                       GDIPlus.GdipIsVisibleRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, out isVisible);
+                       Status status = GDIPlus.GdipIsVisibleRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, out isVisible);
+                       GDIPlus.CheckStatus (status);
 
                         return isVisible;
                }
@@ -1197,7 +1387,8 @@ namespace System.Drawing
                {
                        bool isVisible = false;
 
-                       GDIPlus.GdipIsVisiblePoint (nativeObject, point.X, point.Y, out isVisible);
+                       Status status = GDIPlus.GdipIsVisiblePoint (nativeObject, point.X, point.Y, out isVisible);
+                       GDIPlus.CheckStatus (status);
 
                         return isVisible;
                }
@@ -1206,7 +1397,8 @@ namespace System.Drawing
                {
                        bool isVisible = false;
 
-                       GDIPlus.GdipIsVisibleRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, out isVisible);
+                       Status status = GDIPlus.GdipIsVisibleRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, out isVisible);
+                       GDIPlus.CheckStatus (status);
 
                         return isVisible;
                }
@@ -1232,75 +1424,152 @@ namespace System.Drawing
                        return IsVisible (new Rectangle (x, y, width, height));
                }
 
-               [MonoTODO]
+               
                public Region [] MeasureCharacterRanges (string text, Font font, RectangleF layoutRect, StringFormat stringFormat)
-               {
-                       throw new NotImplementedException ();
+               {       
+                       Status status;                  
+                       int regcount = stringFormat.GetMeasurableCharacterRangeCount ();
+                       IntPtr[] native_regions = new IntPtr [regcount];
+                       Region[] regions = new Region [regcount];
+                       
+                       for (int i = 0; i < regcount; i++) {
+                               regions[i] = new Region ();
+                               native_regions[i] = regions[i].NativeObject;
+                       }
+                       
+                       status =  GDIPlus.GdipMeasureCharacterRanges (nativeObject, text, text.Length,
+                               font.NativeObject, ref layoutRect, stringFormat.NativeObject, 
+                               regcount, out native_regions[0]); 
+                       
+                       GDIPlus.CheckStatus (status);                           
+                                                       
+                       return regions;                                                 
                }
 
                
                public SizeF MeasureString (string text, Font font)
                {
-                       return MeasureString (text, font, new Size(0,0));
+                       return MeasureString (text, font, new Size (0, 0));
                }
 
                
                public SizeF MeasureString (string text, Font font, SizeF layoutArea)
                {
-                       int charactersFitted, linesFilled;                      
+                       int charactersFitted, linesFilled;
                        RectangleF boundingBox = new RectangleF ();
-                       RectangleF rect = new RectangleF (0,0,layoutArea.Width, layoutArea.Height);
-                                       
-                       GDIPlus.GdipMeasureString (nativeObject, text, text.Length, font.NativeObject,
-                ref rect, IntPtr.Zero, out boundingBox, out charactersFitted, out linesFilled);
-                               
-               return new SizeF(boundingBox.Width, boundingBox.Height);
+                       RectangleF rect = new RectangleF (0, 0, layoutArea.Width,
+                                                         layoutArea.Height);
+
+                       if (text == null || text.Length == 0)
+                               return SizeF.Empty;
+
+                       if (font == null)
+                               throw new ArgumentNullException ("font");
+
+                       Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length,
+                                                                  font.NativeObject, ref rect,
+                                                                  IntPtr.Zero, out boundingBox,
+                                                                  out charactersFitted, out linesFilled);
+                       GDIPlus.CheckStatus (status);
+
+                       return new SizeF (boundingBox.Width, boundingBox.Height);
                }
 
-               [MonoTODO]
+               
                public SizeF MeasureString (string text, Font font, int width)
-               {
-                       throw new NotImplementedException ();
+               {                               
+                       RectangleF boundingBox = new RectangleF ();
+                       RectangleF rect = new RectangleF (0, 0, width, 999999);
+                       int charactersFitted, linesFilled;
+
+                       if (text == null || text.Length == 0)
+                               return SizeF.Empty;
+
+                       if (font == null)
+                               throw new ArgumentNullException ("font");
+
+                       Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length, 
+                                                                  font.NativeObject, ref rect,
+                                                                  IntPtr.Zero, out boundingBox,
+                                                                  out charactersFitted, out linesFilled);
+                       GDIPlus.CheckStatus (status);
+
+                       return new SizeF (boundingBox.Width, boundingBox.Height);
                }
 
                
-               public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat stringFormat)
+               public SizeF MeasureString (string text, Font font, SizeF layoutArea,
+                                           StringFormat stringFormat)
                {
                        int charactersFitted, linesFilled;                      
-                       return MeasureString (text, font, layoutArea, stringFormat, out charactersFitted, out linesFilled);
+                       return MeasureString (text, font, layoutArea, stringFormat,
+                                             out charactersFitted, out linesFilled);
                }
 
-               [MonoTODO]
+               
                public SizeF MeasureString (string text, Font font, int width, StringFormat format)
                {
-                       throw new NotImplementedException ();
+                       int charactersFitted, linesFilled;                      
+                       return MeasureString (text, font, new SizeF (width, 999999), 
+                                             format, out charactersFitted, out linesFilled);
                }
 
                
-               public SizeF MeasureString (string text, Font font, PointF origin, StringFormat stringFormat)
+               public SizeF MeasureString (string text, Font font, PointF origin,
+                                           StringFormat stringFormat)
                {
                        RectangleF boundingBox = new RectangleF ();
-                       RectangleF rect = new RectangleF (origin.X, origin.Y, 0,0);
+                       RectangleF rect = new RectangleF (origin.X, origin.Y, 0, 0);
                        int charactersFitted, linesFilled;
-                                       
-                       GDIPlus.GdipMeasureString (nativeObject, text, text.Length, font.NativeObject,
-                ref rect, stringFormat.NativeObject, out boundingBox, out charactersFitted, out linesFilled);
-                               
-               return new SizeF(boundingBox.Width, boundingBox.Height);
+
+                       if (text == null || text.Length == 0)
+                               return SizeF.Empty;
+
+                       if (font == null)
+                               throw new ArgumentNullException ("font");
+
+                       if (stringFormat == null)
+                               stringFormat = new StringFormat ();
+
+                       Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length, 
+                                                                  font.NativeObject, ref rect,
+                                                                  stringFormat.NativeObject, 
+                                                                  out boundingBox,
+                                                                  out charactersFitted,
+                                                                  out linesFilled);
+                       GDIPlus.CheckStatus (status);
+
+                       return new SizeF (boundingBox.Width, boundingBox.Height);
                }
 
                
-               public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat stringFormat, 
-                                out int charactersFitted, out int linesFilled)
+               public SizeF MeasureString (string text, Font font, SizeF layoutArea,
+                                           StringFormat stringFormat, out int charactersFitted,
+                                           out int linesFilled)
                {       
                        RectangleF boundingBox = new RectangleF ();
-                       RectangleF rect = new RectangleF (0,0,layoutArea.Width, layoutArea.Height);
-                                       
-                       GDIPlus.GdipMeasureString (nativeObject, text, text.Length, font.NativeObject,
-                ref rect, stringFormat.NativeObject, out boundingBox, out charactersFitted,
-                               out linesFilled);
-                               
-               return new SizeF(boundingBox.Width, boundingBox.Height);
+                       RectangleF rect = new RectangleF (0, 0, layoutArea.Width, layoutArea.Height);
+                       charactersFitted = 0;
+                       linesFilled = 0;
+
+                       if (text == null || text.Length == 0)
+                               return SizeF.Empty;
+
+                       if (font == null)
+                               throw new ArgumentNullException ("font");
+
+                       if (stringFormat == null)
+                               stringFormat = new StringFormat ();
+
+                       Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length, 
+                                                                  font.NativeObject, ref rect,
+                                                                  stringFormat.NativeObject,
+                                                                  out boundingBox,
+                                                                  out charactersFitted,
+                                                                  out linesFilled);
+                       GDIPlus.CheckStatus (status);
+
+                       return new SizeF (boundingBox.Width, boundingBox.Height);
                }
 
                public void MultiplyTransform (Matrix matrix)
@@ -1310,15 +1579,22 @@ namespace System.Drawing
 
                public void MultiplyTransform (Matrix matrix, MatrixOrder order)
                {
-                       GDIPlus.GdipMultiplyWorldTransform (nativeObject, matrix.nativeMatrix, order);
+                       Status status = GDIPlus.GdipMultiplyWorldTransform (nativeObject,
+                                                                           matrix.nativeMatrix,
+                                                                           order);
+                       GDIPlus.CheckStatus (status);
                }
-               
+
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public void ReleaseHdc (IntPtr hdc)
                {
-                       GDIPlus.GdipReleaseDC (nativeObject, hdc);
+                       Status status = GDIPlus.GdipReleaseDC (nativeObject, hdc);
+                       GDIPlus.CheckStatus (status);
                }
 
                [MonoTODO]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
                public void ReleaseHdcInternal (IntPtr hdc)
                {
                        throw new NotImplementedException ();
@@ -1327,42 +1603,42 @@ namespace System.Drawing
                
                public void ResetClip ()
                {
-                       GDIPlus.GdipResetClip(nativeObject);
+                       Status status = GDIPlus.GdipResetClip (nativeObject);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void ResetTransform ()
                {
-                       GDIPlus.GdipResetWorldTransform (nativeObject);
+                       Status status = GDIPlus.GdipResetWorldTransform (nativeObject);
+                       GDIPlus.CheckStatus (status);
                }
 
-               [MonoTODO]
                public void Restore (GraphicsState gstate)
-               {
-                       Transform = gstate.matrix.Clone();
-                       GDIPlus.GdipRestoreGraphics (nativeObject, gstate.nativeState);
+               {                       
+                       Status status = GDIPlus.GdipRestoreGraphics (nativeObject, gstate.nativeState);
+                       GDIPlus.CheckStatus (status);
                }
 
-               [MonoTODO]
+
                public void RotateTransform (float angle)
                {
-                       RotateTransform(angle, MatrixOrder.Prepend);
+                       RotateTransform (angle, MatrixOrder.Prepend);
                }
 
-               [MonoTODO]
                public void RotateTransform (float angle, MatrixOrder order)
                {
-                       //transform.Rotate(angle, order);
-                       GDIPlus.GdipRotateWorldTransform (nativeObject, angle, order);
+
+                       Status status = GDIPlus.GdipRotateWorldTransform (nativeObject, angle, order);
+                       GDIPlus.CheckStatus (status);
                }
 
-               [MonoTODO]
                public GraphicsState Save ()
-               {
-                       //return implementation.Save();
-                       GraphicsState state = new GraphicsState();
-                       state.matrix = Transform.Clone ();
+               {                                               
                        uint saveState;
-                       GDIPlus.GdipSaveGraphics (nativeObject, out saveState);
+                       Status status = GDIPlus.GdipSaveGraphics (nativeObject, out saveState);
+                       GDIPlus.CheckStatus (status);
+
+                       GraphicsState state = new GraphicsState ();
                        state.nativeState = saveState;
                        return state;
                }
@@ -1374,7 +1650,8 @@ namespace System.Drawing
 
                public void ScaleTransform (float sx, float sy, MatrixOrder order)
                {
-                        GDIPlus.GdipScaleWorldTransform (nativeObject, sx, sy, order);
+                        Status status = GDIPlus.GdipScaleWorldTransform (nativeObject, sx, sy, order);
+                       GDIPlus.CheckStatus (status);
                }
 
                
@@ -1404,31 +1681,36 @@ namespace System.Drawing
                
                public void SetClip (Graphics g, CombineMode combineMode)
                {
-                       GDIPlus.GdipSetClipGraphics (nativeObject, g.NativeObject, combineMode);
+                       Status status = GDIPlus.GdipSetClipGraphics (nativeObject, g.NativeObject, combineMode);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void SetClip (Rectangle rect, CombineMode combineMode)
                {
-                       GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, combineMode);
+                       Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, combineMode);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void SetClip (RectangleF rect, CombineMode combineMode)
                {
-                       GDIPlus.GdipSetClipRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, combineMode);           
+                       Status status = GDIPlus.GdipSetClipRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, combineMode);
+                       GDIPlus.CheckStatus (status);
                }
 
-               [MonoTODO]
+               
                public void SetClip (Region region, CombineMode combineMode)
                {
-                       //GDIPlus.GdipSetClipRegion(nativeObject,  region.NativeObject, combineMode); //TODO: Region not implemented yet
+                       Status status =   GDIPlus.GdipSetClipRegion(nativeObject,  region.NativeObject, combineMode); 
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void SetClip (GraphicsPath path, CombineMode combineMode)
                {
-                       GDIPlus.GdipSetClipPath (nativeObject, path.NativeObject, combineMode);
+                       Status status = GDIPlus.GdipSetClipPath (nativeObject, path.NativeObject, combineMode);
+                       GDIPlus.CheckStatus (status);
                }
 
                
@@ -1437,16 +1719,18 @@ namespace System.Drawing
                        IntPtr ptrPt =  GDIPlus.FromPointToUnManagedMemory (pts);
             
                         Status status = GDIPlus.GdipTransformPoints (nativeObject, destSpace, srcSpace,  ptrPt, pts.Length);
+                       GDIPlus.CheckStatus (status);
                        
                        GDIPlus.FromUnManagedMemoryToPoint (ptrPt, pts);
                }
 
-                               
+
                public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, Point [] pts)
                {                                               
                         IntPtr ptrPt =  GDIPlus.FromPointToUnManagedMemoryI (pts);
             
                         Status status = GDIPlus.GdipTransformPointsI (nativeObject, destSpace, srcSpace, ptrPt, pts.Length);
+                       GDIPlus.CheckStatus (status);
                        
                        GDIPlus.FromUnManagedMemoryToPointI (ptrPt, pts);
                }
@@ -1454,13 +1738,15 @@ namespace System.Drawing
                
                public void TranslateClip (int dx, int dy)
                {
-                       GDIPlus.GdipTranslateClipI (nativeObject, dx, dy);                      
+                       Status status = GDIPlus.GdipTranslateClipI (nativeObject, dx, dy);
+                       GDIPlus.CheckStatus (status);
                }
 
                
                public void TranslateClip (float dx, float dy)
                {
-                       GDIPlus.GdipTranslateClip (nativeObject, dx, dy);
+                       Status status = GDIPlus.GdipTranslateClip (nativeObject, dx, dy);
+                       GDIPlus.CheckStatus (status);
                }
 
                public void TranslateTransform (float dx, float dy)
@@ -1471,35 +1757,42 @@ namespace System.Drawing
                
                public void TranslateTransform (float dx, float dy, MatrixOrder order)
                {                       
-                       GDIPlus.GdipTranslateWorldTransform (nativeObject, dx, dy, order);
+                       Status status = GDIPlus.GdipTranslateWorldTransform (nativeObject, dx, dy, order);
+                       GDIPlus.CheckStatus (status);
                }
 
                public Region Clip {
                        get {
-                               throw new NotImplementedException ();
+                               Region reg = new Region();
+                               Status status = GDIPlus.GdipGetClip (nativeObject, reg.NativeObject);
+                               GDIPlus.CheckStatus (status);
+                               return reg;                             
                        }
                        set {
-                               //throw new NotImplementedException ();
+                               SetClip (value, CombineMode.Replace);
                        }
                }
 
                public RectangleF ClipBounds {
                        get {
-                                RectangleF rect = new RectangleF ();                                   
-                                GDIPlus.GdipGetClipBounds (nativeObject, out rect);
-                                return rect;
+                                RectangleF rect = new RectangleF ();
+                                Status status = GDIPlus.GdipGetClipBounds (nativeObject, out rect);
+                               GDIPlus.CheckStatus (status);
+                               return rect;
                        }
                }
 
                public CompositingMode CompositingMode {
                        get {
                                 CompositingMode mode;
-                                GDIPlus.GdipGetCompositingMode (nativeObject, out mode);    
-                                return mode;
+                                Status status = GDIPlus.GdipGetCompositingMode (nativeObject, out mode);
+                               GDIPlus.CheckStatus (status);
+
+                               return mode;
                        }
                        set {
-                               
-                                GDIPlus.GdipSetCompositingMode (nativeObject, value);    
+                                Status status = GDIPlus.GdipSetCompositingMode (nativeObject, value);
+                               GDIPlus.CheckStatus (status);
                        }
 
                }
@@ -1508,11 +1801,13 @@ namespace System.Drawing
                        get {
                                 CompositingQuality quality;
 
-                                GDIPlus.GdipGetCompositingQuality (nativeObject, out quality);
+                                Status status = GDIPlus.GdipGetCompositingQuality (nativeObject, out quality);
+                               GDIPlus.CheckStatus (status);
                                return quality;
                        }
                        set {
-                                GDIPlus.GdipSetCompositingQuality (nativeObject, value); 
+                                Status status = GDIPlus.GdipSetCompositingQuality (nativeObject, value);
+                               GDIPlus.CheckStatus (status);
                        }
                }
 
@@ -1520,7 +1815,8 @@ namespace System.Drawing
                        get {
                                 float x;
 
-                                       GDIPlus.GdipGetDpiX (nativeObject, out x);
+                                       Status status = GDIPlus.GdipGetDpiX (nativeObject, out x);
+                               GDIPlus.CheckStatus (status);
                                return x;
                        }
                }
@@ -1529,7 +1825,8 @@ namespace System.Drawing
                        get {
                                 float y;
 
-                                       GDIPlus.GdipGetDpiY (nativeObject, out y);
+                                       Status status = GDIPlus.GdipGetDpiY (nativeObject, out y);
+                               GDIPlus.CheckStatus (status);
                                return y;
                        }
                }
@@ -1537,11 +1834,13 @@ namespace System.Drawing
                public InterpolationMode InterpolationMode {
                        get {                           
                                 InterpolationMode imode = InterpolationMode.Invalid;
-                               GDIPlus.GdipGetInterpolationMode (nativeObject, out imode);
+                               Status status = GDIPlus.GdipGetInterpolationMode (nativeObject, out imode);
+                               GDIPlus.CheckStatus (status);
                                return imode;
                        }
                        set {
-                                GDIPlus.GdipSetInterpolationMode (nativeObject, value);
+                                Status status = GDIPlus.GdipSetInterpolationMode (nativeObject, value);
+                               GDIPlus.CheckStatus (status);
                        }
                }
 
@@ -1549,7 +1848,8 @@ namespace System.Drawing
                        get {
                                 bool isEmpty = false;
 
-                               GDIPlus.GdipIsClipEmpty (nativeObject, out isEmpty);
+                               Status status = GDIPlus.GdipIsClipEmpty (nativeObject, out isEmpty);
+                               GDIPlus.CheckStatus (status);
                                return isEmpty;
                        }
                }
@@ -1558,7 +1858,8 @@ namespace System.Drawing
                        get {
                                 bool isEmpty = false;
 
-                               GDIPlus.GdipIsVisibleClipEmpty (nativeObject, out isEmpty);
+                               Status status = GDIPlus.GdipIsVisibleClipEmpty (nativeObject, out isEmpty);
+                               GDIPlus.CheckStatus (status);
                                return isEmpty;
                        }
                }
@@ -1567,11 +1868,13 @@ namespace System.Drawing
                        get {
                                 float scale;
 
-                               GDIPlus.GdipGetPageScale (nativeObject, out scale);
+                               Status status = GDIPlus.GdipGetPageScale (nativeObject, out scale);
+                               GDIPlus.CheckStatus (status);
                                return scale;
                        }
                        set {
-                                GDIPlus.GdipSetPageScale (nativeObject, value);
+                                Status status = GDIPlus.GdipSetPageScale (nativeObject, value);
+                               GDIPlus.CheckStatus (status);
                        }
                }
 
@@ -1579,11 +1882,13 @@ namespace System.Drawing
                        get {
                                 GraphicsUnit unit;
                                 
-                                GDIPlus.GdipGetPageUnit (nativeObject, out unit);
+                                Status status = GDIPlus.GdipGetPageUnit (nativeObject, out unit);
+                               GDIPlus.CheckStatus (status);
                                return unit;
                        }
                        set {
-                                GDIPlus.GdipSetPageUnit (nativeObject, value);
+                                Status status = GDIPlus.GdipSetPageUnit (nativeObject, value);
+                               GDIPlus.CheckStatus (status);
                        }
                }
 
@@ -1591,26 +1896,27 @@ namespace System.Drawing
                        get {
                                PixelOffsetMode pixelOffset = PixelOffsetMode.Invalid;
                                 
-                                GDIPlus.GdipGetPixelOffsetMode (nativeObject, out pixelOffset);
-
+                                Status status = GDIPlus.GdipGetPixelOffsetMode (nativeObject, out pixelOffset);
+                               GDIPlus.CheckStatus (status);
                                return pixelOffset;
                        }
                        set {
-                                GDIPlus.GdipSetPixelOffsetMode (nativeObject, value); 
+                                Status status = GDIPlus.GdipSetPixelOffsetMode (nativeObject, value); 
+                               GDIPlus.CheckStatus (status);
                        }
                }
 
                public Point RenderingOrigin {
                        get {
                                 int x, y;
-                               GDIPlus.GdipGetRenderingOrigin (
-                                        nativeObject, out x, out y);
-
+                               Status status = GDIPlus.GdipGetRenderingOrigin (nativeObject, out x, out y);
+                               GDIPlus.CheckStatus (status);
                                 return new Point (x, y);
                        }
 
                        set {
-                                GDIPlus.GdipSetRenderingOrigin (nativeObject, value.X, value.Y);
+                                Status status = GDIPlus.GdipSetRenderingOrigin (nativeObject, value.X, value.Y);
+                               GDIPlus.CheckStatus (status);
                        }
                }
 
@@ -1618,13 +1924,14 @@ namespace System.Drawing
                        get {
                                 SmoothingMode mode = SmoothingMode.Invalid;
 
-                               GDIPlus.GdipGetSmoothingMode (nativeObject, out mode);
-                                
+                               Status status = GDIPlus.GdipGetSmoothingMode (nativeObject, out mode);
+                               GDIPlus.CheckStatus (status);
                                 return mode;
                        }
 
                        set {
-                                GDIPlus.GdipSetSmoothingMode (nativeObject, value);
+                                Status status = GDIPlus.GdipSetSmoothingMode (nativeObject, value);
+                               GDIPlus.CheckStatus (status);
                        }
                }
 
@@ -1632,12 +1939,14 @@ namespace System.Drawing
                        get {   
                                 int contrast;
                                        
-                                GDIPlus.GdipGetTextContrast (nativeObject, out contrast);
+                                Status status = GDIPlus.GdipGetTextContrast (nativeObject, out contrast);
+                               GDIPlus.CheckStatus (status);
                                 return contrast;
                        }
 
                         set {
-                                GDIPlus.GdipSetTextContrast (nativeObject, value);
+                                Status status = GDIPlus.GdipSetTextContrast (nativeObject, value);
+                               GDIPlus.CheckStatus (status);
                        }
                }
 
@@ -1645,24 +1954,27 @@ namespace System.Drawing
                        get {
                                 TextRenderingHint hint;
 
-                                GDIPlus.GdipGetTextRenderingHint (nativeObject, out hint);
+                                Status status = GDIPlus.GdipGetTextRenderingHint (nativeObject, out hint);
+                               GDIPlus.CheckStatus (status);
                                 return hint;        
                        }
 
                        set {
-                                GDIPlus.GdipSetTextRenderingHint (nativeObject, value);
+                                Status status = GDIPlus.GdipSetTextRenderingHint (nativeObject, value);
+                               GDIPlus.CheckStatus (status);
                        }
                }
 
                public Matrix Transform {
                        get {
                                 Matrix matrix = new Matrix ();
-                                GDIPlus.GdipGetWorldTransform (nativeObject, matrix.nativeMatrix);
-
+                                Status status = GDIPlus.GdipGetWorldTransform (nativeObject, matrix.nativeMatrix);
+                               GDIPlus.CheckStatus (status);
                                 return matrix;
                        }
                        set {
-                                GDIPlus.GdipSetWorldTransform (nativeObject, value.nativeMatrix);
+                                Status status = GDIPlus.GdipSetWorldTransform (nativeObject, value.nativeMatrix);
+                               GDIPlus.CheckStatus (status);
                        }
                }
 
@@ -1670,7 +1982,8 @@ namespace System.Drawing
                        get {
                                 RectangleF rect;
                                        
-                                GDIPlus.GdipGetVisibleClipBounds (nativeObject, out rect);
+                                Status status = GDIPlus.GdipGetVisibleClipBounds (nativeObject, out rect);
+                               GDIPlus.CheckStatus (status);
                                 return rect;
                        }
                }