mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-06-28 15:30:17 +08:00
these issues reported that parsing was failing due to a missing token being reference in the tounicode entry. since neither issue included a sample file it's impossible to determine the right fix accurately, however since the tounicode entry is optional in the spec we can try being more lenient here, this might just result in more errors once we try to use the font but the logger will at least prevent parsing the entire document failing
This commit is contained in:
parent
6b9c3be9f8
commit
0b8252e930
@ -160,12 +160,25 @@
|
|||||||
var cidFontFactory = new CidFontFactory(pdfScanner, filterProvider);
|
var cidFontFactory = new CidFontFactory(pdfScanner, filterProvider);
|
||||||
var encodingReader = new EncodingReader(pdfScanner);
|
var encodingReader = new EncodingReader(pdfScanner);
|
||||||
|
|
||||||
|
var type0Handler = new Type0FontHandler(
|
||||||
|
cidFontFactory,
|
||||||
|
filterProvider,
|
||||||
|
pdfScanner,
|
||||||
|
parsingOptions.Logger);
|
||||||
|
|
||||||
var type1Handler = new Type1FontHandler(pdfScanner, filterProvider, encodingReader);
|
var type1Handler = new Type1FontHandler(pdfScanner, filterProvider, encodingReader);
|
||||||
|
|
||||||
var fontFactory = new FontFactory(parsingOptions.Logger, new Type0FontHandler(cidFontFactory,
|
var trueTypeHandler = new TrueTypeFontHandler(parsingOptions.Logger,
|
||||||
filterProvider, pdfScanner),
|
pdfScanner,
|
||||||
new TrueTypeFontHandler(parsingOptions.Logger, pdfScanner, filterProvider, encodingReader, SystemFontFinder.Instance,
|
filterProvider,
|
||||||
type1Handler),
|
encodingReader,
|
||||||
|
SystemFontFinder.Instance,
|
||||||
|
type1Handler);
|
||||||
|
|
||||||
|
var fontFactory = new FontFactory(
|
||||||
|
parsingOptions.Logger,
|
||||||
|
type0Handler,
|
||||||
|
trueTypeHandler,
|
||||||
type1Handler,
|
type1Handler,
|
||||||
new Type3FontHandler(pdfScanner, filterProvider, encodingReader));
|
new Type3FontHandler(pdfScanner, filterProvider, encodingReader));
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
using Core;
|
using Core;
|
||||||
using Filters;
|
using Filters;
|
||||||
using Fonts;
|
using Fonts;
|
||||||
|
using Logging;
|
||||||
using Parts;
|
using Parts;
|
||||||
using PdfPig.Parser.Parts;
|
using PdfPig.Parser.Parts;
|
||||||
using Tokenization.Scanner;
|
using Tokenization.Scanner;
|
||||||
@ -18,13 +19,18 @@
|
|||||||
private readonly CidFontFactory cidFontFactory;
|
private readonly CidFontFactory cidFontFactory;
|
||||||
private readonly ILookupFilterProvider filterProvider;
|
private readonly ILookupFilterProvider filterProvider;
|
||||||
private readonly IPdfTokenScanner scanner;
|
private readonly IPdfTokenScanner scanner;
|
||||||
|
private readonly ILog logger;
|
||||||
|
|
||||||
public Type0FontHandler(CidFontFactory cidFontFactory, ILookupFilterProvider filterProvider,
|
public Type0FontHandler(
|
||||||
IPdfTokenScanner scanner)
|
CidFontFactory cidFontFactory,
|
||||||
|
ILookupFilterProvider filterProvider,
|
||||||
|
IPdfTokenScanner scanner,
|
||||||
|
ILog logger)
|
||||||
{
|
{
|
||||||
this.cidFontFactory = cidFontFactory;
|
this.cidFontFactory = cidFontFactory;
|
||||||
this.filterProvider = filterProvider;
|
this.filterProvider = filterProvider;
|
||||||
this.scanner = scanner;
|
this.scanner = scanner;
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IFont Generate(DictionaryToken dictionary)
|
public IFont Generate(DictionaryToken dictionary)
|
||||||
@ -79,7 +85,10 @@
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new PdfDocumentFormatException($"Invalid type of toUnicode CMap encountered. Got: {toUnicodeValue}.");
|
// Rather than throwing here, let's try returning the font anyway since
|
||||||
|
// this error is tripping people up as seen in issues #354 and #619.
|
||||||
|
// This will probably just cause errors further along the parsing but it might be more informative.
|
||||||
|
logger.Error($"Invalid type of toUnicode CMap encountered for font named {baseFont}. Got: {toUnicodeValue}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user