addFontOffer method

Future<Uint8List?> addFontOffer(
  1. ByteReader r
)

Handles a fontOffer. Returns the hash to request from the host when the file is not cached, or null when it is already available.

Implementation

Future<Uint8List?> addFontOffer(ByteReader r) async {
  final family = r.string();
  final familyKey = r.string();
  r
    ..u16() // Weight and style are read from the font file itself.
    ..u8();
  final hash = Uint8List.fromList(r.bytes(32));
  final hex = _hex(hash);
  _familyKeys[family] = familyKey;
  _offeredFiles[hex] = familyKey;
  if (_registeredFiles.contains('$familyKey/$hex')) {
    _onFamilyReady(familyKey);
    return null;
  }
  final cached = await fontCache.get(hex);
  if (cached != null && _hex(sha256.convert(cached).bytes) == hex) {
    await _register(familyKey, hex, cached);
    return null;
  }
  return hash;
}