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 (x1, y1) and (x3, y3) as the Bezier control points
///
public class AppendEndControlPointBezierCurve : IGraphicsStateOperation
{
///
/// The symbol for this operation in a stream.
///
public const string Symbol = "y";
///
public string Operator => Symbol;
///
/// The x coordinate of the first control point.
///
public decimal X1 { get; }
///
/// The y coordinate of the first control point.
///
public decimal Y1 { get; }
///
/// The x coordinate of the end point.
///
public decimal X3 { get; }
///
/// The y coordinate of the end point.
///
public decimal Y3 { get; }
///
/// Create a new .
///
/// Control point 1 x coordinate.
/// Control point 1 y coordinate.
/// Control point 2/End x coordinate.
/// Control point 2/End y coordinate.
public AppendEndControlPointBezierCurve(decimal x1, decimal y1, decimal x3, decimal y3)
{
X1 = x1;
Y1 = y1;
X3 = x3;
Y3 = y3;
}
///
public void Run(IOperationContext operationContext)
{
var controlPoint1 = new PdfPoint(X1, Y1);
var end = new PdfPoint(X3, Y3);
var controlPoint1Transform = operationContext.CurrentTransformationMatrix.Transform(controlPoint1);
var endTransform = operationContext.CurrentTransformationMatrix.Transform(end);
operationContext.CurrentSubpath.BezierCurveTo(controlPoint1Transform.X, controlPoint1Transform.Y,
endTransform.X,
endTransform.Y,
endTransform.X,
endTransform.Y);
operationContext.CurrentPosition = endTransform;
}
///
public void Write(Stream stream)
{
stream.WriteDecimal(X1);
stream.WriteWhiteSpace();
stream.WriteDecimal(Y1);
stream.WriteWhiteSpace();
stream.WriteDecimal(X3);
stream.WriteWhiteSpace();
stream.WriteDecimal(Y3);
stream.WriteWhiteSpace();
stream.WriteText(Symbol);
stream.WriteNewLine();
}
///
public override string ToString()
{
return $"{X1} {Y1} {X3} {Y3} {Symbol}";
}
}
}