Skip to content

Commit 21bdf48

Browse files
authored
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
1 parent 9362323 commit 21bdf48

File tree

7 files changed

+35
-20
lines changed

7 files changed

+35
-20
lines changed

src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -594,14 +594,6 @@ public void Flush(System.Drawing.Drawing2D.FlushIntention intention) { }
594594
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
595595
public static System.Drawing.Graphics FromHwndInternal(System.IntPtr hwnd) { throw null; }
596596
public static System.Drawing.Graphics FromImage(System.Drawing.Image image) { throw null; }
597-
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
598-
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
599-
[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}")]
600-
public object GetContextInfo() { throw null; }
601-
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
602-
public void GetContextInfo(out PointF offset) { throw null; }
603-
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
604-
public void GetContextInfo(out PointF offset, out Region? clip) { throw null; }
605597
public static System.IntPtr GetHalftonePalette() { throw null; }
606598
public System.IntPtr GetHdc() { throw null; }
607599
public System.Drawing.Color GetNearestColor(System.Drawing.Color color) { throw null; }

src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ namespace System.Drawing
99
public sealed partial class Graphics
1010
{
1111
public System.Numerics.Matrix3x2 TransformElements { get { throw null; } set { } }
12+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
13+
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
14+
[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}")]
15+
public object GetContextInfo() { throw null; }
16+
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
17+
public void GetContextInfo(out PointF offset) { throw null; }
18+
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
19+
public void GetContextInfo(out PointF offset, out Region? clip) { throw null; }
1220
}
1321
}
1422
namespace System.Drawing.Drawing2D

src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netstandard.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public static partial class ColorTranslator
1515
public static int ToOle(System.Drawing.Color c) { throw null; }
1616
public static int ToWin32(System.Drawing.Color c) { throw null; }
1717
}
18+
public sealed partial class Graphics
19+
{
20+
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
21+
public object GetContextInfo() { throw null; }
22+
}
1823
public static partial class SystemColors
1924
{
2025
public static System.Drawing.Color ActiveBorder { get { throw null; } }

src/libraries/System.Drawing.Common/src/CompatibilitySuppressions.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3-
<Suppression>
4-
<DiagnosticId>CP0002</DiagnosticId>
5-
<Target>M:System.Drawing.Graphics.GetContextInfo(System.Drawing.PointF@)</Target>
6-
<Left>lib/netstandard2.0/System.Drawing.Common.dll</Left>
7-
<Right>lib/net462/System.Drawing.Common.dll</Right>
8-
</Suppression>
9-
<Suppression>
10-
<DiagnosticId>CP0002</DiagnosticId>
11-
<Target>M:System.Drawing.Graphics.GetContextInfo(System.Drawing.PointF@,System.Drawing.Region@)</Target>
12-
<Left>lib/netstandard2.0/System.Drawing.Common.dll</Left>
13-
<Right>lib/net462/System.Drawing.Common.dll</Right>
14-
</Suppression>
153
<Suppression>
164
<DiagnosticId>CP0001</DiagnosticId>
175
<Target>T:System.Drawing.FontConverter</Target>

src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ public object GetContextInfo()
583583
throw new NotImplementedException();
584584
}
585585

586+
#if NETCOREAPP3_1_OR_GREATER
586587
[EditorBrowsable(EditorBrowsableState.Never)]
587588
[SupportedOSPlatform("windows")]
588589
public void GetContextInfo(out PointF offset)
@@ -596,6 +597,7 @@ public void GetContextInfo(out PointF offset, out Region? clip)
596597
{
597598
throw new PlatformNotSupportedException();
598599
}
600+
#endif
599601

600602
private void CheckErrorStatus(int status)
601603
{

src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Windows.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,9 @@ public unsafe void EnumerateMetafile(
684684
/// WARNING: This method is for internal FX support only.
685685
/// </summary>
686686
[EditorBrowsable(EditorBrowsableState.Never)]
687+
#if NETCOREAPP3_1_OR_GREATER
687688
[Obsolete(Obsoletions.GetContextInfoMessage, DiagnosticId = Obsoletions.GetContextInfoDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
689+
#endif
688690
[SupportedOSPlatform("windows")]
689691
public object GetContextInfo()
690692
{
@@ -763,6 +765,7 @@ private void GetContextInfo(out Matrix3x2 cumulativeTransform, bool calculateCli
763765
}
764766
}
765767

768+
#if NETCOREAPP3_1_OR_GREATER
766769
/// <summary>
767770
/// Gets the cumulative offset.
768771
/// </summary>
@@ -789,6 +792,7 @@ public void GetContextInfo(out PointF offset, out Region? clip)
789792
Vector2 translation = cumulativeTransform.Translation;
790793
offset = new PointF(translation.X, translation.Y);
791794
}
795+
#endif
792796

793797
public RectangleF VisibleClipBounds
794798
{

src/libraries/System.Drawing.Common/src/misc/GDI/WindowsGraphics.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public static WindowsGraphics FromGraphics(Graphics g, ApplyGraphicsProperties p
6161
{
6262
Region? clip = null;
6363

64+
#if NETCOREAPP3_1_OR_GREATER
6465
if (properties.HasFlag(ApplyGraphicsProperties.Clipping))
6566
{
6667
g.GetContextInfo(out offset, out clip);
@@ -69,6 +70,21 @@ public static WindowsGraphics FromGraphics(Graphics g, ApplyGraphicsProperties p
6970
{
7071
g.GetContextInfo(out offset);
7172
}
73+
#else
74+
Matrix? worldTransf = null;
75+
if (g.GetContextInfo() is object[] data && data.Length == 2)
76+
{
77+
if (properties.HasFlag(ApplyGraphicsProperties.Clipping))
78+
{
79+
clip = data[0] as Region;
80+
}
81+
worldTransf = data[1] as Matrix;
82+
if (worldTransf != null)
83+
{
84+
offset = worldTransf.Offset;
85+
}
86+
}
87+
#endif
7288

7389
if (clip is not null)
7490
{

0 commit comments

Comments
 (0)