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 cubic Bezier curve to the current path.
|
|
|
|
|
/// The curve extends from the current point to the point (x3, y3), using (x1, y1) and (x3, y3) as the Bezier control points
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class AppendEndControlPointBezierCurve : 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 = "y";
|
|
|
|
|
|
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 first control point.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal X1 { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The y coordinate of the first control point.
|
2019-01-03 22:20:53 +00:00
|
|
|
|
/// </summary>
|
2019-12-21 18:09:49 +00:00
|
|
|
|
public decimal Y1 { get; }
|
2017-11-22 18:41:34 +00:00
|
|
|
|
|
2019-01-03 22:20:53 +00:00
|
|
|
|
/// <summary>
|
2019-12-21 18:09:49 +00:00
|
|
|
|
/// The x coordinate of the end point.
|
2019-01-03 22:20:53 +00:00
|
|
|
|
/// </summary>
|
2019-12-21 18:09:49 +00:00
|
|
|
|
public decimal X3 { 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.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal Y3 { get; }
|
|
|
|
|
|
2019-01-03 22:20:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a new <see cref="AppendEndControlPointBezierCurve"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="x1">Control point 1 x coordinate.</param>
|
|
|
|
|
/// <param name="y1">Control point 1 y coordinate.</param>
|
|
|
|
|
/// <param name="x3">Control point 2/End x coordinate.</param>
|
|
|
|
|
/// <param name="y3">Control point 2/End y coordinate.</param>
|
2017-11-22 18:41:34 +00:00
|
|
|
|
public AppendEndControlPointBezierCurve(decimal x1, decimal y1, decimal x3, decimal y3)
|
|
|
|
|
{
|
2019-12-21 18:09:49 +00:00
|
|
|
|
X1 = x1;
|
|
|
|
|
Y1 = y1;
|
|
|
|
|
X3 = x3;
|
|
|
|
|
Y3 = y3;
|
2017-11-22 18:41:34 +00:00
|
|
|
|
}
|
2019-12-21 18:09:49 +00:00
|
|
|
|
|
2019-01-03 22:20:53 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void Run(IOperationContext operationContext)
|
2017-11-30 23:47:24 +00:00
|
|
|
|
{
|
2019-12-21 18:09:49 +00:00
|
|
|
|
var controlPoint1 = new PdfPoint(X1, Y1);
|
|
|
|
|
var end = new PdfPoint(X3, Y3);
|
|
|
|
|
var controlPoint1Transform = operationContext.CurrentTransformationMatrix.Transform(controlPoint1);
|
|
|
|
|
var endTransform = operationContext.CurrentTransformationMatrix.Transform(end);
|
2019-08-08 21:19:18 +01:00
|
|
|
|
operationContext.CurrentPath.BezierCurveTo(controlPoint1Transform.X, controlPoint1Transform.Y,
|
|
|
|
|
endTransform.X,
|
|
|
|
|
endTransform.Y,
|
|
|
|
|
endTransform.X,
|
|
|
|
|
endTransform.Y);
|
|
|
|
|
operationContext.CurrentPosition = endTransform;
|
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(X1);
|
2018-12-12 00:09:15 +00:00
|
|
|
|
stream.WriteWhiteSpace();
|
2019-12-21 18:09:49 +00:00
|
|
|
|
stream.WriteDecimal(Y1);
|
2018-12-12 00:09:15 +00:00
|
|
|
|
stream.WriteWhiteSpace();
|
2019-12-21 18:09:49 +00:00
|
|
|
|
stream.WriteDecimal(X3);
|
2018-12-12 00:09:15 +00:00
|
|
|
|
stream.WriteWhiteSpace();
|
2019-12-21 18:09:49 +00:00
|
|
|
|
stream.WriteDecimal(Y3);
|
2018-12-12 00:09:15 +00:00
|
|
|
|
stream.WriteWhiteSpace();
|
|
|
|
|
stream.WriteText(Symbol);
|
|
|
|
|
stream.WriteNewLine();
|
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 $"{X1} {Y1} {X3} {Y3} {Symbol}";
|
2017-11-22 18:41:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|