use tokenscanner when converting array to rectangle

an arrray of 4 items representing a rectangle may define its values as indirect references. when converting to a rectangle we pass a pdf token scanner to resolve any indirect references.
This commit is contained in:
Eliot Jones
2020-01-13 10:20:08 +00:00
parent 47672d3f90
commit efc258b0f0
6 changed files with 18 additions and 20 deletions

View File

@@ -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<DictionaryToken>(parentDictionaries) {fieldDictionary};

View File

@@ -53,7 +53,7 @@
var type = annotationDictionary.Get<NameToken>(NameToken.Subtype, tokenScanner);
var annotationType = type.ToAnnotationType();
var rectangle = annotationDictionary.Get<ArrayToken>(NameToken.Rect, tokenScanner).ToRectangle();
var rectangle = annotationDictionary.Get<ArrayToken>(NameToken.Rect, tokenScanner).ToRectangle(tokenScanner);
var contents = GetNamedString(NameToken.Contents, annotationDictionary);
var name = GetNamedString(NameToken.Nm, annotationDictionary);

View File

@@ -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))

View File

@@ -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
{

View File

@@ -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)

View File

@@ -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<NumericToken>(array[0], tokenScanner).Double,
DirectObjectFinder.Get<NumericToken>(array[1], tokenScanner).Double,
DirectObjectFinder.Get<NumericToken>(array[2], tokenScanner).Double,
DirectObjectFinder.Get<NumericToken>(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<NumericToken>(array[0], tokenScanner).Int,
DirectObjectFinder.Get<NumericToken>(array[1], tokenScanner).Int,
DirectObjectFinder.Get<NumericToken>(array[2], tokenScanner).Int,
DirectObjectFinder.Get<NumericToken>(array[3], tokenScanner).Int);
}
}
}