make compact font format parser thread safe

the individual cff parser uses a cff dictionary reader inside it which has a per-instance operands list, for this reason it is not thread-safe and cannot be shared. this change creates a new individual font parser for each call to the top-level cff parser.
This commit is contained in:
Eliot Jones
2020-02-25 14:24:29 +00:00
parent 9f488809ac
commit 50c17f7951

View File

@@ -13,9 +13,6 @@
private const string TagOtto = "OTTO";
private const string TagTtcf = "ttcf";
private const string TagTtfonly = "\u0000\u0001\u0000\u0000";
private static readonly CompactFontFormatIndividualFontParser IndividualFontParser = new CompactFontFormatIndividualFontParser(
new CompactFontFormatTopLevelDictionaryReader(), new CompactFontFormatPrivateDictionaryReader());
/// <summary>
/// Read the Compact Font Format font from the input data.
@@ -50,11 +47,13 @@
var fonts = new Dictionary<string, CompactFontFormatFont>();
var individualFontParser = new CompactFontFormatIndividualFontParser(new CompactFontFormatTopLevelDictionaryReader(), new CompactFontFormatPrivateDictionaryReader());
for (var i = 0; i < fontNames.Length; i++)
{
var fontName = fontNames[i];
fonts[fontName] = IndividualFontParser.Parse(data, fontName, topLevelDictionaryIndex[i], stringIndex, globalSubroutineIndex);
fonts[fontName] = individualFontParser.Parse(data, fontName, topLevelDictionaryIndex[i], stringIndex, globalSubroutineIndex);
}
return new CompactFontFormatFontCollection(header, fonts);