diff --git a/src/UglyToad.PdfPig.Tests/Filters/Ascii85FilterTests.cs b/src/UglyToad.PdfPig.Tests/Filters/Ascii85FilterTests.cs index 8e1fba65b..73312b549 100644 --- a/src/UglyToad.PdfPig.Tests/Filters/Ascii85FilterTests.cs +++ b/src/UglyToad.PdfPig.Tests/Filters/Ascii85FilterTests.cs @@ -20,7 +20,7 @@ public void DecodesWikipediaExample() l(DId uD.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c~>"); - var result = filter.Decode(bytes, dictionary, 0); + var result = filter.Decode(bytes, dictionary, TestFilterProvider.Instance, 0); #if !NET string text = Encoding.ASCII.GetString(result.ToArray()); @@ -39,7 +39,7 @@ public void ReplacesZWithEmptyBytes() { var bytes = Encoding.ASCII.GetBytes("9jqo^zBlbD-"); - var result = filter.Decode(bytes, dictionary, 1); + var result = filter.Decode(bytes, dictionary, TestFilterProvider.Instance, 1); #if !NET string text = Encoding.ASCII.GetString(result.ToArray()); @@ -55,7 +55,7 @@ public void ZInMiddleOf5CharacterSequenceThrows() { var bytes = Encoding.ASCII.GetBytes("qjzqo^"); - Action action = () => filter.Decode(bytes, dictionary, 0); + Action action = () => filter.Decode(bytes, dictionary, TestFilterProvider.Instance, 0); Assert.Throws(action); } @@ -65,7 +65,7 @@ public void SingleCharacterLastThrows() { var bytes = Encoding.ASCII.GetBytes("9jqo^B"); - Action action = () => filter.Decode(bytes, dictionary, 1); + Action action = () => filter.Decode(bytes, dictionary, TestFilterProvider.Instance, 1); Assert.Throws(action); } @@ -110,7 +110,7 @@ public void DecodesEncodedPdfContent() F*22=@:F%a+=SF4C'moi+=Li?EZeh0FD)e-@<>p#@;]TuBl.9kATKCFGA(],AKYo5BOu4*+CT;%+C#7pF_Pr+@VfTuDf0B:+=SF4C'moi+= Li?EZek1DKKT1F`2DD/TboKAKY](@:s.m/h%oBC'mC/$>""*cF*)G6@;Q?_DIdZpC&~>"; - var result = filter.Decode(Encoding.ASCII.GetBytes(input), dictionary, 0); + var result = filter.Decode(Encoding.ASCII.GetBytes(input), dictionary, TestFilterProvider.Instance, 0); #if !NET string text = Encoding.ASCII.GetString(result.ToArray()); @@ -134,7 +134,7 @@ public void DecodesEncodedPdfContentMissingEndOfDataSymbol() F*22=@:F%a+=SF4C'moi+=Li?EZeh0FD)e-@<>p#@;]TuBl.9kATKCFGA(],AKYo5BOu4*+CT;%+C#7pF_Pr+@VfTuDf0B:+=SF4C'moi+= Li?EZek1DKKT1F`2DD/TboKAKY](@:s.m/h%oBC'mC/$>""*cF*)G6@;Q?_DIdZpC&"; - var result = filter.Decode(Encoding.ASCII.GetBytes(input), dictionary, 0); + var result = filter.Decode(Encoding.ASCII.GetBytes(input), dictionary, TestFilterProvider.Instance, 0); #if !NET string text = Encoding.ASCII.GetString(result.ToArray()); @@ -154,7 +154,7 @@ public void DecodeParallel() { var bytes = Encoding.ASCII.GetBytes("9jqo^zBlbD-"); - var result = filter.Decode(bytes, dictionary, 1); + var result = filter.Decode(bytes, dictionary, TestFilterProvider.Instance, 1); #if !NET string text = Encoding.ASCII.GetString(result.ToArray()); @@ -176,7 +176,7 @@ public void DecodeParallel() F*22=@:F%a+=SF4C'moi+=Li?EZeh0FD)e-@<>p#@;]TuBl.9kATKCFGA(],AKYo5BOu4*+CT;%+C#7pF_Pr+@VfTuDf0B:+=SF4C'moi+= Li?EZek1DKKT1F`2DD/TboKAKY](@:s.m/h%oBC'mC/$>""*cF*)G6@;Q?_DIdZpC&~>"; - var result = filter.Decode(Encoding.ASCII.GetBytes(input), dictionary, 0); + var result = filter.Decode(Encoding.ASCII.GetBytes(input), dictionary, TestFilterProvider.Instance, 0); #if !NET string text = Encoding.ASCII.GetString(result.ToArray()); diff --git a/src/UglyToad.PdfPig.Tests/Filters/AsciiHexDecodeFilterTests.cs b/src/UglyToad.PdfPig.Tests/Filters/AsciiHexDecodeFilterTests.cs index 04f0d4dd6..38f7fe42d 100644 --- a/src/UglyToad.PdfPig.Tests/Filters/AsciiHexDecodeFilterTests.cs +++ b/src/UglyToad.PdfPig.Tests/Filters/AsciiHexDecodeFilterTests.cs @@ -16,7 +16,7 @@ public void DecodesEncodedTextProperly() var input = Encoding.ASCII.GetBytes( "7368652073656C6C73207365617368656C6C73206F6E20746865207365612073686F7265"); - var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, 1); + var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, TestFilterProvider.Instance, 1); var decodedText = Encoding.ASCII.GetString(decoded.ToArray()); @@ -31,7 +31,7 @@ public void DecodesEncodedTextWithBracesProperly() var input = Encoding.ASCII.GetBytes( "<7368652073656C6C73207365617368656C6C73206F6E20746865207365612073686F7265>"); - var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, 1); + var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, TestFilterProvider.Instance, 1); var decodedText = Encoding.ASCII.GetString(decoded.ToArray()); @@ -47,7 +47,7 @@ public void DecodesEncodedTextWithWhitespaceProperly() @"6F6E6365207 5706F6E206120 74696D6520696E 20612067616C6178792046617220466172204177 6179"); - var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, 1); + var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, TestFilterProvider.Instance, 1); var decodedText = Encoding.ASCII.GetString(decoded.ToArray()); @@ -61,7 +61,7 @@ public void DecodesEncodedTextLowercaseProperly() var input = Encoding.ASCII.GetBytes("6f6e63652075706f6e20612074696d6520696e20612067616c61787920466172204661722041776179"); - var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, 1); + var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, TestFilterProvider.Instance, 1); var decodedText = Encoding.ASCII.GetString(decoded.ToArray()); @@ -75,7 +75,7 @@ public void DecodeWithInvalidCharactersThrows(string inputString) { var input = Encoding.ASCII.GetBytes(inputString); - Action action = () => new AsciiHexDecodeFilter().Decode(input, dictionary, 1); + Action action = () => new AsciiHexDecodeFilter().Decode(input, dictionary, TestFilterProvider.Instance, 1); Assert.Throws(action); } @@ -85,7 +85,7 @@ public void SubstitutesZeroForLastByte() { var input = Encoding.ASCII.GetBytes("AE5>"); - var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, 1); + var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, TestFilterProvider.Instance, 1); #pragma warning disable SYSLIB0001 var decodedText = Encoding.UTF7.GetString(decoded.ToArray()); @@ -101,7 +101,7 @@ public void DecodesEncodedTextStoppingAtLastBrace() var input = Encoding.ASCII.GetBytes("6f6e63652075706f6e20612074696d6520696e20612067616c61787920466172204661722041776179> There is stuff following the EOD."); - var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, 1); + var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, TestFilterProvider.Instance, 1); var decodedText = Encoding.ASCII.GetString(decoded.ToArray()); diff --git a/src/UglyToad.PdfPig.Tests/Filters/CcittFaxDecodeFilterTests.cs b/src/UglyToad.PdfPig.Tests/Filters/CcittFaxDecodeFilterTests.cs index aa680b26f..cbd2d2be6 100644 --- a/src/UglyToad.PdfPig.Tests/Filters/CcittFaxDecodeFilterTests.cs +++ b/src/UglyToad.PdfPig.Tests/Filters/CcittFaxDecodeFilterTests.cs @@ -31,7 +31,7 @@ public void CanDecodeCCittFaxCompressedImageData() }; var expectedBytes = ImageHelpers.LoadFileBytes("ccittfax-decoded.bin"); - var decodedBytes = filter.Decode(encodedBytes, new DictionaryToken(dictionary), 0); + var decodedBytes = filter.Decode(encodedBytes, new DictionaryToken(dictionary), TestFilterProvider.Instance, 0); Assert.Equal(expectedBytes, decodedBytes.ToArray()); } } diff --git a/src/UglyToad.PdfPig.Tests/Filters/FlateFilterTests.cs b/src/UglyToad.PdfPig.Tests/Filters/FlateFilterTests.cs index db2829f0a..68289e876 100644 --- a/src/UglyToad.PdfPig.Tests/Filters/FlateFilterTests.cs +++ b/src/UglyToad.PdfPig.Tests/Filters/FlateFilterTests.cs @@ -17,7 +17,7 @@ public void EncodeAndDecodePreservesInput() { inputStream.Seek(0, SeekOrigin.Begin); var result = filter.Encode(inputStream, parameters, 0); - var decoded = filter.Decode(result, parameters, 0); + var decoded = filter.Decode(result, parameters, TestFilterProvider.Instance, 0); Assert.Equal(input, decoded.ToArray()); } } diff --git a/src/UglyToad.PdfPig.Tests/Filters/RunLengthFilterTests.cs b/src/UglyToad.PdfPig.Tests/Filters/RunLengthFilterTests.cs index 124147c0e..852908010 100644 --- a/src/UglyToad.PdfPig.Tests/Filters/RunLengthFilterTests.cs +++ b/src/UglyToad.PdfPig.Tests/Filters/RunLengthFilterTests.cs @@ -24,7 +24,7 @@ public void CanDecodeRunLengthEncodedData() 1, 10, 19 }; - var decoded = filter.Decode(data, new DictionaryToken(new Dictionary()), 1); + var decoded = filter.Decode(data, new DictionaryToken(new Dictionary()), TestFilterProvider.Instance, 1); var expectedResult = new byte[] { @@ -53,7 +53,7 @@ public void StopsAtEndOfDataByte() 90, 6, 7 }; - var decoded = filter.Decode(data, new DictionaryToken(new Dictionary()), 0); + var decoded = filter.Decode(data, new DictionaryToken(new Dictionary()), TestFilterProvider.Instance, 0); var expectedResult = new byte[] { diff --git a/src/UglyToad.PdfPig.Tests/Integration/FilterTests.cs b/src/UglyToad.PdfPig.Tests/Integration/FilterTests.cs index 735b6ae10..f9ca67ccd 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/FilterTests.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/FilterTests.cs @@ -62,7 +62,7 @@ public sealed class NoFilter : IFilter { public bool IsSupported => false; - public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, int filterIndex) + public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex) { throw new NotImplementedException(); } diff --git a/src/UglyToad.PdfPig.Tests/Integration/PdfParserTests.cs b/src/UglyToad.PdfPig.Tests/Integration/PdfParserTests.cs index 894d46bae..64f9c85ca 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/PdfParserTests.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/PdfParserTests.cs @@ -96,7 +96,7 @@ public void CanDecompressPngEncodedFlateStream() }); var filter = new FlateFilter(); - var filtered = filter.Decode(streamBytes, dictionary, 0).ToArray(); + var filtered = filter.Decode(streamBytes, dictionary, TestFilterProvider.Instance, 0).ToArray(); var expected = "1 0 15 0 1 0 216 0 1 2 160 0 1 2 210 0 1 3 84 0 1 4 46 0 1 7 165 0 1 70 229 0 1 72 84 0 1 96 235 0 1 98 18 0 2 0 12 0 2 0 12 1 2 0 12 2 2 0 12 3 2 0 12 4 2 0 12 5 2 0 12 6 2 0 12 7 2 0 12 8" diff --git a/src/UglyToad.PdfPig.Tests/TestFilterProvider.cs b/src/UglyToad.PdfPig.Tests/TestFilterProvider.cs index 87f5d4a0e..59394e294 100644 --- a/src/UglyToad.PdfPig.Tests/TestFilterProvider.cs +++ b/src/UglyToad.PdfPig.Tests/TestFilterProvider.cs @@ -6,6 +6,8 @@ internal class TestFilterProvider : ILookupFilterProvider { + public static readonly TestFilterProvider Instance = new TestFilterProvider(); + public IReadOnlyList GetFilters(DictionaryToken dictionary) { return new List(); diff --git a/src/UglyToad.PdfPig/Content/InlineImage.cs b/src/UglyToad.PdfPig/Content/InlineImage.cs index 7c8c0f5ec..b13bf56c3 100644 --- a/src/UglyToad.PdfPig/Content/InlineImage.cs +++ b/src/UglyToad.PdfPig/Content/InlineImage.cs @@ -64,8 +64,9 @@ internal InlineImage(PdfRectangle bounds, int widthInSamples, int heightInSample RenderingIntent renderingIntent, bool interpolate, IReadOnlyList decode, - ReadOnlyMemory rawMemory, - IReadOnlyList filters, + ReadOnlyMemory rawMemory, + ILookupFilterProvider filterProvider, + IReadOnlyList filterNames, DictionaryToken streamDictionary, ColorSpaceDetails colorSpaceDetails) { @@ -79,8 +80,10 @@ internal InlineImage(PdfRectangle bounds, int widthInSamples, int heightInSample Interpolate = interpolate; ImageDictionary = streamDictionary; RawMemory = rawMemory; - ColorSpaceDetails = colorSpaceDetails; - + ColorSpaceDetails = colorSpaceDetails; + + var filters = filterProvider.GetNamedFilters(filterNames); + var supportsFilters = true; foreach (var filter in filters) { @@ -97,7 +100,7 @@ internal InlineImage(PdfRectangle bounds, int widthInSamples, int heightInSample for (var i = 0; i < filters.Count; i++) { var filter = filters[i]; - b = filter.Decode(b.Span, streamDictionary, i); + b = filter.Decode(b.Span, streamDictionary, filterProvider, i); } return b; diff --git a/src/UglyToad.PdfPig/Filters/Ascii85Filter.cs b/src/UglyToad.PdfPig/Filters/Ascii85Filter.cs index 5fafa0772..f58f0bfb1 100644 --- a/src/UglyToad.PdfPig/Filters/Ascii85Filter.cs +++ b/src/UglyToad.PdfPig/Filters/Ascii85Filter.cs @@ -27,7 +27,7 @@ public sealed class Ascii85Filter : IFilter public bool IsSupported { get; } = true; /// - public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, int filterIndex) + public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex) { Span asciiBuffer = stackalloc byte[5]; diff --git a/src/UglyToad.PdfPig/Filters/AsciiHexDecodeFilter.cs b/src/UglyToad.PdfPig/Filters/AsciiHexDecodeFilter.cs index d66871dcf..0993ce651 100644 --- a/src/UglyToad.PdfPig/Filters/AsciiHexDecodeFilter.cs +++ b/src/UglyToad.PdfPig/Filters/AsciiHexDecodeFilter.cs @@ -28,7 +28,7 @@ public sealed class AsciiHexDecodeFilter : IFilter public bool IsSupported { get; } = true; /// - public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, int filterIndex) + public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex) { Span pair = stackalloc byte[2]; var index = 0; diff --git a/src/UglyToad.PdfPig/Filters/CcittFaxDecodeFilter.cs b/src/UglyToad.PdfPig/Filters/CcittFaxDecodeFilter.cs index 7bce8d665..68d83835a 100644 --- a/src/UglyToad.PdfPig/Filters/CcittFaxDecodeFilter.cs +++ b/src/UglyToad.PdfPig/Filters/CcittFaxDecodeFilter.cs @@ -20,7 +20,7 @@ public sealed class CcittFaxDecodeFilter : IFilter public bool IsSupported { get; } = true; /// - public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, int filterIndex) + public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex) { var decodeParms = DecodeParameterResolver.GetFilterParameters(streamDictionary, filterIndex); diff --git a/src/UglyToad.PdfPig/Filters/DctDecodeFilter.cs b/src/UglyToad.PdfPig/Filters/DctDecodeFilter.cs index 4dd158db3..0044192fe 100644 --- a/src/UglyToad.PdfPig/Filters/DctDecodeFilter.cs +++ b/src/UglyToad.PdfPig/Filters/DctDecodeFilter.cs @@ -13,7 +13,7 @@ public sealed class DctDecodeFilter : IFilter public bool IsSupported { get; } = false; /// - public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, int filterIndex) + public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex) { throw new NotSupportedException("The DST (Discrete Cosine Transform) Filter indicates data is encoded in JPEG format. " + "This filter is not currently supported but the raw data can be supplied to JPEG supporting libraries."); diff --git a/src/UglyToad.PdfPig/Filters/FlateFilter.cs b/src/UglyToad.PdfPig/Filters/FlateFilter.cs index 35099c926..fa57f741a 100644 --- a/src/UglyToad.PdfPig/Filters/FlateFilter.cs +++ b/src/UglyToad.PdfPig/Filters/FlateFilter.cs @@ -31,7 +31,7 @@ public sealed class FlateFilter : IFilter public bool IsSupported { get; } = true; /// - public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, int filterIndex) + public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex) { var parameters = DecodeParameterResolver.GetFilterParameters(streamDictionary, filterIndex); diff --git a/src/UglyToad.PdfPig/Filters/IFilter.cs b/src/UglyToad.PdfPig/Filters/IFilter.cs index da5ceaacb..f60b12032 100644 --- a/src/UglyToad.PdfPig/Filters/IFilter.cs +++ b/src/UglyToad.PdfPig/Filters/IFilter.cs @@ -18,8 +18,9 @@ public interface IFilter /// /// The encoded bytes which were encoded using this filter. /// The dictionary of the (or other dictionary types, e.g. inline images) containing these bytes. + /// The filter provider. /// The position of this filter in the pipeline used to encode data. /// The decoded bytes. - ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, int filterIndex); + ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex); } } diff --git a/src/UglyToad.PdfPig/Filters/Jbig2DecodeFilter.cs b/src/UglyToad.PdfPig/Filters/Jbig2DecodeFilter.cs index f32400433..7060e76f8 100644 --- a/src/UglyToad.PdfPig/Filters/Jbig2DecodeFilter.cs +++ b/src/UglyToad.PdfPig/Filters/Jbig2DecodeFilter.cs @@ -13,7 +13,7 @@ public sealed class Jbig2DecodeFilter : IFilter public bool IsSupported { get; } = false; /// - public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, int filterIndex) + public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex) { throw new NotSupportedException("The JBIG2 Filter for monochrome image data is not currently supported. " + "Try accessing the raw compressed data directly."); diff --git a/src/UglyToad.PdfPig/Filters/JpxDecodeFilter.cs b/src/UglyToad.PdfPig/Filters/JpxDecodeFilter.cs index 24d9dd81a..a5af6964a 100644 --- a/src/UglyToad.PdfPig/Filters/JpxDecodeFilter.cs +++ b/src/UglyToad.PdfPig/Filters/JpxDecodeFilter.cs @@ -13,7 +13,7 @@ public sealed class JpxDecodeFilter : IFilter public bool IsSupported { get; } = false; /// - public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, int filterIndex) + public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex) { throw new NotSupportedException("The JPX Filter (JPEG2000) for image data is not currently supported. " + "Try accessing the raw compressed data directly."); diff --git a/src/UglyToad.PdfPig/Filters/LzwFilter.cs b/src/UglyToad.PdfPig/Filters/LzwFilter.cs index bd086cd50..9d593e831 100644 --- a/src/UglyToad.PdfPig/Filters/LzwFilter.cs +++ b/src/UglyToad.PdfPig/Filters/LzwFilter.cs @@ -29,7 +29,7 @@ public sealed class LzwFilter : IFilter public bool IsSupported { get; } = true; /// - public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, int filterIndex) + public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex) { var parameters = DecodeParameterResolver.GetFilterParameters(streamDictionary, filterIndex); diff --git a/src/UglyToad.PdfPig/Filters/RunLengthFilter.cs b/src/UglyToad.PdfPig/Filters/RunLengthFilter.cs index e345d001f..aa7d43157 100644 --- a/src/UglyToad.PdfPig/Filters/RunLengthFilter.cs +++ b/src/UglyToad.PdfPig/Filters/RunLengthFilter.cs @@ -16,7 +16,7 @@ public sealed class RunLengthFilter : IFilter public bool IsSupported { get; } = true; /// - public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, int filterIndex) + public ReadOnlyMemory Decode(ReadOnlySpan input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex) { using var output = new ArrayPoolBufferWriter(input.Length); diff --git a/src/UglyToad.PdfPig/Graphics/InlineImageBuilder.cs b/src/UglyToad.PdfPig/Graphics/InlineImageBuilder.cs index 1f89ac523..87287b1d7 100644 --- a/src/UglyToad.PdfPig/Graphics/InlineImageBuilder.cs +++ b/src/UglyToad.PdfPig/Graphics/InlineImageBuilder.cs @@ -98,18 +98,15 @@ internal InlineImage CreateInlineImage( filterNames.Add(filterName); } - var filters = filterProvider.GetNamedFilters(filterNames); - var decodeRaw = GetByKeys(NameToken.Decode, NameToken.D, false) ?? new ArrayToken(Array.Empty()); var decode = decodeRaw.Data.OfType().Select(x => x.Double).ToArray(); var interpolate = GetByKeys(NameToken.Interpolate, NameToken.I, false)?.Data ?? false; - return new InlineImage(bounds, width, height, bitsPerComponent, isMask, renderingIntent, interpolate, decode, Bytes, - filters, - imgDic, - details); + return new InlineImage(bounds, width, height, bitsPerComponent, + isMask, renderingIntent, interpolate, decode, Bytes, + filterProvider, filterNames, imgDic, details); } #nullable disable diff --git a/src/UglyToad.PdfPig/PdfExtensions.cs b/src/UglyToad.PdfPig/PdfExtensions.cs index fe7d1f91d..e69d00547 100644 --- a/src/UglyToad.PdfPig/PdfExtensions.cs +++ b/src/UglyToad.PdfPig/PdfExtensions.cs @@ -62,7 +62,7 @@ public static ReadOnlyMemory Decode(this StreamToken stream, IFilterProvid var transform = stream.Data; for (var i = 0; i < filters.Count; i++) { - transform = filters[i].Decode(transform.Span, stream.StreamDictionary, i); + transform = filters[i].Decode(transform.Span, stream.StreamDictionary, filterProvider, i); } return transform; @@ -78,7 +78,7 @@ public static ReadOnlyMemory Decode(this StreamToken stream, ILookupFilter var transform = stream.Data; for (var i = 0; i < filters.Count; i++) { - transform = filters[i].Decode(transform.Span, stream.StreamDictionary, i); + transform = filters[i].Decode(transform.Span, stream.StreamDictionary, filterProvider, i); } return transform; @@ -88,12 +88,12 @@ public static ReadOnlyMemory Decode(this StreamToken stream, ILookupFilter /// Returns an equivalent token where any indirect references of child objects are /// recursively traversed and resolved. /// - internal static T Resolve(this T token, IPdfTokenScanner scanner) where T : IToken + internal static T? Resolve(this T? token, IPdfTokenScanner scanner) where T : IToken { - return (T)ResolveInternal(token, scanner); + return (T?)ResolveInternal(token, scanner); } - private static IToken ResolveInternal(this IToken token, IPdfTokenScanner scanner) + private static IToken? ResolveInternal(this IToken? token, IPdfTokenScanner scanner) { if (token is StreamToken stream) { @@ -105,7 +105,7 @@ private static IToken ResolveInternal(this IToken token, IPdfTokenScanner scanne var resolvedItems = new Dictionary(); foreach (var kvp in dict.Data) { - var value = kvp.Value is IndirectReferenceToken reference ? scanner.Get(reference.Data).Data : kvp.Value; + var value = kvp.Value is IndirectReferenceToken reference ? scanner.Get(reference.Data)?.Data : kvp.Value; resolvedItems[NameToken.Create(kvp.Key)] = ResolveInternal(value, scanner); } @@ -117,14 +117,13 @@ private static IToken ResolveInternal(this IToken token, IPdfTokenScanner scanne var resolvedItems = new List(); for (int i = 0; i < arr.Length; i++) { - var value = arr.Data[i] is IndirectReferenceToken reference ? scanner.Get(reference.Data).Data : arr.Data[i]; + var value = arr.Data[i] is IndirectReferenceToken reference ? scanner.Get(reference.Data)?.Data : arr.Data[i]; resolvedItems.Add(ResolveInternal(value, scanner)); } return new ArrayToken(resolvedItems); } - var val = token is IndirectReferenceToken tokenReference ? scanner.Get(tokenReference.Data).Data : token; - return val; + return token is IndirectReferenceToken tokenReference ? scanner.Get(tokenReference.Data)?.Data : token; } } } diff --git a/src/UglyToad.PdfPig/Tokenization/Scanner/IPdfTokenScanner.cs b/src/UglyToad.PdfPig/Tokenization/Scanner/IPdfTokenScanner.cs index 5ba7269c5..a19707dae 100644 --- a/src/UglyToad.PdfPig/Tokenization/Scanner/IPdfTokenScanner.cs +++ b/src/UglyToad.PdfPig/Tokenization/Scanner/IPdfTokenScanner.cs @@ -15,7 +15,7 @@ public interface IPdfTokenScanner : ISeekableTokenScanner, IDisposable /// /// The object number for the object to tokenize. /// The tokenized object. - ObjectToken Get(IndirectReference reference); + ObjectToken? Get(IndirectReference reference); /// /// Adds the token to an internal cache that will be returned instead of diff --git a/src/UglyToad.PdfPig/Tokenization/Scanner/PdfTokenScanner.cs b/src/UglyToad.PdfPig/Tokenization/Scanner/PdfTokenScanner.cs index 75c38ae94..71d355300 100644 --- a/src/UglyToad.PdfPig/Tokenization/Scanner/PdfTokenScanner.cs +++ b/src/UglyToad.PdfPig/Tokenization/Scanner/PdfTokenScanner.cs @@ -5,9 +5,7 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; - using System.IO; using System.Linq; - using System.Text; using System.Text.RegularExpressions; using Core; using Encryption; @@ -714,10 +712,8 @@ public void DeregisterCustomTokenizer(ITokenizer tokenizer) coreTokenScanner.DeregisterCustomTokenizer(tokenizer); } - -#nullable disable - - public ObjectToken Get(IndirectReference reference) + + public ObjectToken? Get(IndirectReference reference) { if (isDisposed) { @@ -769,8 +765,6 @@ public ObjectToken Get(IndirectReference reference) return BruteForceFileToFindReference(reference); } -#nullable enable - public void ReplaceToken(IndirectReference reference, IToken token) { // Using 0 position as it isn't written to stream and this value doesn't