Removed DeflateStream.UnmanagedRead Read loop. Fixes #19313.
[mono.git] / mcs / class / System.Drawing / System.Drawing / Graphics.cs
1 //
2 // System.Drawing.Graphics.cs
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com) (stubbed out)
6 //      Alexandre Pigolkine(pigolkine@gmx.de)
7 //      Jordi Mas i Hernandez (jordi@ximian.com)
8 //      Sebastien Pouliot  <sebastien@ximian.com>
9 //
10 // Copyright (C) 2003 Ximian, Inc. (http://www.ximian.com)
11 // Copyright (C) 2004-2006 Novell, Inc. (http://www.novell.com)
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 using System.Drawing.Drawing2D;
34 using System.Drawing.Imaging;
35 using System.Drawing.Text;
36 using System.ComponentModel;
37 using System.Runtime.InteropServices;
38 using System.Security.Permissions;
39 using System.Text;
40
41 namespace System.Drawing
42 {
43 #if !NET_2_0
44         [ComVisible(false)]  
45 #endif
46         public sealed class Graphics : MarshalByRefObject, IDisposable
47 #if NET_2_0
48         , IDeviceContext
49 #endif
50         {
51                 internal IntPtr nativeObject = IntPtr.Zero;
52                 internal IMacContext maccontext;
53                 private bool disposed = false;
54                 private static float defDpiX = 0;
55                 private static float defDpiY = 0;
56                 private IntPtr deviceContextHdc;
57
58 #if !NET_2_0
59                 [ComVisible(false)]
60 #endif
61                 public delegate bool EnumerateMetafileProc (EmfPlusRecordType recordType,
62                                                             int flags,
63                                                             int dataSize,
64                                                             IntPtr data,
65                                                             PlayRecordCallback callbackData);
66                 
67 #if !NET_2_0
68                 [ComVisible (false)]
69 #endif
70                 public delegate bool DrawImageAbort (IntPtr callbackData);
71
72                 internal Graphics (IntPtr nativeGraphics)
73                 {
74                         nativeObject = nativeGraphics;
75                 }
76
77                 ~Graphics ()
78                 {
79                         Dispose ();                     
80                 }               
81
82                 static internal float systemDpiX {
83                         get {
84                                 if (defDpiX == 0) {
85                                         Bitmap bmp = new Bitmap (1, 1);
86                                         Graphics g = Graphics.FromImage (bmp);
87                                         defDpiX = g.DpiX;
88                                         defDpiY = g.DpiY;
89                                 }
90                                 return defDpiX;
91                         }
92                 }
93
94                 static internal float systemDpiY {
95                         get {
96                                 if (defDpiY == 0) {
97                                         Bitmap bmp = new Bitmap (1, 1);
98                                         Graphics g = Graphics.FromImage (bmp);
99                                         defDpiX = g.DpiX;
100                                         defDpiY = g.DpiY;
101                                 }
102                                 return defDpiY;
103                         }
104                 }
105
106                 internal IntPtr NativeObject {
107                         get {
108                                 return nativeObject;
109                         }
110
111                         set {
112                                 nativeObject = value;
113                         }
114                 }
115                 
116                 [MonoTODO ("Metafiles, both WMF and EMF formats, aren't supported.")]
117                 public void AddMetafileComment (byte [] data)
118                 {
119                         throw new NotImplementedException ();
120                 }
121
122                 public GraphicsContainer BeginContainer ()
123                 {
124                         uint state;
125                         Status status;
126                         status = GDIPlus.GdipBeginContainer2 (nativeObject, out state);
127                         GDIPlus.CheckStatus (status);
128
129                         return new GraphicsContainer(state);
130                 }
131
132                 [MonoTODO ("The rectangles and unit parameters aren't supported in libgdiplus")]                
133                 public GraphicsContainer BeginContainer (Rectangle dstrect, Rectangle srcrect, GraphicsUnit unit)
134                 {
135                         uint state;
136                         Status status;
137                         status = GDIPlus.GdipBeginContainerI (nativeObject, ref dstrect, ref srcrect, unit, out state);
138                         GDIPlus.CheckStatus (status);
139
140                         return new GraphicsContainer (state);
141                 }
142
143                 [MonoTODO ("The rectangles and unit parameters aren't supported in libgdiplus")]                
144                 public GraphicsContainer BeginContainer (RectangleF dstrect, RectangleF srcrect, GraphicsUnit unit)
145                 {
146                         uint state;
147                         Status status;
148                         status = GDIPlus.GdipBeginContainer (nativeObject, ref dstrect, ref srcrect, unit, out state);
149                         GDIPlus.CheckStatus (status);
150
151                         return new GraphicsContainer (state);
152                 }
153
154                 
155                 public void Clear (Color color)
156                 {
157                         Status status;
158                         status = GDIPlus.GdipGraphicsClear (nativeObject, color.ToArgb ());
159                         GDIPlus.CheckStatus (status);
160                 }
161 #if NET_2_0             
162                 [MonoLimitation ("Works on Win32 and on X11 (but not on Cocoa and Quartz)")]
163                 public void CopyFromScreen (Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize)
164                 {
165                         CopyFromScreen (upperLeftSource.X, upperLeftSource.Y, upperLeftDestination.X, upperLeftDestination.Y,
166                                 blockRegionSize, CopyPixelOperation.SourceCopy);                                
167                 }
168
169                 [MonoLimitation ("Works on Win32 and (for CopyPixelOperation.SourceCopy only) on X11 but not on Cocoa and Quartz")]
170                 public void CopyFromScreen (Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
171                 {
172                         CopyFromScreen (upperLeftSource.X, upperLeftSource.Y, upperLeftDestination.X, upperLeftDestination.Y,
173                                 blockRegionSize, copyPixelOperation);
174                 }
175                 
176                 [MonoLimitation ("Works on Win32 and on X11 (but not on Cocoa and Quartz)")]
177                 public void CopyFromScreen (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize)
178                 {
179                         CopyFromScreen (sourceX, sourceY, destinationX, destinationY, blockRegionSize,
180                                 CopyPixelOperation.SourceCopy);
181                 }
182
183                 [MonoLimitation ("Works on Win32 and (for CopyPixelOperation.SourceCopy only) on X11 but not on Cocoa and Quartz")]
184                 public void CopyFromScreen (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
185                 {
186                         if (!Enum.IsDefined (typeof (CopyPixelOperation), copyPixelOperation))
187                                 throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for CopyPixelOperation", copyPixelOperation));
188
189                         if (GDIPlus.UseX11Drawable) {
190                                 CopyFromScreenX11 (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
191                         } else if (GDIPlus.UseCarbonDrawable) {
192                                 CopyFromScreenMac (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
193                         } else if (GDIPlus.UseCocoaDrawable) {
194                                 CopyFromScreenMac (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
195                         } else {
196                                 CopyFromScreenWin32 (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
197                         }
198                 }
199
200                 private void CopyFromScreenWin32 (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
201                 {
202                         IntPtr window = GDIPlus.GetDesktopWindow ();
203                         IntPtr srcDC = GDIPlus.GetDC (window);
204                         IntPtr dstDC = GetHdc ();
205                         GDIPlus.BitBlt (dstDC, destinationX, destinationY, blockRegionSize.Width,
206                                 blockRegionSize.Height, srcDC, sourceX, sourceY, (int) copyPixelOperation);
207
208                         GDIPlus.ReleaseDC (IntPtr.Zero, srcDC);
209                         ReleaseHdc (dstDC);                     
210                 }
211                 
212                 private void CopyFromScreenMac (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
213                 {
214                         throw new NotImplementedException ();
215                 }
216
217                 private void CopyFromScreenX11 (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
218                 {
219                         IntPtr window, image, defvisual, vPtr;
220                         int AllPlanes = ~0, nitems = 0, pixel;
221
222                         if (copyPixelOperation != CopyPixelOperation.SourceCopy)
223                                 throw new NotImplementedException ("Operation not implemented under X11");
224                 
225                         if (GDIPlus.Display == IntPtr.Zero) {
226                                 GDIPlus.Display = GDIPlus.XOpenDisplay (IntPtr.Zero);
227                         }
228
229                         window = GDIPlus.XRootWindow (GDIPlus.Display, 0);
230                         defvisual = GDIPlus.XDefaultVisual (GDIPlus.Display, 0);
231                         XVisualInfo visual = new XVisualInfo ();
232
233                         /* Get XVisualInfo for this visual */
234                         visual.visualid = GDIPlus.XVisualIDFromVisual(defvisual);
235                         vPtr = GDIPlus.XGetVisualInfo (GDIPlus.Display, 0x1 /* VisualIDMask */, ref visual, ref nitems);
236                         visual = (XVisualInfo) Marshal.PtrToStructure(vPtr, typeof (XVisualInfo));
237 #if false
238                         Console.WriteLine ("visual\t{0}", visual.visual);
239                         Console.WriteLine ("visualid\t{0}", visual.visualid);
240                         Console.WriteLine ("screen\t{0}", visual.screen);
241                         Console.WriteLine ("depth\t{0}", visual.depth);
242                         Console.WriteLine ("klass\t{0}", visual.klass);
243                         Console.WriteLine ("red_mask\t{0:X}", visual.red_mask);
244                         Console.WriteLine ("green_mask\t{0:X}", visual.green_mask);
245                         Console.WriteLine ("blue_mask\t{0:X}", visual.blue_mask);
246                         Console.WriteLine ("colormap_size\t{0}", visual.colormap_size);
247                         Console.WriteLine ("bits_per_rgb\t{0}", visual.bits_per_rgb);
248 #endif
249                         image = GDIPlus.XGetImage (GDIPlus.Display, window, sourceX, sourceY, blockRegionSize.Width,
250                                 blockRegionSize.Height, AllPlanes, 2 /* ZPixmap*/);
251                         if (image == IntPtr.Zero) {
252                                 string s = String.Format ("XGetImage returned NULL when asked to for a {0}x{1} region block", 
253                                         blockRegionSize.Width, blockRegionSize.Height);
254                                 throw new InvalidOperationException (s);
255                         }
256                                 
257                         Bitmap bmp = new Bitmap (blockRegionSize.Width, blockRegionSize.Height);
258                         int red, blue, green;
259                         int red_mask = (int) visual.red_mask;
260                         int blue_mask = (int) visual.blue_mask;
261                         int green_mask = (int) visual.green_mask;
262                         for (int y = 0; y < blockRegionSize.Height; y++) {
263                                 for (int x = 0; x < blockRegionSize.Width; x++) {
264                                         pixel = GDIPlus.XGetPixel (image, x, y);
265
266                                         switch (visual.depth) {
267                                                 case 16: /* 16bbp pixel transformation */
268                                                         red = (int) ((pixel & red_mask ) >> 8) & 0xff;
269                                                         green = (int) (((pixel & green_mask ) >> 3 )) & 0xff;
270                                                         blue = (int) ((pixel & blue_mask ) << 3 ) & 0xff;
271                                                         break;
272                                                 case 24:
273                                                 case 32:
274                                                         red = (int) ((pixel & red_mask ) >> 16) & 0xff;
275                                                         green = (int) (((pixel & green_mask ) >> 8 )) & 0xff;
276                                                         blue = (int) ((pixel & blue_mask )) & 0xff;
277                                                         break;
278                                                 default:
279                                                         string text = Locale.GetText ("{0}bbp depth not supported.", visual.depth);
280                                                         throw new NotImplementedException (text);
281                                         }
282                                                 
283                                         bmp.SetPixel (x, y, Color.FromArgb (255, red, green, blue));                                                     
284                                 }
285                         }
286
287                         DrawImage (bmp, destinationX, destinationY);
288                         bmp.Dispose ();
289                         GDIPlus.XDestroyImage (image);
290                         GDIPlus.XFree (vPtr);
291                 }
292 #endif
293
294                 public void Dispose ()
295                 {
296                         Status status;
297                         if (! disposed) {
298                                 if (GDIPlus.UseCarbonDrawable || GDIPlus.UseCocoaDrawable) {
299                                         Flush ();
300                                         if (maccontext != null)
301                                                 maccontext.Release ();
302                                 }
303
304                                 status = GDIPlus.GdipDeleteGraphics (nativeObject);
305                                 nativeObject = IntPtr.Zero;
306                                 GDIPlus.CheckStatus (status);
307                                 disposed = true;                                
308                         }
309
310                         GC.SuppressFinalize(this);
311                 }
312
313                 
314                 public void DrawArc (Pen pen, Rectangle rect, float startAngle, float sweepAngle)
315                 {
316                         DrawArc (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
317                 }
318
319                 
320                 public void DrawArc (Pen pen, RectangleF rect, float startAngle, float sweepAngle)
321                 {
322                         DrawArc (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
323                 }
324
325                 
326                 public void DrawArc (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
327                 {
328                         Status status;
329                         if (pen == null)
330                                 throw new ArgumentNullException ("pen");
331                         
332                         status = GDIPlus.GdipDrawArc (nativeObject, pen.nativeObject,
333                                         x, y, width, height, startAngle, sweepAngle);
334                         GDIPlus.CheckStatus (status);
335                 }
336
337                 // Microsoft documentation states that the signature for this member should be
338                 // public void DrawArc( Pen pen,  int x,  int y,  int width,  int height,   int startAngle,
339                 // int sweepAngle. However, GdipDrawArcI uses also float for the startAngle and sweepAngle params
340                 public void DrawArc (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
341                 {
342                         Status status;
343                         if (pen == null)
344                                 throw new ArgumentNullException ("pen");
345                         status = GDIPlus.GdipDrawArcI (nativeObject, pen.nativeObject,
346                                                 x, y, width, height, startAngle, sweepAngle);
347                         GDIPlus.CheckStatus (status);
348                 }
349
350                 public void DrawBezier (Pen pen, PointF pt1, PointF pt2, PointF pt3, PointF pt4)
351                 {
352                         Status status;
353                         if (pen == null)
354                                 throw new ArgumentNullException ("pen");
355                         status = GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject,
356                                                         pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X,
357                                                         pt3.Y, pt4.X, pt4.Y);
358                         GDIPlus.CheckStatus (status);
359                 }
360
361                 public void DrawBezier (Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)
362                 {
363                         Status status;
364                         if (pen == null)
365                                 throw new ArgumentNullException ("pen");
366                         status = GDIPlus.GdipDrawBezierI (nativeObject, pen.nativeObject,
367                                                         pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X,
368                                                         pt3.Y, pt4.X, pt4.Y);
369                         GDIPlus.CheckStatus (status);
370                 }
371
372                 public void DrawBezier (Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
373                 {
374                         Status status;
375                         if (pen == null)
376                                 throw new ArgumentNullException ("pen");
377                         status = GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject, x1,
378                                                         y1, x2, y2, x3, y3, x4, y4);
379                         GDIPlus.CheckStatus (status);
380                 }
381
382                 public void DrawBeziers (Pen pen, Point [] points)
383                 {
384                         if (pen == null)
385                                 throw new ArgumentNullException ("pen");
386                         if (points == null)
387                                 throw new ArgumentNullException ("points");
388                         
389                         int length = points.Length;
390                         Status status;
391
392                         if (length < 4)
393                                 return;
394
395                         for (int i = 0; i < length - 1; i += 3) {
396                                 Point p1 = points [i];
397                                 Point p2 = points [i + 1];
398                                 Point p3 = points [i + 2];
399                                 Point p4 = points [i + 3];
400
401                                 status = GDIPlus.GdipDrawBezier (nativeObject, 
402                                                         pen.nativeObject,
403                                                         p1.X, p1.Y, p2.X, p2.Y, 
404                                                         p3.X, p3.Y, p4.X, p4.Y);
405                                 GDIPlus.CheckStatus (status);
406                         }
407                 }
408
409                 public void DrawBeziers (Pen pen, PointF [] points)
410                 {
411                         if (pen == null)
412                                 throw new ArgumentNullException ("pen");
413                         if (points == null)
414                                 throw new ArgumentNullException ("points");
415                         
416                         int length = points.Length;
417                         Status status;
418
419                         if (length < 4)
420                                 return;
421
422                         for (int i = 0; i < length - 1; i += 3) {
423                                 PointF p1 = points [i];
424                                 PointF p2 = points [i + 1];
425                                 PointF p3 = points [i + 2];
426                                 PointF p4 = points [i + 3];
427
428                                 status = GDIPlus.GdipDrawBezier (nativeObject, 
429                                                         pen.nativeObject,
430                                                         p1.X, p1.Y, p2.X, p2.Y, 
431                                                         p3.X, p3.Y, p4.X, p4.Y);
432                                 GDIPlus.CheckStatus (status);
433                         }
434                 }
435
436                 
437                 public void DrawClosedCurve (Pen pen, PointF [] points)
438                 {
439                         if (pen == null)
440                                 throw new ArgumentNullException ("pen");
441                         if (points == null)
442                                 throw new ArgumentNullException ("points");
443                         
444                         Status status;
445                         status = GDIPlus.GdipDrawClosedCurve (nativeObject, pen.nativeObject, points, points.Length);
446                         GDIPlus.CheckStatus (status);
447                 }
448                 
449                 public void DrawClosedCurve (Pen pen, Point [] points)
450                 {
451                         if (pen == null)
452                                 throw new ArgumentNullException ("pen");
453                         if (points == null)
454                                 throw new ArgumentNullException ("points");
455                         
456                         Status status;
457                         status = GDIPlus.GdipDrawClosedCurveI (nativeObject, pen.nativeObject, points, points.Length);
458                         GDIPlus.CheckStatus (status);
459                 }
460                         
461                 // according to MSDN fillmode "is required but ignored" which makes _some_ sense since the unmanaged 
462                 // GDI+ call doesn't support it (issue spotted using Gendarme's AvoidUnusedParametersRule)
463                 public void DrawClosedCurve (Pen pen, Point [] points, float tension, FillMode fillmode)
464                 {
465                         if (pen == null)
466                                 throw new ArgumentNullException ("pen");
467                         if (points == null)
468                                 throw new ArgumentNullException ("points");
469                         
470                         Status status;
471                         status = GDIPlus.GdipDrawClosedCurve2I (nativeObject, pen.nativeObject, points, points.Length, tension);
472                         GDIPlus.CheckStatus (status);
473                 }
474
475                 // according to MSDN fillmode "is required but ignored" which makes _some_ sense since the unmanaged 
476                 // GDI+ call doesn't support it (issue spotted using Gendarme's AvoidUnusedParametersRule)
477                 public void DrawClosedCurve (Pen pen, PointF [] points, float tension, FillMode fillmode)
478                 {
479                         if (pen == null)
480                                 throw new ArgumentNullException ("pen");
481                         if (points == null)
482                                 throw new ArgumentNullException ("points");
483                         
484                         Status status;
485                         status = GDIPlus.GdipDrawClosedCurve2 (nativeObject, pen.nativeObject, points, points.Length, tension);
486                         GDIPlus.CheckStatus (status);
487                 }
488                 
489                 public void DrawCurve (Pen pen, Point [] points)
490                 {
491                         if (pen == null)
492                                 throw new ArgumentNullException ("pen");
493                         if (points == null)
494                                 throw new ArgumentNullException ("points");
495                         
496                         Status status;
497                         status = GDIPlus.GdipDrawCurveI (nativeObject, pen.nativeObject, points, points.Length);
498                         GDIPlus.CheckStatus (status);
499                 }
500                 
501                 public void DrawCurve (Pen pen, PointF [] points)
502                 {
503                         if (pen == null)
504                                 throw new ArgumentNullException ("pen");
505                         if (points == null)
506                                 throw new ArgumentNullException ("points");
507                         
508                         Status status;
509                         status = GDIPlus.GdipDrawCurve (nativeObject, pen.nativeObject, points, points.Length);
510                         GDIPlus.CheckStatus (status);
511                 }
512                 
513                 public void DrawCurve (Pen pen, PointF [] points, float tension)
514                 {
515                         if (pen == null)
516                                 throw new ArgumentNullException ("pen");
517                         if (points == null)
518                                 throw new ArgumentNullException ("points");
519                         
520                         Status status;
521                         status = GDIPlus.GdipDrawCurve2 (nativeObject, pen.nativeObject, points, points.Length, tension);
522                         GDIPlus.CheckStatus (status);
523                 }
524                 
525                 public void DrawCurve (Pen pen, Point [] points, float tension)
526                 {
527                         if (pen == null)
528                                 throw new ArgumentNullException ("pen");
529                         if (points == null)
530                                 throw new ArgumentNullException ("points");
531                         
532                         Status status;
533                         status = GDIPlus.GdipDrawCurve2I (nativeObject, pen.nativeObject, points, points.Length, tension);              
534                         GDIPlus.CheckStatus (status);
535                 }
536                 
537                 public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments)
538                 {
539                         if (pen == null)
540                                 throw new ArgumentNullException ("pen");
541                         if (points == null)
542                                 throw new ArgumentNullException ("points");
543                         
544                         Status status;
545                         status = GDIPlus.GdipDrawCurve3 (nativeObject, pen.nativeObject,
546                                                         points, points.Length, offset,
547                                                         numberOfSegments, 0.5f);
548                         GDIPlus.CheckStatus (status);
549                 }
550
551                 public void DrawCurve (Pen pen, Point [] points, int offset, int numberOfSegments, float tension)
552                 {
553                         if (pen == null)
554                                 throw new ArgumentNullException ("pen");
555                         if (points == null)
556                                 throw new ArgumentNullException ("points");
557                         
558                         Status status;
559                         status = GDIPlus.GdipDrawCurve3I (nativeObject, pen.nativeObject,
560                                                         points, points.Length, offset,
561                                                         numberOfSegments, tension);
562                         GDIPlus.CheckStatus (status);
563                 }
564
565                 public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments, float tension)
566                 {
567                         if (pen == null)
568                                 throw new ArgumentNullException ("pen");
569                         if (points == null)
570                                 throw new ArgumentNullException ("points");
571                         
572                         Status status;
573                         status = GDIPlus.GdipDrawCurve3 (nativeObject, pen.nativeObject,
574                                                         points, points.Length, offset,
575                                                         numberOfSegments, tension);
576                         GDIPlus.CheckStatus (status);
577                 }
578
579                 public void DrawEllipse (Pen pen, Rectangle rect)
580                 {
581                         if (pen == null)
582                                 throw new ArgumentNullException ("pen");
583                         
584                         DrawEllipse (pen, rect.X, rect.Y, rect.Width, rect.Height);
585                 }
586
587                 public void DrawEllipse (Pen pen, RectangleF rect)
588                 {
589                         if (pen == null)
590                                 throw new ArgumentNullException ("pen");
591                         DrawEllipse (pen, rect.X, rect.Y, rect.Width, rect.Height);
592                 }
593
594                 public void DrawEllipse (Pen pen, int x, int y, int width, int height)
595                 {
596                         if (pen == null)
597                                 throw new ArgumentNullException ("pen");
598                         Status status;
599                         status = GDIPlus.GdipDrawEllipseI (nativeObject, pen.nativeObject, x, y, width, height);
600                         GDIPlus.CheckStatus (status);
601                 }
602
603                 public void DrawEllipse (Pen pen, float x, float y, float width, float height)
604                 {
605                         if (pen == null)
606                                 throw new ArgumentNullException ("pen");
607                         Status status = GDIPlus.GdipDrawEllipse (nativeObject, pen.nativeObject, x, y, width, height);
608                         GDIPlus.CheckStatus (status);
609                 }
610
611                 public void DrawIcon (Icon icon, Rectangle targetRect)
612                 {
613                         if (icon == null)
614                                 throw new ArgumentNullException ("icon");
615
616                         DrawImage (icon.GetInternalBitmap (), targetRect);
617                 }
618
619                 public void DrawIcon (Icon icon, int x, int y)
620                 {
621                         if (icon == null)
622                                 throw new ArgumentNullException ("icon");
623
624                         DrawImage (icon.GetInternalBitmap (), x, y);
625                 }
626
627                 public void DrawIconUnstretched (Icon icon, Rectangle targetRect)
628                 {
629                         if (icon == null)
630                                 throw new ArgumentNullException ("icon");
631
632                         DrawImageUnscaled (icon.GetInternalBitmap (), targetRect);
633                 }
634                 
635                 public void DrawImage (Image image, RectangleF rect)
636                 {
637                         if (image == null)
638                                 throw new ArgumentNullException ("image");
639                         
640                         Status status = GDIPlus.GdipDrawImageRect(nativeObject, image.NativeObject, rect.X, rect.Y, rect.Width, rect.Height);
641                         GDIPlus.CheckStatus (status);
642                 }
643
644                 public void DrawImage (Image image, PointF point)
645                 {
646                         if (image == null)
647                                 throw new ArgumentNullException ("image");
648                         
649                         Status status = GDIPlus.GdipDrawImage (nativeObject, image.NativeObject, point.X, point.Y);
650                         GDIPlus.CheckStatus (status);
651                 }
652
653                 public void DrawImage (Image image, Point [] destPoints)
654                 {
655                         if (image == null)
656                                 throw new ArgumentNullException ("image");
657                         if (destPoints == null)
658                                 throw new ArgumentNullException ("destPoints");
659                         
660                         Status status = GDIPlus.GdipDrawImagePointsI (nativeObject, image.NativeObject, destPoints, destPoints.Length);
661                         GDIPlus.CheckStatus (status);
662                 }
663
664                 public void DrawImage (Image image, Point point)
665                 {
666                         if (image == null)
667                                 throw new ArgumentNullException ("image");
668                         DrawImage (image, point.X, point.Y);
669                 }
670
671                 public void DrawImage (Image image, Rectangle rect)
672                 {
673                         if (image == null)
674                                 throw new ArgumentNullException ("image");
675                         DrawImage (image, rect.X, rect.Y, rect.Width, rect.Height);
676                 }
677
678                 public void DrawImage (Image image, PointF [] destPoints)
679                 {
680                         if (image == null)
681                                 throw new ArgumentNullException ("image");
682                         if (destPoints == null)
683                                 throw new ArgumentNullException ("destPoints");
684                         Status status = GDIPlus.GdipDrawImagePoints (nativeObject, image.NativeObject, destPoints, destPoints.Length);
685                         GDIPlus.CheckStatus (status);
686                 }
687
688                 public void DrawImage (Image image, int x, int y)
689                 {
690                         if (image == null)
691                                 throw new ArgumentNullException ("image");
692                         Status status = GDIPlus.GdipDrawImageI (nativeObject, image.NativeObject, x, y);
693                         GDIPlus.CheckStatus (status);
694                 }
695
696                 public void DrawImage (Image image, float x, float y)
697                 {
698                         if (image == null)
699                                 throw new ArgumentNullException ("image");
700                         Status status = GDIPlus.GdipDrawImage (nativeObject, image.NativeObject, x, y);
701                         GDIPlus.CheckStatus (status);
702                 }
703
704                 public void DrawImage (Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit)
705                 {
706                         if (image == null)
707                                 throw new ArgumentNullException ("image");
708                         Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
709                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
710                                 srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
711                                 srcUnit, IntPtr.Zero, null, IntPtr.Zero);
712                         GDIPlus.CheckStatus (status);
713                 }
714                 
715                 public void DrawImage (Image image, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit)
716                 {                       
717                         if (image == null)
718                                 throw new ArgumentNullException ("image");
719                         Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
720                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
721                                 srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
722                                 srcUnit, IntPtr.Zero, null, IntPtr.Zero);
723                         GDIPlus.CheckStatus (status);
724                 }
725
726                 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit)
727                 {
728                         if (image == null)
729                                 throw new ArgumentNullException ("image");
730                         if (destPoints == null)
731                                 throw new ArgumentNullException ("destPoints");
732                         
733                         Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
734                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y, 
735                                 srcRect.Width, srcRect.Height, srcUnit, IntPtr.Zero, 
736                                 null, IntPtr.Zero);
737                         GDIPlus.CheckStatus (status);
738                 }
739
740                 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit)
741                 {
742                         if (image == null)
743                                 throw new ArgumentNullException ("image");
744                         if (destPoints == null)
745                                 throw new ArgumentNullException ("destPoints");
746                         
747                         Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
748                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y, 
749                                 srcRect.Width, srcRect.Height, srcUnit, IntPtr.Zero, 
750                                 null, IntPtr.Zero);
751                         GDIPlus.CheckStatus (status);
752                 }
753
754                 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, 
755                                 ImageAttributes imageAttr)
756                 {
757                         if (image == null)
758                                 throw new ArgumentNullException ("image");
759                         if (destPoints == null)
760                                 throw new ArgumentNullException ("destPoints");
761                         Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
762                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
763                                 srcRect.Width, srcRect.Height, srcUnit,
764                                 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
765                         GDIPlus.CheckStatus (status);
766                 }
767                 
768                 public void DrawImage (Image image, float x, float y, float width, float height)
769                 {
770                         if (image == null)
771                                 throw new ArgumentNullException ("image");
772                         Status status = GDIPlus.GdipDrawImageRect(nativeObject, image.NativeObject, x, y,
773                            width, height);
774                         GDIPlus.CheckStatus (status);
775                 }
776
777                 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, 
778                                 ImageAttributes imageAttr)
779                 {
780                         if (image == null)
781                                 throw new ArgumentNullException ("image");
782                         if (destPoints == null)
783                                 throw new ArgumentNullException ("destPoints");
784                         Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
785                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
786                                 srcRect.Width, srcRect.Height, srcUnit, 
787                                 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
788                         GDIPlus.CheckStatus (status);
789                 }
790
791                 public void DrawImage (Image image, int x, int y, Rectangle srcRect, GraphicsUnit srcUnit)
792                 {                       
793                         if (image == null)
794                                 throw new ArgumentNullException ("image");
795                         Status status = GDIPlus.GdipDrawImagePointRectI(nativeObject, image.NativeObject, x, y, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, srcUnit);
796                         GDIPlus.CheckStatus (status);
797                 }
798                 
799                 public void DrawImage (Image image, int x, int y, int width, int height)
800                 {
801                         if (image == null)
802                                 throw new ArgumentNullException ("image");
803                         Status status = GDIPlus.GdipDrawImageRectI (nativeObject, image.nativeObject, x, y, width, height);
804                         GDIPlus.CheckStatus (status);
805                 }
806
807                 public void DrawImage (Image image, float x, float y, RectangleF srcRect, GraphicsUnit srcUnit)
808                 {                       
809                         if (image == null)
810                                 throw new ArgumentNullException ("image");
811                         Status status = GDIPlus.GdipDrawImagePointRect (nativeObject, image.nativeObject, x, y, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, srcUnit);
812                         GDIPlus.CheckStatus (status);
813                 }
814
815                 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
816                 {
817                         if (image == null)
818                                 throw new ArgumentNullException ("image");
819                         if (destPoints == null)
820                                 throw new ArgumentNullException ("destPoints");
821                         Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
822                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
823                                 srcRect.Width, srcRect.Height, srcUnit, 
824                                 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, IntPtr.Zero);
825                         GDIPlus.CheckStatus (status);
826                 }
827
828                 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
829                 {
830                         if (image == null)
831                                 throw new ArgumentNullException ("image");
832                         if (destPoints == null)
833                                 throw new ArgumentNullException ("destPoints");
834                         
835                         Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
836                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
837                                 srcRect.Width, srcRect.Height, srcUnit, 
838                                 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, IntPtr.Zero);
839                         GDIPlus.CheckStatus (status);
840                 }
841
842                 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
843                 {
844                         if (image == null)
845                                 throw new ArgumentNullException ("image");
846                         if (destPoints == null)
847                                 throw new ArgumentNullException ("destPoints");
848
849                         Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
850                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y, 
851                                 srcRect.Width, srcRect.Height, srcUnit, 
852                                 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, (IntPtr) callbackData);
853                         GDIPlus.CheckStatus (status);
854                 }
855
856                 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit)
857                 {
858                         if (image == null)
859                                 throw new ArgumentNullException ("image");
860                         Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
861                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
862                                 srcX, srcY, srcWidth, srcHeight, srcUnit, IntPtr.Zero, 
863                                 null, IntPtr.Zero);
864                         GDIPlus.CheckStatus (status);                                   
865                 }
866                 
867                 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
868                 {
869                         Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
870                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
871                                 srcRect.Width, srcRect.Height, srcUnit, 
872                                 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, (IntPtr) callbackData);
873                         GDIPlus.CheckStatus (status);
874                 }
875
876                 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit)
877                 {
878                         if (image == null)
879                                 throw new ArgumentNullException ("image");
880                         Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
881                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
882                                 srcX, srcY, srcWidth, srcHeight, srcUnit, IntPtr.Zero, 
883                                 null, IntPtr.Zero);
884                         GDIPlus.CheckStatus (status);
885                 }
886
887                 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs)
888                 {
889                         if (image == null)
890                                 throw new ArgumentNullException ("image");
891                         Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
892                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
893                                 srcX, srcY, srcWidth, srcHeight, srcUnit,
894                                 imageAttrs != null ? imageAttrs.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
895                         GDIPlus.CheckStatus (status);
896                 }
897                 
898                 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr)
899                 {                       
900                         if (image == null)
901                                 throw new ArgumentNullException ("image");
902                         Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject, 
903                                         destRect.X, destRect.Y, destRect.Width, 
904                                         destRect.Height, srcX, srcY, srcWidth, srcHeight,
905                                         srcUnit, imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
906                         GDIPlus.CheckStatus (status);
907                 }
908                 
909                 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
910                 {
911                         if (image == null)
912                                 throw new ArgumentNullException ("image");
913                         Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject, 
914                                         destRect.X, destRect.Y, destRect.Width, 
915                                         destRect.Height, srcX, srcY, srcWidth, srcHeight,
916                                         srcUnit, imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback,
917                                         IntPtr.Zero);
918                         GDIPlus.CheckStatus (status);
919                 }
920                 
921                 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback)
922                 {
923                         if (image == null)
924                                 throw new ArgumentNullException ("image");
925                         Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject, 
926                                         destRect.X, destRect.Y, destRect.Width, 
927                                         destRect.Height, srcX, srcY, srcWidth, srcHeight,
928                                         srcUnit, imageAttrs != null ? imageAttrs.NativeObject : IntPtr.Zero, 
929                                         callback, IntPtr.Zero);
930                         GDIPlus.CheckStatus (status);
931                 }
932
933                 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData)
934                 {
935                         if (image == null)
936                                 throw new ArgumentNullException ("image");
937                         Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject, 
938                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
939                                 srcX, srcY, srcWidth, srcHeight, srcUnit, 
940                                 imageAttrs != null ? imageAttrs.NativeObject : IntPtr.Zero, callback, callbackData);
941                         GDIPlus.CheckStatus (status);
942                 }
943
944                 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData)
945                 {
946                         if (image == null)
947                                 throw new ArgumentNullException ("image");
948                         Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject, 
949                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
950                                 srcX, srcY, srcWidth, srcHeight, srcUnit,
951                                 imageAttrs != null ? imageAttrs.NativeObject : IntPtr.Zero, callback, callbackData);
952                         GDIPlus.CheckStatus (status);
953                 }               
954                 
955                 public void DrawImageUnscaled (Image image, Point point)
956                 {
957                         DrawImageUnscaled (image, point.X, point.Y);
958                 }
959                 
960                 public void DrawImageUnscaled (Image image, Rectangle rect)
961                 {
962                         DrawImageUnscaled (image, rect.X, rect.Y, rect.Width, rect.Height);
963                 }
964                 
965                 public void DrawImageUnscaled (Image image, int x, int y)
966                 {
967                         if (image == null)
968                                 throw new ArgumentNullException ("image");
969                         DrawImage (image, x, y, image.Width, image.Height);
970                 }
971
972                 public void DrawImageUnscaled (Image image, int x, int y, int width, int height)
973                 {
974                         if (image == null)
975                                 throw new ArgumentNullException ("image");
976
977                         // avoid creating an empty, or negative w/h, bitmap...
978                         if ((width <= 0) || (height <= 0))
979                                 return;
980
981                         using (Image tmpImg = new Bitmap (width, height)) {
982                                 using (Graphics g = FromImage (tmpImg)) {
983                                         g.DrawImage (image, 0, 0, image.Width, image.Height);
984                                         DrawImage (tmpImg, x, y, width, height);
985                                 }
986                         }
987                 }
988
989 #if NET_2_0
990                 public void DrawImageUnscaledAndClipped (Image image, Rectangle rect)
991                 {
992                         if (image == null)
993                                 throw new ArgumentNullException ("image");
994
995                         int width = (image.Width > rect.Width) ? rect.Width : image.Width;
996                         int height = (image.Height > rect.Height) ? rect.Height : image.Height;
997
998                         DrawImageUnscaled (image, rect.X, rect.Y, width, height);                       
999                 }
1000 #endif
1001
1002                 public void DrawLine (Pen pen, PointF pt1, PointF pt2)
1003                 {
1004                         if (pen == null)
1005                                 throw new ArgumentNullException ("pen");
1006                         Status status = GDIPlus.GdipDrawLine (nativeObject, pen.nativeObject,
1007                                                 pt1.X, pt1.Y, pt2.X, pt2.Y);
1008                         GDIPlus.CheckStatus (status);
1009                 }
1010
1011                 public void DrawLine (Pen pen, Point pt1, Point pt2)
1012                 {
1013                         if (pen == null)
1014                                 throw new ArgumentNullException ("pen");
1015                         Status status = GDIPlus.GdipDrawLineI (nativeObject, pen.nativeObject,
1016                                                 pt1.X, pt1.Y, pt2.X, pt2.Y);
1017                         GDIPlus.CheckStatus (status);
1018                 }
1019
1020                 public void DrawLine (Pen pen, int x1, int y1, int x2, int y2)
1021                 {
1022                         if (pen == null)
1023                                 throw new ArgumentNullException ("pen");
1024                         Status status = GDIPlus.GdipDrawLineI (nativeObject, pen.nativeObject, x1, y1, x2, y2);
1025                         GDIPlus.CheckStatus (status);
1026                 }
1027
1028                 public void DrawLine (Pen pen, float x1, float y1, float x2, float y2)
1029                 {
1030                         if (pen == null)
1031                                 throw new ArgumentNullException ("pen");
1032                         if (!float.IsNaN(x1) && !float.IsNaN(y1) &&
1033                             !float.IsNaN(x2) && !float.IsNaN(y2)) {
1034                                 Status status = GDIPlus.GdipDrawLine (nativeObject, pen.nativeObject, x1, y1, x2, y2);
1035                                 GDIPlus.CheckStatus (status);
1036                         }
1037                 }
1038
1039                 public void DrawLines (Pen pen, PointF [] points)
1040                 {
1041                         if (pen == null)
1042                                 throw new ArgumentNullException ("pen");
1043                         if (points == null)
1044                                 throw new ArgumentNullException ("points");
1045                         Status status = GDIPlus.GdipDrawLines (nativeObject, pen.nativeObject, points, points.Length);
1046                         GDIPlus.CheckStatus (status);
1047                 }
1048
1049                 public void DrawLines (Pen pen, Point [] points)
1050                 {
1051                         if (pen == null)
1052                                 throw new ArgumentNullException ("pen");
1053                         if (points == null)
1054                                 throw new ArgumentNullException ("points");
1055                         Status status = GDIPlus.GdipDrawLinesI (nativeObject, pen.nativeObject, points, points.Length);
1056                         GDIPlus.CheckStatus (status);
1057                 }
1058
1059                 public void DrawPath (Pen pen, GraphicsPath path)
1060                 {
1061                         if (pen == null)
1062                                 throw new ArgumentNullException ("pen");
1063                         if (path == null)
1064                                 throw new ArgumentNullException ("path");
1065                         Status status = GDIPlus.GdipDrawPath (nativeObject, pen.nativeObject, path.nativePath);
1066                         GDIPlus.CheckStatus (status);
1067                 }
1068                 
1069                 public void DrawPie (Pen pen, Rectangle rect, float startAngle, float sweepAngle)
1070                 {
1071                         if (pen == null)
1072                                 throw new ArgumentNullException ("pen");
1073                         DrawPie (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
1074                 }
1075                 
1076                 public void DrawPie (Pen pen, RectangleF rect, float startAngle, float sweepAngle)
1077                 {
1078                         if (pen == null)
1079                                 throw new ArgumentNullException ("pen");
1080                         DrawPie (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
1081                 }
1082                 
1083                 public void DrawPie (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
1084                 {
1085                         if (pen == null)
1086                                 throw new ArgumentNullException ("pen");
1087                         Status status = GDIPlus.GdipDrawPie (nativeObject, pen.nativeObject, x, y, width, height, startAngle, sweepAngle);
1088                         GDIPlus.CheckStatus (status);
1089                 }
1090                 
1091                 // Microsoft documentation states that the signature for this member should be
1092                 // public void DrawPie(Pen pen, int x,  int y,  int width,   int height,   int startAngle
1093                 // int sweepAngle. However, GdipDrawPieI uses also float for the startAngle and sweepAngle params
1094                 public void DrawPie (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
1095                 {
1096                         if (pen == null)
1097                                 throw new ArgumentNullException ("pen");
1098                         Status status = GDIPlus.GdipDrawPieI (nativeObject, pen.nativeObject, x, y, width, height, startAngle, sweepAngle);
1099                         GDIPlus.CheckStatus (status);
1100                 }
1101
1102                 public void DrawPolygon (Pen pen, Point [] points)
1103                 {
1104                         if (pen == null)
1105                                 throw new ArgumentNullException ("pen");
1106                         if (points == null)
1107                                 throw new ArgumentNullException ("points");
1108                         Status status = GDIPlus.GdipDrawPolygonI (nativeObject, pen.nativeObject, points, points.Length);
1109                         GDIPlus.CheckStatus (status);
1110                 }
1111
1112                 public void DrawPolygon (Pen pen, PointF [] points)
1113                 {
1114                         if (pen == null)
1115                                 throw new ArgumentNullException ("pen");
1116                         if (points == null)
1117                                 throw new ArgumentNullException ("points");
1118                         Status status = GDIPlus.GdipDrawPolygon (nativeObject, pen.nativeObject, points, points.Length);
1119                         GDIPlus.CheckStatus (status);
1120                 }
1121
1122                 public void DrawRectangle (Pen pen, Rectangle rect)
1123                 {
1124                         if (pen == null)
1125                                 throw new ArgumentNullException ("pen");
1126                         DrawRectangle (pen, rect.Left, rect.Top, rect.Width, rect.Height);
1127                 }
1128
1129                 public void DrawRectangle (Pen pen, float x, float y, float width, float height)
1130                 {
1131                         if (pen == null)
1132                                 throw new ArgumentNullException ("pen");
1133                         Status status = GDIPlus.GdipDrawRectangle (nativeObject, pen.nativeObject, x, y, width, height);
1134                         GDIPlus.CheckStatus (status);
1135                 }
1136
1137                 public void DrawRectangle (Pen pen, int x, int y, int width, int height)
1138                 {
1139                         if (pen == null)
1140                                 throw new ArgumentNullException ("pen");
1141                         Status status = GDIPlus.GdipDrawRectangleI (nativeObject, pen.nativeObject, x, y, width, height);
1142                         GDIPlus.CheckStatus (status);
1143                 }
1144
1145                 public void DrawRectangles (Pen pen, RectangleF [] rects)
1146                 {
1147                         if (pen == null)
1148                                 throw new ArgumentNullException ("image");
1149                         if (rects == null)
1150                                 throw new ArgumentNullException ("rects");
1151                         Status status = GDIPlus.GdipDrawRectangles (nativeObject, pen.nativeObject, rects, rects.Length);
1152                         GDIPlus.CheckStatus (status);
1153                 }
1154
1155                 public void DrawRectangles (Pen pen, Rectangle [] rects)
1156                 {
1157                         if (pen == null)
1158                                 throw new ArgumentNullException ("image");
1159                         if (rects == null)
1160                                 throw new ArgumentNullException ("rects");
1161                         Status status = GDIPlus.GdipDrawRectanglesI (nativeObject, pen.nativeObject, rects, rects.Length);
1162                         GDIPlus.CheckStatus (status);
1163                 }
1164
1165                 public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle)
1166                 {
1167                         DrawString (s, font, brush, layoutRectangle, null);
1168                 }
1169
1170                 public void DrawString (string s, Font font, Brush brush, PointF point)
1171                 {
1172                         DrawString (s, font, brush, new RectangleF (point.X, point.Y, 0, 0), null);
1173                 }
1174
1175                 public void DrawString (string s, Font font, Brush brush, PointF point, StringFormat format)
1176                 {
1177                         DrawString(s, font, brush, new RectangleF(point.X, point.Y, 0, 0), format);
1178                 }
1179
1180                 public void DrawString (string s, Font font, Brush brush, float x, float y)
1181                 {
1182                         DrawString (s, font, brush, new RectangleF (x, y, 0, 0), null);
1183                 }
1184
1185                 public void DrawString (string s, Font font, Brush brush, float x, float y, StringFormat format)
1186                 {
1187                         DrawString (s, font, brush, new RectangleF(x, y, 0, 0), format);
1188                 }
1189
1190                 public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
1191                 {
1192                         if (font == null)
1193                                 throw new ArgumentNullException ("font");
1194                         if (brush == null)
1195                                 throw new ArgumentNullException ("brush");
1196                         if (s == null || s.Length == 0)
1197                                 return;
1198
1199                         Status status = GDIPlus.GdipDrawString (nativeObject, s, s.Length, font.NativeObject, ref layoutRectangle, format != null ? format.NativeObject : IntPtr.Zero, brush.nativeObject);
1200                         GDIPlus.CheckStatus (status);
1201                 }
1202
1203                 public void EndContainer (GraphicsContainer container)
1204                 {
1205 #if NET_2_0
1206                         if (container == null)
1207                                 throw new ArgumentNullException ("container");
1208 #endif
1209                         Status status = GDIPlus.GdipEndContainer(nativeObject, container.NativeObject);
1210                         GDIPlus.CheckStatus (status);
1211                 }
1212
1213                 private const string MetafileEnumeration = "Metafiles enumeration, for both WMF and EMF formats, isn't supported.";
1214
1215                 [MonoTODO (MetafileEnumeration)]
1216                 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback)
1217                 {
1218                         throw new NotImplementedException ();
1219                 }
1220
1221                 [MonoTODO (MetafileEnumeration)]
1222                 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback)
1223                 {
1224                         throw new NotImplementedException ();
1225                 }
1226
1227                 [MonoTODO (MetafileEnumeration)]
1228                 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback)
1229                 {
1230                         throw new NotImplementedException ();
1231                 }
1232
1233                 [MonoTODO (MetafileEnumeration)]
1234                 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback)
1235                 {
1236                         throw new NotImplementedException ();
1237                 }
1238
1239                 [MonoTODO (MetafileEnumeration)]
1240                 public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback)
1241                 {
1242                         throw new NotImplementedException ();
1243                 }
1244
1245                 [MonoTODO (MetafileEnumeration)]
1246                 public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback)
1247                 {
1248                         throw new NotImplementedException ();
1249                 }
1250
1251                 [MonoTODO (MetafileEnumeration)]
1252                 public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
1253                 {
1254                         throw new NotImplementedException ();
1255                 }
1256
1257                 [MonoTODO (MetafileEnumeration)]
1258                 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData)
1259                 {
1260                         throw new NotImplementedException ();
1261                 }
1262
1263                 [MonoTODO (MetafileEnumeration)]
1264                 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
1265                 {
1266                         throw new NotImplementedException ();
1267                 }
1268
1269                 [MonoTODO (MetafileEnumeration)]
1270                 public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
1271                 {
1272                         throw new NotImplementedException ();
1273                 }
1274
1275                 [MonoTODO (MetafileEnumeration)]
1276                 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
1277                 {
1278                         throw new NotImplementedException ();
1279                 }
1280
1281                 [MonoTODO (MetafileEnumeration)]
1282                 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData)
1283                 {
1284                         throw new NotImplementedException ();
1285                 }
1286
1287                 [MonoTODO (MetafileEnumeration)]
1288                 public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1289                 {
1290                         throw new NotImplementedException ();
1291                 }
1292
1293                 [MonoTODO (MetafileEnumeration)]
1294                 public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1295                 {
1296                         throw new NotImplementedException ();
1297                 }
1298
1299                 [MonoTODO (MetafileEnumeration)]
1300                 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1301                 {
1302                         throw new NotImplementedException ();
1303                 }
1304
1305                 [MonoTODO (MetafileEnumeration)]
1306                 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1307                 {
1308                         throw new NotImplementedException ();
1309                 }
1310
1311                 [MonoTODO (MetafileEnumeration)]
1312                 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1313                 {
1314                         throw new NotImplementedException ();
1315                 }
1316
1317                 [MonoTODO (MetafileEnumeration)]
1318                 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1319                 {
1320                         throw new NotImplementedException ();
1321                 }
1322
1323                 [MonoTODO (MetafileEnumeration)]
1324                 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1325                 {
1326                         throw new NotImplementedException ();
1327                 }
1328
1329                 [MonoTODO (MetafileEnumeration)]
1330                 public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1331                 {
1332                         throw new NotImplementedException ();
1333                 }
1334
1335                 [MonoTODO (MetafileEnumeration)]
1336                 public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1337                 {
1338                         throw new NotImplementedException ();
1339                 }
1340
1341                 [MonoTODO (MetafileEnumeration)]
1342                 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1343                 {
1344                         throw new NotImplementedException ();
1345                 }
1346
1347                 [MonoTODO (MetafileEnumeration)]
1348                 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1349                 {
1350                         throw new NotImplementedException ();
1351                 }
1352
1353                 [MonoTODO (MetafileEnumeration)]
1354                 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1355                 {
1356                         throw new NotImplementedException ();
1357                 }
1358
1359                 [MonoTODO (MetafileEnumeration)]
1360                 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1361                 {
1362                         throw new NotImplementedException ();
1363                 }
1364
1365                 [MonoTODO (MetafileEnumeration)]
1366                 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1367                 {
1368                         throw new NotImplementedException ();
1369                 }
1370
1371                 [MonoTODO (MetafileEnumeration)]
1372                 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1373                 {
1374                         throw new NotImplementedException ();
1375                 }
1376
1377                 [MonoTODO (MetafileEnumeration)]
1378                 public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1379                 {
1380                         throw new NotImplementedException ();
1381                 }
1382
1383                 [MonoTODO (MetafileEnumeration)]
1384                 public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1385                 {
1386                         throw new NotImplementedException ();
1387                 }
1388
1389                 [MonoTODO (MetafileEnumeration)]
1390                 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1391                 {
1392                         throw new NotImplementedException ();
1393                 }
1394
1395                 [MonoTODO (MetafileEnumeration)]
1396                 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1397                 {
1398                         throw new NotImplementedException ();
1399                 }
1400
1401                 [MonoTODO (MetafileEnumeration)]
1402                 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1403                 {
1404                         throw new NotImplementedException ();
1405                 }
1406
1407                 [MonoTODO (MetafileEnumeration)]
1408                 public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1409                 {
1410                         throw new NotImplementedException ();
1411                 }
1412
1413                 [MonoTODO (MetafileEnumeration)]
1414                 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1415                 {
1416                         throw new NotImplementedException ();
1417                 }
1418
1419                 [MonoTODO (MetafileEnumeration)]
1420                 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1421                 {
1422                         throw new NotImplementedException ();
1423                 }
1424
1425                 [MonoTODO (MetafileEnumeration)]
1426                 public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1427                 {
1428                         throw new NotImplementedException ();
1429                 }
1430         
1431                 public void ExcludeClip (Rectangle rect)
1432                 {
1433                         Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Exclude);
1434                         GDIPlus.CheckStatus (status);
1435                 }
1436
1437                 public void ExcludeClip (Region region)
1438                 {
1439                         if (region == null)
1440                                 throw new ArgumentNullException ("region");
1441                         Status status = GDIPlus.GdipSetClipRegion (nativeObject, region.NativeObject, CombineMode.Exclude);
1442                         GDIPlus.CheckStatus (status);
1443                 }
1444
1445                 
1446                 public void FillClosedCurve (Brush brush, PointF [] points)
1447                 {
1448                         if (brush == null)
1449                                 throw new ArgumentNullException ("brush");
1450                         if (points == null)
1451                                 throw new ArgumentNullException ("points");
1452                         Status status = GDIPlus.GdipFillClosedCurve (nativeObject, brush.NativeObject, points, points.Length);
1453                         GDIPlus.CheckStatus (status);
1454                 }
1455                 
1456                 public void FillClosedCurve (Brush brush, Point [] points)
1457                 {
1458                         if (brush == null)
1459                                 throw new ArgumentNullException ("brush");
1460                         if (points == null)
1461                                 throw new ArgumentNullException ("points");
1462                         Status status = GDIPlus.GdipFillClosedCurveI (nativeObject, brush.NativeObject, points, points.Length);
1463                         GDIPlus.CheckStatus (status);
1464                 }
1465
1466                 
1467                 public void FillClosedCurve (Brush brush, PointF [] points, FillMode fillmode)
1468                 {
1469                         if (brush == null)
1470                                 throw new ArgumentNullException ("brush");
1471                         if (points == null)
1472                                 throw new ArgumentNullException ("points");
1473                         FillClosedCurve (brush, points, fillmode, 0.5f);
1474                 }
1475                 
1476                 public void FillClosedCurve (Brush brush, Point [] points, FillMode fillmode)
1477                 {
1478                         if (brush == null)
1479                                 throw new ArgumentNullException ("brush");
1480                         if (points == null)
1481                                 throw new ArgumentNullException ("points");
1482                         FillClosedCurve (brush, points, fillmode, 0.5f);
1483                 }
1484
1485                 public void FillClosedCurve (Brush brush, PointF [] points, FillMode fillmode, float tension)
1486                 {
1487                         if (brush == null)
1488                                 throw new ArgumentNullException ("brush");
1489                         if (points == null)
1490                                 throw new ArgumentNullException ("points");
1491                         Status status = GDIPlus.GdipFillClosedCurve2 (nativeObject, brush.NativeObject, points, points.Length, tension, fillmode);
1492                         GDIPlus.CheckStatus (status);
1493                 }
1494
1495                 public void FillClosedCurve (Brush brush, Point [] points, FillMode fillmode, float tension)
1496                 {
1497                         if (brush == null)
1498                                 throw new ArgumentNullException ("brush");
1499                         if (points == null)
1500                                 throw new ArgumentNullException ("points");
1501                         Status status = GDIPlus.GdipFillClosedCurve2I (nativeObject, brush.NativeObject, points, points.Length, tension, fillmode);
1502                         GDIPlus.CheckStatus (status);
1503                 }
1504
1505                 public void FillEllipse (Brush brush, Rectangle rect)
1506                 {
1507                         if (brush == null)
1508                                 throw new ArgumentNullException ("brush");
1509                         FillEllipse (brush, rect.X, rect.Y, rect.Width, rect.Height);
1510                 }
1511
1512                 public void FillEllipse (Brush brush, RectangleF rect)
1513                 {
1514                         if (brush == null)
1515                                 throw new ArgumentNullException ("brush");
1516                         FillEllipse (brush, rect.X, rect.Y, rect.Width, rect.Height);
1517                 }
1518
1519                 public void FillEllipse (Brush brush, float x, float y, float width, float height)
1520                 {
1521                         if (brush == null)
1522                                 throw new ArgumentNullException ("brush");
1523                         Status status = GDIPlus.GdipFillEllipse (nativeObject, brush.nativeObject, x, y, width, height);
1524                         GDIPlus.CheckStatus (status);
1525                 }
1526
1527                 public void FillEllipse (Brush brush, int x, int y, int width, int height)
1528                 {
1529                         if (brush == null)
1530                                 throw new ArgumentNullException ("brush");
1531                         Status status = GDIPlus.GdipFillEllipseI (nativeObject, brush.nativeObject, x, y, width, height);
1532                         GDIPlus.CheckStatus (status);
1533                 }
1534
1535                 public void FillPath (Brush brush, GraphicsPath path)
1536                 {
1537                         if (brush == null)
1538                                 throw new ArgumentNullException ("brush");
1539                         if (path == null)
1540                                 throw new ArgumentNullException ("path");
1541                         Status status = GDIPlus.GdipFillPath (nativeObject, brush.NativeObject,  path.NativeObject);
1542                         GDIPlus.CheckStatus (status);
1543                 }
1544
1545                 public void FillPie (Brush brush, Rectangle rect, float startAngle, float sweepAngle)
1546                 {
1547                         if (brush == null)
1548                                 throw new ArgumentNullException ("brush");
1549                         Status status = GDIPlus.GdipFillPie (nativeObject, brush.NativeObject, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
1550                         GDIPlus.CheckStatus (status);
1551                 }
1552
1553                 public void FillPie (Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle)
1554                 {
1555                         if (brush == null)
1556                                 throw new ArgumentNullException ("brush");
1557                         Status status = GDIPlus.GdipFillPieI (nativeObject, brush.NativeObject, x, y, width, height, startAngle, sweepAngle);
1558                         GDIPlus.CheckStatus (status);
1559                 }
1560
1561                 public void FillPie (Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle)
1562                 {
1563                         if (brush == null)
1564                                 throw new ArgumentNullException ("brush");
1565                         Status status = GDIPlus.GdipFillPie (nativeObject, brush.NativeObject, x, y, width, height, startAngle, sweepAngle);
1566                         GDIPlus.CheckStatus (status);
1567                 }
1568
1569                 public void FillPolygon (Brush brush, PointF [] points)
1570                 {
1571                         if (brush == null)
1572                                 throw new ArgumentNullException ("brush");
1573                         if (points == null)
1574                                 throw new ArgumentNullException ("points");
1575                         Status status = GDIPlus.GdipFillPolygon2 (nativeObject, brush.nativeObject, points, points.Length);
1576                         GDIPlus.CheckStatus (status);
1577                 }
1578
1579                 public void FillPolygon (Brush brush, Point [] points)
1580                 {
1581                         if (brush == null)
1582                                 throw new ArgumentNullException ("brush");
1583                         if (points == null)
1584                                 throw new ArgumentNullException ("points");
1585                         Status status = GDIPlus.GdipFillPolygon2I (nativeObject, brush.nativeObject, points, points.Length);
1586                         GDIPlus.CheckStatus (status);
1587                 }
1588
1589                 public void FillPolygon (Brush brush, Point [] points, FillMode fillMode)
1590                 {
1591                         if (brush == null)
1592                                 throw new ArgumentNullException ("brush");
1593                         if (points == null)
1594                                 throw new ArgumentNullException ("points");
1595                         Status status = GDIPlus.GdipFillPolygonI (nativeObject, brush.nativeObject, points, points.Length, fillMode);
1596                         GDIPlus.CheckStatus (status);
1597                 }
1598
1599                 public void FillPolygon (Brush brush, PointF [] points, FillMode fillMode)
1600                 {
1601                         if (brush == null)
1602                                 throw new ArgumentNullException ("brush");
1603                         if (points == null)
1604                                 throw new ArgumentNullException ("points");
1605                         Status status = GDIPlus.GdipFillPolygon (nativeObject, brush.nativeObject, points, points.Length, fillMode);
1606                         GDIPlus.CheckStatus (status);
1607                 }
1608
1609                 public void FillRectangle (Brush brush, RectangleF rect)
1610                 {
1611                         if (brush == null)
1612                                 throw new ArgumentNullException ("brush");
1613                         FillRectangle (brush, rect.Left, rect.Top, rect.Width, rect.Height);
1614                 }
1615
1616                 public void FillRectangle (Brush brush, Rectangle rect)
1617                 {
1618                         if (brush == null)
1619                                 throw new ArgumentNullException ("brush");
1620                         FillRectangle (brush, rect.Left, rect.Top, rect.Width, rect.Height);
1621                 }
1622
1623                 public void FillRectangle (Brush brush, int x, int y, int width, int height)
1624                 {
1625                         if (brush == null)
1626                                 throw new ArgumentNullException ("brush");
1627                         
1628                         Status status = GDIPlus.GdipFillRectangleI (nativeObject, brush.nativeObject, x, y, width, height);
1629                         GDIPlus.CheckStatus (status);
1630                 }
1631
1632                 public void FillRectangle (Brush brush, float x, float y, float width, float height)
1633                 {
1634                         if (brush == null)
1635                                 throw new ArgumentNullException ("brush");
1636                         
1637                         Status status = GDIPlus.GdipFillRectangle (nativeObject, brush.nativeObject, x, y, width, height);
1638                         GDIPlus.CheckStatus (status);
1639                 }
1640
1641                 public void FillRectangles (Brush brush, Rectangle [] rects)
1642                 {
1643                         if (brush == null)
1644                                 throw new ArgumentNullException ("brush");
1645                         if (rects == null)
1646                                 throw new ArgumentNullException ("rects");
1647
1648                         Status status = GDIPlus.GdipFillRectanglesI (nativeObject, brush.nativeObject, rects, rects.Length);
1649                         GDIPlus.CheckStatus (status);
1650                 }
1651
1652                 public void FillRectangles (Brush brush, RectangleF [] rects)
1653                 {
1654                         if (brush == null)
1655                                 throw new ArgumentNullException ("brush");
1656                         if (rects == null)
1657                                 throw new ArgumentNullException ("rects");
1658
1659                         Status status = GDIPlus.GdipFillRectangles (nativeObject, brush.nativeObject, rects, rects.Length);
1660                         GDIPlus.CheckStatus (status);
1661                 }
1662
1663                 
1664                 public void FillRegion (Brush brush, Region region)
1665                 {
1666                         if (brush == null)
1667                                 throw new ArgumentNullException ("brush");
1668                         if (region == null)
1669                                 throw new ArgumentNullException ("region");
1670                         
1671                         Status status = GDIPlus.GdipFillRegion (nativeObject, brush.NativeObject, region.NativeObject);                  
1672                         GDIPlus.CheckStatus(status);
1673                 }
1674
1675                 
1676                 public void Flush ()
1677                 {
1678                         Flush (FlushIntention.Flush);
1679                 }
1680
1681                 
1682                 public void Flush (FlushIntention intention)
1683                 {
1684                         if (nativeObject == IntPtr.Zero) {
1685                                 return;
1686                         }
1687
1688                         Status status = GDIPlus.GdipFlush (nativeObject, intention);
1689                         GDIPlus.CheckStatus (status);                    
1690
1691                         if (maccontext != null)
1692                                 maccontext.Synchronize ();
1693                 }
1694
1695                 [EditorBrowsable (EditorBrowsableState.Advanced)]               
1696                 public static Graphics FromHdc (IntPtr hdc)
1697                 {
1698                         IntPtr graphics;
1699                         Status status = GDIPlus.GdipCreateFromHDC (hdc, out graphics);
1700                         GDIPlus.CheckStatus (status);
1701                         return new Graphics (graphics);
1702                 }
1703
1704                 [MonoTODO]
1705                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1706                 public static Graphics FromHdc (IntPtr hdc, IntPtr hdevice)
1707                 {
1708                         throw new NotImplementedException ();
1709                 }
1710
1711                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1712                 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
1713                 public static Graphics FromHdcInternal (IntPtr hdc)
1714                 {
1715                         GDIPlus.Display = hdc;
1716                         return null;
1717                 }
1718
1719                 [EditorBrowsable (EditorBrowsableState.Advanced)]               
1720                 public static Graphics FromHwnd (IntPtr hwnd)
1721                 {
1722                         IntPtr graphics;
1723
1724                         if (GDIPlus.UseCocoaDrawable) {
1725                                 CocoaContext context = MacSupport.GetCGContextForNSView (hwnd);
1726                                 GDIPlus.GdipCreateFromContext_macosx (context.ctx, context.width, context.height, out graphics);
1727
1728                                 Graphics g = new Graphics (graphics);
1729                                 g.maccontext = context;
1730
1731                                 return g;
1732                         }
1733
1734                         if (GDIPlus.UseCarbonDrawable) {
1735                                 CarbonContext context = MacSupport.GetCGContextForView (hwnd);
1736                                 GDIPlus.GdipCreateFromContext_macosx (context.ctx, context.width, context.height, out graphics);
1737                                 
1738                                 Graphics g = new Graphics (graphics);
1739                                 g.maccontext = context;
1740                                 
1741                                 return g;
1742                         }
1743                         if (GDIPlus.UseX11Drawable) {
1744                                 if (GDIPlus.Display == IntPtr.Zero) {
1745                                         GDIPlus.Display = GDIPlus.XOpenDisplay (IntPtr.Zero);
1746                                         if (GDIPlus.Display == IntPtr.Zero)
1747                                                 throw new NotSupportedException ("Could not open display (X-Server required. Check you DISPLAY environment variable)");
1748                                 }
1749                                 if (hwnd == IntPtr.Zero) {
1750                                         hwnd = GDIPlus.XRootWindow (GDIPlus.Display, GDIPlus.XDefaultScreen (GDIPlus.Display));
1751                                 }
1752
1753                                 return FromXDrawable (hwnd, GDIPlus.Display);
1754
1755                         }
1756
1757                         Status status = GDIPlus.GdipCreateFromHWND (hwnd, out graphics);
1758                         GDIPlus.CheckStatus (status);
1759
1760                         return new Graphics (graphics);
1761                 }
1762                 
1763                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1764                 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
1765                 public static Graphics FromHwndInternal (IntPtr hwnd)
1766                 {
1767                         return FromHwnd (hwnd);
1768                 }
1769
1770                 public static Graphics FromImage (Image image)
1771                 {
1772                         IntPtr graphics;
1773
1774                         if (image == null) 
1775                                 throw new ArgumentNullException ("image");
1776
1777                         if ((image.PixelFormat & PixelFormat.Indexed) != 0)
1778                                 throw new Exception (Locale.GetText ("Cannot create Graphics from an indexed bitmap."));
1779
1780                         Status status = GDIPlus.GdipGetImageGraphicsContext (image.nativeObject, out graphics);
1781                         GDIPlus.CheckStatus (status);
1782                         Graphics result = new Graphics (graphics);
1783                                 
1784                         if (GDIPlus.RunningOnUnix ()) {
1785                                 Rectangle rect  = new Rectangle (0,0, image.Width, image.Height);
1786                                 GDIPlus.GdipSetVisibleClip_linux (result.NativeObject, ref rect);
1787                         }
1788                                 
1789                         return result;
1790                 }
1791
1792                 internal static Graphics FromXDrawable (IntPtr drawable, IntPtr display)
1793                 {
1794                         IntPtr graphics;
1795
1796                         Status s = GDIPlus.GdipCreateFromXDrawable_linux (drawable, display, out graphics);
1797                         GDIPlus.CheckStatus (s);
1798                         return new Graphics (graphics);
1799                 }
1800
1801                 [MonoTODO]
1802                 public static IntPtr GetHalftonePalette ()
1803                 {
1804                         throw new NotImplementedException ();
1805                 }
1806
1807 #if !NET_2_0
1808                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1809 #endif
1810                 public IntPtr GetHdc ()
1811                 {
1812                         GDIPlus.CheckStatus (GDIPlus.GdipGetDC (this.nativeObject, out deviceContextHdc));
1813                         return deviceContextHdc;
1814                 }
1815                 
1816                 public Color GetNearestColor (Color color)
1817                 {
1818                         int argb;
1819                         
1820                         Status status = GDIPlus.GdipGetNearestColor (nativeObject, out argb);
1821                         GDIPlus.CheckStatus (status);
1822
1823                         return Color.FromArgb (argb);
1824                 }
1825
1826                 
1827                 public void IntersectClip (Region region)
1828                 {
1829                         if (region == null)
1830                                 throw new ArgumentNullException ("region");
1831                         Status status = GDIPlus.GdipSetClipRegion (nativeObject, region.NativeObject, CombineMode.Intersect);
1832                         GDIPlus.CheckStatus (status);
1833                 }
1834                 
1835                 public void IntersectClip (RectangleF rect)
1836                 {
1837                         Status status = GDIPlus.GdipSetClipRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Intersect);
1838                         GDIPlus.CheckStatus (status);
1839                 }
1840
1841                 public void IntersectClip (Rectangle rect)
1842                 {                       
1843                         Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Intersect);
1844                         GDIPlus.CheckStatus (status);
1845                 }
1846
1847                 public bool IsVisible (Point point)
1848                 {
1849                         bool isVisible = false;
1850
1851                         Status status = GDIPlus.GdipIsVisiblePointI (nativeObject, point.X, point.Y, out isVisible);
1852                         GDIPlus.CheckStatus (status);
1853
1854                         return isVisible;
1855                 }
1856
1857                 
1858                 public bool IsVisible (RectangleF rect)
1859                 {
1860                         bool isVisible = false;
1861
1862                         Status status = GDIPlus.GdipIsVisibleRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, out isVisible);
1863                         GDIPlus.CheckStatus (status);
1864
1865                         return isVisible;
1866                 }
1867
1868                 public bool IsVisible (PointF point)
1869                 {
1870                         bool isVisible = false;
1871
1872                         Status status = GDIPlus.GdipIsVisiblePoint (nativeObject, point.X, point.Y, out isVisible);
1873                         GDIPlus.CheckStatus (status);
1874
1875                         return isVisible;
1876                 }
1877                 
1878                 public bool IsVisible (Rectangle rect)
1879                 {
1880                         bool isVisible = false;
1881
1882                         Status status = GDIPlus.GdipIsVisibleRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, out isVisible);
1883                         GDIPlus.CheckStatus (status);
1884
1885                         return isVisible;
1886                 }
1887                 
1888                 public bool IsVisible (float x, float y)
1889                 {
1890                         return IsVisible (new PointF (x, y));
1891                 }
1892                 
1893                 public bool IsVisible (int x, int y)
1894                 {
1895                         return IsVisible (new Point (x, y));
1896                 }
1897                 
1898                 public bool IsVisible (float x, float y, float width, float height)
1899                 {
1900                         return IsVisible (new RectangleF (x, y, width, height));
1901                 }
1902
1903                 
1904                 public bool IsVisible (int x, int y, int width, int height)
1905                 {
1906                         return IsVisible (new Rectangle (x, y, width, height));
1907                 }
1908
1909                 
1910                 public Region[] MeasureCharacterRanges (string text, Font font, RectangleF layoutRect, StringFormat stringFormat)
1911                 {
1912                         if ((text == null) || (text.Length == 0))
1913                                 return new Region [0];
1914
1915                         if (font == null)
1916                                 throw new ArgumentNullException ("font");
1917
1918                         if (stringFormat == null)
1919                                 throw new ArgumentException ("stringFormat");
1920
1921                         int regcount = stringFormat.GetMeasurableCharacterRangeCount ();
1922                         if (regcount == 0)
1923                                 return new Region[0];
1924
1925                         IntPtr[] native_regions = new IntPtr [regcount];
1926                         Region[] regions = new Region [regcount];
1927                         
1928                         for (int i = 0; i < regcount; i++) {
1929                                 regions[i] = new Region ();
1930                                 native_regions[i] = regions[i].NativeObject;
1931                         }
1932                         
1933                         Status status = GDIPlus.GdipMeasureCharacterRanges (nativeObject, text, text.Length,
1934                                 font.NativeObject, ref layoutRect, stringFormat.NativeObject, regcount, out native_regions[0]); 
1935                         GDIPlus.CheckStatus (status);                           
1936
1937                         return regions;                                                 
1938                 }
1939
1940                 private unsafe SizeF GdipMeasureString (IntPtr graphics, string text, Font font, ref RectangleF layoutRect,
1941                         IntPtr stringFormat)
1942                 {
1943                         if ((text == null) || (text.Length == 0))
1944                                 return SizeF.Empty;
1945
1946                         if (font == null)
1947                                 throw new ArgumentNullException ("font");
1948
1949                         RectangleF boundingBox = new RectangleF ();
1950
1951                         Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length, font.NativeObject, 
1952                                 ref layoutRect, stringFormat, out boundingBox, null, null);
1953                         GDIPlus.CheckStatus (status);
1954
1955                         return new SizeF (boundingBox.Width, boundingBox.Height);
1956                 }
1957
1958                 public SizeF MeasureString (string text, Font font)
1959                 {
1960                         return MeasureString (text, font, SizeF.Empty);
1961                 }
1962
1963                 public SizeF MeasureString (string text, Font font, SizeF layoutArea)
1964                 {
1965                         RectangleF rect = new RectangleF (0, 0, layoutArea.Width, layoutArea.Height);
1966                         return GdipMeasureString (nativeObject, text, font, ref rect, IntPtr.Zero);
1967                 }
1968
1969                 public SizeF MeasureString (string text, Font font, int width)
1970                 {                               
1971                         RectangleF rect = new RectangleF (0, 0, width, Int32.MaxValue);
1972                         return GdipMeasureString (nativeObject, text, font, ref rect, IntPtr.Zero);
1973                 }
1974
1975                 public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat stringFormat)
1976                 {
1977                         RectangleF rect = new RectangleF (0, 0, layoutArea.Width, layoutArea.Height);
1978                         IntPtr format = (stringFormat == null) ? IntPtr.Zero : stringFormat.NativeObject;
1979                         return GdipMeasureString (nativeObject, text, font, ref rect, format);
1980                 }
1981
1982                 public SizeF MeasureString (string text, Font font, int width, StringFormat format)
1983                 {
1984                         RectangleF rect = new RectangleF (0, 0, width, Int32.MaxValue);
1985                         IntPtr stringFormat = (format == null) ? IntPtr.Zero : format.NativeObject;
1986                         return GdipMeasureString (nativeObject, text, font, ref rect, stringFormat);
1987                 }
1988
1989                 public SizeF MeasureString (string text, Font font, PointF origin, StringFormat stringFormat)
1990                 {
1991                         RectangleF rect = new RectangleF (origin.X, origin.Y, 0, 0);
1992                         IntPtr format = (stringFormat == null) ? IntPtr.Zero : stringFormat.NativeObject;
1993                         return GdipMeasureString (nativeObject, text, font, ref rect, format);
1994                 }
1995
1996                 public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat stringFormat, 
1997                         out int charactersFitted, out int linesFilled)
1998                 {       
1999                         charactersFitted = 0;
2000                         linesFilled = 0;
2001
2002                         if ((text == null) || (text.Length == 0))
2003                                 return SizeF.Empty;
2004
2005                         if (font == null)
2006                                 throw new ArgumentNullException ("font");
2007
2008                         RectangleF boundingBox = new RectangleF ();
2009                         RectangleF rect = new RectangleF (0, 0, layoutArea.Width, layoutArea.Height);
2010
2011                         IntPtr format = (stringFormat == null) ? IntPtr.Zero : stringFormat.NativeObject;
2012
2013                         unsafe {
2014                                 fixed (int* pc = &charactersFitted, pl = &linesFilled) {
2015                                         Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length, 
2016                                         font.NativeObject, ref rect, format, out boundingBox, pc, pl);
2017                                         GDIPlus.CheckStatus (status);
2018                                 }
2019                         }
2020                         return new SizeF (boundingBox.Width, boundingBox.Height);
2021                 }
2022
2023                 public void MultiplyTransform (Matrix matrix)
2024                 {
2025                         MultiplyTransform (matrix, MatrixOrder.Prepend);
2026                 }
2027
2028                 public void MultiplyTransform (Matrix matrix, MatrixOrder order)
2029                 {
2030                         if (matrix == null)
2031                                 throw new ArgumentNullException ("matrix");
2032
2033                         Status status = GDIPlus.GdipMultiplyWorldTransform (nativeObject, matrix.nativeMatrix, order);
2034                         GDIPlus.CheckStatus (status);
2035                 }
2036
2037                 [EditorBrowsable (EditorBrowsableState.Advanced)]
2038                 [SecurityPermission (SecurityAction.Demand, UnmanagedCode = true)]
2039                 public void ReleaseHdc (IntPtr hdc)
2040                 {
2041                         ReleaseHdcInternal (hdc);
2042                 }
2043
2044 #if NET_2_0
2045                 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
2046                 public void ReleaseHdc ()
2047                 {
2048                         ReleaseHdcInternal (deviceContextHdc);
2049                 }
2050 #endif
2051
2052                 [MonoLimitation ("Can only be used when hdc was provided by Graphics.GetHdc() method")]
2053 #if NET_2_0
2054                 [EditorBrowsable (EditorBrowsableState.Never)]
2055 #else
2056                 [EditorBrowsable (EditorBrowsableState.Advanced)]
2057 #endif
2058                 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
2059                 public void ReleaseHdcInternal (IntPtr hdc)
2060                 {
2061                         Status status = Status.InvalidParameter;
2062                         if (hdc == deviceContextHdc) {
2063                                 status = GDIPlus.GdipReleaseDC (nativeObject, deviceContextHdc);
2064                                 deviceContextHdc = IntPtr.Zero;
2065                         }
2066                         GDIPlus.CheckStatus (status);
2067                 }
2068                 
2069                 public void ResetClip ()
2070                 {
2071                         Status status = GDIPlus.GdipResetClip (nativeObject);
2072                         GDIPlus.CheckStatus (status);
2073                 }
2074
2075                 public void ResetTransform ()
2076                 {
2077                         Status status = GDIPlus.GdipResetWorldTransform (nativeObject);
2078                         GDIPlus.CheckStatus (status);
2079                 }
2080
2081                 public void Restore (GraphicsState gstate)
2082                 {                       
2083                         // the possible NRE thrown by gstate.nativeState match MS behaviour
2084                         Status status = GDIPlus.GdipRestoreGraphics (nativeObject, gstate.nativeState);
2085                         GDIPlus.CheckStatus (status);
2086                 }
2087
2088                 public void RotateTransform (float angle)
2089                 {
2090                         RotateTransform (angle, MatrixOrder.Prepend);
2091                 }
2092
2093                 public void RotateTransform (float angle, MatrixOrder order)
2094                 {
2095                         Status status = GDIPlus.GdipRotateWorldTransform (nativeObject, angle, order);
2096                         GDIPlus.CheckStatus (status);
2097                 }
2098
2099                 public GraphicsState Save ()
2100                 {                                               
2101                         uint saveState;
2102                         Status status = GDIPlus.GdipSaveGraphics (nativeObject, out saveState);
2103                         GDIPlus.CheckStatus (status);
2104
2105                         GraphicsState state = new GraphicsState ();
2106                         state.nativeState = saveState;
2107                         return state;
2108                 }
2109
2110                 public void ScaleTransform (float sx, float sy)
2111                 {
2112                         ScaleTransform (sx, sy, MatrixOrder.Prepend);
2113                 }
2114
2115                 public void ScaleTransform (float sx, float sy, MatrixOrder order)
2116                 {
2117                         Status status = GDIPlus.GdipScaleWorldTransform (nativeObject, sx, sy, order);
2118                         GDIPlus.CheckStatus (status);
2119                 }
2120
2121                 
2122                 public void SetClip (RectangleF rect)
2123                 {
2124                         SetClip (rect, CombineMode.Replace);
2125                 }
2126
2127                 
2128                 public void SetClip (GraphicsPath path)
2129                 {
2130                         SetClip (path, CombineMode.Replace);
2131                 }
2132
2133                 
2134                 public void SetClip (Rectangle rect)
2135                 {
2136                         SetClip (rect, CombineMode.Replace);
2137                 }
2138
2139                 
2140                 public void SetClip (Graphics g)
2141                 {
2142                         SetClip (g, CombineMode.Replace);
2143                 }
2144
2145                 
2146                 public void SetClip (Graphics g, CombineMode combineMode)
2147                 {
2148                         if (g == null)
2149                                 throw new ArgumentNullException ("g");
2150                         
2151                         Status status = GDIPlus.GdipSetClipGraphics (nativeObject, g.NativeObject, combineMode);
2152                         GDIPlus.CheckStatus (status);
2153                 }
2154
2155                 
2156                 public void SetClip (Rectangle rect, CombineMode combineMode)
2157                 {
2158                         Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, combineMode);
2159                         GDIPlus.CheckStatus (status);
2160                 }
2161
2162                 
2163                 public void SetClip (RectangleF rect, CombineMode combineMode)
2164                 {
2165                         Status status = GDIPlus.GdipSetClipRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, combineMode);
2166                         GDIPlus.CheckStatus (status);
2167                 }
2168
2169                 
2170                 public void SetClip (Region region, CombineMode combineMode)
2171                 {
2172                         if (region == null)
2173                                 throw new ArgumentNullException ("region");
2174                         Status status =   GDIPlus.GdipSetClipRegion(nativeObject,  region.NativeObject, combineMode); 
2175                         GDIPlus.CheckStatus (status);
2176                 }
2177
2178                 
2179                 public void SetClip (GraphicsPath path, CombineMode combineMode)
2180                 {
2181                         if (path == null)
2182                                 throw new ArgumentNullException ("path");
2183                         Status status = GDIPlus.GdipSetClipPath (nativeObject, path.NativeObject, combineMode);
2184                         GDIPlus.CheckStatus (status);
2185                 }
2186
2187                 
2188                 public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, PointF [] pts)
2189                 {
2190                         if (pts == null)
2191                                 throw new ArgumentNullException ("pts");
2192
2193                         IntPtr ptrPt =  GDIPlus.FromPointToUnManagedMemory (pts);
2194             
2195                         Status status = GDIPlus.GdipTransformPoints (nativeObject, destSpace, srcSpace,  ptrPt, pts.Length);
2196                         GDIPlus.CheckStatus (status);
2197                         
2198                         GDIPlus.FromUnManagedMemoryToPoint (ptrPt, pts);
2199                 }
2200
2201
2202                 public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, Point [] pts)
2203                 {                                               
2204                         if (pts == null)
2205                                 throw new ArgumentNullException ("pts");
2206                         IntPtr ptrPt =  GDIPlus.FromPointToUnManagedMemoryI (pts);
2207             
2208                         Status status = GDIPlus.GdipTransformPointsI (nativeObject, destSpace, srcSpace, ptrPt, pts.Length);
2209                         GDIPlus.CheckStatus (status);
2210                         
2211                         GDIPlus.FromUnManagedMemoryToPointI (ptrPt, pts);
2212                 }
2213
2214                 
2215                 public void TranslateClip (int dx, int dy)
2216                 {
2217                         Status status = GDIPlus.GdipTranslateClipI (nativeObject, dx, dy);
2218                         GDIPlus.CheckStatus (status);
2219                 }
2220
2221                 
2222                 public void TranslateClip (float dx, float dy)
2223                 {
2224                         Status status = GDIPlus.GdipTranslateClip (nativeObject, dx, dy);
2225                         GDIPlus.CheckStatus (status);
2226                 }
2227
2228                 public void TranslateTransform (float dx, float dy)
2229                 {
2230                         TranslateTransform (dx, dy, MatrixOrder.Prepend);
2231                 }
2232
2233                 
2234                 public void TranslateTransform (float dx, float dy, MatrixOrder order)
2235                 {                       
2236                         Status status = GDIPlus.GdipTranslateWorldTransform (nativeObject, dx, dy, order);
2237                         GDIPlus.CheckStatus (status);
2238                 }
2239
2240                 public Region Clip {
2241                         get {
2242                                 Region reg = new Region();
2243                                 Status status = GDIPlus.GdipGetClip (nativeObject, reg.NativeObject);
2244                                 GDIPlus.CheckStatus (status);
2245                                 return reg;                             
2246                         }
2247                         set {
2248                                 SetClip (value, CombineMode.Replace);
2249                         }
2250                 }
2251
2252                 public RectangleF ClipBounds {
2253                         get {
2254                                 RectangleF rect = new RectangleF ();
2255                                 Status status = GDIPlus.GdipGetClipBounds (nativeObject, out rect);
2256                                 GDIPlus.CheckStatus (status);
2257                                 return rect;
2258                         }
2259                 }
2260
2261                 public CompositingMode CompositingMode {
2262                         get {
2263                                 CompositingMode mode;
2264                                 Status status = GDIPlus.GdipGetCompositingMode (nativeObject, out mode);
2265                                 GDIPlus.CheckStatus (status);
2266
2267                                 return mode;
2268                         }
2269                         set {
2270                                 Status status = GDIPlus.GdipSetCompositingMode (nativeObject, value);
2271                                 GDIPlus.CheckStatus (status);
2272                         }
2273
2274                 }
2275
2276                 public CompositingQuality CompositingQuality {
2277                         get {
2278                                 CompositingQuality quality;
2279
2280                                 Status status = GDIPlus.GdipGetCompositingQuality (nativeObject, out quality);
2281                                 GDIPlus.CheckStatus (status);
2282                                 return quality;
2283                         }
2284                         set {
2285                                 Status status = GDIPlus.GdipSetCompositingQuality (nativeObject, value);
2286                                 GDIPlus.CheckStatus (status);
2287                         }
2288                 }
2289
2290                 public float DpiX {
2291                         get {
2292                                 float x;
2293
2294                                 Status status = GDIPlus.GdipGetDpiX (nativeObject, out x);
2295                                 GDIPlus.CheckStatus (status);
2296                                 return x;
2297                         }
2298                 }
2299
2300                 public float DpiY {
2301                         get {
2302                                 float y;
2303
2304                                 Status status = GDIPlus.GdipGetDpiY (nativeObject, out y);
2305                                 GDIPlus.CheckStatus (status);
2306                                 return y;
2307                         }
2308                 }
2309
2310                 public InterpolationMode InterpolationMode {
2311                         get {                           
2312                                 InterpolationMode imode = InterpolationMode.Invalid;
2313                                 Status status = GDIPlus.GdipGetInterpolationMode (nativeObject, out imode);
2314                                 GDIPlus.CheckStatus (status);
2315                                 return imode;
2316                         }
2317                         set {
2318                                 Status status = GDIPlus.GdipSetInterpolationMode (nativeObject, value);
2319                                 GDIPlus.CheckStatus (status);
2320                         }
2321                 }
2322
2323                 public bool IsClipEmpty {
2324                         get {
2325                                 bool isEmpty = false;
2326
2327                                 Status status = GDIPlus.GdipIsClipEmpty (nativeObject, out isEmpty);
2328                                 GDIPlus.CheckStatus (status);
2329                                 return isEmpty;
2330                         }
2331                 }
2332
2333                 public bool IsVisibleClipEmpty {
2334                         get {
2335                                 bool isEmpty = false;
2336
2337                                 Status status = GDIPlus.GdipIsVisibleClipEmpty (nativeObject, out isEmpty);
2338                                 GDIPlus.CheckStatus (status);
2339                                 return isEmpty;
2340                         }
2341                 }
2342
2343                 public float PageScale {
2344                         get {
2345                                 float scale;
2346
2347                                 Status status = GDIPlus.GdipGetPageScale (nativeObject, out scale);
2348                                 GDIPlus.CheckStatus (status);
2349                                 return scale;
2350                         }
2351                         set {
2352                                 Status status = GDIPlus.GdipSetPageScale (nativeObject, value);
2353                                 GDIPlus.CheckStatus (status);
2354                         }
2355                 }
2356
2357                 public GraphicsUnit PageUnit {
2358                         get {
2359                                 GraphicsUnit unit;
2360                                 
2361                                 Status status = GDIPlus.GdipGetPageUnit (nativeObject, out unit);
2362                                 GDIPlus.CheckStatus (status);
2363                                 return unit;
2364                         }
2365                         set {
2366                                 Status status = GDIPlus.GdipSetPageUnit (nativeObject, value);
2367                                 GDIPlus.CheckStatus (status);
2368                         }
2369                 }
2370
2371                 [MonoTODO ("This property does not do anything when used with libgdiplus.")]
2372                 public PixelOffsetMode PixelOffsetMode {
2373                         get {
2374                                 PixelOffsetMode pixelOffset = PixelOffsetMode.Invalid;
2375                                 
2376                                 Status status = GDIPlus.GdipGetPixelOffsetMode (nativeObject, out pixelOffset);
2377                                 GDIPlus.CheckStatus (status);
2378                                 return pixelOffset;
2379                         }
2380                         set {
2381                                 Status status = GDIPlus.GdipSetPixelOffsetMode (nativeObject, value); 
2382                                 GDIPlus.CheckStatus (status);
2383                         }
2384                 }
2385
2386                 public Point RenderingOrigin {
2387                         get {
2388                                 int x, y;
2389                                 Status status = GDIPlus.GdipGetRenderingOrigin (nativeObject, out x, out y);
2390                                 GDIPlus.CheckStatus (status);
2391                                 return new Point (x, y);
2392                         }
2393
2394                         set {
2395                                 Status status = GDIPlus.GdipSetRenderingOrigin (nativeObject, value.X, value.Y);
2396                                 GDIPlus.CheckStatus (status);
2397                         }
2398                 }
2399
2400                 public SmoothingMode SmoothingMode {
2401                         get {
2402                                 SmoothingMode mode = SmoothingMode.Invalid;
2403
2404                                 Status status = GDIPlus.GdipGetSmoothingMode (nativeObject, out mode);
2405                                 GDIPlus.CheckStatus (status);
2406                                 return mode;
2407                         }
2408
2409                         set {
2410                                 Status status = GDIPlus.GdipSetSmoothingMode (nativeObject, value);
2411                                 GDIPlus.CheckStatus (status);
2412                         }
2413                 }
2414
2415                 [MonoTODO ("This property does not do anything when used with libgdiplus.")]
2416                 public int TextContrast {
2417                         get {   
2418                                 int contrast;
2419                                         
2420                                 Status status = GDIPlus.GdipGetTextContrast (nativeObject, out contrast);
2421                                 GDIPlus.CheckStatus (status);
2422                                 return contrast;
2423                         }
2424
2425                         set {
2426                                 Status status = GDIPlus.GdipSetTextContrast (nativeObject, value);
2427                                 GDIPlus.CheckStatus (status);
2428                         }
2429                 }
2430
2431                 public TextRenderingHint TextRenderingHint {
2432                         get {
2433                                 TextRenderingHint hint;
2434
2435                                 Status status = GDIPlus.GdipGetTextRenderingHint (nativeObject, out hint);
2436                                 GDIPlus.CheckStatus (status);
2437                                 return hint;        
2438                         }
2439
2440                         set {
2441                                 Status status = GDIPlus.GdipSetTextRenderingHint (nativeObject, value);
2442                                 GDIPlus.CheckStatus (status);
2443                         }
2444                 }
2445
2446                 public Matrix Transform {
2447                         get {
2448                                 Matrix matrix = new Matrix ();
2449                                 Status status = GDIPlus.GdipGetWorldTransform (nativeObject, matrix.nativeMatrix);
2450                                 GDIPlus.CheckStatus (status);
2451                                 return matrix;
2452                         }
2453                         set {
2454                                 if (value == null)
2455                                         throw new ArgumentNullException ("value");
2456                                 
2457                                 Status status = GDIPlus.GdipSetWorldTransform (nativeObject, value.nativeMatrix);
2458                                 GDIPlus.CheckStatus (status);
2459                         }
2460                 }
2461
2462                 public RectangleF VisibleClipBounds {
2463                         get {
2464                                 RectangleF rect;
2465                                         
2466                                 Status status = GDIPlus.GdipGetVisibleClipBounds (nativeObject, out rect);
2467                                 GDIPlus.CheckStatus (status);
2468                                 return rect;
2469                         }
2470                 }
2471
2472 #if NET_2_0
2473                 [MonoTODO]
2474                 [EditorBrowsable (EditorBrowsableState.Never)]
2475                 public object GetContextInfo ()
2476                 {
2477                         // only known source of information @ http://blogs.wdevs.com/jdunlap/Default.aspx
2478                         throw new NotImplementedException ();
2479                 }
2480 #endif
2481         }
2482 }