#215 support filling rectangles on pdf builder

This commit is contained in:
Eliot Jones 2020-11-17 17:00:13 -04:00
parent ad0fb4ec5b
commit d8e0263ec7
2 changed files with 26 additions and 2 deletions

View File

@ -588,6 +588,21 @@
}
}
[Fact]
public void CanCreateDocumentWithFilledRectangle()
{
var builder = new PdfDocumentBuilder();
var page = builder.AddPage(PageSize.A4);
page.SetTextAndFillColor(255, 0, 0);
page.SetStrokeColor(0, 0, 255);
page.DrawRectangle(new PdfPoint(20, 100), 200, 100, 1.5m, true);
var file = builder.Build();
WriteFile(nameof(CanCreateDocumentWithFilledRectangle), file);
}
private static void WriteFile(string name, byte[] bytes, string extension = "pdf")
{
try

View File

@ -91,7 +91,8 @@
/// <param name="width">The width of the rectangle.</param>
/// <param name="height">The height of the rectangle.</param>
/// <param name="lineWidth">The width of the line border of the rectangle.</param>
public void DrawRectangle(PdfPoint position, decimal width, decimal height, decimal lineWidth = 1)
/// <param name="fill">Whether to fill with the color set by <see cref="SetTextAndFillColor"/>.</param>
public void DrawRectangle(PdfPoint position, decimal width, decimal height, decimal lineWidth = 1, bool fill = false)
{
if (lineWidth != 1)
{
@ -99,7 +100,15 @@
}
operations.Add(new AppendRectangle((decimal)position.X, (decimal)position.Y, width, height));
operations.Add(StrokePath.Value);
if (fill)
{
operations.Add(FillPathEvenOddRuleAndStroke.Value);
}
else
{
operations.Add(StrokePath.Value);
}
if (lineWidth != 1)
{