Consolidate Metafile unix/windows code (dotnet/corefx#39758)
authorHugh Bellamy <hughbellars@gmail.com>
Tue, 30 Jul 2019 17:18:48 +0000 (17:18 +0000)
committerSantiago Fernandez Madero <safern@microsoft.com>
Tue, 30 Jul 2019 17:18:48 +0000 (10:18 -0700)
* Fix tests locally

* Consolidate Metafile code

Commit migrated from https://github.com/dotnet/corefx/commit/915a36ce8132070d79661e39f1f1e616215756b2

src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj
src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.cs [new file with mode: 0644]
src/libraries/System.Drawing.Common/tests/BitmapTests.cs
src/libraries/System.Drawing.Common/tests/Imaging/MetafileTests.cs
src/libraries/System.Drawing.Common/tests/Printing/PrinterSettingsTests.cs

index 4d5da30..e7ca7b7 100644 (file)
@@ -33,6 +33,7 @@
     <Compile Include="System\Drawing\StringFormat.cs" />
     <Compile Include="System\Drawing\SystemFonts.cs" />
     <Compile Include="System\Drawing\SystemPens.cs" />
+    <Compile Include="System\Drawing\Imaging\Metafile.cs" />
     <Compile Include="System\Drawing\Printing\PrinterUnit.cs" />
     <Compile Include="System\Drawing\Printing\PreviewPageInfo.cs" />
     <Compile Include="System\Drawing\Printing\PrintEventHandler.cs" />
index 8fc6dc0..bfcda08 100644 (file)
@@ -594,15 +594,6 @@ namespace System.Drawing
             internal static extern int GdipCreateFontFromHfont(IntPtr hdc, out IntPtr font, ref LOGFONT lf);
 
             [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipCreateMetafileFromFile(string filename, out IntPtr metafile);
-
-            [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipCreateMetafileFromEmf(IntPtr hEmf, bool deleteEmf, out IntPtr metafile);
-
-            [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipCreateMetafileFromWmf(IntPtr hWmf, bool deleteWmf, WmfPlaceableFileHeader wmfPlaceableFileHeader, out IntPtr metafile);
-
-            [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
             internal static extern int GdipGetMetafileHeaderFromFile(string filename, IntPtr header);
 
             [DllImport(LibraryName, ExactSpelling = true)]
@@ -624,21 +615,6 @@ namespace System.Drawing
             internal static extern int GdipSetMetafileDownLevelRasterizationLimit(IntPtr metafile, uint metafileRasterizationLimitDpi);
 
             [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipPlayMetafileRecord(IntPtr metafile, EmfPlusRecordType recordType, int flags, int dataSize, byte[] data);
-
-            [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafile(IntPtr hdc, EmfType type, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
-
-            [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileI(IntPtr hdc, EmfType type, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
-
-            [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileFileName(string filename, IntPtr hdc, EmfType type, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
-
-            [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileFileNameI(string filename, IntPtr hdc, EmfType type, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
-
-            [DllImport(LibraryName, ExactSpelling = true)]
             internal static extern int GdipCreateFromContext_macosx(IntPtr cgref, int width, int height, out IntPtr graphics);
 
             [DllImport(LibraryName, ExactSpelling = true)]
index 7214ca6..a6f8afd 100644 (file)
@@ -531,19 +531,16 @@ namespace System.Drawing
             internal static extern int GdipEnumerateMetafileSrcRectDestPointsI(HandleRef graphics, HandleRef metafile, Point* destPoints, int count, ref Rectangle srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, HandleRef callbackdata, HandleRef imageattributes);
 
             [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipPlayMetafileRecord(HandleRef graphics, EmfPlusRecordType recordType, int flags, int dataSize, byte[] data);
-
-            [DllImport(LibraryName, ExactSpelling = true)]
             internal static extern int GdipSaveGraphics(HandleRef graphics, out int state);
 
             [DllImport(LibraryName, ExactSpelling = true)]
             internal static extern int GdipRestoreGraphics(HandleRef graphics, int state);
 
             [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipGetMetafileHeaderFromWmf(HandleRef hMetafile, WmfPlaceableFileHeader wmfplaceable, [In] [Out] MetafileHeaderWmf metafileHeaderWmf);
+            internal static extern int GdipGetMetafileHeaderFromWmf(IntPtr hMetafile, WmfPlaceableFileHeader wmfplaceable, [In] [Out] MetafileHeaderWmf metafileHeaderWmf);
 
             [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipGetMetafileHeaderFromEmf(HandleRef hEnhMetafile, [In] [Out] MetafileHeaderEmf metafileHeaderEmf);
+            internal static extern int GdipGetMetafileHeaderFromEmf(IntPtr hEnhMetafile, [In] [Out] MetafileHeaderEmf metafileHeaderEmf);
 
             [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
             internal static extern int GdipGetMetafileHeaderFromFile(string filename, IntPtr header);
@@ -558,43 +555,16 @@ namespace System.Drawing
             internal static extern int GdipGetHemfFromMetafile(HandleRef metafile, out IntPtr hEnhMetafile);
 
             [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipCreateMetafileFromWmf(HandleRef hMetafile, bool deleteWmf, WmfPlaceableFileHeader wmfplacealbeHeader, out IntPtr metafile);
-
-            [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipCreateMetafileFromEmf(HandleRef hEnhMetafile, bool deleteEmf, out IntPtr metafile);
-
-            [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipCreateMetafileFromFile(string file, out IntPtr metafile);
-
-            [DllImport(LibraryName, ExactSpelling = true)]
             internal static extern int GdipCreateMetafileFromStream(Interop.Ole32.IStream stream, out IntPtr metafile);
 
-            [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipRecordMetafile(HandleRef referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
-
-            [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipRecordMetafile(HandleRef referenceHdc, EmfType emfType, HandleRef pframeRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
-
-            [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipRecordMetafileI(HandleRef referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
-
-            [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileFileName(string fileName, HandleRef referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
-
-            [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileFileName(string fileName, HandleRef referenceHdc, EmfType emfType, HandleRef pframeRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
-
-            [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileFileNameI(string fileName, HandleRef referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
-
             [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileStream(Interop.Ole32.IStream stream, HandleRef referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+            internal static extern int GdipRecordMetafileStream(Interop.Ole32.IStream stream, IntPtr referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileStream(Interop.Ole32.IStream stream, HandleRef referenceHdc, EmfType emfType, HandleRef pframeRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+            internal static extern int GdipRecordMetafileStream(Interop.Ole32.IStream stream, IntPtr referenceHdc, EmfType emfType, IntPtr pframeRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileStreamI(Interop.Ole32.IStream stream, HandleRef referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+            internal static extern int GdipRecordMetafileStreamI(Interop.Ole32.IStream stream, IntPtr referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true)]
             internal static extern int GdipComment(HandleRef graphics, int sizeData, byte[] data);
index 2ed8e7e..45452c3 100644 (file)
@@ -1110,6 +1110,36 @@ namespace System.Drawing
 
             [DllImport(LibraryName, ExactSpelling = true)]
             internal static extern int GdipImageGetFrameDimensionsList(HandleRef image, Guid* dimensionIDs, int count);
+
+            [DllImport(LibraryName, ExactSpelling = true)]
+            internal static extern int GdipCreateMetafileFromEmf(IntPtr hEnhMetafile, bool deleteEmf, out IntPtr metafile);
+
+            [DllImport(LibraryName, ExactSpelling = true)]
+            internal static extern int GdipCreateMetafileFromWmf(IntPtr hMetafile, bool deleteWmf, WmfPlaceableFileHeader wmfplacealbeHeader, out IntPtr metafile);
+
+            [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
+            internal static extern int GdipCreateMetafileFromFile(string file, out IntPtr metafile);
+
+            [DllImport(LibraryName, ExactSpelling = true)]
+            internal static extern int GdipRecordMetafile(IntPtr referenceHdc, EmfType emfType, IntPtr pframeRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+
+            [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
+            internal static extern int GdipRecordMetafile(IntPtr referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+
+            [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
+            internal static extern int GdipRecordMetafileI(IntPtr referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+
+            [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
+            internal static extern int GdipRecordMetafileFileName(string fileName, IntPtr referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+
+            [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
+            internal static extern int GdipRecordMetafileFileName(string fileName, IntPtr referenceHdc, EmfType emfType, IntPtr pframeRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+
+            [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
+            internal static extern int GdipRecordMetafileFileNameI(string fileName, IntPtr referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+
+            [DllImport(LibraryName, ExactSpelling = true)]
+            internal static extern int GdipPlayMetafileRecord(HandleRef metafile, EmfPlusRecordType recordType, int flags, int dataSize, byte[] data);
         }
 
         [StructLayout(LayoutKind.Sequential)]
index 7d53133..def7fd1 100644 (file)
@@ -43,9 +43,7 @@ namespace System.Drawing.Imaging
 #if !NETCORE
     [Editor ("System.Drawing.Design.MetafileEditor, " + Consts.AssemblySystem_Drawing_Design, typeof (System.Drawing.Design.UITypeEditor))]
 #endif
-    [Serializable]
-    [System.Runtime.CompilerServices.TypeForwardedFrom("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
-    public sealed class Metafile : Image
+    public sealed partial class Metafile : Image
     {
 
         // constructors
@@ -74,146 +72,27 @@ namespace System.Drawing.Imaging
             Gdip.CheckStatus(status);
         }
 
-        public Metafile(string filename)
-        {
-            // Called in order to emulate exception behavior from netfx related to invalid file paths.
-            Path.GetFullPath(filename);
-
-            int status = Gdip.GdipCreateMetafileFromFile(filename, out nativeImage);
-            if (status == Gdip.GenericError)
-                throw new ExternalException("Couldn't load specified file.");
-            Gdip.CheckStatus(status);
-        }
-
-        public Metafile(IntPtr henhmetafile, bool deleteEmf)
-        {
-            int status = Gdip.GdipCreateMetafileFromEmf(henhmetafile, deleteEmf, out nativeImage);
-            Gdip.CheckStatus(status);
-        }
-
-        public Metafile(IntPtr referenceHdc, EmfType emfType) :
-            this(referenceHdc, new RectangleF(), MetafileFrameUnit.GdiCompatible, emfType, null)
-        {
-        }
-
-        public Metafile(IntPtr referenceHdc, Rectangle frameRect) :
-            this(referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible, EmfType.EmfPlusDual, null)
-        {
-        }
-
-        public Metafile(IntPtr referenceHdc, RectangleF frameRect) :
-            this(referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible, EmfType.EmfPlusDual, null)
-        {
-        }
-
         public Metafile(IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader)
         {
             int status = Gdip.GdipCreateMetafileFromEmf(hmetafile, false, out nativeImage);
             Gdip.CheckStatus(status);
         }
 
-        public Metafile(Stream stream, IntPtr referenceHdc) :
-            this(stream, referenceHdc, new RectangleF(), MetafileFrameUnit.GdiCompatible, EmfType.EmfPlusDual, null)
-        {
-        }
-
-        public Metafile(string fileName, IntPtr referenceHdc) :
-            this(fileName, referenceHdc, new RectangleF(), MetafileFrameUnit.GdiCompatible, EmfType.EmfPlusDual,
-            null)
-        {
-        }
-
         public Metafile(IntPtr referenceHdc, EmfType emfType, string description) :
             this(referenceHdc, new RectangleF(), MetafileFrameUnit.GdiCompatible, emfType, description)
         {
         }
 
-        public Metafile(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit) :
-            this(referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual, null)
-        {
-        }
-
-        public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit) :
-            this(referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual, null)
-        {
-        }
-
-        public Metafile(IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader, bool deleteWmf)
-        {
-            int status = Gdip.GdipCreateMetafileFromEmf(hmetafile, deleteWmf, out nativeImage);
-            Gdip.CheckStatus(status);
-        }
-
-        public Metafile(Stream stream, IntPtr referenceHdc, EmfType type) :
-            this(stream, referenceHdc, new RectangleF(), MetafileFrameUnit.GdiCompatible, type, null)
-        {
-        }
-
-        public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect) :
-            this(stream, referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible, EmfType.EmfPlusDual, null)
-        {
-        }
-
-        public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect) :
-            this(stream, referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible, EmfType.EmfPlusDual, null)
-        {
-        }
-
-        public Metafile(string fileName, IntPtr referenceHdc, EmfType type) :
-            this(fileName, referenceHdc, new RectangleF(), MetafileFrameUnit.GdiCompatible, type, null)
-        {
-        }
-
-        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect) :
-            this(fileName, referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible, EmfType.EmfPlusDual, null)
-        {
-        }
-
-        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect) :
-            this(fileName, referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible, EmfType.EmfPlusDual, null)
-        {
-        }
-
-        public Metafile(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type) :
-            this(referenceHdc, frameRect, frameUnit, type, null)
-        {
-        }
-
-        public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type) :
-            this(referenceHdc, frameRect, frameUnit, type, null)
-        {
-        }
-
         public Metafile(Stream stream, IntPtr referenceHdc, EmfType type, string description) :
             this(stream, referenceHdc, new RectangleF(), MetafileFrameUnit.GdiCompatible, type, description)
         {
         }
 
-        public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit) :
-            this(stream, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual, null)
-        {
-        }
-
-        public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit) :
-            this(stream, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual, null)
-        {
-        }
-
         public Metafile(string fileName, IntPtr referenceHdc, EmfType type, string description) :
             this(fileName, referenceHdc, new RectangleF(), MetafileFrameUnit.GdiCompatible, type, description)
         {
         }
 
-        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit) :
-            this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual, null)
-        {
-        }
-
-        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit) :
-            this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual, null)
-        {
-        }
-
         public Metafile(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type,
             string desc)
         {
@@ -222,45 +101,6 @@ namespace System.Drawing.Imaging
             Gdip.CheckStatus(status);
         }
 
-        public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type,
-            string description)
-        {
-            int status = Gdip.GdipRecordMetafile(referenceHdc, type, ref frameRect, frameUnit,
-                description, out nativeImage);
-            Gdip.CheckStatus(status);
-        }
-
-        public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit,
-            EmfType type) : this(stream, referenceHdc, frameRect, frameUnit, type, null)
-        {
-        }
-
-        public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit,
-            EmfType type) : this(stream, referenceHdc, frameRect, frameUnit, type, null)
-        {
-        }
-
-        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit,
-            EmfType type) : this(fileName, referenceHdc, frameRect, frameUnit, type, null)
-        {
-        }
-
-        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit,
-            string description) : this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual, description)
-        {
-        }
-
-        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit,
-            EmfType type) : this(fileName, referenceHdc, frameRect, frameUnit, type, null)
-        {
-        }
-
-        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit,
-            string desc) : this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual,
-            desc)
-        {
-        }
-
         public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit,
             EmfType type, string description)
         {
@@ -310,21 +150,6 @@ namespace System.Drawing.Imaging
             Gdip.CheckStatus(status);
         }
 
-        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit,
-            EmfType type, string description)
-        {
-            // Called in order to emulate exception behavior from netfx related to invalid file paths.
-            Path.GetFullPath(fileName);
-
-            int status = Gdip.GdipRecordMetafileFileName(fileName, referenceHdc, type, ref frameRect, frameUnit,
-                description, out nativeImage);
-            Gdip.CheckStatus(status);
-        }
-
-        private Metafile(SerializationInfo info, StreamingContext context) : base(info, context)
-        {
-        }
-
         // methods
 
         public IntPtr GetHenhmetafile()
@@ -391,8 +216,8 @@ namespace System.Drawing.Imaging
 
         public static MetafileHeader GetMetafileHeader(string fileName)
         {
-            if (fileName == null)
-                throw new ArgumentNullException(nameof(fileName));
+            // Called in order to emulate exception behavior from netfx related to invalid file paths.
+            Path.GetFullPath(fileName);
 
             IntPtr header = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MetafileHeader)));
             try
@@ -421,11 +246,5 @@ namespace System.Drawing.Imaging
                 Marshal.FreeHGlobal(header);
             }
         }
-
-        public void PlayRecord(EmfPlusRecordType recordType, int flags, int dataSize, byte[] data)
-        {
-            int status = Gdip.GdipPlayMetafileRecord(nativeImage, recordType, flags, dataSize, data);
-            Gdip.CheckStatus(status);
-        }
     }
 }
index d5b47ae..9c7ec99 100644 (file)
@@ -14,50 +14,15 @@ namespace System.Drawing.Imaging
     /// Defines a graphic metafile. A metafile contains records that describe a sequence of graphics operations that
     /// can be recorded and played back.
     /// </summary>
-    [Serializable]
-    [System.Runtime.CompilerServices.TypeForwardedFrom("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
     public sealed partial class Metafile : Image
     {
-        // GDI+ doesn't handle filenames over MAX_PATH very well
-        private const int MaxPath = 260;
-
         /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class from the specified handle and
         /// <see cref='WmfPlaceableFileHeader'/>.
         /// </summary>
         public Metafile(IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader) :
             this(hmetafile, wmfHeader, false)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified handle and
-        /// <see cref='WmfPlaceableFileHeader'/>.
-        /// </summary>
-        public Metafile(IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader, bool deleteWmf)
-        {
-            Gdip.CheckStatus(Gdip.GdipCreateMetafileFromWmf(new HandleRef(null, hmetafile), deleteWmf, wmfHeader, out IntPtr metafile));
-            SetNativeImage(metafile);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified handle and
-        /// <see cref='WmfPlaceableFileHeader'/>.
-        /// </summary>
-        public Metafile(IntPtr henhmetafile, bool deleteEmf)
         {
-            Gdip.CheckStatus(Gdip.GdipCreateMetafileFromEmf(new HandleRef(null, henhmetafile), deleteEmf, out IntPtr metafile));
-            SetNativeImage(metafile);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified filename.
-        /// </summary>
-        public Metafile(string filename)
-        {
-            // Called in order to emulate exception behavior from netfx related to invalid file paths.
-            Path.GetFullPath(filename);
-            Gdip.CheckStatus(Gdip.GdipCreateMetafileFromFile(filename, out IntPtr metafile));
-            SetNativeImage(metafile);
         }
 
         /// <summary>
@@ -66,7 +31,9 @@ namespace System.Drawing.Imaging
         public Metafile(Stream stream)
         {
             if (stream == null)
+            {
                 throw new ArgumentNullException(nameof(stream));
+            }
 
             Gdip.CheckStatus(Gdip.GdipCreateMetafileFromStream(new GPStream(stream), out IntPtr metafile));
             SetNativeImage(metafile);
@@ -75,19 +42,12 @@ namespace System.Drawing.Imaging
         /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class from the specified handle to a device context.
         /// </summary>
-        public Metafile(IntPtr referenceHdc, EmfType emfType) :
-            this(referenceHdc, emfType, null)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified handle to a device context.
-        /// </summary>
         public Metafile(IntPtr referenceHdc, EmfType emfType, string description)
         {
             Gdip.CheckStatus(Gdip.GdipRecordMetafile(
-                new HandleRef(null, referenceHdc),
+                referenceHdc,
                 emfType,
-                NativeMethods.NullHandleRef,
+                IntPtr.Zero,
                 MetafileFrameUnit.GdiCompatible,
                 description,
                 out IntPtr metafile));
@@ -99,71 +59,6 @@ namespace System.Drawing.Imaging
         /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
         /// by the specified rectangle.
         /// </summary>
-        public Metafile(IntPtr referenceHdc, RectangleF frameRect) :
-            this(referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
-        /// by the specified rectangle.
-        /// </summary>
-        public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit) :
-            this(referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
-        /// by the specified rectangle.
-        /// </summary>
-        public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type) :
-            this(referenceHdc, frameRect, frameUnit, type, null)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
-        /// by the specified rectangle.
-        /// </summary>
-        public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
-        {
-            Gdip.CheckStatus(Gdip.GdipRecordMetafile(
-                new HandleRef(null, referenceHdc),
-                type,
-                ref frameRect,
-                frameUnit,
-                description,
-                out IntPtr metafile));
-
-            SetNativeImage(metafile);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
-        /// by the specified rectangle.
-        /// </summary>
-        public Metafile(IntPtr referenceHdc, Rectangle frameRect) :
-            this(referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
-        /// by the specified rectangle.
-        /// </summary>
-        public Metafile(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit) :
-            this(referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
-        /// by the specified rectangle.
-        /// </summary>
-        public Metafile(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type) :
-            this(referenceHdc, frameRect, frameUnit, type, null)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
-        /// by the specified rectangle.
-        /// </summary>
         public Metafile(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string desc)
         {
             IntPtr metafile = IntPtr.Zero;
@@ -171,9 +66,9 @@ namespace System.Drawing.Imaging
             if (frameRect.IsEmpty)
             {
                 Gdip.CheckStatus(Gdip.GdipRecordMetafile(
-                    new HandleRef(null, referenceHdc),
+                    referenceHdc,
                     type,
-                    NativeMethods.NullHandleRef,
+                    IntPtr.Zero,
                     MetafileFrameUnit.GdiCompatible,
                     desc,
                     out metafile));
@@ -181,7 +76,7 @@ namespace System.Drawing.Imaging
             else
             {
                 Gdip.CheckStatus(Gdip.GdipRecordMetafileI(
-                    new HandleRef(null, referenceHdc),
+                    referenceHdc,
                     type,
                     ref frameRect,
                     frameUnit,
@@ -195,20 +90,6 @@ namespace System.Drawing.Imaging
         /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
         /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc) :
-            this(fileName, referenceHdc, EmfType.EmfPlusDual, null)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
-        /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc, EmfType type) :
-            this(fileName, referenceHdc, type, null)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
-        /// </summary>
         public Metafile(string fileName, IntPtr referenceHdc, EmfType type, string description)
         {
             // Called in order to emulate exception behavior from netfx related to invalid file paths.
@@ -216,9 +97,9 @@ namespace System.Drawing.Imaging
 
             Gdip.CheckStatus(Gdip.GdipRecordMetafileFileName(
                 fileName,
-                new HandleRef(null, referenceHdc),
+                referenceHdc,
                 type,
-                NativeMethods.NullHandleRef,
+                IntPtr.Zero,
                 MetafileFrameUnit.GdiCompatible,
                 description,
                 out IntPtr metafile));
@@ -229,85 +110,6 @@ namespace System.Drawing.Imaging
         /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
         /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect) :
-            this(fileName, referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
-        /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit) :
-            this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
-        /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect,  MetafileFrameUnit frameUnit, EmfType type) :
-            this(fileName, referenceHdc, frameRect, frameUnit, type, null)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
-        /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, string desc) :
-            this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual, desc)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
-        /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
-        {
-            // Called in order to emulate exception behavior from netfx related to invalid file paths.
-            Path.GetFullPath(fileName);
-
-            if (fileName.Length > MaxPath)
-                throw new PathTooLongException();
-
-            Gdip.CheckStatus(Gdip.GdipRecordMetafileFileName(
-                fileName,
-                new HandleRef(null, referenceHdc),
-                type,
-                ref frameRect,
-                frameUnit,
-                description,
-                out IntPtr metafile));
-
-            SetNativeImage(metafile);
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
-        /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect) :
-            this(fileName, referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
-        /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit) :
-            this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
-        /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type) :
-            this(fileName, referenceHdc, frameRect, frameUnit, type, null)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
-        /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, string description) :
-            this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual, description)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
-        /// </summary>
         public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
         {
             // Called in order to emulate exception behavior from netfx related to invalid file paths.
@@ -319,9 +121,9 @@ namespace System.Drawing.Imaging
             {
                 Gdip.CheckStatus(Gdip.GdipRecordMetafileFileName(
                     fileName,
-                    new HandleRef(null, referenceHdc),
+                    referenceHdc,
                     type,
-                    NativeMethods.NullHandleRef,
+                    IntPtr.Zero,
                     frameUnit,
                     description,
                     out metafile));
@@ -330,7 +132,7 @@ namespace System.Drawing.Imaging
             {
                 Gdip.CheckStatus(Gdip.GdipRecordMetafileFileNameI(
                     fileName,
-                    new HandleRef(null, referenceHdc),
+                    referenceHdc,
                     type,
                     ref frameRect,
                     frameUnit,
@@ -344,27 +146,13 @@ namespace System.Drawing.Imaging
         /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class from the specified data stream.
         /// </summary>
-        public Metafile(Stream stream, IntPtr referenceHdc) :
-            this(stream, referenceHdc, EmfType.EmfPlusDual, null)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified data stream.
-        /// </summary>
-        public Metafile(Stream stream, IntPtr referenceHdc, EmfType type) :
-            this(stream, referenceHdc, type, null)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified data stream.
-        /// </summary>
         public Metafile(Stream stream, IntPtr referenceHdc, EmfType type, string description)
         {
             Gdip.CheckStatus(Gdip.GdipRecordMetafileStream(
                 new GPStream(stream),
-                new HandleRef(null, referenceHdc),
+                referenceHdc,
                 type,
-                NativeMethods.NullHandleRef,
+                IntPtr.Zero,
                 MetafileFrameUnit.GdiCompatible,
                 description,
                 out IntPtr metafile));
@@ -373,34 +161,13 @@ namespace System.Drawing.Imaging
         }
 
         /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified data stream.
-        /// </summary>
-        public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect) :
-            this(stream, referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
-        /// </summary>
-        public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit) :
-            this(stream, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
-        /// </summary>
-        public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type) :
-            this(stream, referenceHdc, frameRect, frameUnit, type, null)
-        { }
-
-        /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
         /// </summary>
         public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
         {
             Gdip.CheckStatus(Gdip.GdipRecordMetafileStream(
                 new GPStream(stream),
-                new HandleRef(null, referenceHdc),
+                referenceHdc,
                 type,
                 ref frameRect,
                 frameUnit,
@@ -409,28 +176,7 @@ namespace System.Drawing.Imaging
 
             SetNativeImage(metafile);
         }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified data stream.
-        /// </summary>
-        public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect) :
-            this(stream, referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
-        /// </summary>
-        public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit) :
-            this(stream, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual)
-        { }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
-        /// </summary>
-        public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type) :
-            this(stream, referenceHdc, frameRect, frameUnit, type, null)
-        { }
-
+        
         /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
         /// </summary>
@@ -442,9 +188,9 @@ namespace System.Drawing.Imaging
             {
                 Gdip.CheckStatus(Gdip.GdipRecordMetafileStream(
                     new GPStream(stream),
-                    new HandleRef(null, referenceHdc),
+                    referenceHdc,
                     type,
-                    NativeMethods.NullHandleRef,
+                    IntPtr.Zero,
                     frameUnit,
                     description,
                     out metafile));
@@ -453,7 +199,7 @@ namespace System.Drawing.Imaging
             {
                 Gdip.CheckStatus(Gdip.GdipRecordMetafileStreamI(
                     new GPStream(stream),
-                    new HandleRef(null, referenceHdc),
+                    referenceHdc,
                     type,
                     ref frameRect,
                     frameUnit,
@@ -464,11 +210,6 @@ namespace System.Drawing.Imaging
             SetNativeImage(metafile);
         }
 
-        private Metafile(SerializationInfo info, StreamingContext context) : base(info, context)
-        {
-        }
-
-
         /// <summary>
         /// Returns the <see cref='MetafileHeader'/> associated with the specified <see cref='Metafile'/>.
         /// </summary>
@@ -479,7 +220,7 @@ namespace System.Drawing.Imaging
                 wmf = new MetafileHeaderWmf()
             };
 
-            Gdip.CheckStatus(Gdip.GdipGetMetafileHeaderFromWmf(new HandleRef(null, hmetafile), wmfHeader, header.wmf));
+            Gdip.CheckStatus(Gdip.GdipGetMetafileHeaderFromWmf(hmetafile, wmfHeader, header.wmf));
             return header;
         }
 
@@ -493,7 +234,7 @@ namespace System.Drawing.Imaging
                 emf = new MetafileHeaderEmf()
             };
 
-            Gdip.CheckStatus(Gdip.GdipGetMetafileHeaderFromEmf(new HandleRef(null, henhmetafile), header.emf));
+            Gdip.CheckStatus(Gdip.GdipGetMetafileHeaderFromEmf(henhmetafile, header.emf));
             return header;
         }
 
@@ -637,23 +378,6 @@ namespace System.Drawing.Imaging
         }
 
         /// <summary>
-        /// Plays an EMF+ file.
-        /// </summary>
-        public void PlayRecord(EmfPlusRecordType recordType, int flags, int dataSize, byte[] data)
-        {
-            // Used in conjunction with Graphics.EnumerateMetafile to play an EMF+
-            // The data must be DWORD aligned if it's an EMF or EMF+.  It must be
-            // WORD aligned if it's a WMF.
-
-            Gdip.CheckStatus(Gdip.GdipPlayMetafileRecord(
-                new HandleRef(this, nativeImage),
-                recordType,
-                flags,
-                dataSize,
-                data));
-        }
-
-        /// <summary>
         /// Create a new metafile object from a native metafile handle.
         /// </summary>
         internal static Metafile FromGDIplus(IntPtr nativeImage)
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.cs
new file mode 100644 (file)
index 0000000..5cd557b
--- /dev/null
@@ -0,0 +1,323 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.IO;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Runtime.Serialization;
+using Gdip = System.Drawing.SafeNativeMethods.Gdip;
+
+namespace System.Drawing.Imaging
+{
+    /// <summary>
+    /// Defines a graphic metafile. A metafile contains records that describe a sequence of graphics operations that
+    /// can be recorded and played back.
+    /// </summary>
+    [Serializable]
+    [TypeForwardedFrom("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
+    public sealed partial class Metafile : Image
+    {
+        // GDI+ doesn't handle filenames over MAX_PATH very well
+        private const int MaxPath = 260;
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified handle and
+        /// <see cref='WmfPlaceableFileHeader'/>.
+        /// </summary>
+        public Metafile(IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader, bool deleteWmf)
+        {
+            Gdip.CheckStatus(Gdip.GdipCreateMetafileFromWmf(hmetafile, deleteWmf, wmfHeader, out IntPtr metafile));
+            SetNativeImage(metafile);
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified handle and
+        /// <see cref='WmfPlaceableFileHeader'/>.
+        /// </summary>
+        public Metafile(IntPtr henhmetafile, bool deleteEmf)
+        {
+            Gdip.CheckStatus(Gdip.GdipCreateMetafileFromEmf(henhmetafile, deleteEmf, out IntPtr metafile));
+            SetNativeImage(metafile);
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified filename.
+        /// </summary>
+        public Metafile(string filename)
+        {
+            // Called in order to emulate exception behavior from netfx related to invalid file paths.
+            Path.GetFullPath(filename);
+            Gdip.CheckStatus(Gdip.GdipCreateMetafileFromFile(filename, out IntPtr metafile));
+            SetNativeImage(metafile);
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
+        /// by the specified rectangle.
+        /// </summary>
+        public Metafile(IntPtr referenceHdc, Rectangle frameRect) :
+            this(referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified handle to a device context.
+        /// </summary>
+        public Metafile(IntPtr referenceHdc, EmfType emfType) :
+            this(referenceHdc, emfType, null)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
+        /// by the specified rectangle.
+        /// </summary>
+        public Metafile(IntPtr referenceHdc, RectangleF frameRect) :
+            this(referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
+        /// by the specified rectangle.
+        /// </summary>
+        public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit) :
+            this(referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
+        /// by the specified rectangle.
+        /// </summary>
+        public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type) :
+            this(referenceHdc, frameRect, frameUnit, type, null)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
+        /// by the specified rectangle.
+        /// </summary>
+        public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
+        {
+            Gdip.CheckStatus(Gdip.GdipRecordMetafile(
+                referenceHdc,
+                type,
+                ref frameRect,
+                frameUnit,
+                description,
+                out IntPtr metafile));
+
+            SetNativeImage(metafile);
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
+        /// by the specified rectangle.
+        /// </summary>
+        public Metafile(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit) :
+            this(referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
+        /// by the specified rectangle.
+        /// </summary>
+        public Metafile(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type) :
+            this(referenceHdc, frameRect, frameUnit, type, null)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
+        /// </summary>
+        public Metafile(string fileName, IntPtr referenceHdc) :
+            this(fileName, referenceHdc, EmfType.EmfPlusDual, null)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
+        /// </summary>
+        public Metafile(string fileName, IntPtr referenceHdc, EmfType type) :
+            this(fileName, referenceHdc, type, null)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
+        /// </summary>
+        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect) :
+            this(fileName, referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
+        /// </summary>
+        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit) :
+            this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
+        /// </summary>
+        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect,  MetafileFrameUnit frameUnit, EmfType type) :
+            this(fileName, referenceHdc, frameRect, frameUnit, type, null)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
+        /// </summary>
+        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, string desc) :
+            this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual, desc)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
+        /// </summary>
+        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
+        {
+            // Called in order to emulate exception behavior from netfx related to invalid file paths.
+            Path.GetFullPath(fileName);
+            if (fileName.Length > MaxPath)
+            {
+                throw new PathTooLongException();
+            }
+
+            Gdip.CheckStatus(Gdip.GdipRecordMetafileFileName(
+                fileName,
+                referenceHdc,
+                type,
+                ref frameRect,
+                frameUnit,
+                description,
+                out IntPtr metafile));
+
+            SetNativeImage(metafile);
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
+        /// </summary>
+        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect) :
+            this(fileName, referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
+        /// </summary>
+        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit) :
+            this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
+        /// </summary>
+        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type) :
+            this(fileName, referenceHdc, frameRect, frameUnit, type, null)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
+        /// </summary>
+        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, string description) :
+            this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual, description)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified data stream.
+        /// </summary>
+        public Metafile(Stream stream, IntPtr referenceHdc) :
+            this(stream, referenceHdc, EmfType.EmfPlusDual, null)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified data stream.
+        /// </summary>
+        public Metafile(Stream stream, IntPtr referenceHdc, EmfType type) :
+            this(stream, referenceHdc, type, null)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified data stream.
+        /// </summary>
+        public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect) :
+            this(stream, referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
+        /// </summary>
+        public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit) :
+            this(stream, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
+        /// </summary>
+        public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type) :
+            this(stream, referenceHdc, frameRect, frameUnit, type, null)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified data stream.
+        /// </summary>
+        public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect) :
+            this(stream, referenceHdc, frameRect, MetafileFrameUnit.GdiCompatible)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
+        /// </summary>
+        public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit) :
+            this(stream, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
+        /// </summary>
+        public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type) :
+            this(stream, referenceHdc, frameRect, frameUnit, type, null)
+        {
+        }
+
+        private Metafile(SerializationInfo info, StreamingContext context) : base(info, context)
+        {
+        }
+
+        /// <summary>
+        /// Plays an EMF+ file.
+        /// </summary>
+        public void PlayRecord(EmfPlusRecordType recordType, int flags, int dataSize, byte[] data)
+        {
+            // Used in conjunction with Graphics.EnumerateMetafile to play an EMF+
+            // The data must be DWORD aligned if it's an EMF or EMF+.  It must be
+            // WORD aligned if it's a WMF.
+
+            Gdip.CheckStatus(Gdip.GdipPlayMetafileRecord(
+                new HandleRef(this, nativeImage),
+                recordType,
+                flags,
+                dataSize,
+                data));
+        }
+    }
+}
index 43dd421..961495b 100644 (file)
@@ -544,6 +544,7 @@ namespace System.Drawing.Tests
             AssertExtensions.Throws<ArgumentException>(null, () => bitmap.Clone(new RectangleF(0, 0, 1, 1), PixelFormat.Format32bppArgb));
         }
 
+        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalFact(Helpers.IsDrawingSupported)]
         public void GetFrameCount_NewBitmap_ReturnsZero()
         {
index 2cc526a..e50427d 100644 (file)
@@ -53,7 +53,6 @@ namespace System.Drawing.Imaging.Tests
             }
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalFact(Helpers.IsDrawingSupported)]
         public void Ctor_String_Success()
         {
@@ -88,7 +87,6 @@ namespace System.Drawing.Imaging.Tests
             yield return new object[] { string.Empty };
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalTheory(Helpers.IsDrawingSupported)]
         [InlineData("bad\0name")]
         [InlineData("")]
@@ -97,7 +95,6 @@ namespace System.Drawing.Imaging.Tests
             AssertExtensions.Throws<ArgumentException>("path", null, () => new Metafile(path));
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalFact(Helpers.IsDrawingSupported)]
         public void Ctor_Stream_Success()
         {
@@ -163,7 +160,6 @@ namespace System.Drawing.Imaging.Tests
             }
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalFact(Helpers.IsDrawingSupported)]
         public void Ctor_NullEmfType_ThrowsArgumentException()
         {
@@ -423,7 +419,6 @@ namespace System.Drawing.Imaging.Tests
             File.Delete(fileName);
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalFact(Helpers.IsDrawingSupported)]
         public void Ctor_IntPtrZeroII_ThrowsArgumentException()
         {
@@ -462,7 +457,6 @@ namespace System.Drawing.Imaging.Tests
             }
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalTheory(Helpers.IsDrawingSupported)]
         [InlineData("bad\0path")]
         [InlineData("")]
@@ -478,8 +472,6 @@ namespace System.Drawing.Imaging.Tests
             }
         }
 
-        // Long paths aren't that much of a problem on Unix.
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalFact(Helpers.IsDrawingSupported)]
         public void Ctor_PathTooLong_ThrowsPathTooLongException()
         {
@@ -663,7 +655,6 @@ namespace System.Drawing.Imaging.Tests
             File.Delete(fileName);
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalFact(Helpers.IsDrawingSupported)]
         public void Ctor_IntPtrZeroIII_ThrowsArgumentException()
         {
@@ -747,7 +738,6 @@ namespace System.Drawing.Imaging.Tests
             }
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalTheory(Helpers.IsDrawingSupported)]
         [InlineData("bad\0path")]
         [InlineData("")]
@@ -767,8 +757,6 @@ namespace System.Drawing.Imaging.Tests
             }
         }
 
-        // Long paths aren't that much of a problem on Unix.
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalFact(Helpers.IsDrawingSupported)]
         public void Ctor_PathTooLongI_ThrowsPathTooLongException()
         {
@@ -857,7 +845,6 @@ namespace System.Drawing.Imaging.Tests
             }
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalFact(Helpers.IsDrawingSupported)]
         public void Ctor_IntPtrZeroIV_ThrowsArgumentException()
         {
@@ -938,7 +925,6 @@ namespace System.Drawing.Imaging.Tests
             }
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalTheory(Helpers.IsDrawingSupported)]
         [InlineData("bad\0path")]
         [InlineData("")]
@@ -947,7 +933,6 @@ namespace System.Drawing.Imaging.Tests
             AssertExtensions.Throws<ArgumentException>("path", null, () => Metafile.GetMetafileHeader(fileName));
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalFact(Helpers.IsDrawingSupported)]
         public void Static_GetMetafileHeader_NullString_ThrowsArgumentNullException()
         {
@@ -992,7 +977,6 @@ namespace System.Drawing.Imaging.Tests
             }
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalFact(Helpers.IsDrawingSupported)]
         public void GetMetafileHeader_Disposed_ThrowsArgumentException()
         {
@@ -1002,7 +986,6 @@ namespace System.Drawing.Imaging.Tests
             AssertExtensions.Throws<ArgumentException>(null, () => metafile.GetMetafileHeader());
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalFact(Helpers.IsDrawingSupported)]
         public void GetHenhmetafile_ReturnsExpected()
         {
@@ -1022,7 +1005,6 @@ namespace System.Drawing.Imaging.Tests
             AssertExtensions.Throws<ArgumentException>(null, () => metafile.GetHenhmetafile());
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalFact(Helpers.IsDrawingSupported)]
         public void PlayRecord_Disposed_ThrowsArgumentException()
         {
index 9389ff4..43d222a 100644 (file)
@@ -197,15 +197,15 @@ namespace System.Drawing.Printing.Tests
         public void LandscapeAngle_ReturnsExpected()
         {
             var printerSettings = new PrinterSettings();
-            int[] validValues = new[] { 0, 90, 270 };
-            Assert.True(validValues.Contains(printerSettings.LandscapeAngle), "PrinterSettings.LandscapeAngle must be 0, 90, or 270 degrees.");
+            int[] validValues = new[] { -90, 0, 90, 270 };
+            Assert.True(validValues.Contains(printerSettings.LandscapeAngle), $"PrinterSettings.LandscapeAngle ({printerSettings.LandscapeAngle}) must be 0, 90, or 270 degrees.");
         }
 
         [ConditionalFact(Helpers.AnyInstalledPrinters, Helpers.IsDrawingSupported)]
         public void MaximumCopies_ReturnsExpected()
         {
             var printerSettings = new PrinterSettings();
-            Assert.True(printerSettings.MaximumCopies >= 0, "PrinterSettings.MaximumCopies should not be negative.");
+            Assert.True(printerSettings.MaximumCopies >= 0, $"PrinterSettings.MaximumCopies ({printerSettings.MaximumCopies}) should not be negative.");
         }
 
         [Fact]