Remove reference from CurrentSubpath and CurrentPath in IOperationContext and add MoveTo(), BezierCurveTo(), LineTo() and Rectangle().

This commit is contained in:
BobLd 2020-11-23 10:49:50 +00:00
parent ccd7d81ae3
commit d07baa97d5
10 changed files with 172 additions and 54 deletions

View File

@ -88,6 +88,66 @@
}
public void MoveTo(double x, double y)
{
BeginSubpath();
var point = CurrentTransformationMatrix.Transform(new PdfPoint(x, y));
CurrentPosition = point;
CurrentSubpath.MoveTo(point.X, point.Y);
}
public void BezierCurveTo(double x2, double y2, double x3, double y3)
{
if (CurrentSubpath == null)
{
return;
}
var controlPoint2 = CurrentTransformationMatrix.Transform(new PdfPoint(x2, y2));
var end = CurrentTransformationMatrix.Transform(new PdfPoint(x3, y3));
CurrentSubpath.BezierCurveTo(CurrentPosition.X, CurrentPosition.Y, controlPoint2.X, controlPoint2.Y, end.X, end.Y);
CurrentPosition = end;
}
public void BezierCurveTo(double x1, double y1, double x2, double y2, double x3, double y3)
{
if (CurrentSubpath == null)
{
return;
}
var controlPoint1 = CurrentTransformationMatrix.Transform(new PdfPoint(x1, y1));
var controlPoint2 = CurrentTransformationMatrix.Transform(new PdfPoint(x2, y2));
var end = CurrentTransformationMatrix.Transform(new PdfPoint(x3, y3));
CurrentSubpath.BezierCurveTo(controlPoint1.X, controlPoint1.Y, controlPoint2.X, controlPoint2.Y, end.X, end.Y);
CurrentPosition = end;
}
public void LineTo(double x, double y)
{
if (CurrentSubpath == null)
{
return;
}
var endPoint = CurrentTransformationMatrix.Transform(new PdfPoint(x, y));
CurrentSubpath.LineTo(endPoint.X, endPoint.Y);
CurrentPosition = endPoint;
}
public void Rectangle(double x, double y, double width, double height)
{
BeginSubpath();
var lowerLeft = CurrentTransformationMatrix.Transform(new PdfPoint(x, y));
var upperRight = CurrentTransformationMatrix.Transform(new PdfPoint(x + width, y + height));
CurrentSubpath.Rectangle(lowerLeft.X, lowerLeft.Y, upperRight.X - lowerLeft.X, upperRight.Y - lowerLeft.Y);
AddCurrentSubpath();
}
public void EndPath()
{
}

View File

@ -560,7 +560,67 @@
ClosePath();
}
public void MoveTo(double x, double y)
{
BeginSubpath();
var point = CurrentTransformationMatrix.Transform(new PdfPoint(x, y));
CurrentPosition = point;
CurrentSubpath.MoveTo(point.X, point.Y);
}
public void BezierCurveTo(double x2, double y2, double x3, double y3)
{
if (CurrentSubpath == null)
{
return;
}
var controlPoint2 = CurrentTransformationMatrix.Transform(new PdfPoint(x2, y2));
var end = CurrentTransformationMatrix.Transform(new PdfPoint(x3, y3));
CurrentSubpath.BezierCurveTo(CurrentPosition.X, CurrentPosition.Y, controlPoint2.X, controlPoint2.Y, end.X, end.Y);
CurrentPosition = end;
}
public void BezierCurveTo(double x1, double y1, double x2, double y2, double x3, double y3)
{
if (CurrentSubpath == null)
{
return;
}
var controlPoint1 = CurrentTransformationMatrix.Transform(new PdfPoint(x1, y1));
var controlPoint2 = CurrentTransformationMatrix.Transform(new PdfPoint(x2, y2));
var end = CurrentTransformationMatrix.Transform(new PdfPoint(x3, y3));
CurrentSubpath.BezierCurveTo(controlPoint1.X, controlPoint1.Y, controlPoint2.X, controlPoint2.Y, end.X, end.Y);
CurrentPosition = end;
}
public void LineTo(double x, double y)
{
if (CurrentSubpath == null)
{
return;
}
var endPoint = CurrentTransformationMatrix.Transform(new PdfPoint(x, y));
CurrentSubpath.LineTo(endPoint.X, endPoint.Y);
CurrentPosition = endPoint;
}
public void Rectangle(double x, double y, double width, double height)
{
BeginSubpath();
var lowerLeft = CurrentTransformationMatrix.Transform(new PdfPoint(x, y));
var upperRight = CurrentTransformationMatrix.Transform(new PdfPoint(x + width, y + height));
CurrentSubpath.Rectangle(lowerLeft.X, lowerLeft.Y, upperRight.X - lowerLeft.X, upperRight.Y - lowerLeft.Y);
AddCurrentSubpath();
}
public void EndPath()
{
if (CurrentPath == null)
@ -744,7 +804,10 @@
if (markedContentStack.CanPop)
{
var mc = markedContentStack.Pop(pdfScanner);
if (mc != null) markedContents.Add(mc);
if (mc != null)
{
markedContents.Add(mc);
}
}
}

View File

