Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/UglyToad.PdfPig/Content/ResourceStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ internal class ResourceStore : IResourceStore

private readonly Dictionary<IndirectReference, IFont> loadedFonts = new Dictionary<IndirectReference, IFont>();
private readonly Dictionary<NameToken, IFont> loadedDirectFonts = new Dictionary<NameToken, IFont>();
private readonly StackDictionary<NameToken, IndirectReference> currentResourceState = new StackDictionary<NameToken, IndirectReference>();
private readonly StackDictionary<NameToken, IndirectReference> currentFontState = new StackDictionary<NameToken, IndirectReference>();
private readonly StackDictionary<NameToken, IndirectReference> currentXObjectState = new StackDictionary<NameToken, IndirectReference>();

private readonly Dictionary<NameToken, DictionaryToken> extendedGraphicsStates = new Dictionary<NameToken, DictionaryToken>();

Expand Down Expand Up @@ -53,7 +54,8 @@ public void LoadResourceDictionary(DictionaryToken resourceDictionary)
loadedNamedColorSpaceDetails.Clear();

namedColorSpaces.Push();
currentResourceState.Push();
currentFontState.Push();
currentXObjectState.Push();

if (resourceDictionary.TryGet(NameToken.Font, out var fontBase))
{
Expand All @@ -78,7 +80,7 @@ public void LoadResourceDictionary(DictionaryToken resourceDictionary)
throw new InvalidOperationException($"Expected the XObject dictionary value for key /{pair.Key} to be an indirect reference, instead got: {pair.Value}.");
}

currentResourceState[NameToken.Create(pair.Key)] = reference.Data;
currentXObjectState[NameToken.Create(pair.Key)] = reference.Data;
}
}

Expand Down Expand Up @@ -185,7 +187,8 @@ public void UnloadResourceDictionary()
{
lastLoadedFont = (null, null);
loadedNamedColorSpaceDetails.Clear();
currentResourceState.Pop();
currentFontState.Pop();
currentXObjectState.Pop();
namedColorSpaces.Pop();
}

Expand All @@ -199,7 +202,7 @@ private void LoadFontDictionary(DictionaryToken fontDictionary)
{
var reference = objectKey.Data;

currentResourceState[NameToken.Create(pair.Key)] = reference;
currentFontState[NameToken.Create(pair.Key)] = reference;

if (loadedFonts.ContainsKey(reference))
{
Expand Down Expand Up @@ -245,7 +248,7 @@ private void LoadFontDictionary(DictionaryToken fontDictionary)
}

IFont? font;
if (currentResourceState.TryGetValue(name, out var reference))
if (currentFontState.TryGetValue(name, out var reference))
{
loadedFonts.TryGetValue(reference, out font);
}
Expand Down Expand Up @@ -335,7 +338,7 @@ public ColorSpaceDetails GetColorSpaceDetails(NameToken? name, DictionaryToken?
public bool TryGetXObject(NameToken name, [NotNullWhen(true)] out StreamToken? stream)
{
stream = null;
if (!currentResourceState.TryGetValue(name, out var indirectReference))
if (!currentXObjectState.TryGetValue(name, out var indirectReference))
{
return false;
}
Expand Down
Loading