SpriteFont constructor

SpriteFont({
  1. required Image source,
  2. required double size,
  3. required double ascent,
  4. required List<Glyph> glyphs,
  5. double? defaultCharWidth,
})

Implementation

SpriteFont({
  required this.source,
  required this.size,
  required this.ascent,
  required List<Glyph> glyphs,
  double? defaultCharWidth,
}) : _data = <int, _Chain>{} {
  for (final glyph in glyphs) {
    var data = _data;
    for (var i = 0; i < glyph.char.length - 1; i++) {
      final j = glyph.char.codeUnitAt(i);
      data = (data[j] ??= _Chain()).followOn ??= <int, _Chain>{};
    }
    final j = glyph.char.codeUnitAt(glyph.char.length - 1);
    final chain = data[j] ??= _Chain();
    assert(
      chain.glyph == null,
      'Duplicate definition for glyph "${glyph.char}"',
    );
    glyph.initialize(defaultCharWidth ?? size, size);
    chain.glyph = glyph;
  }
}