diff --git a/src/UglyToad.PdfPig.Tests/Integration/LocalTests.cs b/src/UglyToad.PdfPig.Tests/Integration/LocalTests.cs index 93383b7c..bb1c4c09 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/LocalTests.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/LocalTests.cs @@ -10,9 +10,9 @@ [Fact] public void Tests() { - //using (var document = PdfDocument.Open(@"")) + using (var document = PdfDocument.Open(@"C:\Users\eliot\Downloads\ICML03-081.pdf")) { - //var page = document.GetPage(1); + var page = document.GetPage(1); } } } diff --git a/src/UglyToad.PdfPig/Fonts/Parser/FontDictionaryAccessHelper.cs b/src/UglyToad.PdfPig/Fonts/Parser/FontDictionaryAccessHelper.cs index 37f95de6..68699667 100644 --- a/src/UglyToad.PdfPig/Fonts/Parser/FontDictionaryAccessHelper.cs +++ b/src/UglyToad.PdfPig/Fonts/Parser/FontDictionaryAccessHelper.cs @@ -66,7 +66,7 @@ return descriptor; } - public static CosName GetName(PdfDictionary dictionary, FontDescriptor descriptor) + public static CosName GetName(IPdfObjectParser pdfObjectParser, PdfDictionary dictionary, FontDescriptor descriptor, IRandomAccessRead reader, bool isLenientParsing) { if (dictionary.TryGetName(CosName.BASE_FONT, out CosName name)) { @@ -78,6 +78,14 @@ return descriptor.FontName; } + if (dictionary.TryGetValue(CosName.BASE_FONT, out var baseFont)) + { + if (baseFont is CosObject baseFontObj) + { + return DirectObjectFinder.Find(baseFontObj, pdfObjectParser, reader, isLenientParsing); + } + } + throw new InvalidFontFormatException($"Could not find a name for this font {dictionary}."); } } diff --git a/src/UglyToad.PdfPig/Fonts/Parser/Handlers/TrueTypeFontHandler.cs b/src/UglyToad.PdfPig/Fonts/Parser/Handlers/TrueTypeFontHandler.cs index 1b217a00..88af8530 100644 --- a/src/UglyToad.PdfPig/Fonts/Parser/Handlers/TrueTypeFontHandler.cs +++ b/src/UglyToad.PdfPig/Fonts/Parser/Handlers/TrueTypeFontHandler.cs @@ -46,9 +46,10 @@ var descriptor = FontDictionaryAccessHelper.GetFontDescriptor(pdfObjectParser, fontDescriptorFactory, dictionary, reader, isLenientParsing); - var font = ParseTrueTypeFont(descriptor, reader, isLenientParsing); + // TODO: use the parsed font fully. + //var font = ParseTrueTypeFont(descriptor, reader, isLenientParsing); - var name = FontDictionaryAccessHelper.GetName(dictionary, descriptor); + var name = FontDictionaryAccessHelper.GetName(pdfObjectParser, dictionary, descriptor, reader, isLenientParsing); CMap toUnicodeCMap = null; if (dictionary.TryGetItemOfType(CosName.TO_UNICODE, out CosObject toUnicodeObj)) diff --git a/src/UglyToad.PdfPig/Fonts/Parser/Handlers/Type1FontHandler.cs b/src/UglyToad.PdfPig/Fonts/Parser/Handlers/Type1FontHandler.cs index fd622567..d2470656 100644 --- a/src/UglyToad.PdfPig/Fonts/Parser/Handlers/Type1FontHandler.cs +++ b/src/UglyToad.PdfPig/Fonts/Parser/Handlers/Type1FontHandler.cs @@ -54,7 +54,7 @@ var descriptor = FontDictionaryAccessHelper.GetFontDescriptor(pdfObjectParser, fontDescriptorFactory, dictionary, reader, isLenientParsing); - var name = FontDictionaryAccessHelper.GetName(dictionary, descriptor); + var name = FontDictionaryAccessHelper.GetName(pdfObjectParser, dictionary, descriptor, reader, isLenientParsing); CMap toUnicodeCMap = null; if (dictionary.TryGetItemOfType(CosName.TO_UNICODE, out CosObject toUnicodeObj)) diff --git a/src/UglyToad.PdfPig/Fonts/Simple/Type1Font.cs b/src/UglyToad.PdfPig/Fonts/Simple/Type1Font.cs index 9f955227..6ca00b7b 100644 --- a/src/UglyToad.PdfPig/Fonts/Simple/Type1Font.cs +++ b/src/UglyToad.PdfPig/Fonts/Simple/Type1Font.cs @@ -53,6 +53,16 @@ if (encoding == null) { + try + { + value = char.ConvertFromUtf32(characterCode); + return true; + } + catch + { + // our quick hack has failed, we should decode the type 1 font! + } + return false; }