diff --git a/src/UglyToad.PdfPig.Tests/Graphics/TestOperationContext.cs b/src/UglyToad.PdfPig.Tests/Graphics/TestOperationContext.cs index f5d1b4396..182969705 100644 --- a/src/UglyToad.PdfPig.Tests/Graphics/TestOperationContext.cs +++ b/src/UglyToad.PdfPig.Tests/Graphics/TestOperationContext.cs @@ -2,10 +2,12 @@ { using System.Collections.Generic; using Content; + using Logging; using PdfFonts; using PdfPig.Graphics; using PdfPig.Tokens; using PdfPig.Core; + using System; using Tokens; using UglyToad.PdfPig.Graphics.Core; using UglyToad.PdfPig.Graphics.Operations.TextPositioning; @@ -32,7 +34,11 @@ public TestOperationContext() { StateStack.Push(new CurrentGraphicsState() { - ColorSpaceContext = new ColorSpaceContext(GetCurrentState, new ResourceStore(new TestPdfTokenScanner(), new TestFontFactory(), new TestFilterProvider())) + ColorSpaceContext = new ColorSpaceContext(GetCurrentState, + new ResourceStore(new TestPdfTokenScanner(), + new TestFontFactory(), + new TestFilterProvider(), + new InternalParsingOptions(Array.Empty(), true, false, true, true, new NoOpLog()))) }); CurrentSubpath = new PdfSubpath(); } diff --git a/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs b/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs index d11a0662e..7c2bbaa40 100644 --- a/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs +++ b/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs @@ -81,6 +81,7 @@ public void OnlyExposedApiIsPublic() "UglyToad.PdfPig.Content.Hyperlink", "UglyToad.PdfPig.Content.InlineImage", "UglyToad.PdfPig.Content.IPdfImage", + "UglyToad.PdfPig.Content.IResourceStore", "UglyToad.PdfPig.Content.Letter", "UglyToad.PdfPig.Content.MarkedContentElement", "UglyToad.PdfPig.Content.MediaBox", diff --git a/src/UglyToad.PdfPig/Content/IResourceStore.cs b/src/UglyToad.PdfPig/Content/IResourceStore.cs index 50346a4c9..87cbfff64 100644 --- a/src/UglyToad.PdfPig/Content/IResourceStore.cs +++ b/src/UglyToad.PdfPig/Content/IResourceStore.cs @@ -5,9 +5,15 @@ using System.Collections.Generic; using Tokens; - internal interface IResourceStore + /// + /// Resource store. + /// + public interface IResourceStore { - void LoadResourceDictionary(DictionaryToken resourceDictionary, InternalParsingOptions parsingOptions); + /// + /// Load the resource dictionary. + /// + void LoadResourceDictionary(DictionaryToken resourceDictionary); /// /// Remove any named resources and associated state for the last resource dictionary loaded. @@ -15,22 +21,49 @@ internal interface IResourceStore /// void UnloadResourceDictionary(); + /// + /// Get the font corresponding to the name. + /// IFont GetFont(NameToken name); + /// + /// Try getting the XObject corresponding to the name. + /// bool TryGetXObject(NameToken name, out StreamToken stream); + /// + /// Get the extended graphics state dictionary corresponding to the name. + /// DictionaryToken GetExtendedGraphicsStateDictionary(NameToken name); + /// + /// Get the font from the . + /// IFont GetFontDirectly(IndirectReferenceToken fontReferenceToken); + /// + /// Get the named color space by its name. + /// bool TryGetNamedColorSpace(NameToken name, out ResourceColorSpace namedColorSpace); + /// + /// Get the color space details corresponding to the name. + /// ColorSpaceDetails GetColorSpaceDetails(NameToken name, DictionaryToken dictionary); + /// + /// Get the marked content properties dictionary corresponding to the name. + /// DictionaryToken GetMarkedContentPropertiesDictionary(NameToken name); + /// + /// Get all as a dictionary. Keys are the names. + /// IReadOnlyDictionary GetPatterns(); + /// + /// Get the shading corresponding to the name. + /// Shading GetShading(NameToken name); } } \ No newline at end of file diff --git a/src/UglyToad.PdfPig/Content/ResourceStore.cs b/src/UglyToad.PdfPig/Content/ResourceStore.cs index 08ea50d2e..bb8f344c5 100644 --- a/src/UglyToad.PdfPig/Content/ResourceStore.cs +++ b/src/UglyToad.PdfPig/Content/ResourceStore.cs @@ -16,6 +16,7 @@ internal class ResourceStore : IResourceStore private readonly IPdfTokenScanner scanner; private readonly IFontFactory fontFactory; private readonly ILookupFilterProvider filterProvider; + private readonly InternalParsingOptions parsingOptions; private readonly Dictionary loadedFonts = new Dictionary(); private readonly Dictionary loadedDirectFonts = new Dictionary(); @@ -34,14 +35,18 @@ internal class ResourceStore : IResourceStore private (NameToken name, IFont font) lastLoadedFont; - public ResourceStore(IPdfTokenScanner scanner, IFontFactory fontFactory, ILookupFilterProvider filterProvider) + public ResourceStore(IPdfTokenScanner scanner, + IFontFactory fontFactory, + ILookupFilterProvider filterProvider, + InternalParsingOptions parsingOptions) { this.scanner = scanner; this.fontFactory = fontFactory; this.filterProvider = filterProvider; + this.parsingOptions = parsingOptions; } - public void LoadResourceDictionary(DictionaryToken resourceDictionary, InternalParsingOptions parsingOptions) + public void LoadResourceDictionary(DictionaryToken resourceDictionary) { lastLoadedFont = (null, null); loadedNamedColorSpaceDetails.Clear(); diff --git a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs index c76a19de2..2c2e90e1c 100644 --- a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs +++ b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs @@ -436,7 +436,7 @@ private void ProcessFormXObject(StreamToken formStream, NameToken xObjectName) var hasResources = formStream.StreamDictionary.TryGet(NameToken.Resources, pdfScanner, out var formResources); if (hasResources) { - resourceStore.LoadResourceDictionary(formResources, parsingOptions); + resourceStore.LoadResourceDictionary(formResources); } // 1. Save current state. diff --git a/src/UglyToad.PdfPig/Parser/PageFactory.cs b/src/UglyToad.PdfPig/Parser/PageFactory.cs index 74890e401..20121efe2 100644 --- a/src/UglyToad.PdfPig/Parser/PageFactory.cs +++ b/src/UglyToad.PdfPig/Parser/PageFactory.cs @@ -10,7 +10,6 @@ using Graphics; using Graphics.Operations; using Logging; - using Outline; using Outline.Destinations; using Parts; using Tokenization.Scanner; @@ -66,13 +65,13 @@ public Page Create(int number, DictionaryToken dictionary, PageTreeMembers pageT { var resource = pageTreeMembers.ParentResources.Dequeue(); - resourceStore.LoadResourceDictionary(resource, parsingOptions); + resourceStore.LoadResourceDictionary(resource); stackDepth++; } if (dictionary.TryGet(NameToken.Resources, pdfScanner, out DictionaryToken resources)) { - resourceStore.LoadResourceDictionary(resources, parsingOptions); + resourceStore.LoadResourceDictionary(resources); stackDepth++; } diff --git a/src/UglyToad.PdfPig/Parser/PdfDocumentFactory.cs b/src/UglyToad.PdfPig/Parser/PdfDocumentFactory.cs index 121a0e0ea..8d68d5c5a 100644 --- a/src/UglyToad.PdfPig/Parser/PdfDocumentFactory.cs +++ b/src/UglyToad.PdfPig/Parser/PdfDocumentFactory.cs @@ -187,7 +187,7 @@ private static PdfDocument OpenDocument( type1Handler, new Type3FontHandler(pdfScanner, filterProvider, encodingReader)); - var resourceContainer = new ResourceStore(pdfScanner, fontFactory, filterProvider); + var resourceContainer = new ResourceStore(pdfScanner, fontFactory, filterProvider, parsingOptions); var information = DocumentInformationFactory.Create( pdfScanner,