Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/6.0] Move 2 Drawing APIs that are not implemented in netfx to net6.0 or later #60371

Merged
merged 2 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we consider making this change for netcoreapp3.1 and later instead of net6.0 and later? That could make it so the Obsolete message reaches people earlier: those that update the package without retargeting. The package builds for netcoreapp3.1 as well as net6.0 and moving this change from netstandard2.0 to netcoreapp3.1 instead of net6.0 might reach more folks (and be a smaller difference from what we've already shipped in previews).

I'm fine either way, but I'd like this to be considered.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with including it in netcoreapp3.1. I'll update the PR accordingly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 😄 Thanks for the suggestion.

#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
tarekgh marked this conversation as resolved.
Show resolved Hide resolved
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