Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/UglyToad.PdfPig.Tests/Graphics/TestOperationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ public void SetWordSpacing(double spacing)
GetCurrentState().FontState.WordSpacing = spacing;
}

public void ModifyCurrentTransformationMatrix(double[] value)
public void ModifyCurrentTransformationMatrix(TransformationMatrix value)
{
var ctm = GetCurrentState().CurrentTransformationMatrix;
GetCurrentState().CurrentTransformationMatrix = TransformationMatrix.FromArray(value).Multiply(ctm);
var state = GetCurrentState();
state.CurrentTransformationMatrix = value.Multiply(state.CurrentTransformationMatrix);
}

public void SetCharacterSpacing(double spacing)
Expand Down
15 changes: 7 additions & 8 deletions src/UglyToad.PdfPig/Graphics/BaseStreamProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ protected virtual void ProcessFormXObject(StreamToken formStream, NameToken xObj
.ToArray());
}

// 2. Update current transformation matrix.
startState.CurrentTransformationMatrix = formMatrix.Multiply(startState.CurrentTransformationMatrix);
// 2. Update current transformation matrix.
ModifyCurrentTransformationMatrix(formMatrix);

var contentStream = formStream.Decode(FilterProvider, PdfScanner);

Expand All @@ -576,9 +576,8 @@ protected virtual void ProcessFormXObject(StreamToken formStream, NameToken xObj
if (formStream.StreamDictionary.TryGet<ArrayToken>(NameToken.Bbox, PdfScanner, out var bboxToken))
{
var points = bboxToken.Data.OfType<NumericToken>().Select(x => x.Double).ToArray();
PdfRectangle bbox = new PdfRectangle(points[0], points[1], points[2], points[3]);
PdfRectangle transformedBox = startState.CurrentTransformationMatrix.Transform(bbox).Normalise();
ClipToRectangle(transformedBox, FillingRule.EvenOdd); // TODO - Check that Even Odd is valid
PdfRectangle bbox = new PdfRectangle(points[0], points[1], points[2], points[3]).Normalise();
ClipToRectangle(bbox, FillingRule.EvenOdd); // TODO - Check that Even Odd is valid
}

// 4. Paint the objects.
Expand Down Expand Up @@ -958,10 +957,10 @@ public virtual void SetWordSpacing(double spacing)
}

/// <inheritdoc/>
public virtual void ModifyCurrentTransformationMatrix(double[] value)
public virtual void ModifyCurrentTransformationMatrix(TransformationMatrix value)
{
var ctm = GetCurrentState().CurrentTransformationMatrix;
GetCurrentState().CurrentTransformationMatrix = TransformationMatrix.FromArray(value).Multiply(ctm);
var state = GetCurrentState();
state.CurrentTransformationMatrix = value.Multiply(state.CurrentTransformationMatrix);
}

/// <inheritdoc/>
Expand Down
1 change: 1 addition & 0 deletions src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ protected override void ClipToRectangle(PdfRectangle rectangle, FillingRule clip
{
// https://github.com/apache/pdfbox/blob/f4bfe47de37f6fe69e8f98b164c3546facfd5e91/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java#L611
var graphicsState = GetCurrentState();
rectangle = graphicsState.CurrentTransformationMatrix.Transform(rectangle).Normalise();
var clip = rectangle.ToPdfPath();
clip.SetClipping(clippingRule);

Expand Down
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig/Graphics/IOperationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public interface IOperationContext
/// <summary>
/// Modify the current transformation matrix by concatenating the specified matrix.
/// </summary>
void ModifyCurrentTransformationMatrix(double[] value);
void ModifyCurrentTransformationMatrix(TransformationMatrix value);

/// <summary>
/// Set the character spacing to a number expressed in unscaled text space units.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.IO;
using PdfPig.Core;

/// <inheritdoc />
/// <summary>
Expand Down Expand Up @@ -43,7 +44,7 @@ public ModifyCurrentTransformationMatrix(double[] value)
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.ModifyCurrentTransformationMatrix(Value);
operationContext.ModifyCurrentTransformationMatrix(TransformationMatrix.FromArray(Value));
}

/// <inheritdoc />
Expand Down
Loading