mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
remove preview static local function by moving to class scope
This commit is contained in:
@@ -64,7 +64,13 @@
|
|||||||
return new Catalog(dictionary, pages, pageTree);
|
return new Catalog(dictionary, pages, pageTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PageTreeNode ProcessPagesNode(IndirectReference referenceInput, DictionaryToken nodeDictionaryInput, IndirectReference parentReferenceInput, bool isRoot, IPdfTokenScanner pdfTokenScanner, bool isLenientParsing, PageCounter pageNumber)
|
private static PageTreeNode ProcessPagesNode(IndirectReference referenceInput,
|
||||||
|
DictionaryToken nodeDictionaryInput,
|
||||||
|
IndirectReference parentReferenceInput,
|
||||||
|
bool isRoot,
|
||||||
|
IPdfTokenScanner pdfTokenScanner,
|
||||||
|
bool isLenientParsing,
|
||||||
|
PageCounter pageNumber)
|
||||||
{
|
{
|
||||||
bool isPage = CheckIfIsPage(nodeDictionaryInput, parentReferenceInput, isRoot, pdfTokenScanner, isLenientParsing);
|
bool isPage = CheckIfIsPage(nodeDictionaryInput, parentReferenceInput, isRoot, pdfTokenScanner, isLenientParsing);
|
||||||
|
|
||||||
@@ -77,14 +83,18 @@
|
|||||||
|
|
||||||
//If we got here, we have to iterate till we manage to exit
|
//If we got here, we have to iterate till we manage to exit
|
||||||
|
|
||||||
var toProcess = new Queue<(PageTreeNode thisPage, IndirectReference reference, DictionaryToken nodeDictionary, IndirectReference parentReference, List<PageTreeNode> nodeChildren)>();
|
var toProcess =
|
||||||
|
new Queue<(PageTreeNode thisPage, IndirectReference reference, DictionaryToken nodeDictionary, IndirectReference parentReference,
|
||||||
|
List<PageTreeNode> nodeChildren)>();
|
||||||
var firstPage = new PageTreeNode(nodeDictionaryInput, referenceInput, false, null);
|
var firstPage = new PageTreeNode(nodeDictionaryInput, referenceInput, false, null);
|
||||||
var setChildren = new List<Action>();
|
var setChildren = new List<Action>();
|
||||||
var firstPageChildren = new List<PageTreeNode>();
|
var firstPageChildren = new List<PageTreeNode>();
|
||||||
|
|
||||||
setChildren.Add(() => firstPage.WithChildren(firstPageChildren));
|
setChildren.Add(() => firstPage.WithChildren(firstPageChildren));
|
||||||
|
|
||||||
toProcess.Enqueue((thisPage: firstPage, reference: referenceInput, nodeDictionary: nodeDictionaryInput, parentReference: parentReferenceInput, nodeChildren: firstPageChildren));
|
toProcess.Enqueue(
|
||||||
|
(thisPage: firstPage, reference: referenceInput, nodeDictionary: nodeDictionaryInput, parentReference: parentReferenceInput,
|
||||||
|
nodeChildren: firstPageChildren));
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -92,16 +102,25 @@
|
|||||||
|
|
||||||
if (!current.nodeDictionary.TryGet(NameToken.Kids, pdfTokenScanner, out ArrayToken kids))
|
if (!current.nodeDictionary.TryGet(NameToken.Kids, pdfTokenScanner, out ArrayToken kids))
|
||||||
{
|
{
|
||||||
if (!isLenientParsing) { throw new PdfDocumentFormatException($"Pages node in the document pages tree did not define a kids array: {current.nodeDictionary}."); }
|
if (!isLenientParsing)
|
||||||
|
{
|
||||||
|
throw new PdfDocumentFormatException($"Pages node in the document pages tree did not define a kids array: {current.nodeDictionary}.");
|
||||||
|
}
|
||||||
|
|
||||||
kids = new ArrayToken(EmptyArray<IToken>.Instance);
|
kids = new ArrayToken(EmptyArray<IToken>.Instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var kid in kids.Data)
|
foreach (var kid in kids.Data)
|
||||||
{
|
{
|
||||||
if (!(kid is IndirectReferenceToken kidRef)) { throw new PdfDocumentFormatException($"Kids array contained invalid entry (must be indirect reference): {kid}."); }
|
if (!(kid is IndirectReferenceToken kidRef))
|
||||||
|
{
|
||||||
|
throw new PdfDocumentFormatException($"Kids array contained invalid entry (must be indirect reference): {kid}.");
|
||||||
|
}
|
||||||
|
|
||||||
if (!DirectObjectFinder.TryGet(kidRef, pdfTokenScanner, out DictionaryToken kidDictionaryToken)) { throw new PdfDocumentFormatException($"Could not find dictionary associated with reference in pages kids array: {kidRef}."); }
|
if (!DirectObjectFinder.TryGet(kidRef, pdfTokenScanner, out DictionaryToken kidDictionaryToken))
|
||||||
|
{
|
||||||
|
throw new PdfDocumentFormatException($"Could not find dictionary associated with reference in pages kids array: {kidRef}.");
|
||||||
|
}
|
||||||
|
|
||||||
bool isChildPage = CheckIfIsPage(kidDictionaryToken, current.reference, false, pdfTokenScanner, isLenientParsing);
|
bool isChildPage = CheckIfIsPage(kidDictionaryToken, current.reference, false, pdfTokenScanner, isLenientParsing);
|
||||||
|
|
||||||
@@ -109,14 +128,17 @@
|
|||||||
{
|
{
|
||||||
pageNumber.Increment();
|
pageNumber.Increment();
|
||||||
|
|
||||||
var kidPageNode = new PageTreeNode(kidDictionaryToken, kidRef.Data, true, pageNumber.PageCount).WithChildren(EmptyArray<PageTreeNode>.Instance);
|
var kidPageNode =
|
||||||
|
new PageTreeNode(kidDictionaryToken, kidRef.Data, true, pageNumber.PageCount).WithChildren(EmptyArray<PageTreeNode>.Instance);
|
||||||
current.nodeChildren.Add(kidPageNode);
|
current.nodeChildren.Add(kidPageNode);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var kidChildNode = new PageTreeNode(kidDictionaryToken, kidRef.Data, false, null);
|
var kidChildNode = new PageTreeNode(kidDictionaryToken, kidRef.Data, false, null);
|
||||||
var kidChildren = new List<PageTreeNode>();
|
var kidChildren = new List<PageTreeNode>();
|
||||||
toProcess.Enqueue((thisPage: kidChildNode, reference: kidRef.Data, nodeDictionary: kidDictionaryToken, parentReference: current.reference, nodeChildren: kidChildren));
|
toProcess.Enqueue(
|
||||||
|
(thisPage: kidChildNode, reference: kidRef.Data, nodeDictionary: kidDictionaryToken, parentReference: current.reference,
|
||||||
|
nodeChildren: kidChildren));
|
||||||
|
|
||||||
setChildren.Add(() => kidChildNode.WithChildren(kidChildren));
|
setChildren.Add(() => kidChildNode.WithChildren(kidChildren));
|
||||||
|
|
||||||
@@ -131,9 +153,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
return firstPage;
|
return firstPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool CheckIfIsPage(DictionaryToken nodeDictionary, IndirectReference parentReference, bool isRoot, IPdfTokenScanner pdfTokenScanner, bool isLenientParsing)
|
||||||
static bool CheckIfIsPage(DictionaryToken nodeDictionary, IndirectReference parentReference, bool isRoot, IPdfTokenScanner pdfTokenScanner, bool isLenientParsing)
|
|
||||||
{
|
{
|
||||||
var isPage = false;
|
var isPage = false;
|
||||||
|
|
||||||
@@ -161,4 +183,3 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user