diff --git a/src/System.Drawing.Common/src/Forwards.cs b/src/System.Drawing.Common/src/Forwards.cs index c24451ce7c0..8178458fc67 100644 --- a/src/System.Drawing.Common/src/Forwards.cs +++ b/src/System.Drawing.Common/src/Forwards.cs @@ -1,5 +1,17 @@ #pragma warning disable CS0618,CA2252 +#if NETCOREAPP +// This is required for back-compatibility with legacy Xamarin which had these types in System.Drawing.Common.dll +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.Color))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.KnownColor))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.Point))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.PointF))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.Rectangle))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.RectangleF))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.Size))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.SizeF))] +#endif + #if NETCOREAPP || NETFRAMEWORK [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.ColorTranslator))] [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Drawing.SystemColors))] diff --git a/src/System.Drawing.Common/src/System/Drawing/BufferedGraphics.cs b/src/System.Drawing.Common/src/System/Drawing/BufferedGraphics.cs index f7bcdf448c4..4224959597a 100644 --- a/src/System.Drawing.Common/src/System/Drawing/BufferedGraphics.cs +++ b/src/System.Drawing.Common/src/System/Drawing/BufferedGraphics.cs @@ -13,7 +13,7 @@ namespace System.Drawing /// public sealed class BufferedGraphics : IDisposable { - private Graphics? _targetGraphics; + private readonly Graphics? _targetGraphics; private readonly IntPtr _targetDC; private Graphics _bufferedGraphicsSurface; private BufferedGraphicsContext _context; diff --git a/src/System.Drawing.Common/src/System/Drawing/FontConverter.cs b/src/System.Drawing.Common/src/System/Drawing/FontConverter.cs index 1e2125a60a3..3897358d9e3 100644 --- a/src/System.Drawing.Common/src/System/Drawing/FontConverter.cs +++ b/src/System.Drawing.Common/src/System/Drawing/FontConverter.cs @@ -38,7 +38,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, [NotNullWhen( ValueStringBuilder sb = default; sb.Append(font.Name); sb.Append(culture.TextInfo.ListSeparator[0]); - sb.Append(" "); + sb.Append(' '); sb.Append(font.Size.ToString(culture.NumberFormat)); switch (font.Unit) diff --git a/src/System.Drawing.Common/src/System/Drawing/Icon.cs b/src/System.Drawing.Common/src/System/Drawing/Icon.cs index cb4c250cec5..a3d7c5cce06 100644 --- a/src/System.Drawing.Common/src/System/Drawing/Icon.cs +++ b/src/System.Drawing.Common/src/System/Drawing/Icon.cs @@ -127,7 +127,20 @@ public Icon(Stream stream, int width, int height) : this() ArgumentNullException.ThrowIfNull(stream); _iconData = new byte[(int)stream.Length]; - stream.Read(_iconData, 0, _iconData.Length); +#if NET7_0_OR_GREATER + stream.ReadExactly(_iconData); +#else + int totalRead = 0; + while (totalRead < _iconData.Length) + { + int bytesRead = stream.Read(_iconData, totalRead, _iconData.Length - totalRead); + if (bytesRead <= 0) + { + throw new EndOfStreamException(); + } + totalRead += bytesRead; + } +#endif Initialize(width, height); } diff --git a/src/System.Drawing.Common/src/System/Drawing/ImageInfo.cs b/src/System.Drawing.Common/src/System/Drawing/ImageInfo.cs index 822cdeda47a..9eb32d87300 100644 --- a/src/System.Drawing.Common/src/System/Drawing/ImageInfo.cs +++ b/src/System.Drawing.Common/src/System/Drawing/ImageInfo.cs @@ -29,7 +29,7 @@ private sealed class ImageInfo private readonly bool _animated; private EventHandler? _onFrameChangedHandler; private readonly long[]? _frameEndTimes; - private long _totalAnimationTime; + private readonly long _totalAnimationTime; private long _frameTimer; public ImageInfo(Image image) diff --git a/src/System.Drawing.Common/tests/IconTests.cs b/src/System.Drawing.Common/tests/IconTests.cs index fae209c336d..249d17065b9 100644 --- a/src/System.Drawing.Common/tests/IconTests.cs +++ b/src/System.Drawing.Common/tests/IconTests.cs @@ -113,6 +113,23 @@ public void Ctor_Stream() } } + [ConditionalFact(Helpers.IsDrawingSupported)] + [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug fix in core")] + public void Ctor_Stream_Trickled() + { + var stream = new TrickleStream(File.ReadAllBytes(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"))); + var icon = new Icon(stream); + Assert.Equal(32, icon.Width); + Assert.Equal(32, icon.Height); + Assert.Equal(new Size(32, 32), icon.Size); + } + + private sealed class TrickleStream : MemoryStream + { + public TrickleStream(byte[] bytes) : base(bytes) { } + public override int Read(byte[] buffer, int offset, int count) => base.Read(buffer, offset, Math.Min(count, 1)); + } + [ConditionalTheory(Helpers.IsDrawingSupported)] [MemberData(nameof(Size_TestData))] public void Ctor_Stream_Width_Height(string fileName, Size size, Size expectedSize) diff --git a/src/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs b/src/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs index 094d6101141..e9253c60286 100644 --- a/src/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs +++ b/src/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs @@ -2293,7 +2293,7 @@ public void TestReleaseHdcException2() Assert.Throws(() => g.ReleaseHdc()); } } - [Fact] + [ConditionalFact] public void VisibleClipBound() { if (PlatformDetection.IsArmOrArm64Process) @@ -2329,7 +2329,7 @@ public void VisibleClipBound() } } - [Fact] + [ConditionalFact] public void VisibleClipBound_BigClip() { if (PlatformDetection.IsArmOrArm64Process) @@ -2376,7 +2376,7 @@ public void VisibleClipBound_BigClip() } } - [Fact] + [ConditionalFact] public void Rotate() { if (PlatformDetection.IsArmOrArm64Process)