Make IResourceStore part of the public API and pass InternalParsingOptions to the ResourceStore constructor

This commit is contained in:
BobLd
2023-10-22 18:22:57 +01:00
parent 7ab3a6a2cd
commit ba865b340e
7 changed files with 54 additions and 10 deletions

View File

@@ -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 @@
{
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<string>(), true, false, true, true, new NoOpLog())))
});
CurrentSubpath = new PdfSubpath();
}

View File

@@ -81,6 +81,7 @@
"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",

View File

@@ -5,9 +5,15 @@
using System.Collections.Generic;
using Tokens;
internal interface IResourceStore
/// <summary>
/// Resource store.
/// </summary>
public interface IResourceStore
{
void LoadResourceDictionary(DictionaryToken resourceDictionary, InternalParsingOptions parsingOptions);
/// <summary>
/// Load the resource dictionary.
/// </summary>
void LoadResourceDictionary(DictionaryToken resourceDictionary);
/// <summary>
/// Remove any named resources and associated state for the last resource dictionary loaded.
@@ -15,22 +21,49 @@
/// </summary>
void UnloadResourceDictionary();
/// <summary>
/// Get the font corresponding to the name.
/// </summary>
IFont GetFont(NameToken name);
/// <summary>
/// Try getting the XObject corresponding to the name.
/// </summary>
bool TryGetXObject(NameToken name, out StreamToken stream);
/// <summary>
/// Get the extended graphics state dictionary corresponding to the name.
/// </summary>
DictionaryToken GetExtendedGraphicsStateDictionary(NameToken name);
/// <summary>
/// Get the font from the <see cref="IndirectReferenceToken"/>.
/// </summary>
IFont GetFontDirectly(IndirectReferenceToken fontReferenceToken);
/// <summary>
/// Get the named color space by its name.
/// </summary>
bool TryGetNamedColorSpace(NameToken name, out ResourceColorSpace namedColorSpace);
/// <summary>
/// Get the color space details corresponding to the name.
/// </summary>
ColorSpaceDetails GetColorSpaceDetails(NameToken name, DictionaryToken dictionary);
/// <summary>
/// Get the marked content properties dictionary corresponding to the name.
/// </summary>
DictionaryToken GetMarkedContentPropertiesDictionary(NameToken name);
/// <summary>
/// Get all <see cref="PatternColor"/> as a dictionary. Keys are the <see cref="PatternColor"/> names.
/// </summary>
IReadOnlyDictionary<NameToken, PatternColor> GetPatterns();
/// <summary>
/// Get the shading corresponding to the name.
/// </summary>
Shading GetShading(NameToken name);
}
}

View File

@@ -16,6 +16,7 @@
private readonly IPdfTokenScanner scanner;
private readonly IFontFactory fontFactory;
private readonly ILookupFilterProvider filterProvider;
private readonly InternalParsingOptions parsingOptions;
private readonly Dictionary<IndirectReference, IFont> loadedFonts = new Dictionary<IndirectReference, IFont>();
private readonly Dictionary<NameToken, IFont> loadedDirectFonts = new Dictionary<NameToken, IFont>();
@@ -34,14 +35,18 @@
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();

View File

@@ -436,7 +436,7 @@
var hasResources = formStream.StreamDictionary.TryGet<DictionaryToken>(NameToken.Resources, pdfScanner, out var formResources);
if (hasResources)
{
resourceStore.LoadResourceDictionary(formResources, parsingOptions);
resourceStore.LoadResourceDictionary(formResources);
}
// 1. Save current state.

View File

@@ -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 @@
{
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++;
}

View File

@@ -187,7 +187,7 @@
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,