mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-14 10:55:04 +08:00
move application of transformation matrix outside path
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current path.
|
/// The current path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PdfPath Path { get; } = new PdfPath(Core.TransformationMatrix.Identity);
|
public PdfPath Path { get; } = new PdfPath();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current location of the active point.
|
/// The current location of the active point.
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
public bool IsFlexing { get; set; }
|
public bool IsFlexing { get; set; }
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
public PdfPath Path { get; private set; } = new PdfPath(Core.TransformationMatrix.Identity);
|
public PdfPath Path { get; private set; } = new PdfPath();
|
||||||
|
|
||||||
public PdfPoint CurrentPosition { get; set; }
|
public PdfPoint CurrentPosition { get; set; }
|
||||||
|
|
||||||
|
@@ -5,7 +5,6 @@ namespace UglyToad.PdfPig.Geometry
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Core;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A path in a PDF document, used by glyphs and page content. Can contain multiple sub-paths.
|
/// A path in a PDF document, used by glyphs and page content. Can contain multiple sub-paths.
|
||||||
@@ -20,21 +19,10 @@ namespace UglyToad.PdfPig.Geometry
|
|||||||
public IReadOnlyList<IPathCommand> Commands => commands;
|
public IReadOnlyList<IPathCommand> Commands => commands;
|
||||||
|
|
||||||
private PdfPoint? currentPosition;
|
private PdfPoint? currentPosition;
|
||||||
|
|
||||||
private readonly TransformationMatrix currentTransformationMatrix;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create a new <see cref="PdfPath"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="transformationMatrix">The transformation to apply to all points in this path.</param>
|
|
||||||
public PdfPath(TransformationMatrix transformationMatrix)
|
|
||||||
{
|
|
||||||
currentTransformationMatrix = transformationMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void MoveTo(decimal x, decimal y)
|
internal void MoveTo(decimal x, decimal y)
|
||||||
{
|
{
|
||||||
currentPosition = currentTransformationMatrix.Transform(new PdfPoint(x, y));
|
currentPosition = new PdfPoint(x, y);
|
||||||
commands.Add(new Move(currentPosition.Value));
|
commands.Add(new Move(currentPosition.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,12 +30,13 @@ namespace UglyToad.PdfPig.Geometry
|
|||||||
{
|
{
|
||||||
if (currentPosition.HasValue)
|
if (currentPosition.HasValue)
|
||||||
{
|
{
|
||||||
var to = currentTransformationMatrix.Transform(new PdfPoint(x, y));
|
var to = new PdfPoint(x, y);
|
||||||
commands.Add(new Line(currentPosition.Value, to));
|
commands.Add(new Line(currentPosition.Value, to));
|
||||||
currentPosition = to;
|
currentPosition = to;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// TODO: probably the wrong behaviour here, maybe line starts from (0, 0)?
|
||||||
MoveTo(x, y);
|
MoveTo(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,9 +47,9 @@ namespace UglyToad.PdfPig.Geometry
|
|||||||
{
|
{
|
||||||
if (currentPosition.HasValue)
|
if (currentPosition.HasValue)
|
||||||
{
|
{
|
||||||
var to = currentTransformationMatrix.Transform(new PdfPoint(x3, y3));
|
var to = new PdfPoint(x3, y3);
|
||||||
commands.Add(new BezierCurve(currentPosition.Value,
|
commands.Add(new BezierCurve(currentPosition.Value,
|
||||||
currentTransformationMatrix.Transform(new PdfPoint(x1, y1)), currentTransformationMatrix.Transform(new PdfPoint(x2, y2)), to));
|
new PdfPoint(x1, y1), new PdfPoint(x2, y2), to));
|
||||||
currentPosition = to;
|
currentPosition = to;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -460,7 +449,7 @@ namespace UglyToad.PdfPig.Geometry
|
|||||||
|
|
||||||
internal void Rectangle(decimal x, decimal y, decimal width, decimal height)
|
internal void Rectangle(decimal x, decimal y, decimal width, decimal height)
|
||||||
{
|
{
|
||||||
currentPosition = currentTransformationMatrix.Transform(new PdfPoint(x, y));
|
currentPosition = new PdfPoint(x, y);
|
||||||
LineTo(x + width, y);
|
LineTo(x + width, y);
|
||||||
LineTo(x + width, y + height);
|
LineTo(x + width, y + height);
|
||||||
LineTo(x, y + height);
|
LineTo(x, y + height);
|
||||||
|
@@ -288,7 +288,7 @@
|
|||||||
|
|
||||||
public void BeginSubpath()
|
public void BeginSubpath()
|
||||||
{
|
{
|
||||||
CurrentPath = new PdfPath(CurrentTransformationMatrix);
|
CurrentPath = new PdfPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StrokePath(bool close)
|
public void StrokePath(bool close)
|
||||||
|
@@ -52,10 +52,13 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
operationContext.CurrentPath.BezierCurveTo(ControlPoint1.X, ControlPoint1.Y,
|
var controlPoint1Transform = operationContext.CurrentTransformationMatrix.Transform(ControlPoint1);
|
||||||
ControlPoint2.X, ControlPoint2.Y,
|
var controlPoint2Transform = operationContext.CurrentTransformationMatrix.Transform(ControlPoint2);
|
||||||
End.X, End.Y);
|
var endTransform = operationContext.CurrentTransformationMatrix.Transform(End);
|
||||||
operationContext.CurrentPosition = End;
|
operationContext.CurrentPath.BezierCurveTo(controlPoint1Transform.X, controlPoint1Transform.Y,
|
||||||
|
controlPoint2Transform.X, controlPoint2Transform.Y,
|
||||||
|
endTransform.X, endTransform.Y);
|
||||||
|
operationContext.CurrentPosition = endTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -44,12 +44,14 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
operationContext.CurrentPath.BezierCurveTo(ControlPoint1.X, ControlPoint1.Y,
|
var controlPoint1Transform = operationContext.CurrentTransformationMatrix.Transform(ControlPoint1);
|
||||||
End.X,
|
var endTransform = operationContext.CurrentTransformationMatrix.Transform(End);
|
||||||
End.Y,
|
operationContext.CurrentPath.BezierCurveTo(controlPoint1Transform.X, controlPoint1Transform.Y,
|
||||||
End.X,
|
endTransform.X,
|
||||||
End.Y);
|
endTransform.Y,
|
||||||
operationContext.CurrentPosition = End;
|
endTransform.X,
|
||||||
|
endTransform.Y);
|
||||||
|
operationContext.CurrentPosition = endTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -51,7 +51,8 @@
|
|||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
operationContext.BeginSubpath();
|
operationContext.BeginSubpath();
|
||||||
operationContext.CurrentPath.Rectangle(LowerLeft.X, LowerLeft.Y, Width, Height);
|
var lowerLeftTransform = operationContext.CurrentTransformationMatrix.Transform(LowerLeft);
|
||||||
|
operationContext.CurrentPath.Rectangle(lowerLeftTransform.X, lowerLeftTransform.Y, Width, Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -44,13 +44,15 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
|
var controlPoint2Transform = operationContext.CurrentTransformationMatrix.Transform(ControlPoint2);
|
||||||
|
var endTransform = operationContext.CurrentTransformationMatrix.Transform(End);
|
||||||
operationContext.CurrentPath.BezierCurveTo(operationContext.CurrentPosition.X,
|
operationContext.CurrentPath.BezierCurveTo(operationContext.CurrentPosition.X,
|
||||||
operationContext.CurrentPosition.Y,
|
operationContext.CurrentPosition.Y,
|
||||||
ControlPoint2.X,
|
controlPoint2Transform.X,
|
||||||
ControlPoint2.Y,
|
controlPoint2Transform.Y,
|
||||||
End.X,
|
endTransform.X,
|
||||||
End.Y);
|
endTransform.Y);
|
||||||
operationContext.CurrentPosition = End;
|
operationContext.CurrentPosition = endTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -35,8 +35,9 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
operationContext.CurrentPath.LineTo(End.X, End.Y);
|
var endPoint = operationContext.CurrentTransformationMatrix.Transform(new PdfPoint(End.X, End.Y));
|
||||||
operationContext.CurrentPosition = End;
|
operationContext.CurrentPath.LineTo(endPoint.X, endPoint.Y);
|
||||||
|
operationContext.CurrentPosition = endPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -36,8 +36,9 @@
|
|||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
operationContext.BeginSubpath();
|
operationContext.BeginSubpath();
|
||||||
operationContext.CurrentPosition = Point;
|
var pointTransform = operationContext.CurrentTransformationMatrix.Transform(Point);
|
||||||
operationContext.CurrentPath.LineTo(Point.X, Point.Y);
|
operationContext.CurrentPosition = pointTransform;
|
||||||
|
operationContext.CurrentPath.MoveTo(pointTransform.X, pointTransform.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
Reference in New Issue
Block a user