From f6e12f40d8d011a1110392c3d90d1182cf8be872 Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Tue, 14 Jan 2020 14:58:20 +0000 Subject: [PATCH] support named tounicode cmaps rather than streams type 0 fonts tounicode cmap may refer to a known cmap name rather than an embedded cmap stream. --- .../Parser/Handlers/Type0FontHandler.cs | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type0FontHandler.cs b/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type0FontHandler.cs index fde06063..19206988 100644 --- a/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type0FontHandler.cs +++ b/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/Type0FontHandler.cs @@ -64,13 +64,22 @@ { var toUnicodeValue = dictionary.Data[NameToken.ToUnicode]; - var toUnicode = DirectObjectFinder.Get(toUnicodeValue, scanner); - - var decodedUnicodeCMap = toUnicode?.Decode(filterProvider); - - if (decodedUnicodeCMap != null) + if (DirectObjectFinder.TryGet(toUnicodeValue, scanner, out var toUnicodeStream)) { - toUnicodeCMap = CMapCache.Parse(new ByteArrayInputBytes(decodedUnicodeCMap), isLenientParsing); + var decodedUnicodeCMap = toUnicodeStream?.Decode(filterProvider); + + if (decodedUnicodeCMap != null) + { + toUnicodeCMap = CMapCache.Parse(new ByteArrayInputBytes(decodedUnicodeCMap), isLenientParsing); + } + } + else if (DirectObjectFinder.TryGet(toUnicodeValue, scanner, out var toUnicodeName)) + { + toUnicodeCMap = CMapCache.Get(toUnicodeName.Data); + } + else + { + throw new PdfDocumentFormatException($"Invalid type of toUnicode CMap encountered. Got: {toUnicodeValue}."); } }