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