remove islenientparsing from page classes

This commit is contained in:
Eliot Jones
2020-02-28 11:50:18 +00:00
parent 48d166276d
commit c864fa512c
8 changed files with 19 additions and 50 deletions

View File

@@ -17,19 +17,16 @@
private readonly IPdfTokenScanner pdfScanner;
private readonly IFilterProvider filterProvider;
private readonly Catalog catalog;
private readonly bool isLenientParsing;
private bool isDisposed;
internal AdvancedPdfDocumentAccess(IPdfTokenScanner pdfScanner,
IFilterProvider filterProvider,
Catalog catalog,
bool isLenientParsing)
Catalog catalog)
{
this.pdfScanner = pdfScanner ?? throw new ArgumentNullException(nameof(pdfScanner));
this.filterProvider = filterProvider ?? throw new ArgumentNullException(nameof(filterProvider));
this.catalog = catalog ?? throw new ArgumentNullException(nameof(catalog));
this.isLenientParsing = isLenientParsing;
}
/// <summary>
@@ -51,8 +48,7 @@
return false;
}
var embeddedFileNames = NameTreeParser.FlattenNameTreeToDictionary(embeddedFileNamesDictionary, pdfScanner, isLenientParsing,
x => x);
var embeddedFileNames = NameTreeParser.FlattenNameTreeToDictionary(embeddedFileNamesDictionary, pdfScanner, x => x);
if (embeddedFileNames.Count == 0)
{

View File

@@ -4,7 +4,6 @@
internal interface IPageFactory
{
Page Create(int number, DictionaryToken dictionary, PageTreeMembers pageTreeMembers,
bool isLenientParsing);
Page Create(int number, DictionaryToken dictionary, PageTreeMembers pageTreeMembers);
}
}

View File

@@ -10,17 +10,14 @@
{
private readonly Catalog catalog;
private readonly IPageFactory pageFactory;
private readonly bool isLenientParsing;
private readonly IPdfTokenScanner pdfScanner;
public int Count { get; }
internal Pages(Catalog catalog, IPageFactory pageFactory, bool isLenientParsing,
IPdfTokenScanner pdfScanner)
internal Pages(Catalog catalog, IPageFactory pageFactory, IPdfTokenScanner pdfScanner)
{
this.catalog = catalog ?? throw new ArgumentNullException(nameof(catalog));
this.pageFactory = pageFactory ?? throw new ArgumentNullException(nameof(pageFactory));
this.isLenientParsing = isLenientParsing;
this.pdfScanner = pdfScanner ?? throw new ArgumentNullException(nameof(pdfScanner));
Count = catalog.PagesDictionary.GetIntOrDefault(NameToken.Count);
@@ -66,7 +63,7 @@
}
}
var page = pageFactory.Create(pageNumber, pageNode.NodeDictionary, pageTreeMembers, isLenientParsing);
var page = pageFactory.Create(pageNumber, pageNode.NodeDictionary, pageTreeMembers);
return page;
}

View File

