Merge branch 'master' of github.com:mono/mono into masterwork
[mono.git] / mcs / class / System.Drawing / System.Drawing / gdipFunctions.cs
index b386f461ea983907f48ab885d164db5395932e76..cf48ecd6ec821f2215a8582868eec23b668c0c8f 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.IO;
 using System.Runtime.InteropServices;
 using System.Text;
 using System.Drawing.Drawing2D;
 using System.Drawing.Imaging;
 using System.Drawing.Text;
+using System.Globalization;
 using System.Security;
 #if NET_2_0
 using System.Runtime.InteropServices.ComTypes;
@@ -51,14 +51,17 @@ namespace System.Drawing
        /// GDI+ API Functions
        /// </summary>
        [SuppressUnmanagedCodeSecurity]
-       internal class GDIPlus
-       {
+#if NET_2_0
+       internal static class GDIPlus {
+#else
+       internal class GDIPlus {
+#endif
                public const int FACESIZE = 32;
                public const int LANG_NEUTRAL = 0;
                public static IntPtr Display = IntPtr.Zero;
-               public static bool UseX11Drawable;
-               public static bool UseQuartzDrawable = (Environment.GetEnvironmentVariable ("MONO_MWF_USE_QUARTZ_BACKEND") != null);
-               public static bool UseCocoaDrawable = (Environment.GetEnvironmentVariable ("MONO_GDIP_USE_COCOA_BACKEND") != null);
+               public static bool UseX11Drawable = false;
+               public static bool UseCarbonDrawable = false;
+               public static bool UseCocoaDrawable = false;
 
                #region gdiplus.dll functions
 
@@ -76,30 +79,47 @@ namespace System.Drawing
                        // shutting down
                        GC.Collect ();  
                        GC.WaitForPendingFinalizers ();
-                       
+#if false                      
                        GdiPlusToken = 0;
 
-                       // This causes crashes in MS GDI+ because this call occurs before
-                       // all managed GDI objects are finalized. When they are finalized they call
-                       // into a shutdown GDI+ and we crash.
-                       //GdiplusShutdown (ref GdiPlusToken);
+                       // This causes crashes in because this call occurs before all
+                       // managed GDI+ objects are finalized. When they are finalized 
+                       // they call into a shutdown GDI+ and we crash.
+                       GdiplusShutdown (ref GdiPlusToken);
 
                        // This causes crashes in Mono libgdiplus because this call
                        // occurs before all managed GDI objects are finalized
                        // When they are finalized they use the closed display and
                        // crash
-                       //if (UseX11Drawable && Display != IntPtr.Zero) {
-                       //      XCloseDisplay (Display);
-                       //}
-
+                       if (UseX11Drawable && Display != IntPtr.Zero) {
+                               XCloseDisplay (Display);
+                       }
+#endif
                }
 
                static GDIPlus ()
                {
-                       // check for Unix platforms - see FAQ for more details
-                       // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
                        int platform = (int) Environment.OSVersion.Platform;
-                       UseX11Drawable = ((platform == 4) || (platform == 128));
+                       if ((platform == 4) || (platform == 6) || (platform == 128)) {
+                               if (Environment.GetEnvironmentVariable ("not_supported_MONO_MWF_USE_NEW_X11_BACKEND") != null || Environment.GetEnvironmentVariable ("MONO_MWF_MAC_FORCE_X11") != null) {
+                                       UseX11Drawable = true;
+                               } else {
+                                       IntPtr buf = Marshal.AllocHGlobal (8192);
+                                       // This is kind of a hack but gets us sysname from uname (struct utsname *name) on
+                                       // linux and darwin
+                                       if (uname (buf) != 0) {
+                                               // WTH: We couldn't detect the OS; lets default to X11
+                                               UseX11Drawable = true;
+                                       } else {
+                                               string os = Marshal.PtrToStringAnsi (buf);
+                                               if (os == "Darwin")
+                                                       UseCarbonDrawable = true;
+                                               else
+                                                       UseX11Drawable = true;
+                                       }
+                                       Marshal.FreeHGlobal (buf);
+                               }
+                       }
 
                        GdiplusStartupInput input = GdiplusStartupInput.MakeGdiplusStartupInput();
                        GdiplusStartupOutput output = GdiplusStartupOutput.MakeGdiplusStartupOutput();
@@ -108,54 +128,55 @@ namespace System.Drawing
                        }
                        catch (TypeInitializationException) {
                                Console.Error.WriteLine (
-                                       "* ERROR: Can not initialize GDI+ library\n" +
-                                       "\n" +
-                                       "Please check http://www.mono-project.com/Problem:GDIPlusInit for details");
+                                       "* ERROR: Can not initialize GDI+ library{0}{0}" +
+                                       "Please check http://www.mono-project.com/Problem:GDIPlusInit for details",
+                                       Environment.NewLine);
                        }
-                       
+
+                       // under MS 1.x this event is raised only for the default application domain
                        AppDomain.CurrentDomain.ProcessExit += new EventHandler (ProcessExit);
                }
 
                static public bool RunningOnWindows ()
                {
-                       return !UseX11Drawable;
+                       return !UseX11Drawable && !UseCarbonDrawable && !UseCocoaDrawable;
                }
 
                static public bool RunningOnUnix ()
                {
-                       return UseX11Drawable;
+                       return UseX11Drawable || UseCarbonDrawable || UseCocoaDrawable;
                }
                
                // Copies a Ptr to an array of Points and releases the memory
