Skip to content

Commit

Permalink
Manually apply commits since Feb 12th 2023
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorHofer committed Mar 13, 2023
1 parent 3ae88a6 commit 7d16942
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/System.Drawing.Common/src/Forwards.cs
Original file line number Diff line number Diff line change
@@ -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))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace System.Drawing
/// </summary>
public sealed class BufferedGraphics : IDisposable
{
private Graphics? _targetGraphics;
private readonly Graphics? _targetGraphics;
private readonly IntPtr _targetDC;
private Graphics _bufferedGraphicsSurface;
private BufferedGraphicsContext _context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion src/System.Drawing.Common/src/System/Drawing/Icon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/System.Drawing.Common/src/System/Drawing/ImageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions src/System.Drawing.Common/tests/IconTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2293,7 +2293,7 @@ public void TestReleaseHdcException2()
Assert.Throws<ArgumentException>(() => g.ReleaseHdc());
}
}
[Fact]
[ConditionalFact]
public void VisibleClipBound()
{
if (PlatformDetection.IsArmOrArm64Process)
Expand Down Expand Up @@ -2329,7 +2329,7 @@ public void VisibleClipBound()
}
}

[Fact]
[ConditionalFact]
public void VisibleClipBound_BigClip()
{
if (PlatformDetection.IsArmOrArm64Process)
Expand Down Expand Up @@ -2376,7 +2376,7 @@ public void VisibleClipBound_BigClip()
}
}

[Fact]
[ConditionalFact]
public void Rotate()
{
if (PlatformDetection.IsArmOrArm64Process)
Expand Down

0 comments on commit 7d16942

Please sign in to comment.