@@ -14,13 +14,11 @@
{
private readonly ILog log;
private readonly IPdfTokenScanner pdfScanner;
private readonly bool isLenientParsing;
public BookmarksProvider(ILog log, IPdfTokenScanner pdfScanner, bool isLenientParsing)
public BookmarksProvider(ILog log, IPdfTokenScanner pdfScanner)
{
this.log = log;
this.pdfScanner = pdfScanner;
this.isLenientParsing = isLenientParsing;
}
/// <summary>
@@ -33,10 +31,9 @@
return null;
}
if (!isLenientParsing && outlinesDictionary.TryGet(NameToken.Type, pdfScanner, out NameToken typeName)
&& typeName != NameToken.Outlines)
if (outlinesDictionary.TryGet(NameToken.Type, pdfScanner, out NameToken typeName) && typeName != NameToken.Outlines)
{
throw new PdfDocumentFormatException($"Outlines (bookmarks) dictionary did not have correct type specified: {typeName}.");
log?.Error($"Outlines (bookmarks) dictionary did not have correct type specified: {typeName}.");
}
if (!outlinesDictionary.TryGet(NameToken.First, pdfScanner, out DictionaryToken next))
@@ -44,7 +41,7 @@
return null;
}
var namedDestinations = ReadNamedDestinations(catalog, pdfScanner, isLenientParsing, log);
var namedDestinations = ReadNamedDestinations(catalog, pdfScanner, log);
var roots = new List<BookmarkNode>();
var seen = new HashSet<IndirectReference>();
@@ -102,10 +99,6 @@
{
bookmark = new DocumentBookmarkNode(title, level, destination, children);
}
else if (!isLenientParsing)
{
throw new PdfDocumentFormatException($"Invalid destination name for bookmark node: {destStringToken.Data}.");
}
else
{
return;
@@ -122,10 +115,6 @@
{
bookmark = new DocumentBookmarkNode(title, level, actionResult.destination, children);
}
else if (!isLenientParsing)
{
throw new PdfDocumentFormatException($"Invalid action for bookmark node: {actionDictionary}.");
}
else
{
return;
@@ -168,7 +157,7 @@
#region Named Destinations
private static IReadOnlyDictionary<string, ExplicitDestination> ReadNamedDestinations(Catalog catalog, IPdfTokenScanner pdfScanner,
bool isLenientParsing, ILog log)
ILog log)
{
var result = new Dictionary<string, ExplicitDestination>();
@@ -198,7 +187,7 @@
* The keys in the name tree may be treated as text strings for display purposes.
* The destination value associated with a key in the name tree may be either an array or a dictionary.
*/
NameTreeParser.FlattenNameTree(dests, pdfScanner, isLenientParsing, value =>
NameTreeParser.FlattenNameTree(dests, pdfScanner, value =>
{
if (TryReadExplicitDestination(value, catalog, pdfScanner, log, out var destination))
{

View File

@@ -33,8 +33,7 @@
this.pdfScanner = pdfScanner;
}
public Page Create(int number, DictionaryToken dictionary, PageTreeMembers pageTreeMembers,
bool isLenientParsing)
public Page Create(int number, DictionaryToken dictionary, PageTreeMembers pageTreeMembers)
{
if (dictionary == null)
{

View File

@@ -2,7 +2,6 @@
{
using System;
using System.Collections.Generic;
using Core;
using Tokenization.Scanner;
using Tokens;
@@ -10,19 +9,17 @@
{
public static IReadOnlyDictionary<string, TResult> FlattenNameTreeToDictionary<TResult>(DictionaryToken nameTreeNodeDictionary,
IPdfTokenScanner pdfScanner,
bool isLenientParsing,
Func<IToken, TResult> valuesFactory) where TResult : class
{
var result = new Dictionary<string, TResult>();
FlattenNameTree(nameTreeNodeDictionary, pdfScanner, isLenientParsing, valuesFactory, result);
FlattenNameTree(nameTreeNodeDictionary, pdfScanner, valuesFactory, result);
return result;
}
public static void FlattenNameTree<TResult>(DictionaryToken nameTreeNodeDictionary,
IPdfTokenScanner pdfScanner,
bool isLenientParsing,
Func<IToken, TResult> valuesFactory,
Dictionary<string, TResult> result) where TResult : class
{
@@ -52,11 +49,7 @@
{
if (DirectObjectFinder.TryGet(kid, pdfScanner, out DictionaryToken kidDictionary))
{
FlattenNameTree(kidDictionary, pdfScanner, isLenientParsing, valuesFactory, result);
}
else if (!isLenientParsing)
{
throw new PdfDocumentFormatException($"Invalid kids entry in PDF name tree: {kid} in {kids}.");
FlattenNameTree(kidDictionary, pdfScanner, valuesFactory, result);
}
}
}

View File

@@ -147,9 +147,9 @@
var caching = new ParsingCachingProviders(bruteForceSearcher, resourceContainer);
var acroFormFactory = new AcroFormFactory(pdfScanner, filterProvider, crossReferenceTable);
var bookmarksProvider = new BookmarksProvider(log, pdfScanner, isLenientParsing);
var bookmarksProvider = new BookmarksProvider(log, pdfScanner);
return new PdfDocument(log, inputBytes, version, crossReferenceTable, isLenientParsing, caching, pageFactory, catalog, information,
return new PdfDocument(log, inputBytes, version, crossReferenceTable, caching, pageFactory, catalog, information,
encryptionDictionary,
pdfScanner,
filterProvider,

View File

@@ -25,9 +25,7 @@
{
private bool isDisposed;
private readonly Lazy<AcroForm> documentForm;
private readonly bool isLenientParsing;
[NotNull]
private readonly HeaderVersion version;
@@ -86,7 +84,6 @@
IInputBytes inputBytes,
HeaderVersion version,
CrossReferenceTable crossReferenceTable,
bool isLenientParsing,
ParsingCachingProviders cachingProviders,
IPageFactory pageFactory,
Catalog catalog,
@@ -100,16 +97,15 @@
this.log = log;
this.inputBytes = inputBytes;
this.version = version ?? throw new ArgumentNullException(nameof(version));
this.isLenientParsing = isLenientParsing;
this.cachingProviders = cachingProviders ?? throw new ArgumentNullException(nameof(cachingProviders));
this.encryptionDictionary = encryptionDictionary;
this.pdfScanner = pdfScanner ?? throw new ArgumentNullException(nameof(pdfScanner));
this.filterProvider = filterProvider ?? throw new ArgumentNullException(nameof(filterProvider));
this.bookmarksProvider = bookmarksProvider ?? throw new ArgumentNullException(nameof(bookmarksProvider));
Information = information ?? throw new ArgumentNullException(nameof(information));
pages = new Pages(catalog, pageFactory, isLenientParsing, pdfScanner);
pages = new Pages(catalog, pageFactory, pdfScanner);
Structure = new Structure(catalog, crossReferenceTable, pdfScanner);
Advanced = new AdvancedPdfDocumentAccess(pdfScanner, filterProvider, catalog, isLenientParsing);
Advanced = new AdvancedPdfDocumentAccess(pdfScanner, filterProvider, catalog);
documentForm = new Lazy<AcroForm>(() => acroFormFactory.GetAcroForm(catalog));
}