2018-01-10 19:49:32 +00:00
|
|
|
|
namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction
|
2017-11-22 18:41:34 +00:00
|
|
|
|
{
|
2018-12-02 16:14:55 +00:00
|
|
|
|
using System.IO;
|
2020-01-04 22:39:13 +00:00
|
|
|
|
using PdfPig.Core;
|
2017-11-22 18:41:34 +00:00
|
|
|
|
|
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
|
2017-11-22 18:41:34 +00:00
|
|
|
|
{
|
2019-01-03 22:20:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The symbol for this operation in a stream.
|
|
|
|
|
/// </summary>
|
2017-11-22 18:41:34 +00:00
|
|
|
|
public const string Symbol = "l";
|
|
|
|
|
|
2019-01-03 22:20:53 +00:00
|
|
|
|
/// <inheritdoc />
|
2017-11-22 18:41:34 +00:00
|
|
|
|
public string Operator => Symbol;
|
|
|
|
|
|
2019-01-03 22:20:53 +00:00
|
|
|
|
/// <summary>
|
2019-12-21 18:09:49 +00:00
|
|
|
|
/// The x coordinate of the end point of the line.
|
2019-01-03 22:20:53 +00:00
|
|
|
|
/// </summary>
|
2019-12-21 18:09:49 +00:00
|
|
|
|
public decimal X { get; }
|
2017-11-22 18:41:34 +00:00
|
|
|
|
|
2019-12-21 18:09:49 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The y coordinate of the end point of the line.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal Y { 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>
|
2017-11-22 18:41:34 +00:00
|
|
|
|
public AppendStraightLineSegment(decimal x, decimal y)
|
|
|
|
|
{
|
2019-12-21 18:09:49 +00:00
|
|
|
|
X = x;
|
|
|
|
|
Y = y;
|
2017-11-22 18:41:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-03 22:20:53 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void Run(IOperationContext operationContext)
|
2017-11-30 23:47:24 +00:00
|
|
|
|
{
|
2020-04-05 11:07:02 +01:00
|
|
|
|
if (operationContext.CurrentSubpath == null) return;
|
|
|
|
|
|
2019-12-21 18:09:49 +00:00
|
|
|
|
var endPoint = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(X, Y));
|
2020-04-02 16:39:48 +01:00
|
|
|
|
operationContext.CurrentSubpath.LineTo(endPoint.X, endPoint.Y);
|
2019-08-08 21:19:18 +01:00
|
|
|
|
operationContext.CurrentPosition = endPoint;
|
2017-11-30 23:47:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-03 22:20:53 +00:00
|
|
|
|
/// <inheritdoc />
|
2018-12-02 16:14:55 +00:00
|
|
|
|
public void Write(Stream stream)
|
|
|
|
|
{
|
2019-12-21 18:09:49 +00:00
|
|
|
|
stream.WriteDecimal(X);
|
2018-12-12 00:09:15 +00:00
|
|
|
|
stream.WriteWhiteSpace();
|
2019-12-21 18:09:49 +00:00
|
|
|
|
stream.WriteDecimal(Y);
|
2018-12-12 00:09:15 +00:00
|
|
|
|
stream.WriteWhiteSpace();
|
|
|
|
|
stream.WriteText(Symbol);
|
|
|
|
|
stream.WriteWhiteSpace();
|
2018-12-02 16:14:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-03 22:20:53 +00:00
|
|
|
|
/// <inheritdoc />
|
2017-11-22 18:41:34 +00:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2019-12-21 18:09:49 +00:00
|
|
|
|
return $"{X} {Y} {Symbol}";
|
2017-11-22 18:41:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|