From d69e3fa6a9a2affa395a9bdaf823bad3dff26879 Mon Sep 17 00:00:00 2001 From: Alexander Vinnikov Date: Thu, 5 Feb 2026 19:14:17 +0100 Subject: [PATCH] make ext gstates stacked --- src/UglyToad.PdfPig/Content/ResourceStore.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/UglyToad.PdfPig/Content/ResourceStore.cs b/src/UglyToad.PdfPig/Content/ResourceStore.cs index b764e6e8..898f83eb 100644 --- a/src/UglyToad.PdfPig/Content/ResourceStore.cs +++ b/src/UglyToad.PdfPig/Content/ResourceStore.cs @@ -24,7 +24,7 @@ private readonly StackDictionary currentFontState = new StackDictionary(); private readonly StackDictionary currentXObjectState = new StackDictionary(); - private readonly Dictionary extendedGraphicsStates = new Dictionary(); + private readonly StackDictionary extendedGraphicsStates = new StackDictionary(); private readonly StackDictionary namedColorSpaces = new StackDictionary(); private readonly Dictionary loadedNamedColorSpaceDetails = new Dictionary(); @@ -55,7 +55,8 @@ namedColorSpaces.Push(); currentFontState.Push(); - currentXObjectState.Push(); + currentXObjectState.Push(); + extendedGraphicsStates.Push(); if (resourceDictionary.TryGet(NameToken.Font, out var fontBase)) { @@ -190,6 +191,7 @@ currentFontState.Pop(); currentXObjectState.Pop(); namedColorSpaces.Pop(); + extendedGraphicsStates.Pop(); } private void LoadFontDictionary(DictionaryToken fontDictionary) @@ -348,8 +350,13 @@ public DictionaryToken? GetExtendedGraphicsStateDictionary(NameToken name) { - if (parsingOptions.UseLenientParsing && !extendedGraphicsStates.ContainsKey(name)) - { + if (parsingOptions.UseLenientParsing) + { + if (extendedGraphicsStates.TryGetValue(name, out var dictToken)) + { + return dictToken; + } + parsingOptions.Logger.Error($"The graphic state dictionary does not contain the key '{name}'."); return null; }