parseGlyphContours method
Parses the contours for glyphId.
Returns null if the glyph ID is out of range or the glyph data is
missing. Returns an empty list for whitespace glyphs (e.g. space).
Implementation
List<GlyphContour>? parseGlyphContours(int glyphId) {
if (glyphId < 0 || glyphId >= _numGlyphs) return null;
final glyf = _tableOffsets['glyf'];
if (glyf == null) return null;
final offset = _glyphOffset(glyphId);
final nextOffset = _glyphOffset(glyphId + 1);
if (offset == nextOffset) return []; // empty glyph (e.g. space)
final base = glyf + offset;
if (base + 10 > _data.lengthInBytes) return null;
final numberOfContours = _data.getInt16(base);
try {
if (numberOfContours >= 0) {
return _parseSimpleGlyph(base, numberOfContours);
} else {
return _parseCompositeGlyph(base);
}
} catch (_) {
return null; // malformed glyph data – skip gracefully
}
}