diff --git a/src/UglyToad.PdfPig.Tests/Integration/Documents/SPARC - v9 Architecture Manual.jpg b/src/UglyToad.PdfPig.Tests/Integration/Documents/SPARC - v9 Architecture Manual.jpg new file mode 100644 index 00000000..59d6514e Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Integration/Documents/SPARC - v9 Architecture Manual.jpg differ diff --git a/src/UglyToad.PdfPig.Tests/Integration/Documents/cropped-and-rotated.jpg b/src/UglyToad.PdfPig.Tests/Integration/Documents/cropped-and-rotated.jpg new file mode 100644 index 00000000..eac24874 Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Integration/Documents/cropped-and-rotated.jpg differ diff --git a/src/UglyToad.PdfPig.Tests/Integration/Documents/cropped-and-rotated.pdf b/src/UglyToad.PdfPig.Tests/Integration/Documents/cropped-and-rotated.pdf new file mode 100644 index 00000000..c58b1c18 Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Integration/Documents/cropped-and-rotated.pdf differ diff --git a/src/UglyToad.PdfPig.Tests/Integration/RotationAndCroppingTests.cs b/src/UglyToad.PdfPig.Tests/Integration/RotationAndCroppingTests.cs new file mode 100644 index 00000000..a2864b57 --- /dev/null +++ b/src/UglyToad.PdfPig.Tests/Integration/RotationAndCroppingTests.cs @@ -0,0 +1,30 @@ +namespace UglyToad.PdfPig.Tests.Integration +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using Xunit; + + public class RotationAndCroppingTests + { + [Fact] + public void CroppedPageHasCorrectTextCoordinates() + { + var path = IntegrationHelpers.GetDocumentPath("SPARC - v9 Architecture Manual"); + + using (var document = PdfDocument.Open(path)) + { + var page = document.GetPage(1); + Assert.Equal(page.Width, 612); // Due to cropping + Assert.Equal(page.Height, 792); // Due to cropping + var minX = page.Letters.Select(l => l.GlyphRectangle.Left).Min(); + var maxX = page.Letters.Select(l => l.GlyphRectangle.Right).Max(); + Assert.Equal(72, minX, 0); // If cropping is not applied correctly, these values will be off + Assert.Equal(540, maxX, 0); // If cropping is not applied correctly, these values will be off + // The page is cropped at + Assert.NotNull(page.Content); + } + } + } +} diff --git a/src/UglyToad.PdfPig.Tests/Integration/VisualVerification/GenerateLetterBoundingBoxImages.cs b/src/UglyToad.PdfPig.Tests/Integration/VisualVerification/GenerateLetterBoundingBoxImages.cs index bf5f1e07..f24c9385 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/VisualVerification/GenerateLetterBoundingBoxImages.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/VisualVerification/GenerateLetterBoundingBoxImages.cs @@ -19,7 +19,9 @@ private const string SinglePage90ClockwiseRotation = "SinglePage90ClockwiseRotation - from PdfPig"; private const string SinglePage180ClockwiseRotation = "SinglePage180ClockwiseRotation - from PdfPig"; private const string SinglePage270ClockwiseRotation = "SinglePage270ClockwiseRotation - from PdfPig"; - + private const string SPARCv9ArchitectureManual = "SPARC - v9 Architecture Manual"; + private const string CroppedAndRotatedFile = "cropped-and-rotated"; + private static string GetFilename(string name) { var documentFolder = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "Integration", "Documents")); @@ -116,6 +118,18 @@ Run(SinglePage270ClockwiseRotation, 595); } + [Fact] + public void SPARCv9ArchitectureManualTest() + { + Run(SPARCv9ArchitectureManual); + } + + [Fact] + public void CroppedAndRotatedTest() + { + Run(CroppedAndRotatedFile, 205); + } + private static void Run(string file, int imageHeight = 792) { var pdfFileName = GetFilename(file); @@ -127,6 +141,7 @@ var violetPen = new Pen(Color.BlueViolet, 1); var redPen = new Pen(Color.Crimson, 1); + var bluePen = new Pen(Color.GreenYellow, 1); using (var bitmap = new Bitmap(image)) using (var graphics = Graphics.FromImage(bitmap)) @@ -141,6 +156,11 @@ DrawRectangle(letter.GlyphRectangle, graphics, violetPen, imageHeight); } + foreach (var annotation in page.ExperimentalAccess.GetAnnotations()) + { + DrawRectangle(annotation.Rectangle, graphics, bluePen, imageHeight); + } + var imageName = $"{file}.jpg"; if (!Directory.Exists("Images"))