-               static public void FromUnManagedMemoryToPointI(IntPtr prt, Point [] pts)
+               static public void FromUnManagedMemoryToPointI (IntPtr prt, Point [] pts)
                {                                               
-                       int nPointSize = Marshal.SizeOf(pts[0]);
+                       int nPointSize = Marshal.SizeOf (pts[0]);
                        IntPtr pos = prt;
                        for (int i=0; i<pts.Length; i++, pos = new IntPtr (pos.ToInt64 () + nPointSize))
-                               pts[i] = (Point) Marshal.PtrToStructure(pos, typeof(Point));
+                               pts[i] = (Point) Marshal.PtrToStructure (pos, typeof (Point));
                        
-                       Marshal.FreeHGlobal(prt);                       
+                       Marshal.FreeHGlobal (prt);                      
                }
                
                // Copies a Ptr to an array of Points and releases the memory
                static public void FromUnManagedMemoryToPoint (IntPtr prt, PointF [] pts)
                {                                               
-                       int nPointSize = Marshal.SizeOf(pts[0]);
+                       int nPointSize = Marshal.SizeOf (pts[0]);
                        IntPtr pos = prt;
                        for (int i=0; i<pts.Length; i++, pos = new IntPtr (pos.ToInt64 () + nPointSize))
-                               pts[i] = (PointF) Marshal.PtrToStructure(pos, typeof(Point));
+                               pts[i] = (PointF) Marshal.PtrToStructure (pos, typeof (PointF));
                        
-                       Marshal.FreeHGlobal(prt);                       
+                       Marshal.FreeHGlobal (prt);                      
                }
                
                // Copies an array of Points to unmanaged memory
-               static public IntPtr FromPointToUnManagedMemoryI(Point [] pts)
+               static public IntPtr FromPointToUnManagedMemoryI (Point [] pts)
                {
-                       int nPointSize =  Marshal.SizeOf(pts[0]);
-                       IntPtr dest = Marshal.AllocHGlobal(nPointSize* pts.Length);
+                       int nPointSize =  Marshal.SizeOf (pts[0]);
+                       IntPtr dest = Marshal.AllocHGlobal (nPointSize * pts.Length);
                        IntPtr pos = dest;
                        for (int i=0; i<pts.Length; i++, pos = new IntPtr (pos.ToInt64 () + nPointSize))
-                               Marshal.StructureToPtr(pts[i], pos, false);     
+                               Marshal.StructureToPtr (pts[i], pos, false);    
                        
                        return dest;                    
                }               
@@ -166,78 +187,79 @@ namespace System.Drawing
                        int nPointSize = Marshal.SizeOf (pts[0]);
                        IntPtr pos = prt;
                        for (int i = 0; i < pts.Length; i++, pos = new IntPtr (pos.ToInt64 () + nPointSize))
-                               pts[i] = (RectangleF) Marshal.PtrToStructure(pos, typeof(RectangleF));
+                               pts[i] = (RectangleF) Marshal.PtrToStructure (pos, typeof (RectangleF));
                        
