diff --git a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs
index 7c5f8f890a84d..f9d987de24d1c 100644
--- a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs
+++ b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs
@@ -8,6 +8,8 @@ namespace System.Drawing
{
public sealed partial class Graphics
{
+ public void DrawRectangle(System.Drawing.Pen pen, System.Drawing.RectangleF rect) { }
+ public void FillPie(System.Drawing.Brush brush, System.Drawing.RectangleF rect, float startAngle, float sweepAngle) { }
public System.Numerics.Matrix3x2 TransformElements { get { throw null; } set { } }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs
index 4917e8f33d831..c390a05f92eff 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs
@@ -708,6 +708,16 @@ public void DrawBezier(Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)
DrawBezier(pen, pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
}
+ ///
+ /// Draws the outline of a rectangle specified by .
+ ///
+ /// A Pen that determines the color, width, and style of the rectangle.
+ /// A Rectangle structure that represents the rectangle to draw.
+ public void DrawRectangle(Pen pen, RectangleF rect)
+ {
+ DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
+ }
+
///
/// Draws the outline of a rectangle specified by .
///
@@ -1325,6 +1335,18 @@ public void FillPie(Brush brush, Rectangle rect, float startAngle, float sweepAn
FillPie(brush, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
}
+ ///
+ /// Fills the interior of a pie section defined by an ellipse and two radial lines.
+ ///
+ /// A Brush that determines the characteristics of the fill.
+ /// A Rectangle structure that represents the bounding rectangle that defines the ellipse from which the pie section comes.
+ /// Angle in degrees measured clockwise from the x-axis to the first side of the pie section.
+ /// Angle in degrees measured clockwise from the parameter to the second side of the pie section.
+ public void FillPie(Brush brush, RectangleF rect, float startAngle, float sweepAngle)
+ {
+ FillPie(brush, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
+ }
+
///
/// Fills the interior of a pie section defined by an ellipse and two radial lines.
///
diff --git a/src/libraries/System.Drawing.Common/tests/GraphicsTests.Core.cs b/src/libraries/System.Drawing.Common/tests/GraphicsTests.Core.cs
index 3a137da17c7e5..d691cd23ff9df 100644
--- a/src/libraries/System.Drawing.Common/tests/GraphicsTests.Core.cs
+++ b/src/libraries/System.Drawing.Common/tests/GraphicsTests.Core.cs
@@ -77,5 +77,154 @@ public void TransformElements_RoundTrip()
}
}
}
+
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void DrawRectangle_NullPen_ThrowsArgumentNullException_Core()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (Graphics graphics = Graphics.FromImage(image))
+ {
+ AssertExtensions.Throws("pen", () => graphics.DrawRectangle(null, new RectangleF(0f, 0f, 1f, 1f)));
+ // other DrawRectangle overloads tested in DrawRectangle_NullPen_ThrowsArgumentNullException()
+ }
+ }
+
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void DrawRectangle_DisposedPen_ThrowsArgumentException_Core()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (Graphics graphics = Graphics.FromImage(image))
+ {
+ var pen = new Pen(Color.Red);
+ pen.Dispose();
+
+ AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, new RectangleF(0f, 0f, 1f, 1f)));
+ // other DrawRectangle overloads tested in DrawRectangle_DisposedPen_ThrowsArgumentException()
+ }
+ }
+
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)]
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void DrawRectangle_Busy_ThrowsInvalidOperationException_Core()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (Graphics graphics = Graphics.FromImage(image))
+ using (var pen = new Pen(Color.Red))
+ {
+ graphics.GetHdc();
+ try
+ {
+ Assert.Throws(() => graphics.DrawRectangle(pen, new RectangleF(0f, 0f, 1f, 1f)));
+ // other DrawRectangle overloads tested in DrawRectangle_Busy_ThrowsInvalidOperationException()
+ }
+ finally
+ {
+ graphics.ReleaseHdc();
+ }
+ }
+ }
+
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void DrawRectangle_Disposed_ThrowsArgumentException_Core()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (var pen = new Pen(Color.Red))
+ {
+ Graphics graphics = Graphics.FromImage(image);
+ graphics.Dispose();
+
+ AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, new RectangleF(0f, 0f, 1f, 1f)));
+ // other DrawRectangle overloads tested in DrawRectangle_Disposed_ThrowsArgumentException()
+ }
+ }
+
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void FillPie_NullPen_ThrowsArgumentNullException_Core()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (Graphics graphics = Graphics.FromImage(image))
+ {
+ AssertExtensions.Throws("brush", () => graphics.FillPie(null, new RectangleF(0, 0, 1, 1), 0, 90));
+ // other FillPie overloads tested in FillPie_NullPen_ThrowsArgumentNullException()
+ }
+ }
+
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void FillPie_DisposedPen_ThrowsArgumentException_Core()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (Graphics graphics = Graphics.FromImage(image))
+ {
+ var brush = new SolidBrush(Color.Red);
+ brush.Dispose();
+
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 1, 1), 0, 90));
+ // other FillPie overloads tested in FillPie_DisposedPen_ThrowsArgumentException()
+ }
+ }
+
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)]
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void FillPie_ZeroWidth_ThrowsArgumentException_Core()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (Graphics graphics = Graphics.FromImage(image))
+ using (var brush = new SolidBrush(Color.Red))
+ {
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 0, 1), 0, 90));
+ // other FillPie overloads tested in FillPie_ZeroWidth_ThrowsArgumentException()
+ }
+ }
+
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)]
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void FillPie_ZeroHeight_ThrowsArgumentException_Core()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (Graphics graphics = Graphics.FromImage(image))
+ using (var brush = new SolidBrush(Color.Red))
+ {
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 1, 0), 0, 90));
+ // other FillPie overloads tested in FillPie_ZeroHeight_ThrowsArgumentException()
+ }
+ }
+
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)]
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void FillPie_Busy_ThrowsInvalidOperationException_Core()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (Graphics graphics = Graphics.FromImage(image))
+ using (var brush = new SolidBrush(Color.Red))
+ {
+ graphics.GetHdc();
+ try
+ {
+ Assert.Throws(() => graphics.FillPie(brush, new RectangleF(0, 0, 1, 1), 0, 90));
+ // other FillPie overloads tested in FillPie_Busy_ThrowsInvalidOperationException()
+ }
+ finally
+ {
+ graphics.ReleaseHdc();
+ }
+ }
+ }
+
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void FillPie_Disposed_ThrowsArgumentException_Core()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (var brush = new SolidBrush(Color.Red))
+ {
+ Graphics graphics = Graphics.FromImage(image);
+ graphics.Dispose();
+
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 1, 1), 0, 90));
+ // other FillPie overloads tested in FillPie_Disposed_ThrowsArgumentException()
+ }
+ }
+
+
+
}
}
diff --git a/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs b/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs
index 8c0f280b86361..c99ad88ea40ae 100644
--- a/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs
+++ b/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs
@@ -2399,7 +2399,6 @@ public void DrawRectangle_DisposedPen_ThrowsArgumentException()
var pen = new Pen(Color.Red);
pen.Dispose();
-
AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, new Rectangle(0, 0, 1, 1)));
AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, 0, 0, 1, 1));
AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, 0f, 0f, 1f, 1f));
@@ -3099,6 +3098,98 @@ public void DrawClosedCurve_Disposed_ThrowsArgumentException()
}
}
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void FillPie_NullPen_ThrowsArgumentNullException()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (Graphics graphics = Graphics.FromImage(image))
+ {
+ AssertExtensions.Throws("brush", () => graphics.FillPie(null, new Rectangle(0, 0, 1, 1), 0, 90));
+ AssertExtensions.Throws("brush", () => graphics.FillPie(null, 0, 0, 1, 1, 0, 90));
+ AssertExtensions.Throws("brush", () => graphics.FillPie(null, 0f, 0f, 1f, 1f, 0, 90));
+ }
+ }
+
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void FillPie_DisposedPen_ThrowsArgumentException()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (Graphics graphics = Graphics.FromImage(image))
+ {
+ var brush = new SolidBrush(Color.Red);
+ brush.Dispose();
+
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 1, 1), 0, 90));
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0, 0, 1, 1, 0, 90));
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0f, 0f, 1f, 1f, 0, 90));
+ }
+ }
+
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)]
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void FillPie_ZeroWidth_ThrowsArgumentException()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (Graphics graphics = Graphics.FromImage(image))
+ using (var brush = new SolidBrush(Color.Red))
+ {
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 0, 1), 0, 90));
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0, 0, 0, 1, 0, 90));
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0f, 0f, 0f, 1f, 0, 90));
+ }
+ }
+
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)]
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void FillPie_ZeroHeight_ThrowsArgumentException()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (Graphics graphics = Graphics.FromImage(image))
+ using (var brush = new SolidBrush(Color.Red))
+ {
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 1, 0), 0, 90));
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0, 0, 1, 0, 0, 90));
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0f, 0f, 1f, 0f, 0, 90));
+ }
+ }
+
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)]
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void FillPie_Busy_ThrowsInvalidOperationException()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (Graphics graphics = Graphics.FromImage(image))
+ using (var brush = new SolidBrush(Color.Red))
+ {
+ graphics.GetHdc();
+ try
+ {
+ Assert.Throws(() => graphics.FillPie(brush, new Rectangle(0, 0, 1, 1), 0, 90));
+ Assert.Throws(() => graphics.FillPie(brush, 0, 0, 1, 1, 0, 90));
+ Assert.Throws(() => graphics.FillPie(brush, 0f, 0f, 1f, 1f, 0, 90));
+ }
+ finally
+ {
+ graphics.ReleaseHdc();
+ }
+ }
+ }
+
+ [ConditionalFact(Helpers.IsDrawingSupported)]
+ public void FillPie_Disposed_ThrowsArgumentException()
+ {
+ using (var image = new Bitmap(10, 10))
+ using (var brush = new SolidBrush(Color.Red))
+ {
+ Graphics graphics = Graphics.FromImage(image);
+ graphics.Dispose();
+
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 1, 1), 0, 90));
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0, 0, 1, 1, 0, 90));
+ AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0f, 0f, 1f, 1f, 0, 90));
+ }
+ }
+
[ConditionalFact(Helpers.IsDrawingSupported)]
public void Clear_Color_Success()
{