Fix integration tests for #579 (3)

This commit is contained in:
BobLd
2023-04-13 19:08:41 +01:00
parent 906066ec58
commit 42e4171c31
6 changed files with 548 additions and 546 deletions

View File

@@ -1,17 +1,17 @@
namespace UglyToad.PdfPig.Annotations;
using System;
using System.Collections.Generic;
using Tokens;
/// <summary>
/// Appearance stream (PDF Reference 8.4.4) that describes what an annotation looks like. Each stream is a Form XObject.
/// The appearance stream is either stateless (in which case <see cref="IsStateless"/> is true)
/// or stateful, in which case <see cref="IsStateless"/> is false and the states can be retrieved via <see cref="GetStates"/>.
/// The states can then be used to retrieve the state-specific appearances using <see cref="Get"/>.
/// </summary>
public class AppearanceStream
namespace UglyToad.PdfPig.Annotations
{
using System;
using System.Collections.Generic;
using Tokens;
/// <summary>
/// Appearance stream (PDF Reference 8.4.4) that describes what an annotation looks like. Each stream is a Form XObject.
/// The appearance stream is either stateless (in which case <see cref="IsStateless"/> is true)
/// or stateful, in which case <see cref="IsStateless"/> is false and the states can be retrieved via <see cref="GetStates"/>.
/// The states can then be used to retrieve the state-specific appearances using <see cref="Get"/>.
/// </summary>
public class AppearanceStream
{
private readonly IDictionary<string, StreamToken> appearanceStreamsByState;
private readonly StreamToken statelessAppearanceStream;
@@ -63,4 +63,5 @@ public class AppearanceStream
}
return appearanceStreamsByState[state];
}
}
}

View File

@@ -1,11 +1,11 @@
namespace UglyToad.PdfPig.Annotations;
using System.Collections.Generic;
using Tokenization.Scanner;
using Tokens;
internal static class AppearanceStreamFactory
namespace UglyToad.PdfPig.Annotations
{
using System.Collections.Generic;
using Tokenization.Scanner;
using Tokens;
internal static class AppearanceStreamFactory
{
public static bool TryCreate(DictionaryToken appearanceDictionary, NameToken name, IPdfTokenScanner tokenScanner, out AppearanceStream appearanceStream)
{
if (appearanceDictionary.TryGet(name, out IndirectReferenceToken appearanceReference))
@@ -26,7 +26,6 @@ internal static class AppearanceStreamFactory
var streamToken = tokenScanner.Get(appearanceRef.Data)?.Data as StreamToken;
dict[state] = streamToken;
}
}
if (dict.Count > 0)
@@ -39,4 +38,5 @@ internal static class AppearanceStreamFactory
appearanceStream = null;
return false;
}
}
}

View File

@@ -1,17 +1,17 @@
namespace UglyToad.PdfPig.Content;
using Core;
using Logging;
using Parser.Parts;
using System;
using System.Collections.Generic;
using System.Linq;
using Tokenization.Scanner;
using Tokens;
using Util;
internal class PagesFactory
namespace UglyToad.PdfPig.Content
{
using Core;
using Logging;
using Parser.Parts;
using System;
using System.Collections.Generic;
using System.Linq;
using Tokenization.Scanner;
using Tokens;
using Util;
internal class PagesFactory
{
private class PageCounter
{
public int PageCount { get; private set; }
@@ -45,7 +45,6 @@ internal class PagesFactory
return new Pages(pageFactory, scanner, pageTree, pagesByNumber);
}
private static PageTreeNode ProcessPagesNode(IndirectReference referenceInput,
DictionaryToken nodeDictionaryInput,
IndirectReference parentReferenceInput,
@@ -63,8 +62,6 @@ internal class PagesFactory
return new PageTreeNode(nodeDictionaryInput, referenceInput, true, pageNumber.PageCount).WithChildren(EmptyArray<PageTreeNode>.Instance);
}
//If we got here, we have to iterate till we manage to exit
// Attempt to detect (and break) any infinite loop (IL) by recording the ids of the last 1000 (by default) tokens processed.
@@ -102,7 +99,7 @@ internal class PagesFactory
var listOfLastVisitedToken = visitedTokensWorkingWindow.ToList();
var indexOfCurrentTokenInListOfLastVisitedToken = listOfLastVisitedToken.IndexOf((currentReferenceObjectNumber, currentReferenceGeneration));
var howManyTokensBack = Math.Abs(indexOfCurrentTokenInListOfLastVisitedToken - listOfLastVisitedToken.Count); //eg initate loop is taking us back to last token or five token back
System.Diagnostics.Debug.WriteLine($"Break infinite loop while processing page {pageNumber.PageCount+1} tokens. Token with object number {currentReferenceObjectNumber} and generation {currentReferenceGeneration} processed {howManyTokensBack} token(s) back. ");
System.Diagnostics.Debug.WriteLine($"Break infinite loop while processing page {pageNumber.PageCount + 1} tokens. Token with object number {currentReferenceObjectNumber} and generation {currentReferenceGeneration} processed {howManyTokensBack} token(s) back.");
continue; // don't reprocess token already processed. break infinite loop. Issue #519
}
else
@@ -184,7 +181,7 @@ internal class PagesFactory
action();
}
foreach (var child in firstPage.Children.ToRecursiveOrderList(x=>x.Children).Where(child => child.IsPage))
foreach (var child in firstPage.Children.ToRecursiveOrderList(x => x.Children).Where(child => child.IsPage))
{
pageNumber.Increment();
child.PageNumber = pageNumber.PageCount;
@@ -238,4 +235,5 @@ internal class PagesFactory
PopulatePageByNumberDictionary(child, result);
}
}
}
}

