BitmapFont.fromZip constructor
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? fontFile;
for (var i = 0; i < arc.numberOfFiles(); ++i) {
if (arc.fileName(i).endsWith('.fnt')) {
fontFile = arc.files[i];
break;
}
}
if (fontFile == null) {
throw ImageException('Invalid font archive');
}
/// Remove leading whitespace so xml detection is correct
final fontStr =
String.fromCharCodes(fontFile.content as List<int>).trimLeft();
XmlDocument xml;
/// Added <?xml which may be present, appropriately
if (fontStr.startsWith('<?xml') || fontStr.startsWith('<font>')) {
xml = XmlDocument.parse(fontStr);
} else {
xml = _parseTextFnt(fontStr);
}
_parseFnt(xml, {}, arc);
}