remove lenient parsing from font related classes

lenient parsing gives us more code to maintain for no real benefit, parsing should always be as lenient as possible. remove the flag from some of the font code.
This commit is contained in:
Eliot Jones
2020-02-27 18:10:02 +00:00
parent ec9e425712
commit 746cbfa30c
20 changed files with 68 additions and 140 deletions

View File

@@ -17,20 +17,17 @@
internal class CidFontFactory
{
private readonly FontDescriptorFactory descriptorFactory;
private readonly IFilterProvider filterProvider;
private readonly IPdfTokenScanner pdfScanner;
public CidFontFactory(IPdfTokenScanner pdfScanner, FontDescriptorFactory descriptorFactory,
IFilterProvider filterProvider)
public CidFontFactory(IPdfTokenScanner pdfScanner, IFilterProvider filterProvider)
{
this.pdfScanner = pdfScanner;
this.descriptorFactory = descriptorFactory;
this.filterProvider = filterProvider;
}
public ICidFont Generate(DictionaryToken dictionary, bool isLenientParsing)
{
public ICidFont Generate(DictionaryToken dictionary)
{
var type = dictionary.GetNameOrDefault(NameToken.Type);
if (!NameToken.Font.Equals(type))
{
@@ -50,7 +47,7 @@
FontDescriptor descriptor = null;
if (TryGetFontDescriptor(dictionary, out var descriptorDictionary))
{
descriptor = descriptorFactory.Generate(descriptorDictionary, pdfScanner, isLenientParsing);
descriptor = FontDescriptorFactory.Generate(descriptorDictionary, pdfScanner);
}
var fontProgram = ReadDescriptorFile(descriptor);
@@ -67,7 +64,7 @@
if (NameToken.CidFontType2.Equals(subType))
{
var cidToGid = GetCharacterIdentifierToGlyphIndexMap(dictionary, isLenientParsing);
var cidToGid = GetCharacterIdentifierToGlyphIndexMap(dictionary);
return new Type2CidFont(type, subType, baseFont, systemInfo, descriptor, fontProgram, verticalWritingMetrics, widths, defaultWidth, cidToGid);
}
@@ -287,20 +284,15 @@
return new CharacterIdentifierSystemInfo(registry, ordering, supplement);
}
private CharacterIdentifierToGlyphIndexMap GetCharacterIdentifierToGlyphIndexMap(DictionaryToken dictionary, bool isLenientParsing)
private CharacterIdentifierToGlyphIndexMap GetCharacterIdentifierToGlyphIndexMap(DictionaryToken dictionary)
{
if (!dictionary.TryGet(NameToken.CidToGidMap, out var entry))
{
return new CharacterIdentifierToGlyphIndexMap();
}
if (entry is NameToken name)
if (entry is NameToken)
{
if (!name.Equals(NameToken.Identity) && !isLenientParsing)
{
throw new InvalidOperationException($"The CIDToGIDMap in a Type 0 font should have the value /Identity, instead got: {name}.");
}
return new CharacterIdentifierToGlyphIndexMap();
}