mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-13 18:34:58 +08:00
Remove reference from CurrentSubpath and CurrentPath in IOperationContext and add MoveTo(), BezierCurveTo(), LineTo() and Rectangle().
This commit is contained in:
@@ -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()
|
public void EndPath()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@@ -560,7 +560,67 @@
|
|||||||
|
|
||||||
ClosePath();
|
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()
|
public void EndPath()
|
||||||
{
|
{
|
||||||
if (CurrentPath == null)
|
if (CurrentPath == null)
|
||||||
@@ -744,7 +804,10 @@
|
|||||||
if (markedContentStack.CanPop)
|
if (markedContentStack.CanPop)
|
||||||
{
|
{
|
||||||
var mc = markedContentStack.Pop(pdfScanner);
|
var mc = markedContentStack.Pop(pdfScanner);
|
||||||
if (mc != null) markedContents.Add(mc);
|
if (mc != null)
|
||||||
|
{
|
||||||
|
markedContents.Add(mc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,18 +10,6 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IOperationContext
|
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>
|
/// <summary>
|
||||||
/// The active colorspaces for this content stream.
|
/// The active colorspaces for this content stream.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -116,6 +104,46 @@
|
|||||||
/// <param name="close">Whether to also close the path.</param>
|
/// <param name="close">Whether to also close the path.</param>
|
||||||
void FillStrokePath(FillingRule fillingRule, bool close);
|
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>
|
/// <summary>
|
||||||
/// End the path object without filling or stroking it. This operator shall be a path-painting no-op,
|
/// 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").
|
/// used primarily for the side effect of changing the current clipping path (see 8.5.4, "Clipping Path Operators").
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Applies the operation to the current context with the provided resources.
|
/// Applies the operation to the current context with the provided resources.
|
||||||
|
/// <para>Matrix transformations should be implemented in <see cref="IOperationContext"/>.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="operationContext"></param>
|
/// <param name="operationContext"></param>
|
||||||
void Run(IOperationContext operationContext);
|
void Run(IOperationContext operationContext);
|
||||||
|
@@ -71,14 +71,7 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
if (operationContext.CurrentSubpath == null) return;
|
operationContext.BezierCurveTo((double)X1, (double)Y1, (double)X2, (double)Y2, (double)X3, (double)Y3);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -56,12 +56,7 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
if (operationContext.CurrentSubpath == null) return;
|
operationContext.BezierCurveTo((double)X1, (double)Y1, (double)X3, (double)Y3, (double)X3, (double)Y3);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -56,12 +56,7 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
operationContext.BeginSubpath();
|
operationContext.Rectangle((double)LowerLeftX, (double)LowerLeftY, (double)Width, (double)Height);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -56,17 +56,7 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
if (operationContext.CurrentSubpath == null) return;
|
operationContext.BezierCurveTo((double)X2, (double)Y2, (double)X3, (double)Y3);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -41,11 +41,7 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
if (operationContext.CurrentSubpath == null) return;
|
operationContext.LineTo((double)X, (double)Y);
|
||||||
|
|
||||||
var endPoint = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(X, Y));
|
|
||||||
operationContext.CurrentSubpath.LineTo(endPoint.X, endPoint.Y);
|
|
||||||
operationContext.CurrentPosition = endPoint;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -41,10 +41,7 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
operationContext.BeginSubpath();
|
operationContext.MoveTo((double)X, (double)Y);
|
||||||
var point = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(X, Y));
|
|
||||||
operationContext.CurrentPosition = point;
|
|
||||||
operationContext.CurrentSubpath.MoveTo(point.X, point.Y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
Reference in New Issue
Block a user