Skip to content

Commit

Permalink
Fix null reference in GlyphDataTable occuring after ReadGlyphs()
Browse files Browse the repository at this point in the history
  • Loading branch information
BobLd committed Aug 5, 2023
1 parent d1e8b42 commit 4a480ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig.Fonts/TrueType/Glyphs/Glyph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;

internal class Glyph : IGlyphDescription
internal sealed class Glyph : IGlyphDescription
{
/// <summary>
/// The bounding rectangle for the character.
Expand Down
23 changes: 12 additions & 11 deletions src/UglyToad.PdfPig.Fonts/TrueType/Tables/GlyphDataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
using System;
using System.Collections.Generic;
using System.Linq;
using Core;
using Glyphs;
using Parser;
Expand All @@ -12,7 +11,7 @@
/// The 'glyf' table contains the data that defines the appearance of the glyphs in the font.
/// This includes specification of the points that describe the contours that make up a glyph outline and the instructions that grid-fit that glyph.
/// </summary>
internal class GlyphDataTable : ITrueTypeTable
internal sealed class GlyphDataTable : ITrueTypeTable
{
private readonly IReadOnlyList<uint> glyphOffsets;
private readonly PdfRectangle maxGlyphBounds;
Expand Down Expand Up @@ -71,19 +70,21 @@ public bool TryGetGlyphBounds(int glyphIndex, out PdfRectangle bounds)
return true;
}

tableBytes.Seek(offset);
bounds = Glyphs[glyphIndex].Bounds;

// ReSharper disable once UnusedVariable
var contourCount = tableBytes.ReadSignedShort();
return true;
}

var minX = tableBytes.ReadSignedShort();
var minY = tableBytes.ReadSignedShort();
var maxX = tableBytes.ReadSignedShort();
var maxY = tableBytes.ReadSignedShort();
public bool TryGetGlyphPath(int glyphIndex, out IReadOnlyList<PdfSubpath> subpaths)
{
subpaths = null;

bounds = new PdfRectangle(minX, minY, maxX, maxY);
if (glyphIndex < 0 || glyphIndex > Glyphs.Count - 1)
{
return false;
}

return true;
return Glyphs[glyphIndex].TryGetGlyphPath(out subpaths);
}

public static GlyphDataTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table, TableRegister.Builder tableRegister)
Expand Down
4 changes: 2 additions & 2 deletions src/UglyToad.PdfPig.Fonts/TrueType/TrueTypeFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public bool TryGetPath(int characterCode, Func<int, int?> characterCodeToGlyphId
return false;
}

return TableRegister.GlyphTable.Glyphs[index].TryGetGlyphPath(out path);
return TableRegister.GlyphTable.TryGetGlyphPath(index, out path);
}

/// <summary>
Expand Down Expand Up @@ -210,4 +210,4 @@ private bool TryGetGlyphIndex(int characterIdentifier, Func<int, int?> character
return TableRegister.CMapTable.TryGetGlyphIndex(characterIdentifier, out glyphId);
}
}
}
}

0 comments on commit 4a480ff

Please sign in to comment.