-                       Marshal.FreeHGlobal(prt);                       
+                       Marshal.FreeHGlobal (prt);                      
                }
                
                // Copies an array of Points to unmanaged memory
-               static public IntPtr FromPointToUnManagedMemory(PointF [] pts)
+               static public IntPtr FromPointToUnManagedMemory (PointF [] pts)
                {
-                       int nPointSize =  Marshal.SizeOf(pts[0]);
-                       IntPtr dest = Marshal.AllocHGlobal(nPointSize* pts.Length);                     
+                       int nPointSize =  Marshal.SizeOf (pts[0]);
+                       IntPtr dest = Marshal.AllocHGlobal (nPointSize * pts.Length);                   
                        IntPtr pos = dest;
                        for (int i=0; i<pts.Length; i++, pos = new IntPtr (pos.ToInt64 () + nPointSize))
-                               Marshal.StructureToPtr(pts[i], pos, false);     
+                               Marshal.StructureToPtr (pts[i], pos, false);    
                        
                        return dest;                    
                }
 
                // Converts a status into exception
+               // TODO: Add more status code mappings here
                static internal void CheckStatus (Status status)
                {
+                       string msg;
                        switch (status) {
-
-                               case Status.Ok:
-                                       return;
-
-                               // TODO: Add more status code mappings here
-
-                               case Status.GenericError:
-                                       throw new Exception ("Generic Error.");
-
-                               case Status.InvalidParameter:
-                                       throw new ArgumentException ("Invalid Parameter. A null reference or invalid value was found.");
-
-                               case Status.OutOfMemory:
-                                       throw new OutOfMemoryException ("Out of memory.");
-
-                               case Status.ObjectBusy:
-                                       throw new MemberAccessException ("Object busy.");
-
-                               case Status.InsufficientBuffer:
-                                       throw new IO.InternalBufferOverflowException ("Insufficient buffer.");
-
-                               case Status.PropertyNotSupported:
-                                       throw new NotSupportedException ("Property not supported.");
-
-                               case Status.FileNotFound:
-                                       throw new IO.FileNotFoundException ("File not found.");
-
-                               case Status.AccessDenied:
-                                       throw new UnauthorizedAccessException ("Access denied.");
-
-                               case Status.UnknownImageFormat:
-                                       throw new NotSupportedException ("Either image format is unknown or you don't have the required libraries for this format.");
-
-                               case Status.NotImplemented:
-                                       throw new NotImplementedException ("Feature not implemented.");
-
-                               case Status.WrongState:
-                                       throw new ArgumentException ("Properties not set properly.");
-
-                               case Status.FontFamilyNotFound:
-                                       throw new ArgumentException ("FontFamily wasn't found.");
-
-                               case Status.ValueOverflow:
-                                       throw new OverflowException ("Argument out of range.");
-
-                               default:
-                                       throw new Exception ("Unknown Error.");
+                       case Status.Ok:
+                               return;
+                       case Status.GenericError:
+                               msg = Locale.GetText ("Generic Error [GDI+ status: {0}]", status);
+                               throw new Exception (msg);
+                       case Status.InvalidParameter:
+                               msg = Locale.GetText ("A null reference or invalid value was found [GDI+ status: {0}]", status);
+                               throw new ArgumentException (msg);
+                       case Status.OutOfMemory:
+                               msg = Locale.GetText ("Not enough memory to complete operation [GDI+ status: {0}]", status);
+                               throw new OutOfMemoryException (msg);
+                       case Status.ObjectBusy:
+                               msg = Locale.GetText ("Object is busy and cannot state allow this operation [GDI+ status: {0}]", status);
+                               throw new MemberAccessException (msg);
+                       case Status.InsufficientBuffer:
+                               msg = Locale.GetText ("Insufficient buffer provided to complete operation [GDI+ status: {0}]", status);
+                               throw new InternalBufferOverflowException (msg);
+                       case Status.PropertyNotSupported:
+                               msg = Locale.GetText ("Property not supported [GDI+ status: {0}]", status);
+                               throw new NotSupportedException (msg);
+                       case Status.FileNotFound:
+                               msg = Locale.GetText ("Requested file was not found [GDI+ status: {0}]", status);
+                               throw new FileNotFoundException (msg);
+                       case Status.AccessDenied:
+                               msg = Locale.GetText ("Access to resource was denied [GDI+ status: {0}]", status);
+                               throw new UnauthorizedAccessException (msg);
+                       case Status.UnknownImageFormat:
+                               msg = Locale.GetText ("Either the image format is unknown or you don't have the required libraries to decode this format [GDI+ status: {0}]", status);
+                               throw new NotSupportedException (msg);
+                       case Status.NotImplemented:
+                               msg = Locale.GetText ("The requested feature is not implemented [GDI+ status: {0}]", status);
+                               throw new NotImplementedException (msg);
+                       case Status.WrongState:
+                               msg = Locale.GetText ("Object is not in a state that can allow this operation [GDI+ status: {0}]", status);
+                               throw new ArgumentException (msg);
+                       case Status.FontFamilyNotFound:
+                               msg = Locale.GetText ("The requested FontFamily could not be found [GDI+ status: {0}]", status);
+                               throw new ArgumentException (msg);
+                       case Status.ValueOverflow:
+                               msg = Locale.GetText ("Argument is out of range [GDI+ status: {0}]", status);
+                               throw new OverflowException (msg);
+                       case Status.Win32Error:
+                               msg = Locale.GetText ("The operation is invalid [GDI+ status: {0}]", status);
+                               throw new InvalidOperationException (msg);
+                       default:
+                               msg = Locale.GetText ("Unknown Error [GDI+ status: {0}]", status);
+                               throw new Exception (msg);
                        }
                }
                
