BitmapFont.fromZip constructor

BitmapFont.fromZip(
  1. List<int> fileData
)

Decode a BitmapFont from the contents of a zip file that stores the .fnt font definition and associated PNG images.

Implementation

BitmapFont.fromZip(List<int> fileData) {
  final arc = ZipDecoder().decodeBytes(fileData);

  ArchiveFile? font_file;
  for (var i = 0; i < arc.numberOfFiles(); ++i) {
    if (arc.fileName(i).endsWith('.fnt')) {
      font_file = arc.files[i];
      break;
    }
  }

  if (font_file == null) {
    throw ImageException('Invalid font archive');
  }

  /// Remove leading whitespace so xml detection is correct
  final font_str =
      String.fromCharCodes(font_file.content as List<int>).trimLeft();
  XmlDocument xml;

  /// Added <?xml which may be present, appropriately
  if (font_str.startsWith('<?xml') || font_str.startsWith('<font>')) {
    xml = XmlDocument.parse(font_str);
  } else {
    xml = _parseTextFnt(font_str);
  }

  _parseFnt(xml, {}, arc);
}