mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-14 19:05:01 +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]
|
[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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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))
|
||||||
|
@@ -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))
|
||||||
|
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user