diff --git a/src/UglyToad.PdfPig/Fonts/TrueType/Parser/TableRegister.cs b/src/UglyToad.PdfPig/Fonts/TrueType/Parser/TableRegister.cs index d01f1531..dc80e7ee 100644 --- a/src/UglyToad.PdfPig/Fonts/TrueType/Parser/TableRegister.cs +++ b/src/UglyToad.PdfPig/Fonts/TrueType/Parser/TableRegister.cs @@ -18,7 +18,6 @@ /// /// This table contains the data that defines the appearance of the glyphs in the font. /// - [NotNull] public GlyphDataTable GlyphTable { get; } /// @@ -36,7 +35,6 @@ /// /// This table stores the offsets to the locations of the glyphs (relative to the glyph table). /// - [NotNull] public IndexToLocationTable IndexToLocationTable { get; } /// @@ -73,10 +71,10 @@ } HeaderTable = builder.HeaderTable ?? throw new ArgumentException("The builder did not contain the header table"); - GlyphTable = builder.GlyphDataTable ?? throw new ArgumentException("The builder did not contain the glyph data table."); + GlyphTable = builder.GlyphDataTable; HorizontalHeaderTable = builder.HorizontalHeaderTable ?? throw new ArgumentException("The builder did not contain the horizontal header table."); HorizontalMetricsTable = builder.HorizontalMetricsTable; - IndexToLocationTable = builder.IndexToLocationTable ?? throw new ArgumentException("The builder did not contain the index to location table."); + IndexToLocationTable = builder.IndexToLocationTable; MaximumProfileTable = builder.MaximumProfileTable ?? throw new ArgumentException("The builder did not contain the maximum profile table."); NameTable = builder.NameTable; PostScriptTable = builder.PostScriptTable; diff --git a/src/UglyToad.PdfPig/Fonts/TrueType/Parser/TrueTypeFontParser.cs b/src/UglyToad.PdfPig/Fonts/TrueType/Parser/TrueTypeFontParser.cs index 7b982c3f..ca85b404 100644 --- a/src/UglyToad.PdfPig/Fonts/TrueType/Parser/TrueTypeFontParser.cs +++ b/src/UglyToad.PdfPig/Fonts/TrueType/Parser/TrueTypeFontParser.cs @@ -20,7 +20,7 @@ int rangeShift = data.ReadUnsignedShort(); // ReSharper restore UnusedVariable - var tables = new Dictionary(); + var tables = new Dictionary(StringComparer.OrdinalIgnoreCase); for (var i = 0; i < numberOfTables; i++) { @@ -46,7 +46,7 @@ var length = data.ReadUnsignedInt(); // skip tables with zero length (except glyf) - if (length == 0 && !string.Equals(tag, TrueTypeHeaderTable.Glyf)) + if (length == 0 && !string.Equals(tag, TrueTypeHeaderTable.Glyf, StringComparison.OrdinalIgnoreCase)) { return null; } diff --git a/src/UglyToad.PdfPig/Fonts/TrueType/TrueTypeFontProgram.cs b/src/UglyToad.PdfPig/Fonts/TrueType/TrueTypeFontProgram.cs index 5298a8ad..1dab1129 100644 --- a/src/UglyToad.PdfPig/Fonts/TrueType/TrueTypeFontProgram.cs +++ b/src/UglyToad.PdfPig/Fonts/TrueType/TrueTypeFontProgram.cs @@ -68,7 +68,8 @@ { boundingBox = default(PdfRectangle); - if (!TryGetGlyphIndex(characterIdentifier, characterCodeToGlyphId, out var index)) + if (!TryGetGlyphIndex(characterIdentifier, characterCodeToGlyphId, out var index) + || TableRegister.GlyphTable == null) { return false; } @@ -112,6 +113,13 @@ private bool TryGetBoundingAdvancedWidthByIndex(int index, out decimal width) { + width = 0; + + if (TableRegister.HorizontalMetricsTable == null) + { + return false; + } + width = TableRegister.HorizontalMetricsTable.GetAdvanceWidth(index); return true;