make transform stack consistent
Some checks failed
Build, test and publish draft / build (push) Has been cancelled
Build and test [MacOS] / build (push) Has been cancelled
Run Common Crawl Tests / build (0000-0001) (push) Has been cancelled
Run Common Crawl Tests / build (0002-0003) (push) Has been cancelled
Run Common Crawl Tests / build (0004-0005) (push) Has been cancelled
Run Common Crawl Tests / build (0006-0007) (push) Has been cancelled
Run Integration Tests / build (push) Has been cancelled
Nightly Release / Check if this commit has already been published (push) Has been cancelled
Nightly Release / tests (push) Has been cancelled
Nightly Release / build_and_publish_nightly (push) Has been cancelled

This commit is contained in:
Alexander Vinnikov
2025-10-23 15:50:22 +02:00
committed by BobLd
parent 6ce6986d78
commit 181fa9d837
5 changed files with 14 additions and 13 deletions

View File

@@ -270,10 +270,10 @@
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)

View File

@@ -563,8 +563,8 @@
.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);
@@ -576,9 +576,8 @@
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.
@@ -958,10 +957,10 @@
}
/// <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/>

View File

@@ -452,6 +452,7 @@ namespace UglyToad.PdfPig.Graphics
{
// 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);

View File

@@ -243,7 +243,7 @@
/// <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.

View File

@@ -2,6 +2,7 @@
{
using System;
using System.IO;
using PdfPig.Core;
/// <inheritdoc />
/// <summary>
@@ -43,7 +44,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.ModifyCurrentTransformationMatrix(Value);
operationContext.ModifyCurrentTransformationMatrix(TransformationMatrix.FromArray(Value));
}
/// <inheritdoc />