-               
                // Memory functions
                [DllImport("gdiplus.dll")]
                static internal extern IntPtr GdipAlloc (int size);
@@ -782,9 +804,9 @@ namespace System.Drawing
                                
                // Pen functions
                [DllImport("gdiplus.dll")]
-               internal static extern Status GdipCreatePen1 (int argb, float width, Unit unit, out IntPtr pen);
+               internal static extern Status GdipCreatePen1 (int argb, float width, GraphicsUnit unit, out IntPtr pen);
                [DllImport("gdiplus.dll")]
-               internal static extern Status GdipCreatePen2 (IntPtr brush, float width, Unit unit, out IntPtr pen);
+               internal static extern Status GdipCreatePen2 (IntPtr brush, float width, GraphicsUnit unit, out IntPtr pen);
                 [DllImport("gdiplus.dll")]
                 internal static extern Status GdipClonePen (IntPtr pen, out IntPtr clonepen);
                [DllImport("gdiplus.dll")]
@@ -925,9 +947,9 @@ namespace System.Drawing
                internal static extern Status GdipCreateFromHWND (IntPtr hwnd, out IntPtr graphics);
 
                [DllImport("gdiplus.dll", CharSet=CharSet.Unicode)]
-               internal static extern Status GdipMeasureString(IntPtr graphics, string str, int length, IntPtr font,
-                ref RectangleF layoutRect, IntPtr stringFormat, out RectangleF boundingBox, out int codepointsFitted,
-                               out int linesFilled);                                           
+               internal unsafe static extern Status GdipMeasureString(IntPtr graphics, string str, int length,
+                       IntPtr font, ref RectangleF layoutRect, IntPtr stringFormat, out RectangleF boundingBox,
+                       int *codepointsFitted, int *linesFilled);
                                
                [DllImport("gdiplus.dll", CharSet=CharSet.Unicode)]
                internal static extern Status GdipMeasureCharacterRanges (IntPtr graphics, string str, int length, IntPtr font,
@@ -1067,7 +1089,7 @@ namespace System.Drawing
                internal static extern Status GdipRemovePropertyItem (IntPtr image, int propertyId);
                
                [DllImport("gdiplus.dll")]
-               internal static extern Status GdipSetPropertyItem (IntPtr image, IntPtr propertyItem);
+               internal unsafe static extern Status GdipSetPropertyItem (IntPtr image, GdipPropertyItem *propertyItem);
                
                [DllImport("gdiplus.dll")]
                internal static extern Status GdipGetImageThumbnail ( IntPtr image, uint width, uint height, out IntPtr thumbImage, IntPtr callback, IntPtr callBackData );
@@ -1408,8 +1430,8 @@ namespace System.Drawing
                internal static extern Status GdipCloneImageAttributes(IntPtr imageattr, out IntPtr cloneImageattr);
 
                [DllImport ("gdiplus.dll")]     
-               internal static extern Status GdipGetImageAttributesAdjustedPalette(IntPtr imageattr,
-                       out IntPtr colorPalette,  ColorAdjustType colorAdjustType);
+               internal static extern Status GdipGetImageAttributesAdjustedPalette (IntPtr imageattr, IntPtr colorPalette,
+                       ColorAdjustType colorAdjustType);
                        
                [DllImport ("gdiplus.dll")]     
                internal static extern Status GdipSetImageAttributesWrapMode(IntPtr imageattr,  WrapMode wrap,
@@ -1431,8 +1453,6 @@ namespace System.Drawing
 
                // These are our private functions, they exists in our own libgdiplus library, this way we
                // avoid relying on wine in System.Drawing
-               [DllImport("gdiplus.dll")]
-               internal static extern Status GdipGetHfont (IntPtr font, out IntPtr Hfont);     
                [DllImport("gdiplus.dll", CharSet=CharSet.Ansi)]                   
                internal static extern Status GdipCreateFontFromHfont(IntPtr hdc, out IntPtr font, ref LOGFONT lf);
 
@@ -1451,7 +1471,8 @@ namespace System.Drawing
                internal static extern IntPtr CreateIconIndirect ([In] ref IconInfo piconinfo);
                [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, SetLastError=true)]
                internal static extern bool DestroyIcon (IntPtr hIcon);
+               [DllImport("gdi32.dll")]
+               internal static extern bool DeleteObject (IntPtr hObject);
                [DllImport("user32.dll")]
                internal static extern IntPtr GetDesktopWindow ();
 
@@ -1459,6 +1480,9 @@ namespace System.Drawing
                public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, 
                        int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
 
+               [DllImport ("user32.dll", EntryPoint = "GetSysColor", CallingConvention = CallingConvention.StdCall)]
+               public static extern uint Win32GetSysColor (GetSysColorIndex index);
+
 
                // Some special X11 stuff
                [DllImport("libX11", EntryPoint="XOpenDisplay")]
@@ -1470,6 +1494,9 @@ namespace System.Drawing
                [DllImport ("libX11", EntryPoint="XRootWindow")]
                internal extern static IntPtr XRootWindow(IntPtr display, int screen);
                        
+               [DllImport ("libX11", EntryPoint="XDefaultScreen")]
+               internal extern static int XDefaultScreen(IntPtr display);
+
                [DllImport ("libX11", EntryPoint="XDefaultDepth")]
                internal extern static uint XDefaultDepth(IntPtr display, int screen);
 
@@ -1489,7 +1516,7 @@ namespace System.Drawing
                internal extern static IntPtr XGetVisualInfo (IntPtr display, int vinfo_mask, ref XVisualInfo vinfo_template, ref int nitems);
 
                [DllImport ("libX11", EntryPoint="XVisualIDFromVisual")]
-               internal extern static int XVisualIDFromVisual(IntPtr visual);
+               internal extern static IntPtr XVisualIDFromVisual (IntPtr visual);
 
                [DllImport ("libX11", EntryPoint="XFree")]
                internal extern static void XFree (IntPtr data);        
@@ -1561,6 +1588,9 @@ namespace System.Drawing
                
                [DllImport ("gdiplus.dll")]
                internal static extern Status GdipGetFontHeightGivenDPI (IntPtr font, float dpi, out float height);
+
+               [DllImport ("gdiplus.dll")]
+               internal static extern Status GdipCloneFontFamily (IntPtr fontFamily, out IntPtr clone);
                
                
                // String Format
@@ -1628,11 +1658,31 @@ namespace System.Drawing
                internal static extern Status GdipSetMetafileDownLevelRasterizationLimit (IntPtr metafile, uint metafileRasterizationLimitDpi);
                [DllImport ("gdiplus.dll")]
                internal static extern Status GdipPlayMetafileRecord (IntPtr metafile, EmfPlusRecordType recordType, int flags, int dataSize, byte[] data);
+
+               [DllImport ("gdiplus.dll")]
+               internal static extern Status GdipRecordMetafile (IntPtr hdc, EmfType type, ref RectangleF frameRect, 
+                       MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
+               [DllImport ("gdiplus.dll")]
+               internal static extern Status GdipRecordMetafileI (IntPtr hdc, EmfType type, ref Rectangle frameRect, 
+                       MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
+               [DllImport ("gdiplus.dll")]
+               internal static extern Status GdipRecordMetafileFileName ([MarshalAs (UnmanagedType.LPWStr)] string filename, IntPtr hdc, EmfType type,
+                       ref RectangleF frameRect, MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
+               [DllImport ("gdiplus.dll")]
+               internal static extern Status GdipRecordMetafileFileNameI ([MarshalAs (UnmanagedType.LPWStr)] string filename, IntPtr hdc, EmfType type,
+                       ref Rectangle frameRect, MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
 #if !TEST
                [DllImport("gdiplus.dll", ExactSpelling=true, CharSet=CharSet.Unicode)]
                internal static extern Status GdipCreateMetafileFromStream([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))] IStream stream, out IntPtr metafile);
                [DllImport("gdiplus.dll", ExactSpelling=true, CharSet=CharSet.Unicode)]
                internal static extern Status GdipGetMetafileHeaderFromStream([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))] IStream stream, IntPtr header);
+
+               [DllImport ("gdiplus.dll")]
+               internal static extern Status GdipRecordMetafileStream ([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))] IStream stream, IntPtr hdc, 
+                       EmfType type, ref RectangleF frameRect, MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
+               [DllImport ("gdiplus.dll")]
+               internal static extern Status GdipRecordMetafileStreamI ([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))] IStream stream, IntPtr hdc, 
+                       EmfType type, ref Rectangle frameRect, MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
 #endif
                //ImageCodecInfo functions
                [DllImport("gdiplus.dll")]
