load static method
Loads a TTF/OTF font from raw bytes.
All tables are parsed eagerly (cmap, hmtx, kern) so that subsequent calls to getGlyphId and getAdvanceWidth are synchronous and O(1). Glyph outlines are parsed lazily on first access.
Throws StateError if required tables (head, hhea, maxp, cmap,
hmtx) are missing.
Throws ArgumentError if the font is CFF-based (.otf with CFF
table), which is not yet supported.
Implementation
static TtfFont load(Uint8List bytes) {
final parser = TtfParser(bytes);
if (!parser.isTrueType) {
throw ArgumentError(
'CFF/PostScript-based fonts are not yet supported. '
'Use a TrueType-based font (with a "glyf" table).',
);
}
final metrics = parser.parseFontMetrics();
final cmap = parser.parseCmap();
final hmtx = parser.parseHmtx();
final kern = parser.parseKern();
return TtfFont._(
parser: parser,
metrics: metrics,
cmap: cmap,
hmtx: hmtx,
kern: kern,
);
}