View File

@@ -1,16 +1,16 @@
namespace UglyToad.PdfPig.Outline;
using Content;
using Destinations;
using Logging;
using System.Collections.Generic;
using Tokens;
/// <summary>
/// Named destinations in a PDF document
/// </summary>
internal class NamedDestinations
namespace UglyToad.PdfPig.Outline
{
using Content;
using Destinations;
using Logging;
using System.Collections.Generic;
using Tokens;
/// <summary>
/// Named destinations in a PDF document
/// </summary>
internal class NamedDestinations
{
/// <summary>
/// Dictionary containing explicit destinations, keyed by name
/// </summary>
@@ -41,4 +41,5 @@ internal class NamedDestinations
{
return NamedDestinationsProvider.TryGetExplicitDestination(explicitDestinationArray, pages, log, isRemoteDestination, out destination);
}
}
}

View File

@@ -1,15 +1,15 @@
namespace UglyToad.PdfPig.Outline;
using Content;
using Destinations;
using Logging;
using Parser.Parts;
using System.Collections.Generic;
using Tokenization.Scanner;
using Tokens;
internal static class NamedDestinationsProvider
namespace UglyToad.PdfPig.Outline
{
using Content;
using Destinations;
using Logging;
using Parser.Parts;
using System.Collections.Generic;
using Tokenization.Scanner;
using Tokens;
internal static class NamedDestinationsProvider
{
internal static NamedDestinations Read(DictionaryToken catalogDictionary, IPdfTokenScanner pdfScanner, Pages pages, ILog log)
{
var destinationsByName = new Dictionary<string, ExplicitDestination>();
@@ -217,4 +217,5 @@ internal static class NamedDestinationsProvider
return false;
}
}
}

View File

@@ -1,16 +1,16 @@
namespace UglyToad.PdfPig.Outline;
using Destinations;
using System;
using System.Collections.Generic;
/// <inheritdoc />
/// <summary>
/// A node in the <see cref="Bookmarks" /> of a PDF document which corresponds
/// to a location in an embedded file.
/// </summary>
public class EmbeddedBookmarkNode : DocumentBookmarkNode
namespace UglyToad.PdfPig.Outline
{
using Destinations;
using System;
using System.Collections.Generic;
/// <inheritdoc />
/// <summary>
/// A node in the <see cref="Bookmarks" /> of a PDF document which corresponds
/// to a location in an embedded file.
/// </summary>
public class EmbeddedBookmarkNode : DocumentBookmarkNode
{
/// <summary>
/// The file specification for the embedded file
/// </summary>
@@ -30,4 +30,5 @@ public class EmbeddedBookmarkNode : DocumentBookmarkNode
{
return $"Embedded file '{FileSpecification}', {Level}, {Title}";
}
}
}