diff --git a/src/UglyToad.PdfPig/AcroForms/AcroFormFactory.cs b/src/UglyToad.PdfPig/AcroForms/AcroFormFactory.cs index b74782d7..fef344fd 100644 --- a/src/UglyToad.PdfPig/AcroForms/AcroFormFactory.cs +++ b/src/UglyToad.PdfPig/AcroForms/AcroFormFactory.cs @@ -159,7 +159,7 @@ PdfRectangle? bounds = null; if (fieldDictionary.TryGet(NameToken.Rect, tokenScanner, out ArrayToken rectArray) && rectArray.Length == 4) { - bounds = rectArray.ToRectangle(); + bounds = rectArray.ToRectangle(tokenScanner); } var newParentDictionaries = new List(parentDictionaries) {fieldDictionary}; diff --git a/src/UglyToad.PdfPig/Annotations/AnnotationProvider.cs b/src/UglyToad.PdfPig/Annotations/AnnotationProvider.cs index 4d8b6505..7cdf9e98 100644 --- a/src/UglyToad.PdfPig/Annotations/AnnotationProvider.cs +++ b/src/UglyToad.PdfPig/Annotations/AnnotationProvider.cs @@ -53,7 +53,7 @@ var type = annotationDictionary.Get(NameToken.Subtype, tokenScanner); var annotationType = type.ToAnnotationType(); - var rectangle = annotationDictionary.Get(NameToken.Rect, tokenScanner).ToRectangle(); + var rectangle = annotationDictionary.Get(NameToken.Rect, tokenScanner).ToRectangle(tokenScanner); var contents = GetNamedString(NameToken.Contents, annotationDictionary); var name = GetNamedString(NameToken.Nm, annotationDictionary); diff --git a/src/UglyToad.PdfPig/Content/Pages.cs b/src/UglyToad.PdfPig/Content/Pages.cs index bf9cdac3..f6a216ac 100644 --- a/src/UglyToad.PdfPig/Content/Pages.cs +++ b/src/UglyToad.PdfPig/Content/Pages.cs @@ -57,7 +57,7 @@ if (currentNode.NodeDictionary.TryGet(NameToken.MediaBox, pdfScanner, out ArrayToken mediaBox)) { - pageTreeMembers.MediaBox = new MediaBox(mediaBox.ToRectangle()); + pageTreeMembers.MediaBox = new MediaBox(mediaBox.ToRectangle(pdfScanner)); } if (currentNode.NodeDictionary.TryGet(NameToken.Rotate, pdfScanner, out NumericToken rotateToken)) diff --git a/src/UglyToad.PdfPig/Parser/PageFactory.cs b/src/UglyToad.PdfPig/Parser/PageFactory.cs index ea5ea9d0..4d086ccb 100644 --- a/src/UglyToad.PdfPig/Parser/PageFactory.cs +++ b/src/UglyToad.PdfPig/Parser/PageFactory.cs @@ -177,7 +177,7 @@ return cropBox; } - cropBox = new CropBox(cropBoxArray.ToIntRectangle()); + cropBox = new CropBox(cropBoxArray.ToIntRectangle(pdfScanner)); } else { @@ -202,7 +202,7 @@ return mediaBox; } - mediaBox = new MediaBox(mediaboxArray.ToIntRectangle()); + mediaBox = new MediaBox(mediaboxArray.ToIntRectangle(pdfScanner)); } else { diff --git a/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/FontDescriptorFactory.cs b/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/FontDescriptorFactory.cs index b38d804e..d7fc92ef 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/FontDescriptorFactory.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Parser/Parts/FontDescriptorFactory.cs @@ -21,7 +21,7 @@ var family = GetFontFamily(dictionary); var stretch = GetFontStretch(dictionary); var flags = GetFlags(dictionary, isLenientParsing); - var bounding = GetBoundingBox(dictionary); + var bounding = GetBoundingBox(dictionary, pdfScanner); var charSet = GetCharSet(dictionary); var fontFile = GetFontFile(dictionary); @@ -119,7 +119,7 @@ return (FontDescriptorFlags) flags; } - private static PdfRectangle GetBoundingBox(DictionaryToken dictionary) + private static PdfRectangle GetBoundingBox(DictionaryToken dictionary, IPdfTokenScanner pdfScanner) { if (!dictionary.TryGet(NameToken.FontBbox, out var box) || !(box is ArrayToken boxArray)) { @@ -131,7 +131,7 @@ return new PdfRectangle(0, 0, 0, 0); } - return boxArray.ToRectangle(); + return boxArray.ToRectangle(pdfScanner); } private static string GetCharSet(DictionaryToken dictionary) diff --git a/src/UglyToad.PdfPig/Util/DictionaryTokenExtensions.cs b/src/UglyToad.PdfPig/Util/DictionaryTokenExtensions.cs index 75d66d72..e1117c8a 100644 --- a/src/UglyToad.PdfPig/Util/DictionaryTokenExtensions.cs +++ b/src/UglyToad.PdfPig/Util/DictionaryTokenExtensions.cs @@ -2,8 +2,6 @@ { using System; using Core; - using Exceptions; - using Geometry; using JetBrains.Annotations; using Parser.Parts; using Tokenization.Scanner; @@ -125,7 +123,7 @@ throw new PdfDocumentFormatException($"The array did not contain a number at index {index}. Array was: {array}."); } - public static PdfRectangle ToRectangle(this ArrayToken array) + public static PdfRectangle ToRectangle(this ArrayToken array, IPdfTokenScanner tokenScanner) { if (array == null) { @@ -137,13 +135,13 @@ throw new PdfDocumentFormatException($"Cannot convert array to rectangle, expected 4 values instead got: {array}."); } - return new PdfRectangle(array.GetNumeric(0).Double, - array.GetNumeric(1).Double, - array.GetNumeric(2).Double, - array.GetNumeric(3).Double); + return new PdfRectangle(DirectObjectFinder.Get(array[0], tokenScanner).Double, + DirectObjectFinder.Get(array[1], tokenScanner).Double, + DirectObjectFinder.Get(array[2], tokenScanner).Double, + DirectObjectFinder.Get(array[3], tokenScanner).Double); } - public static PdfRectangle ToIntRectangle(this ArrayToken array) + public static PdfRectangle ToIntRectangle(this ArrayToken array, IPdfTokenScanner tokenScanner) { if (array == null) { @@ -155,10 +153,10 @@ throw new PdfDocumentFormatException($"Cannot convert array to rectangle, expected 4 values instead got: {array}."); } - return new PdfRectangle(array.GetNumeric(0).Int, - array.GetNumeric(1).Int, - array.GetNumeric(2).Int, - array.GetNumeric(3).Int); + return new PdfRectangle(DirectObjectFinder.Get(array[0], tokenScanner).Int, + DirectObjectFinder.Get(array[1], tokenScanner).Int, + DirectObjectFinder.Get(array[2], tokenScanner).Int, + DirectObjectFinder.Get(array[3], tokenScanner).Int); } } }