Files
PdfPig/src/UglyToad.PdfPig/Graphics/Operations/PathConstruction/AppendStraightLineSegment.cs

60 lines
1.8 KiB
C#
Raw Normal View History

namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction
{
using System.IO;
using Geometry;
2019-01-03 22:20:53 +00:00
/// <inheritdoc />
/// <summary>
/// Append a straight line segment from the current point to the point (x, y).
/// </summary>
public class AppendStraightLineSegment : IGraphicsStateOperation
{
2019-01-03 22:20:53 +00:00
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "l";
2019-01-03 22:20:53 +00:00
/// <inheritdoc />
public string Operator => Symbol;
2019-01-03 22:20:53 +00:00
/// <summary>
/// The end point of the line.
/// </summary>
public PdfPoint End { get; }
2019-01-03 22:20:53 +00:00
/// <summary>
/// Create a new <see cref="AppendStraightLineSegment"/>.
/// </summary>
/// <param name="x">The x coordinate of the line's end point.</param>
/// <param name="y">The y coordinate of the line's end point.</param>
public AppendStraightLineSegment(decimal x, decimal y)
{
End = new PdfPoint(x, y);
}
2019-01-03 22:20:53 +00:00
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
var endPoint = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(End.X, End.Y));
operationContext.CurrentPath.LineTo(endPoint.X, endPoint.Y);
operationContext.CurrentPosition = endPoint;
}
2019-01-03 22:20:53 +00:00
/// <inheritdoc />
public void Write(Stream stream)
{
stream.WriteDecimal(End.X);
stream.WriteWhiteSpace();
stream.WriteDecimal(End.Y);
stream.WriteWhiteSpace();
stream.WriteText(Symbol);
stream.WriteWhiteSpace();
}
2019-01-03 22:20:53 +00:00
/// <inheritdoc />
public override string ToString()
{
return $"{End.X} {End.Y} {Symbol}";
}
}
}