@@ -1654,8 +1704,7 @@ namespace System.Drawing
                public delegate void StreamCloseDelegate ();
                public delegate long StreamSizeDelegate ();
 
-               internal class GdiPlusStreamHelper 
-               {
+               internal sealed class GdiPlusStreamHelper {
                        public Stream stream;
                        
                        private StreamGetHeaderDelegate sghd = null;
@@ -1670,12 +1719,12 @@ namespace System.Drawing
                        private byte[]  managedBuf;
                        private const int default_bufsize = 4096;
                        
-                       public GdiPlusStreamHelper (Stream s) 
+                       public GdiPlusStreamHelper (Stream s, bool seekToOrigin
                        { 
                                managedBuf = new byte [default_bufsize];
                                
                                stream = s;
-                               if (stream != null && stream.CanSeek) {
+                               if (stream != null && stream.CanSeek && seekToOrigin) {
                                        stream.Seek (0, SeekOrigin.Begin);
                                }
                        }
@@ -1889,7 +1938,7 @@ namespace System.Drawing
                
                /* Mac only function calls */
                [DllImport("gdiplus.dll")]
-               internal static extern Status GdipCreateFromQuartz_macosx (IntPtr cgref, int width, int height, out IntPtr graphics);
+               internal static extern Status GdipCreateFromContext_macosx (IntPtr cgref, int width, int height, out IntPtr graphics);
 
                /* Linux only function calls*/
                [DllImport("gdiplus.dll")]
@@ -1918,6 +1967,21 @@ namespace System.Drawing
                static internal extern Status GdipGetMetafileHeaderFromDelegate_linux (StreamGetHeaderDelegate getHeader, 
                        StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, 
                        StreamCloseDelegate close, StreamSizeDelegate size, IntPtr header);
+
+               [DllImport("gdiplus.dll")]
+               static internal extern Status GdipRecordMetafileFromDelegate_linux (StreamGetHeaderDelegate getHeader, 
+                       StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, 
+                       StreamCloseDelegate close, StreamSizeDelegate size, IntPtr hdc, EmfType type, ref RectangleF frameRect, 
+                       MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
+
+               [DllImport("gdiplus.dll")]
+               static internal extern Status GdipRecordMetafileFromDelegateI_linux (StreamGetHeaderDelegate getHeader, 
+                       StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, 
+                       StreamCloseDelegate close, StreamSizeDelegate size, IntPtr hdc, EmfType type, ref Rectangle frameRect, 
+                       MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
+
+               [DllImport ("libc")]
+               static extern int uname (IntPtr buf);
 #endregion
        }
 }