Merge pull request #4453 from lambdageek/bug-49721
[mono.git] / mcs / class / System.Drawing / System.Drawing / gdipFunctions.cs
1 //
2 // System.Drawing.gdipFunctions.cs
3 //
4 // Authors: 
5 //      Alexandre Pigolkine (pigolkine@gmx.de)
6 //      Jordi Mas i Hernandez (jordi@ximian.com)
7 //      Sanjay Gupta (gsanjay@novell.com)
8 //      Ravindra (rkumar@novell.com)
9 //      Peter Dennis Bartok (pbartok@novell.com)
10 //      Sebastien Pouliot <sebastien@ximian.com>
11 //
12 // Copyright (C) 2004 - 2007 Novell, Inc (http://www.novell.com)
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33
34 using System.IO;
35 using System.Runtime.InteropServices;
36 using System.Text;
37 using System.Drawing.Drawing2D;
38 using System.Drawing.Imaging;
39 using System.Drawing.Text;
40 using System.Globalization;
41 using System.Security;
42 using System.Runtime.InteropServices.ComTypes;
43
44 namespace System.Drawing
45 {
46         /// <summary>
47         /// GDI+ API Functions
48         /// </summary>
49         [SuppressUnmanagedCodeSecurity]
50         internal static class GDIPlus {
51                 public const int FACESIZE = 32;
52                 public const int LANG_NEUTRAL = 0;
53                 public static IntPtr Display = IntPtr.Zero;
54                 public static bool UseX11Drawable = false;
55                 public static bool UseCarbonDrawable = false;
56                 public static bool UseCocoaDrawable = false;
57
58                 private const string GdiPlus = "gdiplus";
59
60                 #region gdiplus.dll functions
61
62                 // startup / shutdown
63                 [DllImport(GdiPlus)]
64                 static internal extern Status GdiplusStartup(ref ulong token, ref GdiplusStartupInput input, ref GdiplusStartupOutput output);
65                 [DllImport(GdiPlus)]
66                 static internal extern void GdiplusShutdown(ref ulong token);
67
68                 internal static ulong GdiPlusToken = 0;
69
70                 static void ProcessExit (object sender, EventArgs e)
71                 {
72                         // Called all pending objects and claim any pending handle before
73                         // shutting down
74                         GC.Collect ();
75                         GC.WaitForPendingFinalizers ();
76 #if false
77                         GdiPlusToken = 0;
78
79                         // This causes crashes in because this call occurs before all
80                         // managed GDI+ objects are finalized. When they are finalized
81                         // they call into a shutdown GDI+ and we crash.
82                         GdiplusShutdown (ref GdiPlusToken);
83
84                         // This causes crashes in Mono libgdiplus because this call
85                         // occurs before all managed GDI objects are finalized
86                         // When they are finalized they use the closed display and
87                         // crash
88                         if (UseX11Drawable && Display != IntPtr.Zero) {
89                                 XCloseDisplay (Display);
90                         }
91 #endif
92                 }
93
94                 static GDIPlus ()
95                 {
96                         int platform = (int) Environment.OSVersion.Platform;
97                         if ((platform == 4) || (platform == 6) || (platform == 128)) {
98                                 if (Environment.GetEnvironmentVariable ("not_supported_MONO_MWF_USE_NEW_X11_BACKEND") != null || Environment.GetEnvironmentVariable ("MONO_MWF_MAC_FORCE_X11") != null) {
99                                         UseX11Drawable = true;
100                                 } else {
101                                         IntPtr buf = Marshal.AllocHGlobal (8192);
102                                         // This is kind of a hack but gets us sysname from uname (struct utsname *name) on
103                                         // linux and darwin
104                                         if (uname (buf) != 0) {
105                                                 // WTH: We couldn't detect the OS; lets default to X11
106                                                 UseX11Drawable = true;
107                                         } else {
108                                                 string os = Marshal.PtrToStringAnsi (buf);
109                                                 if (os == "Darwin")
110                                                         UseCarbonDrawable = true;
111                                                 else
112                                                         UseX11Drawable = true;
113                                         }
114                                         Marshal.FreeHGlobal (buf);
115                                 }
116                         }
117
118                         GdiplusStartupInput input = GdiplusStartupInput.MakeGdiplusStartupInput();
119                         GdiplusStartupOutput output = GdiplusStartupOutput.MakeGdiplusStartupOutput();
120                         try {
121                                 GdiplusStartup (ref GdiPlusToken, ref input, ref output);
122                         }
123                         catch (TypeInitializationException) {
124                                 Console.Error.WriteLine (
125                                         "* ERROR: Can not initialize GDI+ library{0}{0}" +
126                                         "Please check http://www.mono-project.com/Problem:GDIPlusInit for details",
127                                         Environment.NewLine);
128                         }
129
130                         // under MS 1.x this event is raised only for the default application domain
131                         AppDomain.CurrentDomain.ProcessExit += new EventHandler (ProcessExit);
132                 }
133
134                 static public bool RunningOnWindows ()
135                 {
136                         return !UseX11Drawable && !UseCarbonDrawable && !UseCocoaDrawable;
137                 }
138
139                 static public bool RunningOnUnix ()
140                 {
141                         return UseX11Drawable || UseCarbonDrawable || UseCocoaDrawable;
142                 }
143
144                 // Copies a Ptr to an array of Points and releases the memory
145                 static public void FromUnManagedMemoryToPointI (IntPtr prt, Point [] pts)
146                 {
147                         int nPointSize = Marshal.SizeOf (pts[0]);
148                         IntPtr pos = prt;
149                         for (int i=0; i<pts.Length; i++, pos = new IntPtr (pos.ToInt64 () + nPointSize))
150                                 pts[i] = (Point) Marshal.PtrToStructure (pos, typeof (Point));
151
152                         Marshal.FreeHGlobal (prt);
153                 }
154
155                 // Copies a Ptr to an array of Points and releases the memory
156                 static public void FromUnManagedMemoryToPoint (IntPtr prt, PointF [] pts)
157                 {
158                         int nPointSize = Marshal.SizeOf (pts[0]);
159                         IntPtr pos = prt;
160                         for (int i=0; i<pts.Length; i++, pos = new IntPtr (pos.ToInt64 () + nPointSize))
161                                 pts[i] = (PointF) Marshal.PtrToStructure (pos, typeof (PointF));
162
163                         Marshal.FreeHGlobal (prt);
164                 }
165
166                 // Copies an array of Points to unmanaged memory
167                 static public IntPtr FromPointToUnManagedMemoryI (Point [] pts)
168                 {
169                         int nPointSize = Marshal.SizeOf (pts[0]);
170                         IntPtr dest = Marshal.AllocHGlobal (nPointSize * pts.Length);
171                         IntPtr pos = dest;
172                         for (int i=0; i<pts.Length; i++, pos = new IntPtr (pos.ToInt64 () + nPointSize))
173                                 Marshal.StructureToPtr (pts[i], pos, false);
174
175                         return dest;
176                 }
177
178                 // Copies a Ptr to an array of v and releases the memory
179                 static public void FromUnManagedMemoryToRectangles (IntPtr prt, RectangleF [] pts)
180                 {
181                         int nPointSize = Marshal.SizeOf (pts[0]);
182                         IntPtr pos = prt;
183                         for (int i = 0; i < pts.Length; i++, pos = new IntPtr (pos.ToInt64 () + nPointSize))
184                                 pts[i] = (RectangleF) Marshal.PtrToStructure (pos, typeof (RectangleF));
185
186                         Marshal.FreeHGlobal (prt);
187                 }
188
189                 // Copies an array of Points to unmanaged memory
190                 static public IntPtr FromPointToUnManagedMemory (PointF [] pts)
191                 {
192                         int nPointSize = Marshal.SizeOf (pts[0]);
193                         IntPtr dest = Marshal.AllocHGlobal (nPointSize * pts.Length);
194                         IntPtr pos = dest;
195                         for (int i=0; i<pts.Length; i++, pos = new IntPtr (pos.ToInt64 () + nPointSize))
196                                 Marshal.StructureToPtr (pts[i], pos, false);
197
198                         return dest;
199                 }
200
201                 // Converts a status into exception
202                 // TODO: Add more status code mappings here
203                 static internal void CheckStatus (Status status)
204                 {
205                         string msg;
206                         switch (status) {
207                         case Status.Ok:
208                                 return;
209                         case Status.GenericError:
210                                 msg = Locale.GetText ("Generic Error [GDI+ status: {0}]", status);
211                                 throw new Exception (msg);
212                         case Status.InvalidParameter:
213                                 msg = Locale.GetText ("A null reference or invalid value was found [GDI+ status: {0}]", status);
214                                 throw new ArgumentException (msg);
215                         case Status.OutOfMemory:
216                                 msg = Locale.GetText ("Not enough memory to complete operation [GDI+ status: {0}]", status);
217                                 throw new OutOfMemoryException (msg);
218                         case Status.ObjectBusy:
219                                 msg = Locale.GetText ("Object is busy and cannot state allow this operation [GDI+ status: {0}]", status);
220                                 throw new MemberAccessException (msg);
221                         case Status.InsufficientBuffer:
222                                 msg = Locale.GetText ("Insufficient buffer provided to complete operation [GDI+ status: {0}]", status);
223                                 throw new InternalBufferOverflowException (msg);
224                         case Status.PropertyNotSupported:
225                                 msg = Locale.GetText ("Property not supported [GDI+ status: {0}]", status);
226                                 throw new NotSupportedException (msg);
227                         case Status.FileNotFound:
228                                 msg = Locale.GetText ("Requested file was not found [GDI+ status: {0}]", status);
229                                 throw new FileNotFoundException (msg);
230                         case Status.AccessDenied:
231                                 msg = Locale.GetText ("Access to resource was denied [GDI+ status: {0}]", status);
232                                 throw new UnauthorizedAccessException (msg);
233                         case Status.UnknownImageFormat:
234                                 msg = Locale.GetText ("Either the image format is unknown or you don't have the required libraries to decode this format [GDI+ status: {0}]", status);
235                                 throw new NotSupportedException (msg);
236                         case Status.NotImplemented:
237                                 msg = Locale.GetText ("The requested feature is not implemented [GDI+ status: {0}]", status);
238                                 throw new NotImplementedException (msg);
239                         case Status.WrongState:
240                                 msg = Locale.GetText ("Object is not in a state that can allow this operation [GDI+ status: {0}]", status);
241                                 throw new ArgumentException (msg);
242                         case Status.FontFamilyNotFound:
243                                 msg = Locale.GetText ("The requested FontFamily could not be found [GDI+ status: {0}]", status);
244                                 throw new ArgumentException (msg);
245                         case Status.ValueOverflow:
246                                 msg = Locale.GetText ("Argument is out of range [GDI+ status: {0}]", status);
247                                 throw new OverflowException (msg);
248                         case Status.Win32Error:
249                                 msg = Locale.GetText ("The operation is invalid [GDI+ status: {0}]", status);
250                                 throw new InvalidOperationException (msg);
251                         default:
252                                 msg = Locale.GetText ("Unknown Error [GDI+ status: {0}]", status);
253                                 throw new Exception (msg);
254                         }
255                 }
256
257                 // Memory functions
258                 [DllImport(GdiPlus)]
259                 static internal extern IntPtr GdipAlloc (int size);
260                 [DllImport(GdiPlus)]
261                 static internal extern void GdipFree (IntPtr ptr);
262
263
264                 // Brush functions
265                 [DllImport(GdiPlus)]
266                 static internal extern Status GdipCloneBrush (IntPtr brush, out IntPtr clonedBrush);
267                 [DllImport(GdiPlus)]
268                 static internal extern Status GdipDeleteBrush (IntPtr brush);
269                 [DllImport(GdiPlus)]
270                 static internal extern Status GdipGetBrushType (IntPtr brush, out BrushType type);
271
272
273                 // Region functions
274                 [DllImport(GdiPlus)]
275                 static internal extern Status GdipCreateRegion (out IntPtr region);
276
277                 [DllImport(GdiPlus)]
278                 static internal extern Status GdipCreateRegionRgnData (byte[] data, int size, out IntPtr region);
279
280                 [DllImport(GdiPlus)]
281                 static internal extern Status GdipDeleteRegion (IntPtr region);
282
283                 [DllImport(GdiPlus)]
284                 static internal extern Status GdipCloneRegion (IntPtr region, out IntPtr cloned);
285
286                 [DllImport(GdiPlus)]
287                 static internal extern Status GdipCreateRegionRect (ref RectangleF rect, out IntPtr region);
288
289                 [DllImport(GdiPlus)]
290                 static internal extern Status GdipCreateRegionRectI (ref Rectangle rect, out IntPtr region);
291
292                 [DllImport(GdiPlus)]
293                 static internal extern Status GdipCreateRegionPath (IntPtr path, out IntPtr region);
294
295                 [DllImport(GdiPlus)]
296                 static internal extern Status GdipTranslateRegion (IntPtr region, float dx, float dy);
297
298                 [DllImport(GdiPlus)]
299                 static internal extern Status GdipTranslateRegionI (IntPtr region, int dx, int dy);
300
301                 [DllImport(GdiPlus)]
302                 static internal extern Status GdipIsVisibleRegionPoint (IntPtr region, float x, float y,
303                         IntPtr graphics, out bool result);
304
305                 [DllImport(GdiPlus)]
306                 static internal extern Status GdipIsVisibleRegionPointI (IntPtr region, int x, int y,
307                         IntPtr graphics, out bool result);
308
309                 [DllImport(GdiPlus)]
310                 static internal extern Status GdipIsVisibleRegionRect (IntPtr region, float x, float y, float width,
311                         float height, IntPtr graphics, out bool result);
312
313                 [DllImport(GdiPlus)]
314                 static internal extern Status GdipIsVisibleRegionRectI (IntPtr region, int x, int y, int width,
315                         int height, IntPtr graphics, out bool result);
316
317
318                 [DllImport(GdiPlus)]
319                 static internal extern Status GdipCombineRegionRect (IntPtr region, ref RectangleF rect,
320                         CombineMode combineMode);
321
322                 [DllImport(GdiPlus)]
323                 static internal extern Status GdipCombineRegionRectI (IntPtr region, ref Rectangle rect,
324                         CombineMode combineMode);
325
326                 [DllImport(GdiPlus)]
327                 static internal extern Status GdipCombineRegionPath (IntPtr region, IntPtr path, CombineMode combineMode);
328
329                 [DllImport(GdiPlus)]
330                 static internal extern Status GdipGetRegionBounds (IntPtr region, IntPtr graphics, ref RectangleF rect);
331
332                 [DllImport(GdiPlus)]
333                 static internal extern Status GdipSetInfinite (IntPtr region);
334
335                 [DllImport(GdiPlus)]
336                 static internal extern Status GdipSetEmpty (IntPtr region);
337
338                 [DllImport(GdiPlus)]
339                 static internal extern Status GdipIsEmptyRegion (IntPtr region, IntPtr graphics, out bool result);
340
341                 [DllImport(GdiPlus)]
342                 static internal extern Status GdipIsInfiniteRegion (IntPtr region, IntPtr graphics, out bool result);
343
344                 [DllImport(GdiPlus)]
345                 static internal extern Status GdipCombineRegionRegion (IntPtr region, IntPtr region2,
346                         CombineMode combineMode);
347
348                 [DllImport(GdiPlus)]
349                 static internal extern Status GdipIsEqualRegion (IntPtr region, IntPtr region2,
350                         IntPtr graphics, out bool result);
351
352                 [DllImport(GdiPlus)]
353                 static internal extern Status GdipGetRegionDataSize (IntPtr region, out int bufferSize);
354
355                 [DllImport(GdiPlus)]
356                 static internal extern Status GdipGetRegionData (IntPtr region, byte[] buffer, int bufferSize,
357                  out int sizeFilled);
358
359                 [DllImport(GdiPlus)]
360                 static internal extern Status GdipGetRegionScansCount (IntPtr region, out int count, IntPtr matrix);
361
362                 [DllImport(GdiPlus)]
363                 static internal extern Status GdipGetRegionScans (IntPtr region, IntPtr rects, out int count,
364                         IntPtr matrix);
365
366                 [DllImport(GdiPlus)]
367                 static internal extern Status GdipTransformRegion(IntPtr region, IntPtr matrix);
368
369                 [DllImport(GdiPlus)]
370                 static internal extern Status GdipFillRegion(IntPtr graphics, IntPtr brush, IntPtr region);
371
372                 [DllImport(GdiPlus)]
373                 static internal extern Status GdipGetRegionHRgn (IntPtr region, IntPtr graphics, ref IntPtr hRgn);
374
375                 [DllImport(GdiPlus)]
376                 static internal extern Status GdipCreateRegionHrgn (IntPtr hRgn, out IntPtr region);
377
378                 // Solid brush functions
379                 [DllImport(GdiPlus)]
380                 static internal extern Status GdipCreateSolidFill (int color, out IntPtr brush);
381                 [DllImport(GdiPlus)]
382                 static internal extern Status GdipGetSolidFillColor (IntPtr brush, out int color);
383                 [DllImport(GdiPlus)]
384                 static internal extern Status GdipSetSolidFillColor (IntPtr brush, int color);
385
386                 // Hatch Brush functions
387                 [DllImport(GdiPlus)]
388                 static internal extern Status GdipCreateHatchBrush (HatchStyle hatchstyle, int foreColor, int backColor, out IntPtr brush);
389                 [DllImport(GdiPlus)]
390                 static internal extern Status GdipGetHatchStyle (IntPtr brush, out HatchStyle hatchstyle);
391                 [DllImport(GdiPlus)]
392                 static internal extern Status GdipGetHatchForegroundColor (IntPtr brush, out int foreColor);
393                 [DllImport(GdiPlus)]
394                 static internal extern Status GdipGetHatchBackgroundColor (IntPtr brush, out int backColor);
395
396                 // Texture brush functions
397                 [DllImport(GdiPlus)]
398                 static internal extern Status GdipGetTextureImage (IntPtr texture, out IntPtr image);
399                 [DllImport(GdiPlus)]
400                 static internal extern Status GdipCreateTexture (IntPtr image, WrapMode wrapMode, out IntPtr texture);
401                 [DllImport(GdiPlus)]
402                 static internal extern Status GdipCreateTextureIAI (IntPtr image, IntPtr imageAttributes, int x, int y, int width, int height, out IntPtr texture);
403                 [DllImport(GdiPlus)]
404                 static internal extern Status GdipCreateTextureIA (IntPtr image, IntPtr imageAttributes, float x, float y, float width, float height, out IntPtr texture);
405                 [DllImport(GdiPlus)]
406                 static internal extern Status GdipCreateTexture2I (IntPtr image, WrapMode wrapMode, int x, int y, int width, int height, out IntPtr texture);
407                 [DllImport(GdiPlus)]
408                 static internal extern Status GdipCreateTexture2 (IntPtr image, WrapMode wrapMode, float x, float y, float width, float height, out IntPtr texture);
409                 [DllImport(GdiPlus)]
410                 static internal extern Status GdipGetTextureTransform (IntPtr texture, IntPtr matrix);
411                 [DllImport(GdiPlus)]
412                 static internal extern Status GdipSetTextureTransform (IntPtr texture, IntPtr matrix);
413                 [DllImport(GdiPlus)]
414                 static internal extern Status GdipGetTextureWrapMode (IntPtr texture, out WrapMode wrapMode);
415                 [DllImport(GdiPlus)]
416                 static internal extern Status GdipSetTextureWrapMode (IntPtr texture, WrapMode wrapMode);
417                 [DllImport(GdiPlus)]
418                 static internal extern Status GdipMultiplyTextureTransform (IntPtr texture, IntPtr matrix, MatrixOrder order);
419                 [DllImport(GdiPlus)]
420                 static internal extern Status GdipResetTextureTransform (IntPtr texture);
421                 [DllImport(GdiPlus)]
422                 static internal extern Status GdipRotateTextureTransform (IntPtr texture, float angle, MatrixOrder order);
423                 [DllImport(GdiPlus)]
424                 static internal extern Status GdipScaleTextureTransform (IntPtr texture, float sx, float sy, MatrixOrder order);
425                 [DllImport(GdiPlus)]
426                 static internal extern Status GdipTranslateTextureTransform (IntPtr texture, float dx, float dy, MatrixOrder order);
427
428                 // PathGradientBrush functions
429                 [DllImport(GdiPlus)]
430                 static internal extern Status GdipCreatePathGradientFromPath (IntPtr path, out IntPtr brush);
431                 [DllImport(GdiPlus)]
432                 static internal extern Status GdipCreatePathGradientI (Point [] points, int count, WrapMode wrapMode, out IntPtr brush);
433                 [DllImport(GdiPlus)]
434                 static internal extern Status GdipCreatePathGradient (PointF [] points, int count, WrapMode wrapMode, out IntPtr brush);
435                 [DllImport(GdiPlus)]
436                 static internal extern Status GdipGetPathGradientBlendCount (IntPtr brush, out int count);
437                 [DllImport(GdiPlus)]
438                 static internal extern Status GdipGetPathGradientBlend (IntPtr brush, float [] blend, float [] positions, int count);
439                 [DllImport(GdiPlus)]
440                 static internal extern Status GdipSetPathGradientBlend (IntPtr brush, float [] blend, float [] positions, int count);
441                 [DllImport(GdiPlus)]
442                 static internal extern Status GdipGetPathGradientCenterColor (IntPtr brush, out int color);
443                 [DllImport(GdiPlus)]
444                 static internal extern Status GdipSetPathGradientCenterColor (IntPtr brush, int color);
445                 [DllImport(GdiPlus)]
446                 static internal extern Status GdipGetPathGradientCenterPoint (IntPtr brush, out PointF point);
447                 [DllImport(GdiPlus)]
448                 static internal extern Status GdipSetPathGradientCenterPoint (IntPtr brush, ref PointF point);
449                 [DllImport(GdiPlus)]
450                 static internal extern Status GdipGetPathGradientFocusScales (IntPtr brush, out float xScale, out float yScale);
451                 [DllImport(GdiPlus)]
452                 static internal extern Status GdipSetPathGradientFocusScales (IntPtr brush, float xScale, float yScale);
453                 [DllImport(GdiPlus)]
454                 static internal extern Status GdipGetPathGradientPresetBlendCount (IntPtr brush, out int count);
455                 [DllImport(GdiPlus)]
456                 static internal extern Status GdipGetPathGradientPresetBlend (IntPtr brush, int [] blend, float [] positions, int count);
457                 [DllImport(GdiPlus)]
458                 static internal extern Status GdipSetPathGradientPresetBlend (IntPtr brush, int [] blend, float [] positions, int count);
459                 [DllImport(GdiPlus)]
460                 static internal extern Status GdipGetPathGradientRect (IntPtr brush, out RectangleF rect);
461                 [DllImport(GdiPlus)]
462                 static internal extern Status GdipGetPathGradientSurroundColorCount (IntPtr brush, out int count);
463                 [DllImport(GdiPlus)]
464                 static internal extern Status GdipGetPathGradientSurroundColorsWithCount (IntPtr brush, int [] color, ref int count);
465                 [DllImport(GdiPlus)]
466                 static internal extern Status GdipSetPathGradientSurroundColorsWithCount (IntPtr brush, int [] color, ref int count);
467                 [DllImport(GdiPlus)]
468                 static internal extern Status GdipGetPathGradientTransform (IntPtr brush, IntPtr matrix);
469                 [DllImport(GdiPlus)]
470                 static internal extern Status GdipSetPathGradientTransform (IntPtr brush, IntPtr matrix);
471                 [DllImport(GdiPlus)]
472                 static internal extern Status GdipGetPathGradientWrapMode (IntPtr brush, out WrapMode wrapMode);
473                 [DllImport(GdiPlus)]
474                 static internal extern Status GdipSetPathGradientWrapMode (IntPtr brush, WrapMode wrapMode);
475                 [DllImport(GdiPlus)]
476                 static internal extern Status GdipSetPathGradientLinearBlend (IntPtr brush, float focus, float scale);
477                 [DllImport(GdiPlus)]
478                 static internal extern Status GdipSetPathGradientSigmaBlend (IntPtr brush, float focus, float scale);
479                 [DllImport(GdiPlus)]
480                 static internal extern Status GdipMultiplyPathGradientTransform (IntPtr texture, IntPtr matrix, MatrixOrder order);
481                 [DllImport(GdiPlus)]
482                 static internal extern Status GdipResetPathGradientTransform (IntPtr brush);
483                 [DllImport(GdiPlus)]
484                 static internal extern Status GdipRotatePathGradientTransform (IntPtr brush, float angle, MatrixOrder order);
485                 [DllImport(GdiPlus)]
486                 static internal extern Status GdipScalePathGradientTransform (IntPtr brush, float sx, float sy, MatrixOrder order);
487                 [DllImport(GdiPlus)]
488                 static internal extern Status GdipTranslatePathGradientTransform (IntPtr brush, float dx, float dy, MatrixOrder order);
489
490                 // LinearGradientBrush functions
491                 [DllImport(GdiPlus)]
492                 static internal extern Status GdipCreateLineBrushI (ref Point point1, ref Point point2, int color1, int color2, WrapMode wrapMode, out IntPtr brush);
493                 [DllImport(GdiPlus)]
494                 static internal extern Status GdipCreateLineBrush (ref PointF point1, ref PointF point2, int color1, int color2, WrapMode wrapMode, out IntPtr brush);
495                 [DllImport(GdiPlus)]
496                 static internal extern Status GdipCreateLineBrushFromRectI (ref Rectangle rect, int color1, int color2, LinearGradientMode linearGradientMode, WrapMode wrapMode, out IntPtr brush);
497                 [DllImport(GdiPlus)]
498                 static internal extern Status GdipCreateLineBrushFromRect (ref RectangleF rect, int color1, int color2, LinearGradientMode linearGradientMode, WrapMode wrapMode, out IntPtr brush);
499                 [DllImport(GdiPlus)]
500                 static internal extern Status GdipCreateLineBrushFromRectWithAngleI (ref Rectangle rect, int color1, int color2, float angle, bool isAngleScaleable, WrapMode wrapMode, out IntPtr brush);
501                 [DllImport(GdiPlus)]
502                 static internal extern Status GdipCreateLineBrushFromRectWithAngle (ref RectangleF rect, int color1, int color2, float angle, bool isAngleScaleable, WrapMode wrapMode, out IntPtr brush);
503                 [DllImport(GdiPlus)]
504                 static internal extern Status GdipGetLineBlendCount (IntPtr brush, out int count);
505                 [DllImport(GdiPlus)]
506                 static internal extern Status GdipSetLineBlend (IntPtr brush, float [] blend, float [] positions, int count);
507                 [DllImport(GdiPlus)]
508                 static internal extern Status GdipGetLineBlend (IntPtr brush, float [] blend, float [] positions, int count);
509                 [DllImport(GdiPlus)]
510                 static internal extern Status GdipSetLineGammaCorrection (IntPtr brush, bool useGammaCorrection);
511                 [DllImport(GdiPlus)]
512                 static internal extern Status GdipGetLineGammaCorrection (IntPtr brush, out bool useGammaCorrection);
513                 [DllImport(GdiPlus)]
514                 static internal extern Status GdipGetLinePresetBlendCount (IntPtr brush, out int count);
515                 [DllImport(GdiPlus)]
516                 static internal extern Status GdipSetLinePresetBlend (IntPtr brush, int [] blend, float [] positions, int count);
517                 [DllImport(GdiPlus)]
518                 static internal extern Status GdipGetLinePresetBlend (IntPtr brush, int [] blend, float [] positions, int count);
519                 [DllImport(GdiPlus)]
520                 static internal extern Status GdipSetLineColors (IntPtr brush, int color1, int color2);
521                 [DllImport(GdiPlus)]
522                 static internal extern Status GdipGetLineColors (IntPtr brush, int [] colors);
523                 [DllImport(GdiPlus)]
524                 static internal extern Status GdipGetLineRectI (IntPtr brush, out Rectangle rect);
525                 [DllImport(GdiPlus)]
526                 static internal extern Status GdipGetLineRect (IntPtr brush, out RectangleF rect);
527                 [DllImport(GdiPlus)]
528                 static internal extern Status GdipSetLineTransform (IntPtr brush, IntPtr matrix);
529                 [DllImport(GdiPlus)]
530                 static internal extern Status GdipGetLineTransform (IntPtr brush, IntPtr matrix);
531                 [DllImport(GdiPlus)]
532                 static internal extern Status GdipSetLineWrapMode (IntPtr brush, WrapMode wrapMode);
533                 [DllImport(GdiPlus)]
534                 static internal extern Status GdipGetLineWrapMode (IntPtr brush, out WrapMode wrapMode);
535                 [DllImport(GdiPlus)]
536                 static internal extern Status GdipSetLineLinearBlend (IntPtr brush, float focus, float scale);
537                 [DllImport(GdiPlus)]
538                 static internal extern Status GdipSetLineSigmaBlend (IntPtr brush, float focus, float scale);
539                 [DllImport(GdiPlus)]
540                 static internal extern Status GdipMultiplyLineTransform (IntPtr brush, IntPtr matrix, MatrixOrder order);
541                 [DllImport(GdiPlus)]
542                 static internal extern Status GdipResetLineTransform (IntPtr brush);
543                 [DllImport(GdiPlus)]
544                 static internal extern Status GdipRotateLineTransform (IntPtr brush, float angle, MatrixOrder order);
545                 [DllImport(GdiPlus)]
546                 static internal extern Status GdipScaleLineTransform (IntPtr brush, float sx, float sy, MatrixOrder order);
547                 [DllImport(GdiPlus)]
548                 static internal extern Status GdipTranslateLineTransform (IntPtr brush, float dx, float dy, MatrixOrder order);
549
550                 // Graphics functions
551                 [DllImport(GdiPlus)]
552                 static internal extern Status GdipCreateFromHDC(IntPtr hDC, out IntPtr graphics);
553                 [DllImport(GdiPlus)]
554                 static internal extern Status GdipDeleteGraphics(IntPtr graphics);
555                 [DllImport(GdiPlus)]
556                 static internal extern Status GdipRestoreGraphics(IntPtr graphics, uint graphicsState);
557                 [DllImport(GdiPlus)]
558                 static internal extern Status GdipSaveGraphics(IntPtr graphics, out uint state);
559                 [DllImport(GdiPlus)]
560                 static internal extern Status GdipMultiplyWorldTransform (IntPtr graphics, IntPtr matrix, MatrixOrder order);
561
562                 [DllImport(GdiPlus)]
563                 static internal extern Status GdipRotateWorldTransform(IntPtr graphics, float angle, MatrixOrder order);
564                 [DllImport(GdiPlus)]
565                 static internal extern Status GdipTranslateWorldTransform(IntPtr graphics, float dx, float dy, MatrixOrder order);
566                 [DllImport(GdiPlus)]
567                 static internal extern Status GdipDrawArc (IntPtr graphics, IntPtr pen, float x, float y, float width, float height, float startAngle, float sweepAngle);
568                 [DllImport(GdiPlus)]
569                 static internal extern Status GdipDrawArcI (IntPtr graphics, IntPtr pen, int x, int y, int width, int height, float startAngle, float sweepAngle);
570                 [DllImport(GdiPlus)]
571                 static internal extern Status GdipDrawBezier (IntPtr graphics, IntPtr pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
572                 [DllImport(GdiPlus)]
573                 static internal extern Status GdipDrawBezierI (IntPtr graphics, IntPtr pen, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
574                 [DllImport(GdiPlus)]
575                 static internal extern Status GdipDrawEllipseI (IntPtr graphics, IntPtr pen, int x, int y, int width, int height);
576                 [DllImport(GdiPlus)]
577                 static internal extern Status GdipDrawEllipse (IntPtr graphics, IntPtr pen, float x, float y, float width, float height);
578                 [DllImport(GdiPlus)]
579                 static internal extern Status GdipDrawLine (IntPtr graphics, IntPtr pen, float x1, float y1, float x2, float y2);
580                 [DllImport(GdiPlus)]
581                 static internal extern Status GdipDrawLineI (IntPtr graphics, IntPtr pen, int x1, int y1, int x2, int y2);
582                 [DllImport (GdiPlus)]
583                 static internal extern Status GdipDrawLines (IntPtr graphics, IntPtr pen, PointF [] points, int count);
584                 [DllImport (GdiPlus)]
585                 static internal extern Status GdipDrawLinesI (IntPtr graphics, IntPtr pen, Point [] points, int count);
586                 [DllImport (GdiPlus)]
587                 static internal extern Status GdipDrawPath (IntPtr graphics, IntPtr pen, IntPtr path);
588                 [DllImport (GdiPlus)]
589                 static internal extern Status GdipDrawPie (IntPtr graphics, IntPtr pen, float x, float y, float width, float height, float startAngle, float sweepAngle);
590                 [DllImport (GdiPlus)]
591                 static internal extern Status GdipDrawPieI (IntPtr graphics, IntPtr pen, int x, int y, int width, int height, float startAngle, float sweepAngle);
592                 [DllImport (GdiPlus)]
593                 static internal extern Status GdipDrawPolygon (IntPtr graphics, IntPtr pen, PointF [] points, int count);
594                 [DllImport (GdiPlus)]
595                 static internal extern Status GdipDrawPolygonI (IntPtr graphics, IntPtr pen, Point [] points, int count);
596                 [DllImport (GdiPlus)]
597                 static internal extern Status GdipDrawRectangle (IntPtr graphics, IntPtr pen, float x, float y, float width, float height);
598                 [DllImport (GdiPlus)]
599                 static internal extern Status GdipDrawRectangleI (IntPtr graphics, IntPtr pen, int x, int y, int width, int height);
600                 [DllImport (GdiPlus)]
601                 static internal extern Status GdipDrawRectangles (IntPtr graphics, IntPtr pen, RectangleF [] rects, int count);
602                 [DllImport (GdiPlus)]
603                 static internal extern Status GdipDrawRectanglesI (IntPtr graphics, IntPtr pen, Rectangle [] rects, int count);
604                 [DllImport(GdiPlus)]
605                 static internal extern Status GdipFillEllipseI (IntPtr graphics, IntPtr pen, int x, int y, int width, int height);
606                 [DllImport(GdiPlus)]
607                 static internal extern Status GdipFillEllipse (IntPtr graphics, IntPtr pen, float x, float y, float width, float height);
608                 [DllImport (GdiPlus)]
609                 static internal extern Status GdipFillPolygon (IntPtr graphics, IntPtr brush, PointF [] points, int count, FillMode fillMode);
610                 [DllImport (GdiPlus)]
611                 static internal extern Status GdipFillPolygonI (IntPtr graphics, IntPtr brush, Point [] points, int count, FillMode fillMode);
612                 [DllImport (GdiPlus)]
613                 static internal extern Status GdipFillPolygon2 (IntPtr graphics, IntPtr brush, PointF [] points, int count);
614                 [DllImport (GdiPlus)]
615                 static internal extern Status GdipFillPolygon2I (IntPtr graphics, IntPtr brush, Point [] points, int count);
616                 [DllImport(GdiPlus)]
617                 static internal extern Status GdipFillRectangle (IntPtr graphics, IntPtr brush, float x1, float y1, float x2, float y2);
618                 [DllImport(GdiPlus)]
619                 static internal extern Status GdipFillRectangleI (IntPtr graphics, IntPtr brush, int x1, int y1, int x2, int y2);
620                 [DllImport(GdiPlus)]
621                 static internal extern Status GdipFillRectangles (IntPtr graphics, IntPtr brush, RectangleF [] rects, int count);
622                 [DllImport(GdiPlus)]
623                 static internal extern Status GdipFillRectanglesI (IntPtr graphics, IntPtr brush, Rectangle [] rects, int count);
624                 [DllImport(GdiPlus, CharSet=CharSet.Unicode)]
625                 static internal extern Status GdipDrawString (IntPtr graphics, string text, int len, IntPtr font, ref RectangleF rc, IntPtr format, IntPtr brush);
626                 [DllImport(GdiPlus)]
627                 static internal extern Status GdipGetDC (IntPtr graphics, out IntPtr hdc);
628                 [DllImport(GdiPlus)]
629                 static internal extern Status GdipReleaseDC (IntPtr graphics, IntPtr hdc);
630                 [DllImport(GdiPlus)]
631                 static internal extern Status GdipDrawImageRectI (IntPtr graphics, IntPtr image, int x, int y, int width, int height);
632                 [DllImport (GdiPlus)]
633                 static internal extern Status GdipGetRenderingOrigin (IntPtr graphics, out int x, out int y);
634                 [DllImport (GdiPlus)]
635                 static internal extern Status GdipSetRenderingOrigin (IntPtr graphics, int x, int y);
636                 [DllImport(GdiPlus)]
637                 internal static extern Status GdipCloneBitmapArea (float x, float y, float width, float height, PixelFormat format, IntPtr original, out IntPtr bitmap);
638                 [DllImport(GdiPlus)]
639                 internal static extern Status GdipCloneBitmapAreaI (int x, int y, int width, int height, PixelFormat format, IntPtr original, out IntPtr bitmap);
640                 [DllImport(GdiPlus)]
641                 internal static extern Status GdipResetWorldTransform (IntPtr graphics);
642                 [DllImport(GdiPlus)]
643                 internal static extern Status GdipSetWorldTransform (IntPtr graphics, IntPtr matrix);
644                 [DllImport(GdiPlus)]
645                 internal static extern Status GdipGetWorldTransform (IntPtr graphics, IntPtr matrix);
646                 [DllImport(GdiPlus)]
647                 internal static extern Status GdipScaleWorldTransform (IntPtr graphics, float sx, float sy, MatrixOrder order);
648                 [DllImport(GdiPlus)]
649                 internal static extern Status GdipGraphicsClear(IntPtr graphics, int argb);
650                 [DllImport(GdiPlus)]
651                 internal static extern Status GdipDrawClosedCurve(IntPtr graphics, IntPtr pen, PointF [] points, int count);
652                 [DllImport(GdiPlus)]
653                 internal static extern Status GdipDrawClosedCurveI(IntPtr graphics, IntPtr pen, Point [] points, int count);
654                 [DllImport(GdiPlus)]
655                 internal static extern Status GdipDrawClosedCurve2(IntPtr graphics, IntPtr pen, PointF [] points, int count, float tension);
656                 [DllImport(GdiPlus)]
657                 internal static extern Status GdipDrawClosedCurve2I(IntPtr graphics, IntPtr pen, Point [] points, int count, float tension);
658                 [DllImport(GdiPlus)]
659                 internal static extern Status GdipDrawCurve(IntPtr graphics, IntPtr pen, PointF [] points, int count);
660                 [DllImport(GdiPlus)]
661                 internal static extern Status GdipDrawCurveI(IntPtr graphics, IntPtr pen, Point [] points, int count);
662                 [DllImport(GdiPlus)]
663                 internal static extern Status GdipDrawCurve2(IntPtr graphics, IntPtr pen, PointF [] points, int count, float tension);
664                 [DllImport(GdiPlus)]
665                 internal static extern Status GdipDrawCurve2I(IntPtr graphics, IntPtr pen, Point [] points, int count, float tension);
666                 [DllImport(GdiPlus)]
667                 internal static extern Status GdipDrawCurve3(IntPtr graphics, IntPtr pen, PointF [] points, int count, int offset, int numberOfSegments, float tension);
668                 [DllImport(GdiPlus)]
669                 internal static extern Status GdipDrawCurve3I(IntPtr graphics, IntPtr pen, Point [] points, int count, int offset, int numberOfSegments, float tension);
670                 [DllImport(GdiPlus)]
671                 internal static extern Status GdipSetClipRect(IntPtr graphics, float x, float y, float width, float height, CombineMode combineMode);
672                 [DllImport(GdiPlus)]
673                 internal static extern Status GdipSetClipRectI(IntPtr graphics, int x, int y, int width, int height, CombineMode combineMode);
674                 [DllImport(GdiPlus)]
675                 internal static extern Status GdipSetClipPath(IntPtr graphics, IntPtr path, CombineMode combineMode);
676                 [DllImport(GdiPlus)]
677                 internal static extern Status GdipSetClipRegion(IntPtr graphics, IntPtr region, CombineMode combineMode);
678                 [DllImport(GdiPlus)]
679                 internal static extern Status GdipSetClipGraphics(IntPtr graphics, IntPtr srcgraphics, CombineMode combineMode);
680                 [DllImport(GdiPlus)]
681                 internal static extern Status GdipResetClip(IntPtr graphics);
682                 [DllImport(GdiPlus)]
683                 internal static extern Status GdipEndContainer(IntPtr graphics, uint state);
684                 [DllImport(GdiPlus)]
685                 internal static extern Status GdipGetClip (IntPtr graphics, IntPtr region);
686
687                 [DllImport(GdiPlus)]
688                 internal static extern Status GdipFillClosedCurve(IntPtr graphics, IntPtr brush, PointF [] points, int count);
689
690                 [DllImport(GdiPlus)]
691                 internal static extern Status GdipFillClosedCurveI(IntPtr graphics, IntPtr brush, Point [] points, int count);
692
693                 [DllImport(GdiPlus)]
694                 internal static extern Status GdipFillClosedCurve2(IntPtr graphics, IntPtr brush,
695                                         PointF [] points, int count, float tension, FillMode fillMode);
696
697                 [DllImport(GdiPlus)]
698                 internal static extern Status GdipFillClosedCurve2I(IntPtr graphics, IntPtr brush,
699                         Point [] points, int count, float tension, FillMode fillMode);
700
701                 [DllImport(GdiPlus)]
702                 internal static extern Status GdipFillPie(IntPtr graphics, IntPtr brush, float x, float y,
703                         float width, float height, float startAngle, float sweepAngle);
704
705                 [DllImport(GdiPlus)]
706                 internal static extern Status GdipFillPieI(IntPtr graphics, IntPtr brush, int x, int y,
707                         int width, int height, float startAngle, float sweepAngle);
708
709                 [DllImport(GdiPlus)]
710                 internal static extern Status GdipFillPath(IntPtr graphics, IntPtr brush, IntPtr path);
711
712                 [DllImport(GdiPlus)]
713                 internal static extern Status GdipGetNearestColor(IntPtr graphics, out int argb);
714
715                 [DllImport(GdiPlus)]
716                 internal static extern Status GdipIsVisiblePoint(IntPtr graphics, float x, float y, out bool result);
717
718                 [DllImport(GdiPlus)]
719                 internal static extern Status GdipIsVisiblePointI(IntPtr graphics, int x, int y, out bool result);
720
721                 [DllImport(GdiPlus)]
722                 internal static extern Status GdipIsVisibleRect(IntPtr graphics, float x, float y,
723                         float width, float height, out bool result);
724
725                 [DllImport(GdiPlus)]
726                 internal static extern Status GdipIsVisibleRectI(IntPtr graphics, int x, int y,
727                         int width, int height, out bool result);
728
729                 [DllImport(GdiPlus)]
730                 internal static extern Status GdipTransformPoints(IntPtr graphics, CoordinateSpace destSpace,
731                         CoordinateSpace srcSpace, IntPtr points, int count);
732
733                 [DllImport(GdiPlus)]
734                 internal static extern Status GdipTransformPointsI(IntPtr graphics, CoordinateSpace destSpace,
735                         CoordinateSpace srcSpace, IntPtr points, int count);
736
737                 [DllImport(GdiPlus)]
738                 internal static extern Status GdipTranslateClip(IntPtr graphics, float dx, float dy);
739                 [DllImport(GdiPlus)]
740                 internal static extern Status GdipTranslateClipI(IntPtr graphics, int dx, int dy);
741                 [DllImport(GdiPlus)]
742                 internal static extern Status GdipGetClipBounds(IntPtr graphics, out RectangleF rect);
743                 [DllImport(GdiPlus)]
744                 internal static extern Status GdipSetCompositingMode(IntPtr graphics, CompositingMode compositingMode);
745                 [DllImport(GdiPlus)]
746                 internal static extern Status GdipGetCompositingMode(IntPtr graphics, out CompositingMode compositingMode);
747                 [DllImport(GdiPlus)]
748                 internal static extern Status GdipSetCompositingQuality(IntPtr graphics, CompositingQuality compositingQuality);
749                 [DllImport(GdiPlus)]
750                 internal static extern Status GdipGetCompositingQuality(IntPtr graphics, out CompositingQuality compositingQuality);
751                 [DllImport(GdiPlus)]
752                 internal static extern Status GdipSetInterpolationMode(IntPtr graphics, InterpolationMode interpolationMode);
753                 [DllImport(GdiPlus)]
754                 internal static extern Status GdipGetInterpolationMode(IntPtr graphics, out InterpolationMode interpolationMode);
755                 [DllImport(GdiPlus)]
756                 internal static extern Status GdipGetDpiX(IntPtr graphics, out float dpi);
757                 [DllImport(GdiPlus)]
758                 internal static extern Status GdipGetDpiY(IntPtr graphics, out float dpi);
759                 [DllImport(GdiPlus)]
760                 internal static extern Status GdipIsClipEmpty(IntPtr graphics, out bool result);
761                 [DllImport(GdiPlus)]
762                 internal static extern Status GdipIsVisibleClipEmpty(IntPtr graphics, out bool result);
763                 [DllImport(GdiPlus)]
764                 internal static extern Status GdipGetPageUnit(IntPtr graphics, out GraphicsUnit unit);
765                 [DllImport(GdiPlus)]
766                 internal static extern Status GdipGetPageScale(IntPtr graphics, out float scale);
767                 [DllImport(GdiPlus)]
768                 internal static extern Status GdipSetPageUnit(IntPtr graphics, GraphicsUnit unit);
769                 [DllImport(GdiPlus)]
770                 internal static extern Status GdipSetPageScale(IntPtr graphics, float scale);
771                 [DllImport(GdiPlus)]
772                 internal static extern Status GdipSetPixelOffsetMode(IntPtr graphics, PixelOffsetMode pixelOffsetMode);
773                 [DllImport(GdiPlus)]
774                 internal static extern Status GdipGetPixelOffsetMode(IntPtr graphics, out PixelOffsetMode pixelOffsetMode);
775                 [DllImport(GdiPlus)]
776                 internal static extern Status GdipSetSmoothingMode(IntPtr graphics, SmoothingMode smoothingMode);
777                 [DllImport(GdiPlus)]
778                 internal static extern Status GdipGetSmoothingMode(IntPtr graphics, out SmoothingMode smoothingMode);
779                 [DllImport(GdiPlus)]
780                 internal static extern Status GdipSetTextContrast(IntPtr graphics, int contrast);
781                 [DllImport(GdiPlus)]
782                 internal static extern Status GdipGetTextContrast(IntPtr graphics, out int contrast);
783                 [DllImport(GdiPlus)]
784                 internal static extern Status GdipSetTextRenderingHint(IntPtr graphics, TextRenderingHint mode);
785                 [DllImport(GdiPlus)]
786                 internal static extern Status GdipGetTextRenderingHint(IntPtr graphics, out TextRenderingHint mode);
787                 [DllImport(GdiPlus)]
788                 internal static extern Status GdipGetVisibleClipBounds(IntPtr graphics, out RectangleF rect);
789
790                 [DllImport(GdiPlus)]
791                 internal static extern Status GdipFlush(IntPtr graphics, FlushIntention intention);
792
793                 [DllImport(GdiPlus, CharSet=CharSet.Unicode)]
794                 internal static extern Status GdipAddPathString (IntPtr path, string s, int lenght, IntPtr family, int style, float emSize, ref RectangleF layoutRect, IntPtr format);
795                 [DllImport(GdiPlus, CharSet=CharSet.Unicode)]
796                 internal static extern Status GdipAddPathStringI (IntPtr path, string s, int lenght, IntPtr family, int style, float emSize, ref Rectangle layoutRect, IntPtr format);
797
798
799                 // Pen functions
800                 [DllImport(GdiPlus)]
801                 internal static extern Status GdipCreatePen1 (int argb, float width, GraphicsUnit unit, out IntPtr pen);
802                 [DllImport(GdiPlus)]
803                 internal static extern Status GdipCreatePen2 (IntPtr brush, float width, GraphicsUnit unit, out IntPtr pen);
804                 [DllImport(GdiPlus)]
805                 internal static extern Status GdipClonePen (IntPtr pen, out IntPtr clonepen);
806                 [DllImport(GdiPlus)]
807                 internal static extern Status GdipDeletePen(IntPtr pen);
808                 [DllImport(GdiPlus)]
809                 internal static extern Status GdipSetPenBrushFill (IntPtr pen, IntPtr brush);
810                 [DllImport(GdiPlus)]
811                 internal static extern Status GdipGetPenBrushFill (IntPtr pen, out IntPtr brush);
812                 [DllImport(GdiPlus)]
813                 internal static extern Status GdipGetPenFillType (IntPtr pen, out PenType type);
814                 [DllImport(GdiPlus)]
815                 internal static extern Status GdipSetPenColor (IntPtr pen, int color);
816                 [DllImport(GdiPlus)]
817                 internal static extern Status GdipGetPenColor (IntPtr pen, out int color);
818                 [DllImport(GdiPlus)]
819                 internal static extern Status GdipSetPenCompoundArray (IntPtr pen, float[] dash, int count);
820                 [DllImport(GdiPlus)]
821                 internal static extern Status GdipGetPenCompoundArray (IntPtr pen, float[] dash, int count);
822                 [DllImport(GdiPlus)]
823                 internal static extern Status GdipGetPenCompoundCount (IntPtr pen, out int count);
824                 [DllImport(GdiPlus)]
825                 internal static extern Status GdipSetPenDashCap197819 (IntPtr pen, DashCap dashCap);
826                 [DllImport(GdiPlus)]
827                 internal static extern Status GdipGetPenDashCap197819 (IntPtr pen, out DashCap dashCap);
828                 [DllImport(GdiPlus)]
829                 internal static extern Status GdipSetPenDashStyle (IntPtr pen, DashStyle dashStyle);
830                 [DllImport(GdiPlus)]
831                 internal static extern Status GdipGetPenDashStyle (IntPtr pen, out DashStyle dashStyle);
832                 [DllImport(GdiPlus)]
833                 internal static extern Status GdipSetPenDashOffset (IntPtr pen, float offset);
834                 [DllImport(GdiPlus)]
835                 internal static extern Status GdipGetPenDashOffset (IntPtr pen, out float offset);
836                 [DllImport(GdiPlus)]
837                 internal static extern Status GdipGetPenDashCount (IntPtr pen, out int count);
838                 [DllImport(GdiPlus)]
839                 internal static extern Status GdipSetPenDashArray (IntPtr pen, float[] dash, int count);
840                 [DllImport(GdiPlus)]
841                 internal static extern Status GdipGetPenDashArray (IntPtr pen, float[] dash, int count);
842                 [DllImport(GdiPlus)]
843                 internal static extern Status GdipSetPenMiterLimit (IntPtr pen, float miterLimit);
844                 [DllImport(GdiPlus)]
845                 internal static extern Status GdipGetPenMiterLimit (IntPtr pen, out float miterLimit);
846                 [DllImport(GdiPlus)]
847                 internal static extern Status GdipSetPenLineJoin (IntPtr pen, LineJoin lineJoin);
848                 [DllImport(GdiPlus)]
849                 internal static extern Status GdipGetPenLineJoin (IntPtr pen, out LineJoin lineJoin);
850                 [DllImport(GdiPlus)]
851                 internal static extern Status GdipSetPenLineCap197819 (IntPtr pen, LineCap startCap, LineCap endCap, DashCap dashCap);
852                 [DllImport(GdiPlus)]
853                 internal static extern Status GdipSetPenMode (IntPtr pen, PenAlignment alignment);
854                 [DllImport(GdiPlus)]
855                 internal static extern Status GdipGetPenMode (IntPtr pen, out PenAlignment alignment);
856                 [DllImport(GdiPlus)]
857                 internal static extern Status GdipSetPenStartCap (IntPtr pen, LineCap startCap);
858                 [DllImport(GdiPlus)]
859                 internal static extern Status GdipGetPenStartCap (IntPtr pen, out LineCap startCap);
860                 [DllImport(GdiPlus)]
861                 internal static extern Status GdipSetPenEndCap (IntPtr pen, LineCap endCap);
862                 [DllImport(GdiPlus)]
863                 internal static extern Status GdipGetPenEndCap (IntPtr pen, out LineCap endCap);
864                 [DllImport(GdiPlus)]
865                 internal static extern Status GdipSetPenCustomStartCap (IntPtr pen, IntPtr customCap);
866                 [DllImport(GdiPlus)]
867                 internal static extern Status GdipGetPenCustomStartCap (IntPtr pen, out IntPtr customCap);
868                 [DllImport(GdiPlus)]
869                 internal static extern Status GdipSetPenCustomEndCap (IntPtr pen, IntPtr customCap);
870                 [DllImport(GdiPlus)]
871                 internal static extern Status GdipGetPenCustomEndCap (IntPtr pen, out IntPtr customCap);
872                 [DllImport(GdiPlus)]
873                 internal static extern Status GdipSetPenTransform (IntPtr pen, IntPtr matrix);
874                 [DllImport(GdiPlus)]
875                 internal static extern Status GdipGetPenTransform (IntPtr pen, IntPtr matrix);
876                 [DllImport(GdiPlus)]
877                 internal static extern Status GdipSetPenWidth (IntPtr pen, float width);
878                 [DllImport(GdiPlus)]
879                 internal static extern Status GdipGetPenWidth (IntPtr pen, out float width);
880                 [DllImport(GdiPlus)]
881                 internal static extern Status GdipResetPenTransform (IntPtr pen);
882                 [DllImport(GdiPlus)]
883                 internal static extern Status GdipMultiplyPenTransform (IntPtr pen, IntPtr matrix, MatrixOrder order);
884                 [DllImport(GdiPlus)]
885                 internal static extern Status GdipRotatePenTransform (IntPtr pen, float angle, MatrixOrder order);
886                 [DllImport(GdiPlus)]
887                 internal static extern Status GdipScalePenTransform (IntPtr pen, float sx, float sy, MatrixOrder order);
888                 [DllImport(GdiPlus)]
889                 internal static extern Status GdipTranslatePenTransform (IntPtr pen, float dx, float dy, MatrixOrder order);
890
891                 // CustomLineCap functions
892                 [DllImport(GdiPlus)]
893                 internal static extern Status GdipCreateCustomLineCap (IntPtr fillPath, IntPtr strokePath, LineCap baseCap, float baseInset, out IntPtr customCap);
894                 [DllImport(GdiPlus)]
895                 internal static extern Status GdipDeleteCustomLineCap (IntPtr customCap);
896                 [DllImport(GdiPlus)]
897                 internal static extern Status GdipCloneCustomLineCap (IntPtr customCap, out IntPtr clonedCap);
898                 [DllImport(GdiPlus)]
899                 internal static extern Status GdipSetCustomLineCapStrokeCaps (IntPtr customCap, LineCap startCap, LineCap endCap);
900                 [DllImport(GdiPlus)]
901                 internal static extern Status GdipGetCustomLineCapStrokeCaps (IntPtr customCap, out LineCap startCap, out LineCap endCap);
902                 [DllImport(GdiPlus)]
903                 internal static extern Status GdipSetCustomLineCapStrokeJoin (IntPtr customCap, LineJoin lineJoin);
904                 [DllImport(GdiPlus)]
905                 internal static extern Status GdipGetCustomLineCapStrokeJoin (IntPtr customCap, out LineJoin lineJoin);
906                 [DllImport(GdiPlus)]
907                 internal static extern Status GdipSetCustomLineCapBaseCap (IntPtr customCap, LineCap baseCap);
908                 [DllImport(GdiPlus)]
909                 internal static extern Status GdipGetCustomLineCapBaseCap (IntPtr customCap, out LineCap baseCap);
910                 [DllImport(GdiPlus)]
911                 internal static extern Status GdipSetCustomLineCapBaseInset (IntPtr customCap, float inset);
912                 [DllImport(GdiPlus)]
913                 internal static extern Status GdipGetCustomLineCapBaseInset (IntPtr customCap, out float inset);
914                 [DllImport(GdiPlus)]
915                 internal static extern Status GdipSetCustomLineCapWidthScale (IntPtr customCap, float widthScale);
916                 [DllImport(GdiPlus)]
917                 internal static extern Status GdipGetCustomLineCapWidthScale (IntPtr customCap, out float widthScale);
918
919                 // AdjustableArrowCap functions
920                 [DllImport(GdiPlus)]
921                 internal static extern Status GdipCreateAdjustableArrowCap (float height, float width, bool isFilled, out IntPtr arrowCap);
922                 [DllImport(GdiPlus)]
923                 internal static extern Status GdipSetAdjustableArrowCapHeight (IntPtr arrowCap, float height);
924                 [DllImport(GdiPlus)]
925                 internal static extern Status GdipGetAdjustableArrowCapHeight (IntPtr arrowCap, out float height);
926                 [DllImport(GdiPlus)]
927                 internal static extern Status GdipSetAdjustableArrowCapWidth (IntPtr arrowCap, float width);
928                 [DllImport(GdiPlus)]
929                 internal static extern Status GdipGetAdjustableArrowCapWidth (IntPtr arrowCap, out float width);
930                 [DllImport(GdiPlus)]
931                 internal static extern Status GdipSetAdjustableArrowCapMiddleInset (IntPtr arrowCap, float middleInset);
932                 [DllImport(GdiPlus)]
933                 internal static extern Status GdipGetAdjustableArrowCapMiddleInset (IntPtr arrowCap, out float middleInset);
934                 [DllImport(GdiPlus)]
935                 internal static extern Status GdipSetAdjustableArrowCapFillState (IntPtr arrowCap, bool isFilled);
936                 [DllImport(GdiPlus)]
937                 internal static extern Status GdipGetAdjustableArrowCapFillState (IntPtr arrowCap, out bool isFilled);
938
939
940                 [DllImport(GdiPlus)]
941                 internal static extern Status GdipCreateFromHWND (IntPtr hwnd, out IntPtr graphics);
942
943                 [DllImport(GdiPlus, CharSet=CharSet.Unicode)]
944                 internal unsafe static extern Status GdipMeasureString(IntPtr graphics, string str, int length,
945                         IntPtr font, ref RectangleF layoutRect, IntPtr stringFormat, out RectangleF boundingBox,
946                         int *codepointsFitted, int *linesFilled);
947
948                 [DllImport(GdiPlus, CharSet=CharSet.Unicode)]
949                 internal static extern Status GdipMeasureCharacterRanges (IntPtr graphics, string str, int length, IntPtr font,
950                         ref RectangleF layoutRect, IntPtr stringFormat, int regcount, out IntPtr regions);
951
952                 [DllImport(GdiPlus)]
953                 internal static extern Status GdipSetStringFormatMeasurableCharacterRanges (IntPtr native,
954                         int cnt, CharacterRange [] range);
955
956                 [DllImport(GdiPlus)]
957                 internal static extern Status GdipGetStringFormatMeasurableCharacterRangeCount (IntPtr native,
958                         out int cnt);
959
960                 // Bitmap functions
961                 [DllImport(GdiPlus)]
962                 internal static extern Status GdipCreateBitmapFromScan0 (int width, int height, int stride, PixelFormat format, IntPtr scan0, out IntPtr bmp);
963
964                 [DllImport(GdiPlus)]
965                 internal static extern Status GdipCreateBitmapFromGraphics (int width, int height, IntPtr target, out IntPtr bitmap);
966
967                 [DllImport(GdiPlus)]
968                 internal static extern Status GdipBitmapLockBits (IntPtr bmp, ref Rectangle rc, ImageLockMode flags, PixelFormat format, [In, Out] BitmapData bmpData);
969
970                 [DllImport(GdiPlus)]
971                 internal static extern Status GdipBitmapSetResolution(IntPtr bmp, float xdpi, float ydpi);
972
973                 [DllImport(GdiPlus)]
974                 internal static extern Status GdipBitmapUnlockBits (IntPtr bmp, [In,Out] BitmapData bmpData);
975
976                 [DllImport(GdiPlus)]
977                 internal static extern Status GdipBitmapGetPixel (IntPtr bmp, int x, int y, out int argb);
978
979                 [DllImport(GdiPlus)]
980                 internal static extern Status GdipBitmapSetPixel (IntPtr bmp, int x, int y, int argb);
981
982                 // Image functions
983                 [DllImport(GdiPlus, CharSet=CharSet.Auto)]
984                 internal static extern Status GdipLoadImageFromFile ( [MarshalAs(UnmanagedType.LPWStr)] string filename, out IntPtr image );
985
986 #if !TEST
987                 // Stream functions for Win32 (original Win32 ones)
988                 [DllImport(GdiPlus, ExactSpelling=true, CharSet=CharSet.Unicode)]
989                 internal static extern Status GdipLoadImageFromStream([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))] IStream stream, out IntPtr image);
990
991                 [DllImport(GdiPlus, ExactSpelling=true, CharSet=CharSet.Unicode)]
992                 internal static extern Status GdipSaveImageToStream(HandleRef image, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))] IStream stream, [In()] ref Guid clsidEncoder, HandleRef encoderParams);
993 #endif
994
995                 [DllImport(GdiPlus)]
996                 internal static extern Status GdipCloneImage(IntPtr image, out IntPtr imageclone);
997
998                 [DllImport(GdiPlus, CharSet=CharSet.Auto)]
999                 internal static extern Status GdipLoadImageFromFileICM ( [MarshalAs(UnmanagedType.LPWStr)] string filename, out IntPtr image );
1000
1001                 [DllImport(GdiPlus)]
1002                 internal static extern Status GdipCreateBitmapFromHBITMAP ( IntPtr hBitMap, IntPtr gdiPalette, out IntPtr image );
1003
1004                 [DllImport(GdiPlus)]
1005                 internal static extern Status GdipDisposeImage ( IntPtr image );
1006
1007                 [DllImport(GdiPlus)]
1008                 internal static extern Status GdipGetImageFlags(IntPtr image, out int flag);
1009
1010                 [DllImport (GdiPlus)]
1011                 internal static extern Status GdipGetImageType (IntPtr image, out ImageType type);
1012
1013                 [DllImport(GdiPlus)]
1014                 internal static extern Status GdipImageGetFrameDimensionsCount ( IntPtr image, out uint count );
1015
1016                 [DllImport(GdiPlus)]
1017                 internal static extern Status GdipImageGetFrameDimensionsList ( IntPtr image, [Out] Guid [] dimensionIDs, uint count );
1018
1019                 [DllImport(GdiPlus)]
1020                 internal static extern Status GdipGetImageHeight (IntPtr image, out uint height);
1021
1022                 [DllImport(GdiPlus)]
1023                 internal static extern Status GdipGetImageHorizontalResolution ( IntPtr image, out float resolution );
1024
1025                 [DllImport(GdiPlus)]
1026                 internal static extern Status GdipGetImagePaletteSize ( IntPtr image, out int size );
1027
1028                 [DllImport(GdiPlus)]
1029                 internal static extern Status GdipGetImagePalette (IntPtr image, IntPtr palette, int size);
1030
1031                 [DllImport(GdiPlus)]
1032                 internal static extern Status GdipSetImagePalette (IntPtr image, IntPtr palette);
1033
1034                 [DllImport(GdiPlus)]
1035                 internal static extern Status GdipGetImageDimension ( IntPtr image, out float width, out float height );
1036
1037                 [DllImport(GdiPlus)]
1038                 internal static extern Status GdipGetImagePixelFormat ( IntPtr image, out PixelFormat format );
1039
1040                 [DllImport(GdiPlus)]
1041                 internal static extern Status GdipGetPropertyCount (IntPtr image, out uint propNumbers);
1042
1043                 [DllImport(GdiPlus)]
1044                 internal static extern Status GdipGetPropertyIdList (IntPtr image, uint propNumbers, [Out] int [] list);
1045
1046                 [DllImport(GdiPlus)]
1047                 internal static extern Status GdipGetPropertySize (IntPtr image, out int bufferSize, out int propNumbers);
1048
1049                 [DllImport(GdiPlus)]
1050                 internal static extern Status GdipGetAllPropertyItems (IntPtr image, int bufferSize, int propNumbers, IntPtr items);
1051
1052                 [DllImport(GdiPlus)]
1053                 internal static extern Status GdipGetImageRawFormat ( IntPtr image, out Guid format );
1054
1055                 [DllImport(GdiPlus)]
1056                 internal static extern Status GdipGetImageVerticalResolution ( IntPtr image, out float resolution );
1057
1058                 [DllImport(GdiPlus)]
1059                 internal static extern Status GdipGetImageWidth (IntPtr image, out uint width);
1060
1061                 [DllImport(GdiPlus)]
1062                 internal static extern Status GdipGetImageBounds ( IntPtr image, out RectangleF source, ref GraphicsUnit unit );
1063
1064                 [DllImport(GdiPlus)]
1065                 internal static extern Status GdipGetEncoderParameterListSize ( IntPtr image, ref Guid encoder, out uint size );
1066
1067                 [DllImport(GdiPlus)]
1068                 internal static extern Status GdipGetEncoderParameterList ( IntPtr image, ref Guid encoder, uint size, IntPtr buffer );
1069
1070                 [DllImport(GdiPlus)]
1071                 internal static extern Status GdipImageGetFrameCount (IntPtr image, ref Guid guidDimension, out uint count );
1072
1073                 [DllImport(GdiPlus)]
1074                 internal static extern Status GdipImageSelectActiveFrame (IntPtr image, ref Guid guidDimension, int frameIndex);
1075
1076                 [DllImport(GdiPlus)]
1077                 internal static extern Status GdipGetPropertyItemSize (IntPtr image, int propertyID, out int propertySize);
1078
1079                 [DllImport(GdiPlus)]
1080                 internal static extern Status GdipGetPropertyItem (IntPtr image, int propertyID, int propertySize, IntPtr buffer);
1081
1082                 [DllImport(GdiPlus)]
1083                 internal static extern Status GdipRemovePropertyItem (IntPtr image, int propertyId);
1084
1085                 [DllImport(GdiPlus)]
1086                 internal unsafe static extern Status GdipSetPropertyItem (IntPtr image, GdipPropertyItem *propertyItem);
1087
1088                 [DllImport(GdiPlus)]
1089                 internal static extern Status GdipGetImageThumbnail ( IntPtr image, uint width, uint height, out IntPtr thumbImage, IntPtr callback, IntPtr callBackData );
1090
1091                 [DllImport(GdiPlus)]
1092                 internal static extern Status GdipImageRotateFlip ( IntPtr image, RotateFlipType rotateFlipType );
1093
1094                 [DllImport(GdiPlus, CharSet=CharSet.Unicode)]
1095                 internal static extern Status GdipSaveImageToFile (IntPtr image, string filename, ref Guid encoderClsID, IntPtr encoderParameters);
1096
1097                 [DllImport(GdiPlus)]
1098                 internal static extern Status GdipSaveAdd ( IntPtr image, IntPtr encoderParameters );
1099
1100                 [DllImport(GdiPlus)]
1101                 internal static extern Status GdipSaveAddImage (IntPtr image, IntPtr imagenew, IntPtr encoderParameters);
1102
1103                 [DllImport(GdiPlus)]
1104                 internal static extern Status GdipDrawImageI (IntPtr graphics, IntPtr image, int x, int y);
1105                 [DllImport(GdiPlus)]
1106                 internal static extern Status GdipGetImageGraphicsContext (IntPtr image, out IntPtr graphics);
1107                 [DllImport(GdiPlus)]
1108                 internal static extern Status GdipDrawImage (IntPtr graphics, IntPtr image, float x, float y);
1109
1110                 [DllImport(GdiPlus)]
1111                 internal static extern Status GdipBeginContainer (IntPtr graphics, ref RectangleF dstrect, ref RectangleF srcrect, GraphicsUnit unit, out uint state);
1112                 [DllImport(GdiPlus)]
1113                 internal static extern Status GdipBeginContainerI (IntPtr graphics, ref Rectangle dstrect, ref Rectangle srcrect, GraphicsUnit unit, out uint state);
1114                 [DllImport(GdiPlus)]
1115                 internal static extern Status GdipBeginContainer2 (IntPtr graphics, out uint state);
1116
1117                 [DllImport(GdiPlus)]
1118                 internal static extern Status GdipDrawImagePoints (IntPtr graphics, IntPtr image, PointF [] destPoints, int count);
1119
1120
1121                 [DllImport(GdiPlus)]
1122                 internal static extern Status GdipDrawImagePointsI (IntPtr graphics, IntPtr image, Point [] destPoints, int count);
1123
1124                 [DllImport(GdiPlus)]
1125                 internal static extern Status GdipDrawImageRectRectI (IntPtr graphics, IntPtr image,
1126                         int dstx, int dsty, int dstwidth, int dstheight,
1127                         int srcx, int srcy, int srcwidth, int srcheight,
1128                         GraphicsUnit srcUnit, IntPtr imageattr, Graphics.DrawImageAbort callback, IntPtr callbackData);
1129
1130                 [DllImport(GdiPlus)]
1131                 internal static extern Status GdipDrawImageRectRect (IntPtr graphics, IntPtr image,
1132                         float dstx, float dsty, float dstwidth, float dstheight,
1133                         float srcx, float srcy, float srcwidth, float srcheight,
1134                         GraphicsUnit srcUnit, IntPtr imageattr, Graphics.DrawImageAbort callback, IntPtr callbackData);
1135
1136                 [DllImport(GdiPlus)]
1137                 internal static extern Status GdipDrawImagePointsRectI (IntPtr graphics, IntPtr image,
1138                          Point [] destPoints, int count, int srcx, int srcy, int srcwidth, int srcheight,
1139                          GraphicsUnit srcUnit, IntPtr imageattr, Graphics.DrawImageAbort callback, IntPtr callbackData);
1140
1141                 [DllImport(GdiPlus)]
1142                 internal static extern Status GdipDrawImagePointsRect (IntPtr graphics, IntPtr image,
1143                          PointF [] destPoints, int count, float srcx, float srcy, float srcwidth, float srcheight,
1144                          GraphicsUnit srcUnit, IntPtr imageattr, Graphics.DrawImageAbort callback, IntPtr callbackData);
1145
1146                 [DllImport(GdiPlus)]
1147                 internal static extern Status GdipDrawImageRect(IntPtr graphics, IntPtr image, float x, float y, float width, float height);
1148                 [DllImport(GdiPlus)]
1149                 internal static extern Status GdipDrawImagePointRect(IntPtr graphics, IntPtr image, float x,
1150                                 float y, float srcx, float srcy, float srcwidth, float srcheight, GraphicsUnit srcUnit);
1151
1152                 [DllImport(GdiPlus)]
1153                 internal static extern Status GdipDrawImagePointRectI(IntPtr graphics, IntPtr image, int x,
1154                                 int y, int srcx, int srcy, int srcwidth,
1155                                 int srcheight, GraphicsUnit srcUnit);
1156
1157                 [DllImport(GdiPlus)]
1158                 internal static extern Status GdipCreateStringFormat(StringFormatFlags formatAttributes, int language, out IntPtr native);
1159
1160                 [DllImport(GdiPlus)]
1161                 internal static extern Status GdipCreateHBITMAPFromBitmap (IntPtr bmp, out IntPtr HandleBmp, int clrbackground);
1162
1163                 [DllImport(GdiPlus, CharSet=CharSet.Auto)]
1164                 internal static extern Status GdipCreateBitmapFromFile ([MarshalAs (UnmanagedType.LPWStr)] string filename, out IntPtr bitmap);
1165
1166                 [DllImport(GdiPlus, CharSet=CharSet.Auto)]
1167                 internal static extern Status GdipCreateBitmapFromFileICM ([MarshalAs (UnmanagedType.LPWStr)] string filename, out IntPtr bitmap);
1168
1169                 [DllImport(GdiPlus)]
1170                 internal static extern Status GdipCreateHICONFromBitmap (IntPtr bmp, out IntPtr HandleIcon);
1171
1172                 [DllImport(GdiPlus)]
1173                 internal static extern Status GdipCreateBitmapFromHICON (IntPtr hicon, out IntPtr bitmap);
1174
1175                 [DllImport(GdiPlus)]
1176                 internal static extern Status GdipCreateBitmapFromResource (IntPtr hInstance,
1177                                 string lpBitmapName, out IntPtr bitmap);
1178
1179                 // Matrix functions
1180                 [DllImport (GdiPlus)]
1181                 internal static extern Status GdipCreateMatrix (out IntPtr matrix);
1182                 [DllImport (GdiPlus)]
1183                 internal static extern Status GdipCreateMatrix2 (float m11, float m12, float m21, float m22, float dx, float dy, out IntPtr matrix);
1184                 [DllImport (GdiPlus)]
1185                 internal static extern Status GdipCreateMatrix3 (ref RectangleF rect, PointF [] dstplg, out IntPtr matrix);
1186                 [DllImport (GdiPlus)]
1187                 internal static extern Status GdipCreateMatrix3I (ref Rectangle rect, Point [] dstplg, out IntPtr matrix);
1188                 [DllImport (GdiPlus)]
1189                 internal static extern Status GdipDeleteMatrix (IntPtr matrix);
1190
1191                 [DllImport (GdiPlus)]
1192                 internal static extern Status GdipCloneMatrix (IntPtr matrix, out IntPtr cloneMatrix);
1193                 [DllImport (GdiPlus)]
1194                 internal static extern Status GdipSetMatrixElements (IntPtr matrix, float m11, float m12, float m21, float m22, float dx, float dy);
1195                 [DllImport (GdiPlus)]
1196                 internal static extern Status GdipGetMatrixElements (IntPtr matrix, IntPtr matrixOut);
1197                 [DllImport (GdiPlus)]
1198                 internal static extern Status GdipMultiplyMatrix (IntPtr matrix, IntPtr matrix2, MatrixOrder order);
1199                 [DllImport (GdiPlus)]
1200                 internal static extern Status GdipTranslateMatrix (IntPtr matrix, float offsetX, float offsetY, MatrixOrder order);
1201                 [DllImport (GdiPlus)]
1202                 internal static extern Status GdipScaleMatrix (IntPtr matrix, float scaleX, float scaleY, MatrixOrder order);
1203                 [DllImport (GdiPlus)]
1204                 internal static extern Status GdipRotateMatrix (IntPtr matrix, float angle, MatrixOrder order);
1205
1206                 [DllImport (GdiPlus)]
1207                 internal static extern Status GdipShearMatrix (IntPtr matrix, float shearX, float shearY, MatrixOrder order);
1208
1209                 [DllImport (GdiPlus)]
1210                 internal static extern Status GdipInvertMatrix (IntPtr matrix);
1211                 [DllImport (GdiPlus)]
1212                 internal static extern Status GdipTransformMatrixPoints (IntPtr matrix, [In, Out] PointF [] pts, int count);
1213                 [DllImport (GdiPlus)]
1214                 internal static extern Status GdipTransformMatrixPointsI (IntPtr matrix, [In, Out] Point [] pts, int count);
1215                 [DllImport (GdiPlus)]
1216                 internal static extern Status GdipVectorTransformMatrixPoints (IntPtr matrix, [In, Out] PointF [] pts, int count);
1217                 [DllImport (GdiPlus)]
1218                 internal static extern Status GdipVectorTransformMatrixPointsI (IntPtr matrix, [In, Out] Point [] pts, int count);
1219                 [DllImport (GdiPlus)]
1220                 internal static extern Status GdipIsMatrixInvertible (IntPtr matrix, out bool result);
1221
1222                 [DllImport (GdiPlus)]
1223                 internal static extern Status GdipIsMatrixIdentity (IntPtr matrix, out bool result);
1224                 [DllImport (GdiPlus)]
1225                 internal static extern Status GdipIsMatrixEqual (IntPtr matrix, IntPtr matrix2, out bool result);
1226
1227                 // GraphicsPath functions
1228                 [DllImport (GdiPlus)]
1229                 internal static extern Status GdipCreatePath (FillMode brushMode, out IntPtr path);
1230                 [DllImport (GdiPlus)]
1231                 internal static extern Status GdipCreatePath2 (PointF [] points, byte [] types, int count, FillMode brushMode, out IntPtr path);
1232                 [DllImport (GdiPlus)]
1233                 internal static extern Status GdipCreatePath2I (Point [] points, byte [] types, int count, FillMode brushMode, out IntPtr path);
1234                 [DllImport (GdiPlus)]
1235                 internal static extern Status GdipClonePath (IntPtr path, out IntPtr clonePath);
1236                 [DllImport (GdiPlus)]
1237                 internal static extern Status GdipDeletePath (IntPtr path);
1238                 [DllImport (GdiPlus)]
1239                 internal static extern Status GdipResetPath (IntPtr path);
1240                 [DllImport (GdiPlus)]
1241                 internal static extern Status GdipGetPointCount (IntPtr path, out int count);
1242                 [DllImport (GdiPlus)]
1243                 internal static extern Status GdipGetPathTypes (IntPtr path, [Out] byte [] types, int count);
1244                 [DllImport (GdiPlus)]
1245                 internal static extern Status GdipGetPathPoints (IntPtr path, [Out] PointF [] points, int count);
1246                 [DllImport (GdiPlus)]
1247                 internal static extern Status GdipGetPathPointsI (IntPtr path, [Out] Point [] points, int count);
1248                 [DllImport (GdiPlus)]
1249                 internal static extern Status GdipGetPathFillMode (IntPtr path, out FillMode fillMode);
1250                 [DllImport (GdiPlus)]
1251                 internal static extern Status GdipSetPathFillMode (IntPtr path, FillMode fillMode);
1252                 [DllImport (GdiPlus)]
1253                 internal static extern Status GdipStartPathFigure (IntPtr path);
1254                 [DllImport (GdiPlus)]
1255                 internal static extern Status GdipClosePathFigure (IntPtr path);
1256                 [DllImport (GdiPlus)]
1257                 internal static extern Status GdipClosePathFigures (IntPtr path);
1258                 [DllImport (GdiPlus)]
1259                 internal static extern Status GdipSetPathMarker (IntPtr path);
1260                 [DllImport (GdiPlus)]
1261                 internal static extern Status GdipClearPathMarkers (IntPtr path);
1262                 [DllImport (GdiPlus)]
1263                 internal static extern Status GdipReversePath (IntPtr path);
1264                 [DllImport (GdiPlus)]
1265                 internal static extern Status GdipGetPathLastPoint (IntPtr path, out PointF lastPoint);
1266                 [DllImport (GdiPlus)]
1267                 internal static extern Status GdipAddPathLine (IntPtr path, float x1, float y1, float x2, float y2);
1268                 [DllImport (GdiPlus)]
1269                 internal static extern Status GdipAddPathLine2 (IntPtr path, PointF[] points, int count);
1270                 [DllImport (GdiPlus)]
1271                 internal static extern Status GdipAddPathLine2I (IntPtr path, Point[] points, int count);
1272                 [DllImport (GdiPlus)]
1273                 internal static extern Status GdipAddPathArc (IntPtr path, float x, float y, float width, float height, float startAngle, float sweepAngle);
1274                 [DllImport (GdiPlus)]
1275                 internal static extern Status GdipAddPathBezier (IntPtr path, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
1276                 [DllImport (GdiPlus)]
1277                 internal static extern Status GdipAddPathBeziers (IntPtr path, PointF [] points, int count);
1278                 [DllImport (GdiPlus)]
1279                 internal static extern Status GdipAddPathCurve (IntPtr path, PointF [] points, int count);
1280                 [DllImport (GdiPlus)]
1281                 internal static extern Status GdipAddPathCurveI (IntPtr path, Point [] points, int count);
1282                 [DllImport (GdiPlus)]
1283                 internal static extern Status GdipAddPathCurve2 (IntPtr path, PointF [] points, int count, float tension);
1284                 [DllImport (GdiPlus)]
1285                 internal static extern Status GdipAddPathCurve2I (IntPtr path, Point [] points, int count, float tension);
1286                 [DllImport (GdiPlus)]
1287                 internal static extern Status GdipAddPathCurve3 (IntPtr path, PointF [] points, int count, int offset, int numberOfSegments, float tension);
1288                 [DllImport (GdiPlus)]
1289                 internal static extern Status GdipAddPathCurve3I (IntPtr path, Point [] points, int count, int offset, int numberOfSegments, float tension);
1290                 [DllImport (GdiPlus)]
1291                 internal static extern Status GdipAddPathClosedCurve (IntPtr path, PointF [] points, int count);
1292                 [DllImport (GdiPlus)]
1293                 internal static extern Status GdipAddPathClosedCurveI (IntPtr path, Point [] points, int count);
1294                 [DllImport (GdiPlus)]
1295                 internal static extern Status GdipAddPathClosedCurve2 (IntPtr path, PointF [] points, int count, float tension);
1296                 [DllImport (GdiPlus)]
1297                 internal static extern Status GdipAddPathClosedCurve2I (IntPtr path, Point [] points, int count, float tension);
1298                 [DllImport (GdiPlus)]
1299                 internal static extern Status GdipAddPathRectangle (IntPtr path, float x, float y, float width, float height);
1300                 [DllImport (GdiPlus)]
1301                 internal static extern Status GdipAddPathRectangles (IntPtr path, RectangleF [] rects, int count);
1302                 [DllImport (GdiPlus)]
1303                 internal static extern Status GdipAddPathEllipse (IntPtr path, float x, float y, float width, float height);
1304                 [DllImport (GdiPlus)]
1305                 internal static extern Status GdipAddPathEllipseI (IntPtr path, int x, int y, int width, int height);
1306                 [DllImport (GdiPlus)]
1307                 internal static extern Status GdipAddPathPie (IntPtr path, float x, float y, float width, float height, float startAngle, float sweepAngle);
1308                 [DllImport (GdiPlus)]
1309                 internal static extern Status GdipAddPathPieI (IntPtr path, int x, int y, int width, int height, float startAngle, float sweepAngle);
1310                 [DllImport (GdiPlus)]
1311                 internal static extern Status GdipAddPathPolygon (IntPtr path, PointF [] points, int count);
1312                 [DllImport (GdiPlus)]
1313                 internal static extern Status GdipAddPathPath (IntPtr path, IntPtr addingPath, bool connect);
1314                 [DllImport (GdiPlus)]
1315                 internal static extern Status GdipAddPathLineI (IntPtr path, int x1, int y1, int x2, int y2);
1316                 [DllImport (GdiPlus)]
1317                 internal static extern Status GdipAddPathArcI (IntPtr path, int x, int y, int width, int height, float startAngle, float sweepAngle);
1318
1319                 [DllImport (GdiPlus)]
1320                 internal static extern Status GdipAddPathBezierI (IntPtr path, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
1321                 [DllImport (GdiPlus)]
1322                 internal static extern Status GdipAddPathBeziersI (IntPtr path, Point [] points, int count);
1323
1324                 [DllImport (GdiPlus)]
1325                 internal static extern Status GdipAddPathPolygonI (IntPtr path, Point [] points, int count);
1326                 [DllImport (GdiPlus)]
1327                 internal static extern Status GdipAddPathRectangleI (IntPtr path, int x, int y, int width, int height);
1328                 [DllImport (GdiPlus)]
1329                 internal static extern Status GdipAddPathRectanglesI (IntPtr path, Rectangle [] rects, int count);
1330                 [DllImport (GdiPlus)]
1331                 internal static extern Status GdipFlattenPath (IntPtr path, IntPtr matrix, float floatness);
1332                 [DllImport (GdiPlus)]
1333                 internal static extern Status GdipTransformPath (IntPtr path, IntPtr matrix);
1334                 [DllImport (GdiPlus)]
1335                 internal static extern Status GdipWarpPath (IntPtr path, IntPtr matrix,
1336                         PointF [] points, int count,
1337                         float srcx, float srcy, float srcwidth, float srcheight,
1338                         WarpMode mode, float flatness);
1339                 [DllImport (GdiPlus)]
1340                 internal static extern Status GdipWidenPath (IntPtr path, IntPtr pen, IntPtr matrix, float flatness);
1341                 [DllImport (GdiPlus)]
1342                 internal static extern Status GdipGetPathWorldBounds (IntPtr path, out RectangleF bounds, IntPtr matrix, IntPtr pen);
1343                 [DllImport (GdiPlus)]
1344                 internal static extern Status GdipGetPathWorldBoundsI (IntPtr path, out Rectangle bounds, IntPtr matrix, IntPtr pen);
1345                 [DllImport (GdiPlus)]
1346                 internal static extern Status GdipIsVisiblePathPoint (IntPtr path, float x, float y, IntPtr graphics, out bool result);
1347                 [DllImport (GdiPlus)]
1348                 internal static extern Status GdipIsVisiblePathPointI (IntPtr path, int x, int y, IntPtr graphics, out bool result);
1349                 [DllImport (GdiPlus)]
1350                 internal static extern Status GdipIsOutlineVisiblePathPoint (IntPtr path, float x, float y, IntPtr pen, IntPtr graphics, out bool result);
1351                 [DllImport (GdiPlus)]
1352                 internal static extern Status GdipIsOutlineVisiblePathPointI (IntPtr path, int x, int y, IntPtr pen, IntPtr graphics, out bool result);
1353
1354                 // GraphicsPathIterator
1355                 [DllImport(GdiPlus)]
1356                 internal static extern Status GdipCreatePathIter (out IntPtr iterator, IntPtr path);
1357                 [DllImport(GdiPlus)]
1358                 internal static extern Status GdipPathIterGetCount (IntPtr iterator, out int count);
1359                 [DllImport(GdiPlus)]
1360                 internal static extern Status GdipPathIterGetSubpathCount (IntPtr iterator, out int count);
1361                 [DllImport(GdiPlus)]
1362                 internal static extern Status GdipDeletePathIter (IntPtr iterator);
1363                 [DllImport(GdiPlus)]
1364                 internal static extern Status GdipPathIterCopyData (IntPtr iterator, out int resultCount, PointF [] points, byte [] types, int startIndex, int endIndex);
1365                 [DllImport(GdiPlus)]
1366                 internal static extern Status GdipPathIterEnumerate (IntPtr iterator, out int resultCount, PointF [] points, byte [] types, int count);
1367                 [DllImport(GdiPlus)]
1368                 internal static extern Status GdipPathIterHasCurve (IntPtr iterator, out bool curve);
1369                 [DllImport(GdiPlus)]
1370                 internal static extern Status GdipPathIterNextMarkerPath (IntPtr iterator, out int resultCount, IntPtr path);
1371                 [DllImport(GdiPlus)]
1372                 internal static extern Status GdipPathIterNextMarker (IntPtr iterator, out int resultCount, out int startIndex, out int endIndex);
1373                 [DllImport(GdiPlus)]
1374                 internal static extern Status GdipPathIterNextPathType (IntPtr iterator, out int resultCount, out byte pathType, out int startIndex, out int endIndex);
1375                 [DllImport(GdiPlus)]
1376                 internal static extern Status GdipPathIterNextSubpathPath (IntPtr iterator, out int resultCount, IntPtr path, out bool isClosed);
1377                 [DllImport(GdiPlus)]
1378                 internal static extern Status GdipPathIterNextSubpath (IntPtr iterator, out int resultCount, out int startIndex, out int endIndex, out bool isClosed);
1379                 [DllImport(GdiPlus)]
1380                 internal static extern Status GdipPathIterRewind (IntPtr iterator);
1381
1382                 // ImageAttributes
1383                 [DllImport (GdiPlus)]
1384                 internal static extern Status GdipCreateImageAttributes (out IntPtr imageattr);
1385
1386                 [DllImport (GdiPlus)]
1387                 internal static extern Status GdipSetImageAttributesColorKeys (IntPtr imageattr,
1388                                 ColorAdjustType type, bool enableFlag, int colorLow, int colorHigh);
1389
1390                 [DllImport (GdiPlus)]
1391                 internal static extern Status GdipDisposeImageAttributes (IntPtr imageattr);
1392
1393                 [DllImport (GdiPlus)]
1394                 internal static extern Status GdipSetImageAttributesColorMatrix (IntPtr imageattr,
1395                                 ColorAdjustType type, bool enableFlag, IntPtr colorMatrix,
1396                                 IntPtr grayMatrix, ColorMatrixFlag flags);
1397
1398                 [DllImport (GdiPlus)]
1399                 internal static extern Status GdipSetImageAttributesGamma (IntPtr imageattr,
1400                         ColorAdjustType type, bool enableFlag,
1401                                                                                                                                                         float gamma);
1402
1403                 [DllImport (GdiPlus)]
1404                 internal static extern Status GdipSetImageAttributesNoOp (IntPtr imageattr,
1405                         ColorAdjustType type, bool enableFlag);
1406
1407                 [DllImport (GdiPlus)]
1408                 internal static extern Status GdipSetImageAttributesOutputChannel (IntPtr imageattr,
1409                         ColorAdjustType type, bool enableFlag,  ColorChannelFlag channelFlags);
1410
1411                 [DllImport (GdiPlus, CharSet=CharSet.Auto)]
1412                 internal static extern Status GdipSetImageAttributesOutputChannelColorProfile (IntPtr imageattr,
1413                         ColorAdjustType type, bool enableFlag, [MarshalAs (UnmanagedType.LPWStr)] string profileName);
1414
1415                 [DllImport (GdiPlus)]
1416                 internal static extern Status GdipSetImageAttributesRemapTable (IntPtr imageattr,
1417                         ColorAdjustType type, bool enableFlag,  uint mapSize, IntPtr colorMap);
1418
1419                 [DllImport (GdiPlus)]
1420                 internal static extern Status GdipSetImageAttributesThreshold (IntPtr imageattr,
1421                         ColorAdjustType type, bool enableFlag, float thresHold);
1422
1423                 [DllImport (GdiPlus)]
1424                 internal static extern Status GdipCloneImageAttributes(IntPtr imageattr, out IntPtr cloneImageattr);
1425
1426                 [DllImport (GdiPlus)]
1427                 internal static extern Status GdipGetImageAttributesAdjustedPalette (IntPtr imageattr, IntPtr colorPalette,
1428                         ColorAdjustType colorAdjustType);
1429
1430                 [DllImport (GdiPlus)]
1431                 internal static extern Status GdipSetImageAttributesWrapMode(IntPtr imageattr, WrapMode wrap,
1432                         int argb, bool clamp);
1433
1434
1435                 // Font
1436                 [DllImport(GdiPlus)]
1437                 internal static extern Status GdipCreateFont (IntPtr fontFamily, float emSize, FontStyle style, GraphicsUnit unit, out IntPtr font);
1438                 [DllImport(GdiPlus)]
1439                 internal static extern Status GdipDeleteFont (IntPtr font);
1440                 [DllImport(GdiPlus, CharSet=CharSet.Auto)]
1441                 internal static extern Status GdipGetLogFont(IntPtr font, IntPtr graphics, [MarshalAs(UnmanagedType.AsAny), Out] object logfontA);
1442
1443                 [DllImport(GdiPlus)]
1444                 internal static extern Status GdipCreateFontFromDC(IntPtr hdc, out IntPtr font);
1445                 [DllImport(GdiPlus, SetLastError=true, CharSet=CharSet.Auto)]
1446                 internal static extern Status GdipCreateFontFromLogfont(IntPtr hdc, ref LOGFONT lf, out IntPtr ptr);
1447
1448                 // These are our private functions, they exists in our own libgdiplus library, this way we
1449                 // avoid relying on wine in System.Drawing
1450                 [DllImport(GdiPlus, CharSet=CharSet.Ansi)]
1451                 internal static extern Status GdipCreateFontFromHfont(IntPtr hdc, out IntPtr font, ref LOGFONT lf);
1452
1453                 // This is win32/gdi, not gdiplus, but it's easier to keep in here, also see above comment
1454                 [DllImport("gdi32.dll", CallingConvention=CallingConvention.StdCall, CharSet = CharSet.Auto)]
1455                 internal static extern IntPtr CreateFontIndirect (ref LOGFONT logfont);
1456                 [DllImport("user32.dll", EntryPoint="GetDC", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
1457                 internal static extern IntPtr GetDC(IntPtr hwnd);
1458                 [DllImport("user32.dll", EntryPoint="ReleaseDC", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
1459                 internal static extern int ReleaseDC (IntPtr hWnd, IntPtr hDC);
1460                 [DllImport("gdi32.dll", EntryPoint="SelectObject", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
1461                 internal static extern IntPtr SelectObject(IntPtr hdc, IntPtr obj);
1462                 [DllImport("user32.dll", SetLastError=true)]
1463                 internal static extern bool GetIconInfo (IntPtr hIcon, out IconInfo iconinfo);
1464                 [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, SetLastError=true)]
1465                 internal static extern IntPtr CreateIconIndirect ([In] ref IconInfo piconinfo);
1466                 [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, SetLastError=true)]
1467                 internal static extern bool DestroyIcon (IntPtr hIcon);
1468                 [DllImport("gdi32.dll")]
1469                 internal static extern bool DeleteObject (IntPtr hObject);
1470                 [DllImport("user32.dll")]
1471                 internal static extern IntPtr GetDesktopWindow ();
1472
1473                 [DllImport("gdi32.dll", SetLastError=true)]
1474                 public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest,
1475                         int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
1476
1477                 [DllImport ("user32.dll", EntryPoint = "GetSysColor", CallingConvention = CallingConvention.StdCall)]
1478                 public static extern uint Win32GetSysColor (GetSysColorIndex index);
1479
1480
1481                 // Some special X11 stuff
1482                 [DllImport("libX11", EntryPoint="XOpenDisplay")]
1483                 internal extern static IntPtr XOpenDisplay(IntPtr display);
1484
1485                 [DllImport("libX11", EntryPoint="XCloseDisplay")]
1486                 internal extern static int XCloseDisplay(IntPtr display);
1487
1488                 [DllImport ("libX11", EntryPoint="XRootWindow")]
1489                 internal extern static IntPtr XRootWindow(IntPtr display, int screen);
1490
1491                 [DllImport ("libX11", EntryPoint="XDefaultScreen")]
1492                 internal extern static int XDefaultScreen(IntPtr display);
1493
1494                 [DllImport ("libX11", EntryPoint="XDefaultDepth")]
1495                 internal extern static uint XDefaultDepth(IntPtr display, int screen);
1496
1497                 [DllImport ("libX11", EntryPoint="XGetImage")]
1498                 internal extern static IntPtr XGetImage(IntPtr display, IntPtr drawable, int src_x, int src_y, int width, int height, int pane, int format);
1499
1500                 [DllImport ("libX11", EntryPoint="XGetPixel")]
1501                 internal extern static int XGetPixel(IntPtr image, int x, int y);
1502
1503                 [DllImport ("libX11", EntryPoint="XDestroyImage")]
1504                 internal extern static int XDestroyImage(IntPtr image);
1505
1506                 [DllImport ("libX11", EntryPoint="XDefaultVisual")]
1507                 internal extern static IntPtr XDefaultVisual(IntPtr display, int screen);
1508
1509                 [DllImport ("libX11", EntryPoint="XGetVisualInfo")]
1510                 internal extern static IntPtr XGetVisualInfo (IntPtr display, int vinfo_mask, ref XVisualInfo vinfo_template, ref int nitems);
1511
1512                 [DllImport ("libX11", EntryPoint="XVisualIDFromVisual")]
1513                 internal extern static IntPtr XVisualIDFromVisual (IntPtr visual);
1514
1515                 [DllImport ("libX11", EntryPoint="XFree")]
1516                 internal extern static void XFree (IntPtr data);
1517
1518                 // FontCollection
1519                 [DllImport (GdiPlus)]
1520                 internal static extern Status GdipGetFontCollectionFamilyCount (IntPtr collection, out int found);
1521
1522                 [DllImport (GdiPlus)]
1523                 internal static extern Status GdipGetFontCollectionFamilyList (IntPtr collection, int getCount, IntPtr[] dest, out int retCount);
1524                 //internal static extern Status GdipGetFontCollectionFamilyList( IntPtr collection, int getCount, [Out] FontFamily [] familyList, out int retCount );
1525
1526                 [DllImport (GdiPlus)]
1527                 internal static extern Status GdipNewInstalledFontCollection (out IntPtr collection);
1528
1529                 [DllImport (GdiPlus)]
1530                 internal static extern Status GdipNewPrivateFontCollection (out IntPtr collection);
1531
1532                 [DllImport (GdiPlus)]
1533                 internal static extern Status GdipDeletePrivateFontCollection (ref IntPtr collection);
1534
1535                 [DllImport (GdiPlus, CharSet=CharSet.Auto)]
1536                 internal static extern Status GdipPrivateAddFontFile (IntPtr collection,
1537                                 [MarshalAs (UnmanagedType.LPWStr)] string fileName );
1538
1539                 [DllImport (GdiPlus)]
1540                 internal static extern Status GdipPrivateAddMemoryFont (IntPtr collection, IntPtr mem, int length);
1541
1542                 //FontFamily
1543                 [DllImport (GdiPlus, CharSet=CharSet.Auto)]
1544                 internal static extern Status GdipCreateFontFamilyFromName (
1545                         [MarshalAs(UnmanagedType.LPWStr)] string fName, IntPtr collection, out IntPtr fontFamily);
1546
1547                 [DllImport (GdiPlus, CharSet=CharSet.Unicode)]
1548                 internal static extern Status GdipGetFamilyName(IntPtr family, StringBuilder name, int language);
1549
1550                 [DllImport (GdiPlus)]
1551                 internal static extern Status GdipGetGenericFontFamilySansSerif (out IntPtr fontFamily);
1552
1553                 [DllImport (GdiPlus)]
1554                 internal static extern Status GdipGetGenericFontFamilySerif (out IntPtr fontFamily);
1555
1556                 [DllImport (GdiPlus)]
1557                 internal static extern Status GdipGetGenericFontFamilyMonospace (out IntPtr fontFamily);
1558
1559                 [DllImport (GdiPlus)]
1560                 internal static extern Status GdipGetCellAscent (IntPtr fontFamily, int style, out short ascent);
1561
1562                 [DllImport (GdiPlus)]
1563                 internal static extern Status GdipGetCellDescent (IntPtr fontFamily, int style, out short descent);
1564
1565                 [DllImport (GdiPlus)]
1566                 internal static extern Status GdipGetLineSpacing (IntPtr fontFamily, int style, out short spacing);
1567
1568                 [DllImport (GdiPlus)]
1569                 internal static extern Status GdipGetEmHeight (IntPtr fontFamily, int style, out short emHeight);
1570
1571                 [DllImport (GdiPlus)]
1572                 internal static extern Status GdipIsStyleAvailable (IntPtr fontFamily, int style, out bool styleAvailable);
1573
1574                 [DllImport (GdiPlus)]
1575                 internal static extern Status GdipDeleteFontFamily (IntPtr fontFamily);
1576
1577                 [DllImport (GdiPlus)]
1578                 internal static extern Status GdipGetFontSize (IntPtr font, out float size);
1579
1580                 [DllImport (GdiPlus)]
1581                 internal static extern Status GdipGetFontHeight (IntPtr font, IntPtr graphics, out float height);
1582
1583                 [DllImport (GdiPlus)]
1584                 internal static extern Status GdipGetFontHeightGivenDPI (IntPtr font, float dpi, out float height);
1585
1586                 [DllImport (GdiPlus)]
1587                 internal static extern Status GdipCloneFontFamily (IntPtr fontFamily, out IntPtr clone);
1588
1589
1590                 // String Format
1591                 [DllImport (GdiPlus)]
1592                 internal static extern Status GdipCreateStringFormat(int formatAttributes, int language, out IntPtr format);
1593                 [DllImport (GdiPlus)]
1594                 internal static extern Status GdipStringFormatGetGenericDefault(out IntPtr format);
1595                 [DllImport (GdiPlus)]
1596                 internal static extern Status GdipStringFormatGetGenericTypographic(out IntPtr format);
1597                 [DllImport (GdiPlus)]
1598                 internal static extern Status GdipDeleteStringFormat(IntPtr format);
1599                 [DllImport (GdiPlus)]
1600                 internal static extern Status GdipCloneStringFormat(IntPtr srcformat, out IntPtr format);
1601                 [DllImport (GdiPlus)]
1602                 internal static extern Status GdipSetStringFormatFlags(IntPtr format, StringFormatFlags flags);
1603                 [DllImport (GdiPlus)]
1604                 internal static extern Status GdipGetStringFormatFlags(IntPtr format, out StringFormatFlags flags);
1605                 [DllImport (GdiPlus)]
1606                 internal static extern Status GdipSetStringFormatAlign(IntPtr format, StringAlignment align);
1607                 [DllImport (GdiPlus)]
1608                 internal static extern Status GdipGetStringFormatAlign(IntPtr format, out StringAlignment align);
1609                 [DllImport (GdiPlus)]
1610                 internal static extern Status GdipSetStringFormatLineAlign(IntPtr format, StringAlignment align);
1611                 [DllImport (GdiPlus)]
1612                 internal static extern Status GdipGetStringFormatLineAlign(IntPtr format, out StringAlignment align);
1613                 [DllImport (GdiPlus)]
1614                 internal static extern Status GdipSetStringFormatTrimming(IntPtr format, StringTrimming trimming);
1615                 [DllImport (GdiPlus)]
1616                 internal static extern Status GdipGetStringFormatTrimming(IntPtr format, out StringTrimming trimming);
1617                 [DllImport (GdiPlus)]
1618                 internal static extern Status GdipSetStringFormatHotkeyPrefix(IntPtr format, HotkeyPrefix hotkeyPrefix);
1619                 [DllImport (GdiPlus)]
1620                 internal static extern Status GdipGetStringFormatHotkeyPrefix(IntPtr format, out HotkeyPrefix hotkeyPrefix);
1621                 [DllImport (GdiPlus)]
1622                 internal static extern Status GdipSetStringFormatTabStops(IntPtr format, float firstTabOffset, int count, float [] tabStops);
1623                 [DllImport (GdiPlus)]
1624                 internal static extern Status GdipGetStringFormatDigitSubstitution(IntPtr format, int language, out StringDigitSubstitute substitute);
1625                 [DllImport (GdiPlus)]
1626                 internal static extern Status GdipSetStringFormatDigitSubstitution(IntPtr format, int language, StringDigitSubstitute substitute);
1627                 [DllImport (GdiPlus)]
1628                 internal static extern Status GdipGetStringFormatTabStopCount(IntPtr format, out int count);
1629                 [DllImport (GdiPlus)]
1630                 internal static extern Status GdipGetStringFormatTabStops(IntPtr format, int count, out float firstTabOffset, [In, Out] float [] tabStops);
1631
1632                 // metafile
1633                 [DllImport (GdiPlus, CharSet = CharSet.Auto)]
1634                 internal static extern Status GdipCreateMetafileFromFile ([MarshalAs (UnmanagedType.LPWStr)] string filename, out IntPtr metafile);
1635                 [DllImport (GdiPlus)]
1636                 internal static extern Status GdipCreateMetafileFromEmf (IntPtr hEmf, bool deleteEmf, out IntPtr metafile);
1637                 [DllImport (GdiPlus)]
1638                 internal static extern Status GdipCreateMetafileFromWmf (IntPtr hWmf, bool deleteWmf, WmfPlaceableFileHeader wmfPlaceableFileHeader, out IntPtr metafile);
1639                 [DllImport (GdiPlus, CharSet = CharSet.Auto)]
1640                 internal static extern Status GdipGetMetafileHeaderFromFile ([MarshalAs (UnmanagedType.LPWStr)] string filename, IntPtr header);
1641                 [DllImport (GdiPlus)]
1642                 internal static extern Status GdipGetMetafileHeaderFromMetafile (IntPtr metafile, IntPtr header);
1643                 [DllImport (GdiPlus)]
1644                 internal static extern Status GdipGetMetafileHeaderFromEmf (IntPtr hEmf, IntPtr header);
1645                 [DllImport (GdiPlus)]
1646                 internal static extern Status GdipGetMetafileHeaderFromWmf (IntPtr hWmf, IntPtr wmfPlaceableFileHeader, IntPtr header);
1647                 [DllImport (GdiPlus)]
1648                 internal static extern Status GdipGetHemfFromMetafile (IntPtr metafile, out IntPtr hEmf);
1649                 [DllImport (GdiPlus)]
1650                 internal static extern Status GdipGetMetafileDownLevelRasterizationLimit (IntPtr metafile, ref uint metafileRasterizationLimitDpi);
1651                 [DllImport (GdiPlus)]
1652                 internal static extern Status GdipSetMetafileDownLevelRasterizationLimit (IntPtr metafile, uint metafileRasterizationLimitDpi);
1653                 [DllImport (GdiPlus)]
1654                 internal static extern Status GdipPlayMetafileRecord (IntPtr metafile, EmfPlusRecordType recordType, int flags, int dataSize, byte[] data);
1655
1656                 [DllImport (GdiPlus)]
1657                 internal static extern Status GdipRecordMetafile (IntPtr hdc, EmfType type, ref RectangleF frameRect,
1658                         MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
1659                 [DllImport (GdiPlus)]
1660                 internal static extern Status GdipRecordMetafileI (IntPtr hdc, EmfType type, ref Rectangle frameRect,
1661                         MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
1662                 [DllImport (GdiPlus)]
1663                 internal static extern Status GdipRecordMetafileFileName ([MarshalAs (UnmanagedType.LPWStr)] string filename, IntPtr hdc, EmfType type,
1664                         ref RectangleF frameRect, MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
1665                 [DllImport (GdiPlus)]
1666                 internal static extern Status GdipRecordMetafileFileNameI ([MarshalAs (UnmanagedType.LPWStr)] string filename, IntPtr hdc, EmfType type,
1667                         ref Rectangle frameRect, MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
1668 #if !TEST
1669                 [DllImport(GdiPlus, ExactSpelling=true, CharSet=CharSet.Unicode)]
1670                 internal static extern Status GdipCreateMetafileFromStream([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))] IStream stream, out IntPtr metafile);
1671                 [DllImport(GdiPlus, ExactSpelling=true, CharSet=CharSet.Unicode)]
1672                 internal static extern Status GdipGetMetafileHeaderFromStream([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))] IStream stream, IntPtr header);
1673
1674                 [DllImport (GdiPlus)]
1675                 internal static extern Status GdipRecordMetafileStream ([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))] IStream stream, IntPtr hdc,
1676                         EmfType type, ref RectangleF frameRect, MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
1677                 [DllImport (GdiPlus)]
1678                 internal static extern Status GdipRecordMetafileStreamI ([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))] IStream stream, IntPtr hdc,
1679                         EmfType type, ref Rectangle frameRect, MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
1680 #endif
1681                 //ImageCodecInfo functions
1682                 [DllImport(GdiPlus)]
1683                 static internal extern Status GdipGetImageDecodersSize (out int decoderNums, out int arraySize);
1684                 [DllImport(GdiPlus)]
1685                 static internal extern Status GdipGetImageDecoders (int decoderNums, int arraySize, IntPtr decoders);
1686                 [DllImport(GdiPlus)]
1687                 static internal extern Status GdipGetImageEncodersSize (out int encoderNums, out int arraySize);
1688                 [DllImport(GdiPlus)]
1689                 static internal extern Status GdipGetImageEncoders (int encoderNums, int arraySize, IntPtr encoders);
1690
1691                 //
1692                 // These are stuff that is unix-only
1693                 //
1694                 public delegate int StreamGetHeaderDelegate(IntPtr buf, int bufsz);
1695                 public delegate int StreamGetBytesDelegate (IntPtr buf, int bufsz, bool peek);
1696                 public delegate long StreamSeekDelegate (int offset, int whence);
1697                 public delegate int StreamPutBytesDelegate (IntPtr buf, int bufsz);
1698                 public delegate void StreamCloseDelegate ();
1699                 public delegate long StreamSizeDelegate ();
1700
1701                 internal sealed class GdiPlusStreamHelper {
1702                         public Stream stream;
1703
1704                         private StreamGetHeaderDelegate sghd = null;
1705                         private StreamGetBytesDelegate sgbd = null;
1706                         private StreamSeekDelegate skd = null;
1707                         private StreamPutBytesDelegate spbd = null;
1708                         private StreamCloseDelegate scd = null;
1709                         private StreamSizeDelegate ssd = null;
1710                         private byte[]  start_buf;
1711                         private int     start_buf_pos;
1712                         private int     start_buf_len;
1713                         private byte[] managedBuf;
1714                         private const int default_bufsize = 4096;
1715
1716                         public GdiPlusStreamHelper (Stream s, bool seekToOrigin)
1717                         {
1718                                 managedBuf = new byte [default_bufsize];
1719
1720                                 stream = s;
1721                                 if (stream != null && stream.CanSeek && seekToOrigin) {
1722                                         stream.Seek (0, SeekOrigin.Begin);
1723                                 }
1724                         }
1725
1726                         public int StreamGetHeaderImpl (IntPtr buf, int bufsz) {
1727                                 int     bytesRead;
1728
1729                                 start_buf = new byte[bufsz];
1730
1731                                 try {
1732                                         bytesRead = stream.Read (start_buf, 0, bufsz);
1733                                 } catch (IOException) {
1734                                         return -1;
1735                                 }
1736
1737                                 if (bytesRead > 0 && buf != IntPtr.Zero) {
1738                                         Marshal.Copy (start_buf, 0, (IntPtr) (buf.ToInt64()), bytesRead);
1739                                 }
1740
1741                                 start_buf_pos = 0;
1742                                 start_buf_len = bytesRead;
1743
1744                                 return bytesRead;
1745                         }
1746
1747                         public StreamGetHeaderDelegate GetHeaderDelegate {
1748                                 get {
1749                                         if (stream != null && stream.CanRead) {
1750                                                 if (sghd == null) {
1751                                                         sghd = new StreamGetHeaderDelegate (StreamGetHeaderImpl);
1752                                                 }
1753                                                 return sghd;
1754                                         }
1755                                         return null;
1756                                 }
1757                         }
1758
1759                         public int StreamGetBytesImpl (IntPtr buf, int bufsz, bool peek)
1760                         {
1761                                 if (buf == IntPtr.Zero && peek) {
1762                                         return -1;
1763                                 }
1764
1765                                 if (bufsz > managedBuf.Length)
1766                                         managedBuf = new byte[bufsz];
1767                                 int bytesRead = 0;
1768                                 long streamPosition = 0;
1769
1770                                 if (bufsz > 0) {
1771                                         if (stream.CanSeek) {
1772                                                 streamPosition = stream.Position;
1773                                         }
1774                                         if (start_buf_len > 0) {
1775                                                 if (start_buf_len > bufsz) {
1776                                                         Array.Copy(start_buf, start_buf_pos, managedBuf, 0, bufsz);
1777                                                         start_buf_pos += bufsz;
1778                                                         start_buf_len -= bufsz;
1779                                                         bytesRead = bufsz;
1780                                                         bufsz = 0;
1781                                                 } else {
1782                                                         // this is easy
1783                                                         Array.Copy(start_buf, start_buf_pos, managedBuf, 0, start_buf_len);
1784                                                         bufsz -= start_buf_len;
1785                                                         bytesRead = start_buf_len;
1786                                                         start_buf_len = 0;
1787                                                 }
1788                                         }
1789
1790                                         if (bufsz > 0) {
1791                                                 try {
1792                                                         bytesRead += stream.Read (managedBuf, bytesRead, bufsz);
1793                                                 } catch (IOException) {
1794                                                         return -1;
1795                                                 }
1796                                         }
1797
1798                                         if (bytesRead > 0 && buf != IntPtr.Zero) {
1799                                                 Marshal.Copy (managedBuf, 0, (IntPtr) (buf.ToInt64()), bytesRead);
1800                                         }
1801
1802                                         if (!stream.CanSeek && (bufsz == 10) && peek) {
1803                                                 // Special 'hack' to support peeking of the type for gdi+ on non-seekable streams
1804                                         }
1805
1806                                         if (peek) {
1807                                                 if (stream.CanSeek) {
1808                                                         // If we are peeking bytes, then go back to original position before peeking
1809                                                         stream.Seek (streamPosition, SeekOrigin.Begin);
1810                                                 } else {
1811                                                         throw new NotSupportedException();
1812                                                 }
1813                                         }
1814                                 }
1815
1816                                 return bytesRead;
1817                         }
1818
1819                         public StreamGetBytesDelegate GetBytesDelegate {
1820                                 get {
1821                                         if (stream != null && stream.CanRead) {
1822                                                 if (sgbd == null) {
1823                                                         sgbd = new StreamGetBytesDelegate (StreamGetBytesImpl);
1824                                                 }
1825                                                 return sgbd;
1826                                         }
1827                                         return null;
1828                                 }
1829                         }
1830
1831                         public long StreamSeekImpl (int offset, int whence)
1832                         {
1833                                 // Make sure we have a valid 'whence'.
1834                                 if ((whence < 0) || (whence > 2))
1835                                         return -1;
1836
1837                                 // Invalidate the start_buf if we're actually going to call a Seek method.
1838                                 start_buf_pos += start_buf_len;
1839                                 start_buf_len = 0;
1840
1841                                 SeekOrigin origin;
1842
1843                                 // Translate 'whence' into a SeekOrigin enum member.
1844                                 switch (whence)
1845                                 {
1846                                         case 0: origin = SeekOrigin.Begin;   break;
1847                                         case 1: origin = SeekOrigin.Current; break;
1848                                         case 2: origin = SeekOrigin.End;     break;
1849
1850                                         // The following line is redundant but necessary to avoid a
1851                                         // "Use of unassigned local variable" error without actually
1852                                         // initializing 'origin' to a dummy value.
1853                                         default: return -1;
1854                                 }
1855
1856                                 // Do the actual seek operation and return its result.
1857                                 return stream.Seek ((long) offset, origin);
1858                         }
1859
1860                         public StreamSeekDelegate SeekDelegate {
1861                                 get {
1862                                         if (stream != null && stream.CanSeek) {
1863                                                 if (skd == null) {
1864                                                         skd = new StreamSeekDelegate (StreamSeekImpl);
1865                                                 }
1866                                                 return skd;
1867                                         }
1868                                         return null;
1869                                 }
1870                         }
1871
1872                         public int StreamPutBytesImpl (IntPtr buf, int bufsz)
1873                         {
1874                                 if (bufsz > managedBuf.Length)
1875                                         managedBuf = new byte[bufsz];
1876                                 Marshal.Copy (buf, managedBuf, 0, bufsz);
1877                                 stream.Write (managedBuf, 0, bufsz);
1878                                 return bufsz;
1879                         }
1880
1881                         public StreamPutBytesDelegate PutBytesDelegate {
1882                                 get {
1883                                         if (stream != null && stream.CanWrite) {
1884                                                 if (spbd == null) {
1885                                                         spbd = new StreamPutBytesDelegate (StreamPutBytesImpl);
1886                                                 }
1887                                                 return spbd;
1888                                         }
1889                                         return null;
1890                                 }
1891                         }
1892
1893                         public void StreamCloseImpl ()
1894                         {
1895                                 stream.Close ();
1896                         }
1897
1898                         public StreamCloseDelegate CloseDelegate {
1899                                 get {
1900                                         if (stream != null) {
1901                                                 if (scd == null) {
1902                                                         scd = new StreamCloseDelegate (StreamCloseImpl);
1903                                                 }
1904                                                 return scd;
1905                                         }
1906                                         return null;
1907                                 }
1908                         }
1909
1910                         public long StreamSizeImpl ()
1911                         {
1912                                 try {
1913                                         return stream.Length;
1914                                 } catch {
1915                                         return -1;
1916                                 }
1917                         }
1918
1919                         public StreamSizeDelegate SizeDelegate {
1920                                 get {
1921                                         if (stream != null) {
1922                                                 if (ssd == null) {
1923                                                         ssd = new StreamSizeDelegate (StreamSizeImpl);
1924                                                 }
1925                                                 return ssd;
1926                                         }
1927                                         return null;
1928                                 }
1929                         }
1930
1931                 }
1932
1933                 /* Mac only function calls */
1934                 [DllImport(GdiPlus)]
1935                 internal static extern Status GdipCreateFromContext_macosx (IntPtr cgref, int width, int height, out IntPtr graphics);
1936
1937                 /* Linux only function calls*/
1938                 [DllImport(GdiPlus)]
1939                 internal static extern Status GdipSetVisibleClip_linux (IntPtr graphics, ref Rectangle rect);
1940
1941                 [DllImport(GdiPlus)]
1942                 internal static extern Status GdipCreateFromXDrawable_linux (IntPtr drawable, IntPtr display, out IntPtr graphics);
1943
1944                 // Stream functions for non-Win32 (libgdiplus specific)
1945                 [DllImport(GdiPlus)]
1946                 static internal extern Status GdipLoadImageFromDelegate_linux (StreamGetHeaderDelegate getHeader,
1947                         StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek,
1948                         StreamCloseDelegate close, StreamSizeDelegate size, out IntPtr image);
1949
1950                 [DllImport(GdiPlus)]
1951                 static internal extern Status GdipSaveImageToDelegate_linux (IntPtr image, StreamGetBytesDelegate getBytes,
1952                         StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, StreamCloseDelegate close,
1953                         StreamSizeDelegate size, ref Guid encoderClsID, IntPtr encoderParameters);
1954
1955                 [DllImport(GdiPlus)]
1956                 static internal extern Status GdipCreateMetafileFromDelegate_linux (StreamGetHeaderDelegate getHeader,
1957                         StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek,
1958                         StreamCloseDelegate close, StreamSizeDelegate size, out IntPtr metafile);
1959
1960                 [DllImport(GdiPlus)]
1961                 static internal extern Status GdipGetMetafileHeaderFromDelegate_linux (StreamGetHeaderDelegate getHeader,
1962                         StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek,
1963                         StreamCloseDelegate close, StreamSizeDelegate size, IntPtr header);
1964
1965                 [DllImport(GdiPlus)]
1966                 static internal extern Status GdipRecordMetafileFromDelegate_linux (StreamGetHeaderDelegate getHeader,
1967                         StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek,
1968                         StreamCloseDelegate close, StreamSizeDelegate size, IntPtr hdc, EmfType type, ref RectangleF frameRect,
1969                         MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
1970
1971                 [DllImport(GdiPlus)]
1972                 static internal extern Status GdipRecordMetafileFromDelegateI_linux (StreamGetHeaderDelegate getHeader,
1973                         StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek,
1974                         StreamCloseDelegate close, StreamSizeDelegate size, IntPtr hdc, EmfType type, ref Rectangle frameRect,
1975                         MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
1976
1977                 [DllImport ("libc")]
1978                 static extern int uname (IntPtr buf);
1979 #endregion
1980         }
1981 }