handle case insensitive truetype table tags and missing tables for postscript fonts

This commit is contained in:
Eliot Jones
2019-12-20 14:40:25 +00:00
parent 3084a9aab6
commit f401ab3ba0
3 changed files with 13 additions and 7 deletions

View File

@@ -18,7 +18,6 @@
/// <summary>
/// This table contains the data that defines the appearance of the glyphs in the font.
/// </summary>
[NotNull]
public GlyphDataTable GlyphTable { get; }
/// <summary>
@@ -36,7 +35,6 @@
/// <summary>
/// This table stores the offsets to the locations of the glyphs (relative to the glyph table).
/// </summary>
[NotNull]
public IndexToLocationTable IndexToLocationTable { get; }
/// <summary>
@@ -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;

View File

@@ -20,7 +20,7 @@
int rangeShift = data.ReadUnsignedShort();
// ReSharper restore UnusedVariable
var tables = new Dictionary<string, TrueTypeHeaderTable>();
var tables = new Dictionary<string, TrueTypeHeaderTable>(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;
}

View File

@@ -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;