Fix bug where FormXObject bbox needs to be normalised

This commit is contained in:
BobLd 2025-03-30 21:54:12 +01:00
parent ede77c20f5
commit 4fbcc112d3
2 changed files with 22 additions and 1 deletions

View File

@ -1,5 +1,7 @@
namespace UglyToad.PdfPig.Tests.Integration
{
using DocumentLayoutAnalysis.PageSegmenter;
using DocumentLayoutAnalysis.WordExtractor;
using UglyToad.PdfPig.Core;
public class XObjectFormTests
@ -32,5 +34,24 @@
var page = document.GetPage(1);
}
}
[Fact]
public void XObjectFormXClipping()
{
using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("ICML03-081"), new ParsingOptions()
{
ClipPaths = true
}))
{
var page = document.GetPage(4);
Assert.True(page.Paths.Count > 3);
var words = page.GetWords(NearestNeighbourWordExtractor.Instance);
var blocks = DocstrumBoundingBoxes.Instance.GetBlocks(words).SelectMany(b => b.TextLines).ToArray();
Assert.Equal(2, blocks.Count(l => l.Text.Equals("Training Examples per Class")));
Assert.Equal(2, blocks.Count(l => l.Text.Equals("Classification Weight")));
}
}
}
}

View File

@ -576,7 +576,7 @@
{
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);
PdfRectangle transformedBox = startState.CurrentTransformationMatrix.Transform(bbox).Normalise();
ClipToRectangle(transformedBox, FillingRule.EvenOdd); // TODO - Check that Even Odd is valid
}