Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ public void DrawPie(System.Drawing.Pen pen, float x, float y, float width, float
public void DrawPolygon(System.Drawing.Pen pen, System.Drawing.PointF[] points) { }
public void DrawPolygon(System.Drawing.Pen pen, System.Drawing.Point[] points) { }
public void DrawRectangle(System.Drawing.Pen pen, System.Drawing.Rectangle rect) { }
public void DrawRectangle(System.Drawing.Pen pen, System.Drawing.RectangleF rect) { }
public void DrawRectangle(System.Drawing.Pen pen, int x, int y, int width, int height) { }
public void DrawRectangle(System.Drawing.Pen pen, float x, float y, float width, float height) { }
public void DrawRectangles(System.Drawing.Pen pen, System.Drawing.RectangleF[] rects) { }
Expand Down Expand Up @@ -567,6 +568,7 @@ public void FillEllipse(System.Drawing.Brush brush, int x, int y, int width, int
public void FillEllipse(System.Drawing.Brush brush, float x, float y, float width, float height) { }
public void FillPath(System.Drawing.Brush brush, System.Drawing.Drawing2D.GraphicsPath path) { }
public void FillPie(System.Drawing.Brush brush, System.Drawing.Rectangle rect, float startAngle, float sweepAngle) { }
public void FillPie(System.Drawing.Brush brush, System.Drawing.RectangleF rect, float startAngle, float sweepAngle) { }
public void FillPie(System.Drawing.Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle) { }
public void FillPie(System.Drawing.Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle) { }
public void FillPolygon(System.Drawing.Brush brush, System.Drawing.PointF[] points) { }
Expand Down
16 changes: 16 additions & 0 deletions src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,14 @@ 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);
}

/// <summary>
/// Draws the outline of a rectangle specified by <paramref name="rect"/>.
/// </summary>
Comment thread
medo64 marked this conversation as resolved.
public void DrawRectangle(Pen pen, RectangleF rect)
{
DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
}

/// <summary>
/// Draws the outline of a rectangle specified by <paramref name="rect"/>.
/// </summary>
Expand Down Expand Up @@ -1325,6 +1333,14 @@ public void FillPie(Brush brush, Rectangle rect, float startAngle, float sweepAn
FillPie(brush, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
}

/// <summary>
/// Fills the interior of a pie section defined by an ellipse and two radial lines.
/// </summary>
Comment thread
medo64 marked this conversation as resolved.
public void FillPie(Brush brush, RectangleF rect, float startAngle, float sweepAngle)
{
FillPie(brush, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
}

/// <summary>
/// Fills the interior of a pie section defined by an ellipse and two radial lines.
/// </summary>
Expand Down
102 changes: 102 additions & 0 deletions src/libraries/System.Drawing.Common/tests/GraphicsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2385,6 +2385,7 @@ public void DrawRectangle_NullPen_ThrowsArgumentNullException()
using (Graphics graphics = Graphics.FromImage(image))
{
AssertExtensions.Throws<ArgumentNullException>("pen", () => graphics.DrawRectangle(null, new Rectangle(0, 0, 1, 1)));
AssertExtensions.Throws<ArgumentNullException>("pen", () => graphics.DrawRectangle(null, new RectangleF(0f, 0f, 1f, 1f)));
AssertExtensions.Throws<ArgumentNullException>("pen", () => graphics.DrawRectangle(null, 0, 0, 1, 1));
AssertExtensions.Throws<ArgumentNullException>("pen", () => graphics.DrawRectangle(null, 0f, 0f, 1f, 1f));
}
Expand All @@ -2401,6 +2402,7 @@ public void DrawRectangle_DisposedPen_ThrowsArgumentException()


AssertExtensions.Throws<ArgumentException>(null, () => graphics.DrawRectangle(pen, new Rectangle(0, 0, 1, 1)));
AssertExtensions.Throws<ArgumentException>(null, () => graphics.DrawRectangle(pen, new RectangleF(0f, 0f, 1f, 1f)));
AssertExtensions.Throws<ArgumentException>(null, () => graphics.DrawRectangle(pen, 0, 0, 1, 1));
AssertExtensions.Throws<ArgumentException>(null, () => graphics.DrawRectangle(pen, 0f, 0f, 1f, 1f));
}
Expand All @@ -2418,6 +2420,7 @@ public void DrawRectangle_Busy_ThrowsInvalidOperationException()
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DrawRectangle(pen, new Rectangle(0, 0, 1, 1)));
Assert.Throws<InvalidOperationException>(() => graphics.DrawRectangle(pen, new RectangleF(0f, 0f, 1f, 1f)));
Assert.Throws<InvalidOperationException>(() => graphics.DrawRectangle(pen, 0, 0, 1, 1));
Assert.Throws<InvalidOperationException>(() => graphics.DrawRectangle(pen, 0f, 0f, 1f, 1f));
}
Expand All @@ -2438,6 +2441,7 @@ public void DrawRectangle_Disposed_ThrowsArgumentException()
graphics.Dispose();

