namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction { using System.IO; using Geometry; /// /// /// Append a rectangle to the current path as a complete subpath. /// public class AppendRectangle : IGraphicsStateOperation { /// /// The symbol for this operation in a stream. /// public const string Symbol = "re"; /// public string Operator => Symbol; /// /// The lower left corner. /// public PdfPoint LowerLeft { get; } /// /// The width of the rectangle. /// public decimal Width { get; } /// /// The height of the rectangle. /// public decimal Height { get; } /// /// Create a new . /// /// The x coordinate of the lower left corner. /// The y coordinate of the lower left corner. /// The width of the rectangle. /// The height of the rectangle. public AppendRectangle(decimal x, decimal y, decimal width, decimal height) { LowerLeft = new PdfPoint(x, y); Width = width; Height = height; } /// public void Run(IOperationContext operationContext) { operationContext.BeginSubpath(); operationContext.CurrentPath.Rectangle(LowerLeft.X, LowerLeft.Y, Width, Height); operationContext.CurrentPath.ClosePath(); } /// public void Write(Stream stream) { stream.WriteDecimal(LowerLeft.X); stream.WriteWhiteSpace(); stream.WriteDecimal(LowerLeft.Y); stream.WriteWhiteSpace(); stream.WriteDecimal(Width); stream.WriteWhiteSpace(); stream.WriteDecimal(Height); stream.WriteWhiteSpace(); stream.WriteText(Symbol); stream.WriteNewLine(); } /// public override string ToString() { return $"{LowerLeft.X} {LowerLeft.Y} {Width} {Height} {Symbol}"; } } }