mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-04-05 20:55:01 +08:00
#215 support filling rectangles on pdf builder
This commit is contained in:
parent
ad0fb4ec5b
commit
d8e0263ec7
@ -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")
|
private static void WriteFile(string name, byte[] bytes, string extension = "pdf")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -91,7 +91,8 @@
|
|||||||
/// <param name="width">The width of the rectangle.</param>
|
/// <param name="width">The width of the rectangle.</param>
|
||||||
/// <param name="height">The height 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>
|
/// <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)
|
if (lineWidth != 1)
|
||||||
{
|
{
|
||||||
@ -99,7 +100,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
operations.Add(new AppendRectangle((decimal)position.X, (decimal)position.Y, width, height));
|
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)
|
if (lineWidth != 1)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user