diff --git a/src/UglyToad.PdfPig.Fonts/CompactFontFormat/Charsets/CompactFontFormatCharset.cs b/src/UglyToad.PdfPig.Fonts/CompactFontFormat/Charsets/CompactFontFormatCharset.cs index 06379af0..44c27c09 100644 --- a/src/UglyToad.PdfPig.Fonts/CompactFontFormat/Charsets/CompactFontFormatCharset.cs +++ b/src/UglyToad.PdfPig.Fonts/CompactFontFormat/Charsets/CompactFontFormatCharset.cs @@ -32,7 +32,7 @@ public virtual string GetNameByStringId(int stringId) { - return GlyphIdToStringIdAndName.SingleOrDefault(x => x.Value.stringId == stringId).Value.name; + return GlyphIdToStringIdAndName.FirstOrDefault(x => x.Value.stringId == stringId).Value.name; } public virtual int GetStringIdByGlyphId(int glyphId) diff --git a/src/UglyToad.PdfPig/PdfFonts/FontFactory.cs b/src/UglyToad.PdfPig/PdfFonts/FontFactory.cs index 7114d1a7..4a4ccad3 100644 --- a/src/UglyToad.PdfPig/PdfFonts/FontFactory.cs +++ b/src/UglyToad.PdfPig/PdfFonts/FontFactory.cs @@ -44,6 +44,25 @@ return handler.Generate(dictionary); } + // Try simple font recovery: + NameToken[] orderedFallbacks = [NameToken.Type1, NameToken.TrueType]; + foreach (var fallback in orderedFallbacks) + { + if (!handlers.TryGetValue(fallback, out handler)) + { + continue; + } + + try + { + return handler.Generate(dictionary); + } + catch (Exception ex) + { + log?.Error($"Tried to parse font as fallback type: {fallback}", ex); + } + } + throw new NotImplementedException($"Parsing not implemented for fonts of type: {subtype}, please submit a pull request or an issue."); } }