namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction { using System.IO; using PdfPig.Core; /// /// /// Append a cubic Bezier curve to the current path. /// The curve extends from the current point to the point (x3, y3), using the current point and (x2, y2) as the Bezier control points /// public class AppendStartControlPointBezierCurve : IGraphicsStateOperation { /// /// The symbol for this operation in a stream. /// public const string Symbol = "v"; /// public string Operator => Symbol; /// /// The x coordinate of the second control point. /// public decimal X2 { get; } /// /// The y coordinate of the second control point. /// public decimal Y2 { get; } /// /// The x coordinate of the end point of the curve. /// public decimal X3 { get; } /// /// The y coordinate of the end point of the curve. /// public decimal Y3 { get; } /// /// Create a new . /// /// The x coordinate of the second control point. /// The y coordinate of the second control point. /// The x coordinate of the end point. /// The y coordinate of the end point. public AppendStartControlPointBezierCurve(decimal x2, decimal y2, decimal x3, decimal y3) { X2 = x2; Y2 = y2; X3 = x3; Y3 = y3; } /// public void Run(IOperationContext operationContext) { var controlPoint2 = new PdfPoint(X2, Y2); var end = new PdfPoint(X3, Y3); var controlPoint2Transform = operationContext.CurrentTransformationMatrix.Transform(controlPoint2); var endTransform = operationContext.CurrentTransformationMatrix.Transform(end); operationContext.CurrentPath.BezierCurveTo(operationContext.CurrentPosition.X, operationContext.CurrentPosition.Y, controlPoint2Transform.X, controlPoint2Transform.Y, endTransform.X, endTransform.Y); operationContext.CurrentPosition = endTransform; } /// public void Write(Stream stream) { stream.WriteDecimal(X2); stream.WriteWhiteSpace(); stream.WriteDecimal(Y2); stream.WriteWhiteSpace(); stream.WriteDecimal(X3); stream.WriteWhiteSpace(); stream.WriteDecimal(Y3); stream.WriteWhiteSpace(); stream.WriteText(Symbol); stream.WriteNewLine(); } /// public override string ToString() { return $"{X2} {Y2} {X3} {Y3} {Symbol}"; } } }