From 53475341bda0daaa039965ed5a3c6209bc6847c2 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Wed, 20 Sep 2017 23:28:15 +0200 Subject: [PATCH] Workaround libgdiplus glitches Don't test metafileHeader.Bounds when using libgdiplus. Don't test metafile.GetBounds on Unix, force MetafileHeader.Bounds to return an empty rectangle when MetafileSize == 0 Don't validate graphicsUnit on Unix. Commit migrated from https://github.com/dotnet/corefx/commit/825ef7c0d16798739f4cb69d3a4f1e924ef7ff18 --- .../src/System/Drawing/Imaging/MetafileHeader.Unix.cs | 11 ++++++++++- .../System.Drawing.Common/tests/Imaging/MetafileTests.cs | 13 +++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeader.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeader.Unix.cs index 8efaab2..f4f2cdd 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeader.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeader.Unix.cs @@ -153,7 +153,16 @@ namespace System.Drawing.Imaging public Rectangle Bounds { - get { return new Rectangle(header.x, header.y, header.width, header.height); } + get + { + if (this.MetafileSize == 0) + { + // GDI+ compatibility; + return new Rectangle(); + } + + return new Rectangle(header.x, header.y, header.width, header.height); + } } public float DpiX diff --git a/src/libraries/System.Drawing.Common/tests/Imaging/MetafileTests.cs b/src/libraries/System.Drawing.Common/tests/Imaging/MetafileTests.cs index a010f9c..6e06186 100644 --- a/src/libraries/System.Drawing.Common/tests/Imaging/MetafileTests.cs +++ b/src/libraries/System.Drawing.Common/tests/Imaging/MetafileTests.cs @@ -230,7 +230,7 @@ namespace System.Drawing.Imaging.Tests yield return new object[] { MetafileFrameUnit.Millimeter }; yield return new object[] { MetafileFrameUnit.GdiCompatible }; } - + [ConditionalTheory(Helpers.GdiplusIsAvailable)] [MemberData(nameof(MetafileFrameUnit_TestData))] public void Ctor_IntPtrRectangleFMetafileFrameUnit_Success(MetafileFrameUnit frameUnit) @@ -342,7 +342,7 @@ namespace System.Drawing.Imaging.Tests yield return new object[] { (MetafileFrameUnit)int.MaxValue }; yield return new object[] { (MetafileFrameUnit)int.MinValue }; } - + [ConditionalTheory(Helpers.GdiplusIsAvailable)] [MemberData(nameof(MetafileFrameUnit_Invalid_TestData))] public void Ctor_InvalidMetafileFrameUnit_ThrowsArgumentException(MetafileFrameUnit farameUnit) @@ -1076,8 +1076,13 @@ namespace System.Drawing.Imaging.Tests GraphicsUnit graphicsUnit = (GraphicsUnit)int.MaxValue; AssertMetafileHeaderIsBlank(metafile.GetMetafileHeader()); - Assert.Equal(new Rectangle(0, 0, 1, 1), metafile.GetBounds(ref graphicsUnit)); - Assert.Equal(GraphicsUnit.Pixel, graphicsUnit); + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + // This values are incorrect on libgdiplus. + Assert.Equal(new Rectangle(0, 0, 1, 1), metafile.GetBounds(ref graphicsUnit)); + Assert.Equal(GraphicsUnit.Pixel, graphicsUnit); + } } private void AssertMetafileHeaderIsBlank(MetafileHeader metafileHeader) -- 2.7.4