@ -10,18 +10,6 @@
/// </summary>
public interface IOperationContext
{
/// <summary>
/// The current subpath being drawn if applicable.
/// </summary>
[CanBeNull]
PdfSubpath CurrentSubpath { get; }
/// <summary>
/// The current path being drawn if applicable.
/// </summary>
[CanBeNull]
PdfPath CurrentPath { get; }
/// <summary>
/// The active colorspaces for this content stream.
/// </summary>
@ -116,6 +104,46 @@
/// <param name="close">Whether to also close the path.</param>
void FillStrokePath(FillingRule fillingRule, bool close);
/// <summary>
/// Add a move command to the path.
/// <para>Should implement matrix transformations.</para>
/// </summary>
void MoveTo(double x, double y);
/// <summary>
/// Add a bezier curve to the current subpath.
/// <para>Should implement matrix transformations.</para>
/// </summary>
/// <param name="x1"></param>
/// <param name="y1"></param>
/// <param name="x2"></param>
/// <param name="y2"></param>
/// <param name="x3"></param>
/// <param name="y3"></param>
void BezierCurveTo(double x1, double y1, double x2, double y2, double x3, double y3);
/// <summary>
/// Add a bezier curve to the current subpath.
/// <para>Should implement matrix transformations.</para>
/// </summary>
/// <param name="x2"></param>
/// <param name="y2"></param>
/// <param name="x3"></param>
/// <param name="y3"></param>
void BezierCurveTo(double x2, double y2, double x3, double y3);
/// <summary>
/// Add a line command to the subpath.
/// <para>Should implement matrix transformations.</para>
/// </summary>
void LineTo(double x, double y);
/// <summary>
/// Add a rectangle following the pdf specification (m, l, l, l, c) path. A new subpath will be created.
/// <para>Should implement matrix transformations.</para>
/// </summary>
void Rectangle(double x, double y, double width, double height);
/// <summary>
/// End the path object without filling or stroking it. This operator shall be a path-painting no-op,
/// used primarily for the side effect of changing the current clipping path (see 8.5.4, "Clipping Path Operators").

View File

@ -20,6 +20,7 @@
/// <summary>
/// Applies the operation to the current context with the provided resources.
/// <para>Matrix transformations should be implemented in <see cref="IOperationContext"/>.</para>
/// </summary>
/// <param name="operationContext"></param>
void Run(IOperationContext operationContext);

View File

@ -71,14 +71,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
if (operationContext.CurrentSubpath == null) return;
var controlPoint1 = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(X1, Y1));
var controlPoint2 = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(X2, Y2));
var end = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(X3, Y3));
operationContext.CurrentSubpath.BezierCurveTo(controlPoint1.X, controlPoint1.Y,
controlPoint2.X, controlPoint2.Y, end.X, end.Y);
operationContext.CurrentPosition = end;
operationContext.BezierCurveTo((double)X1, (double)Y1, (double)X2, (double)Y2, (double)X3, (double)Y3);
}
/// <inheritdoc />

View File

@ -56,12 +56,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
if (operationContext.CurrentSubpath == null) return;
var controlPoint1 = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(X1, Y1));
var end = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(X3, Y3));
operationContext.CurrentSubpath.BezierCurveTo(controlPoint1.X, controlPoint1.Y, end.X, end.Y, end.X, end.Y);
operationContext.CurrentPosition = end;
operationContext.BezierCurveTo((double)X1, (double)Y1, (double)X3, (double)Y3, (double)X3, (double)Y3);
}
/// <inheritdoc />

View File

@ -56,12 +56,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.BeginSubpath();
var lowerLeft = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(LowerLeftX, LowerLeftY));
var upperRight = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(LowerLeftX + Width, LowerLeftY + Height));
operationContext.CurrentSubpath.Rectangle(lowerLeft.X, lowerLeft.Y, upperRight.X - lowerLeft.X, upperRight.Y - lowerLeft.Y);
operationContext.AddCurrentSubpath();
operationContext.Rectangle((double)LowerLeftX, (double)LowerLeftY, (double)Width, (double)Height);
}
/// <inheritdoc />

View File

@ -56,17 +56,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
if (operationContext.CurrentSubpath == null) return;
var controlPoint2 = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(X2, Y2));
var end = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(X3, Y3));
operationContext.CurrentSubpath.BezierCurveTo(operationContext.CurrentPosition.X,
operationContext.CurrentPosition.Y,
controlPoint2.X,
controlPoint2.Y,
end.X,
end.Y);
operationContext.CurrentPosition = end;
operationContext.BezierCurveTo((double)X2, (double)Y2, (double)X3, (double)Y3);
}
/// <inheritdoc />

View File

@ -41,11 +41,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
if (operationContext.CurrentSubpath == null) return;
var endPoint = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(X, Y));
operationContext.CurrentSubpath.LineTo(endPoint.X, endPoint.Y);
operationContext.CurrentPosition = endPoint;
operationContext.LineTo((double)X, (double)Y);
}
/// <inheritdoc />

View File

@ -41,10 +41,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.BeginSubpath();
var point = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(X, Y));
operationContext.CurrentPosition = point;
operationContext.CurrentSubpath.MoveTo(point.X, point.Y);
operationContext.MoveTo((double)X, (double)Y);
}
/// <inheritdoc />