use direct object finder when getting the name of the base font in type 1 and truetype fonts.

This commit is contained in:
Eliot Jones
2018-01-13 20:06:58 +00:00
parent c88db947ad
commit 95ead2a3de
5 changed files with 25 additions and 6 deletions

View File

@@ -10,9 +10,9 @@
[Fact] [Fact]
public void Tests() 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);
} }
} }
} }

View File

@@ -66,7 +66,7 @@
return descriptor; 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)) if (dictionary.TryGetName(CosName.BASE_FONT, out CosName name))
{ {
@@ -78,6 +78,14 @@
return descriptor.FontName; return descriptor.FontName;
} }
if (dictionary.TryGetValue(CosName.BASE_FONT, out var baseFont))
{
if (baseFont is CosObject baseFontObj)
{
return DirectObjectFinder.Find<CosName>(baseFontObj, pdfObjectParser, reader, isLenientParsing);
}
}
throw new InvalidFontFormatException($"Could not find a name for this font {dictionary}."); throw new InvalidFontFormatException($"Could not find a name for this font {dictionary}.");
} }
} }

View File

@@ -46,9 +46,10 @@
var descriptor = FontDictionaryAccessHelper.GetFontDescriptor(pdfObjectParser, fontDescriptorFactory, dictionary, reader, isLenientParsing); 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; CMap toUnicodeCMap = null;
if (dictionary.TryGetItemOfType(CosName.TO_UNICODE, out CosObject toUnicodeObj)) if (dictionary.TryGetItemOfType(CosName.TO_UNICODE, out CosObject toUnicodeObj))

View File

@@ -54,7 +54,7 @@
var descriptor = FontDictionaryAccessHelper.GetFontDescriptor(pdfObjectParser, fontDescriptorFactory, dictionary, reader, isLenientParsing); 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; CMap toUnicodeCMap = null;
if (dictionary.TryGetItemOfType(CosName.TO_UNICODE, out CosObject toUnicodeObj)) if (dictionary.TryGetItemOfType(CosName.TO_UNICODE, out CosObject toUnicodeObj))

View File

@@ -53,6 +53,16 @@
if (encoding == null) 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; return false;
} }