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.
This commit is contained in:
Eliot Jones
2020-01-14 14:58:20 +00:00
parent a36f5a3af3
commit f6e12f40d8

View File

@@ -64,13 +64,22 @@
{ {
var toUnicodeValue = dictionary.Data[NameToken.ToUnicode]; var toUnicodeValue = dictionary.Data[NameToken.ToUnicode];
var toUnicode = DirectObjectFinder.Get<StreamToken>(toUnicodeValue, scanner); if (DirectObjectFinder.TryGet<StreamToken>(toUnicodeValue, scanner, out var toUnicodeStream))
var decodedUnicodeCMap = toUnicode?.Decode(filterProvider);
if (decodedUnicodeCMap != null)
{ {
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<NameToken>(toUnicodeValue, scanner, out var toUnicodeName))
{
toUnicodeCMap = CMapCache.Get(toUnicodeName.Data);
}
else
{
throw new PdfDocumentFormatException($"Invalid type of toUnicode CMap encountered. Got: {toUnicodeValue}.");
} }
} }