diff --git a/src/UglyToad.PdfPig/Fonts/CompactFontFormat/CompactFontFormatData.cs b/src/UglyToad.PdfPig/Fonts/CompactFontFormat/CompactFontFormatData.cs index 7a7e80e7..46bd064a 100644 --- a/src/UglyToad.PdfPig/Fonts/CompactFontFormat/CompactFontFormatData.cs +++ b/src/UglyToad.PdfPig/Fonts/CompactFontFormat/CompactFontFormatData.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Text; + using Util; /// /// Provides access to the raw bytes of this Compact Font Format file with utility methods for reading data types from it. @@ -112,6 +113,11 @@ public CompactFontFormatData SnapshotPortion(int startLocation, int length) { + if (length == 0) + { + return new CompactFontFormatData(EmptyArray.Instance); + } + if (startLocation > dataBytes.Count - 1 || startLocation + length > dataBytes.Count) { throw new ArgumentException($"Attempted to create a snapshot of an invalid portion of the data. Length was {dataBytes.Count}, requested start: {startLocation} and requested length: {length}."); diff --git a/src/UglyToad.PdfPig/Fonts/Composite/ToUnicodeCMap.cs b/src/UglyToad.PdfPig/Fonts/Composite/ToUnicodeCMap.cs index 426540f3..31bcfeea 100644 --- a/src/UglyToad.PdfPig/Fonts/Composite/ToUnicodeCMap.cs +++ b/src/UglyToad.PdfPig/Fonts/Composite/ToUnicodeCMap.cs @@ -31,7 +31,7 @@ if (CanMapToUnicode) { IsUsingIdentityAsUnicodeMap = - cMap.Name.StartsWith("Identity-", StringComparison.InvariantCultureIgnoreCase); + cMap.Name?.StartsWith("Identity-", StringComparison.InvariantCultureIgnoreCase) == true; } } diff --git a/src/UglyToad.PdfPig/Fonts/Parser/Parts/CidFontFactory.cs b/src/UglyToad.PdfPig/Fonts/Parser/Parts/CidFontFactory.cs index e05fda32..ed377446 100644 --- a/src/UglyToad.PdfPig/Fonts/Parser/Parts/CidFontFactory.cs +++ b/src/UglyToad.PdfPig/Fonts/Parser/Parts/CidFontFactory.cs @@ -151,7 +151,7 @@ } } - private static IReadOnlyDictionary ReadWidths(DictionaryToken dict) + private IReadOnlyDictionary ReadWidths(DictionaryToken dict) { var widths = new Dictionary(); @@ -166,7 +166,7 @@ { var firstCode = (NumericToken)widthArray.Data[counter++]; var next = widthArray.Data[counter++]; - if (next is ArrayToken array) + if (DirectObjectFinder.TryGet(next, pdfScanner, out ArrayToken array)) { int startRange = firstCode.Int; int arraySize = array.Data.Count;