Skip to content

Commit 4fbcc11

Browse files
committed
Fix bug where FormXObject bbox needs to be normalised
1 parent ede77c2 commit 4fbcc11

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/UglyToad.PdfPig.Tests/Integration/XObjectFormTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace UglyToad.PdfPig.Tests.Integration
22
{
3+
using DocumentLayoutAnalysis.PageSegmenter;
4+
using DocumentLayoutAnalysis.WordExtractor;
35
using UglyToad.PdfPig.Core;
46

57
public class XObjectFormTests
@@ -32,5 +34,24 @@ public void CanReadDocumentMOZILLA_3136_0()
3234
var page = document.GetPage(1);
3335
}
3436
}
37+
38+
[Fact]
39+
public void XObjectFormXClipping()
40+
{
41+
using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("ICML03-081"), new ParsingOptions()
42+
{
43+
ClipPaths = true
44+
}))
45+
{
46+
var page = document.GetPage(4);
47+
Assert.True(page.Paths.Count > 3);
48+
49+
var words = page.GetWords(NearestNeighbourWordExtractor.Instance);
50+
var blocks = DocstrumBoundingBoxes.Instance.GetBlocks(words).SelectMany(b => b.TextLines).ToArray();
51+
52+
Assert.Equal(2, blocks.Count(l => l.Text.Equals("Training Examples per Class")));
53+
Assert.Equal(2, blocks.Count(l => l.Text.Equals("Classification Weight")));
54+
}
55+
}
3556
}
3657
}

src/UglyToad.PdfPig/Graphics/BaseStreamProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ protected virtual void ProcessFormXObject(StreamToken formStream, NameToken xObj
576576
{
577577
var points = bboxToken.Data.OfType<NumericToken>().Select(x => x.Double).ToArray();
578578
PdfRectangle bbox = new PdfRectangle(points[0], points[1], points[2], points[3]);
579-
PdfRectangle transformedBox = startState.CurrentTransformationMatrix.Transform(bbox);
579+
PdfRectangle transformedBox = startState.CurrentTransformationMatrix.Transform(bbox).Normalise();
580580
ClipToRectangle(transformedBox, FillingRule.EvenOdd); // TODO - Check that Even Odd is valid
581581
}
582582

0 commit comments

Comments
 (0)