Skip to content

Commit

Permalink
[release/6.0] Move 2 Drawing APIs that are not implemented in netfx t…
Browse files Browse the repository at this point in the history
…o netcoreapp3.1 or later (#60371)
  • Loading branch information
safern authored Oct 15, 2021
1 parent 80b7531 commit f94d65e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,16 @@ public void Flush(System.Drawing.Drawing2D.FlushIntention intention) { }
public static System.Drawing.Graphics FromImage(System.Drawing.Image image) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
#if NETCOREAPP3_1_OR_GREATER
[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}")]
#endif
public object GetContextInfo() { throw null; }
#if NETCOREAPP3_1_OR_GREATER
[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; }
#endif
public static System.IntPtr GetHalftonePalette() { throw null; }
public System.IntPtr GetHdc() { throw null; }
public System.Drawing.Color GetNearestColor(System.Drawing.Color color) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Drawing.Graphics.GetContextInfo(System.Drawing.PointF@)</Target>
<Left>lib/netstandard2.0/System.Drawing.Common.dll</Left>
<Right>lib/net461/System.Drawing.Common.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Drawing.Graphics.GetContextInfo(System.Drawing.PointF@,System.Drawing.Region@)</Target>
<Left>lib/netstandard2.0/System.Drawing.Common.dll</Left>
<Right>lib/net461/System.Drawing.Common.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.Drawing.FontConverter</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -596,6 +597,7 @@ public void GetContextInfo(out PointF offset, out Region? clip)
{
throw new PlatformNotSupportedException();
}
#endif

private void CheckErrorStatus(int status)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,9 @@ public unsafe void EnumerateMetafile(
/// WARNING: This method is for internal FX support only.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
#if NETCOREAPP3_1_OR_GREATER
[Obsolete(Obsoletions.GetContextInfoMessage, DiagnosticId = Obsoletions.GetContextInfoDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
#endif
[SupportedOSPlatform("windows")]
public object GetContextInfo()
{
Expand Down Expand Up @@ -763,6 +765,7 @@ private void GetContextInfo(out Matrix3x2 cumulativeTransform, bool calculateCli
}
}

#if NETCOREAPP3_1_OR_GREATER
/// <summary>
/// Gets the cumulative offset.
/// </summary>
Expand All @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down

0 comments on commit f94d65e

Please sign in to comment.