AssertExtensions.Throws<ArgumentException>(null, () => graphics.DrawRectangle(pen, new Rectangle(0, 0, 1, 1)));
AssertExtensions.Throws<ArgumentException>(null, () => graphics.DrawRectangle(pen, new RectangleF(0f, 0f, 1f, 1f)));
AssertExtensions.Throws<ArgumentException>(null, () => graphics.DrawRectangle(pen, 0, 0, 1, 1));
AssertExtensions.Throws<ArgumentException>(null, () => graphics.DrawRectangle(pen, 0f, 0f, 1f, 1f));
}
Expand Down Expand Up @@ -3099,6 +3103,104 @@ 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<ArgumentNullException>("brush", () => graphics.FillPie(null, new Rectangle(0, 0, 1, 1), 0, 90));
AssertExtensions.Throws<ArgumentNullException>("brush", () => graphics.FillPie(null, 0, 0, 1, 1, 0, 90));
AssertExtensions.Throws<ArgumentNullException>("brush", () => graphics.FillPie(null, new RectangleF(0, 0, 1, 1), 0, 90));
AssertExtensions.Throws<ArgumentNullException>("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<ArgumentException>(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 1, 1), 0, 90));
AssertExtensions.Throws<ArgumentException>(null, () => graphics.FillPie(brush, 0, 0, 1, 1, 0, 90));
AssertExtensions.Throws<ArgumentException>(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 1, 1), 0, 90));
AssertExtensions.Throws<ArgumentException>(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<ArgumentException>(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 0, 1), 0, 90));
AssertExtensions.Throws<ArgumentException>(null, () => graphics.FillPie(brush, 0, 0, 0, 1, 0, 90));
AssertExtensions.Throws<ArgumentException>(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 0, 1), 0, 90));
AssertExtensions.Throws<ArgumentException>(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<ArgumentException>(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 1, 0), 0, 90));
AssertExtensions.Throws<ArgumentException>(null, () => graphics.FillPie(brush, 0, 0, 1, 0, 0, 90));
AssertExtensions.Throws<ArgumentException>(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 1, 0), 0, 90));
AssertExtensions.Throws<ArgumentException>(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<InvalidOperationException>(() => graphics.FillPie(brush, new Rectangle(0, 0, 1, 1), 0, 90));
Assert.Throws<InvalidOperationException>(() => graphics.FillPie(brush, 0, 0, 1, 1, 0, 90));
Assert.Throws<InvalidOperationException>(() => graphics.FillPie(brush, new RectangleF(0, 0, 1, 1), 0, 90));
Assert.Throws<InvalidOperationException>(() => 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<ArgumentException>(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 1, 1), 0, 90));
AssertExtensions.Throws<ArgumentException>(null, () => graphics.FillPie(brush, 0, 0, 1, 1, 0, 90));
AssertExtensions.Throws<ArgumentException>(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 1, 1), 0, 90));
AssertExtensions.Throws<ArgumentException>(null, () => graphics.FillPie(brush, 0f, 0f, 1f, 1f, 0, 90));
}
}

[ConditionalFact(Helpers.IsDrawingSupported)]
public void Clear_Color_Success()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ public void DrawRectangle_Negative()
g.DrawRectangle(pen, 5, 5, -10, -10);
g.DrawRectangle(pen, 0.0f, 0.0f, 5.0f, -10.0f);
g.DrawRectangle(pen, new Rectangle(15, 0, -10, 5));
g.DrawRectangle(pen, new RectangleF(0.0f, 5.0f, -10.0f, -10.0f));
CheckForEmptyBitmap(bitmap);
pen.Dispose();
g.Dispose();
Expand Down Expand Up @@ -964,6 +965,7 @@ public void FillRectangle_Negative()
g.FillRectangle(brush, 5, 5, -10, -10);
g.FillRectangle(brush, 0.0f, 0.0f, 5.0f, -10.0f);
g.FillRectangle(brush, new Rectangle(15, 0, -10, 5));
g.FillRectangle(brush, new RectangleF(15.0f, 0.0f, -10.0f, 5.0f));
CheckForEmptyBitmap(bitmap);
brush.Dispose();
g.Dispose();
Expand Down