mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-14 10:55:04 +08:00
use direct object finder when getting the name of the base font in type 1 and truetype fonts.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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<CosName>(baseFontObj, pdfObjectParser, reader, isLenientParsing);
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidFontFormatException($"Could not find a name for this font {dictionary}.");
|
||||
}
|
||||
}
|
||||
|
@@ -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))
|
||||
|
@@ -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))
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user