From 21bdf4840357f1e1895c030f4fe91217e90c83a3 Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Madero Date: Tue, 19 Oct 2021 12:40:45 -0700 Subject: [PATCH] Move 2 Drawing APIs that are not implemented in netfx to netcoreapp (#60599) * Move 2 Drawing APIs that are not implemented in netfx to netcoreapp3.1 or later (#60371) * Don't use ifdefs on ref file --- .../ref/System.Drawing.Common.cs | 8 -------- .../ref/System.Drawing.Common.netcoreapp.cs | 8 ++++++++ .../ref/System.Drawing.Common.netstandard.cs | 5 +++++ .../src/CompatibilitySuppressions.xml | 12 ------------ .../src/System/Drawing/Graphics.Unix.cs | 2 ++ .../src/System/Drawing/Graphics.Windows.cs | 4 ++++ .../src/misc/GDI/WindowsGraphics.cs | 16 ++++++++++++++++ 7 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs index 2a6e2a49ef363..8c057f5369b77 100644 --- a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs +++ b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs @@ -594,14 +594,6 @@ public void Flush(System.Drawing.Drawing2D.FlushIntention intention) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] public static System.Drawing.Graphics FromHwndInternal(System.IntPtr hwnd) { throw null; } public static System.Drawing.Graphics FromImage(System.Drawing.Image image) { throw null; } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] - [System.ObsoleteAttribute("Use the Graphics.GetContextInfo overloads that accept arguments for better performance and fewer allocations.", DiagnosticId = "SYSLIB0016", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] - public object GetContextInfo() { throw null; } - [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] - public void GetContextInfo(out PointF offset) { throw null; } - [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] - public void GetContextInfo(out PointF offset, out Region? clip) { throw null; } public static System.IntPtr GetHalftonePalette() { throw null; } public System.IntPtr GetHdc() { throw null; } public System.Drawing.Color GetNearestColor(System.Drawing.Color color) { throw null; } diff --git a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs index f4fc55188f3d0..7c5f8f890a84d 100644 --- a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs +++ b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs @@ -9,6 +9,14 @@ namespace System.Drawing public sealed partial class Graphics { public System.Numerics.Matrix3x2 TransformElements { get { throw null; } set { } } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] + [System.ObsoleteAttribute("Use the Graphics.GetContextInfo overloads that accept arguments for better performance and fewer allocations.", DiagnosticId = "SYSLIB0016", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] + public object GetContextInfo() { throw null; } + [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] + public void GetContextInfo(out PointF offset) { throw null; } + [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] + public void GetContextInfo(out PointF offset, out Region? clip) { throw null; } } } namespace System.Drawing.Drawing2D diff --git a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netstandard.cs b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netstandard.cs index 671f9cbe6e75b..caa2811da3b95 100644 --- a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netstandard.cs +++ b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netstandard.cs @@ -15,6 +15,11 @@ public static partial class ColorTranslator public static int ToOle(System.Drawing.Color c) { throw null; } public static int ToWin32(System.Drawing.Color c) { throw null; } } + public sealed partial class Graphics + { + [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] + public object GetContextInfo() { throw null; } + } public static partial class SystemColors { public static System.Drawing.Color ActiveBorder { get { throw null; } } diff --git a/src/libraries/System.Drawing.Common/src/CompatibilitySuppressions.xml b/src/libraries/System.Drawing.Common/src/CompatibilitySuppressions.xml index 1e8545d32cfc3..2fb526dc172a6 100644 --- a/src/libraries/System.Drawing.Common/src/CompatibilitySuppressions.xml +++ b/src/libraries/System.Drawing.Common/src/CompatibilitySuppressions.xml @@ -1,17 +1,5 @@  - - CP0002 - M:System.Drawing.Graphics.GetContextInfo(System.Drawing.PointF@) - lib/netstandard2.0/System.Drawing.Common.dll - lib/net462/System.Drawing.Common.dll - - - CP0002 - M:System.Drawing.Graphics.GetContextInfo(System.Drawing.PointF@,System.Drawing.Region@) - lib/netstandard2.0/System.Drawing.Common.dll - lib/net462/System.Drawing.Common.dll - CP0001 T:System.Drawing.FontConverter diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs index cba7e4aab0a55..4baa41dad2449 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs @@ -583,6 +583,7 @@ public object GetContextInfo() throw new NotImplementedException(); } +#if NETCOREAPP3_1_OR_GREATER [EditorBrowsable(EditorBrowsableState.Never)] [SupportedOSPlatform("windows")] public void GetContextInfo(out PointF offset) @@ -596,6 +597,7 @@ public void GetContextInfo(out PointF offset, out Region? clip) { throw new PlatformNotSupportedException(); } +#endif private void CheckErrorStatus(int status) { diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Windows.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Windows.cs index 8dd2ad15b22d5..475e35a176cea 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Windows.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Windows.cs @@ -684,7 +684,9 @@ public unsafe void EnumerateMetafile( /// WARNING: This method is for internal FX support only. /// [EditorBrowsable(EditorBrowsableState.Never)] +#if NETCOREAPP3_1_OR_GREATER [Obsolete(Obsoletions.GetContextInfoMessage, DiagnosticId = Obsoletions.GetContextInfoDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] +#endif [SupportedOSPlatform("windows")] public object GetContextInfo() { @@ -763,6 +765,7 @@ private void GetContextInfo(out Matrix3x2 cumulativeTransform, bool calculateCli } } +#if NETCOREAPP3_1_OR_GREATER /// /// Gets the cumulative offset. /// @@ -789,6 +792,7 @@ public void GetContextInfo(out PointF offset, out Region? clip) Vector2 translation = cumulativeTransform.Translation; offset = new PointF(translation.X, translation.Y); } +#endif public RectangleF VisibleClipBounds { diff --git a/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsGraphics.cs b/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsGraphics.cs index 6257a8219199b..1322bd6e81d08 100644 --- a/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsGraphics.cs +++ b/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsGraphics.cs @@ -61,6 +61,7 @@ public static WindowsGraphics FromGraphics(Graphics g, ApplyGraphicsProperties p { Region? clip = null; +#if NETCOREAPP3_1_OR_GREATER if (properties.HasFlag(ApplyGraphicsProperties.Clipping)) { g.GetContextInfo(out offset, out clip); @@ -69,6 +70,21 @@ public static WindowsGraphics FromGraphics(Graphics g, ApplyGraphicsProperties p { g.GetContextInfo(out offset); } +#else + Matrix? worldTransf = null; + if (g.GetContextInfo() is object[] data && data.Length == 2) + { + if (properties.HasFlag(ApplyGraphicsProperties.Clipping)) + { + clip = data[0] as Region; + } + worldTransf = data[1] as Matrix; + if (worldTransf != null) + { + offset = worldTransf.Offset; + } + } +#endif if (clip is not null) {