pack method

  1. @override
Uint8List pack()
override

Corresponding parser should be called from frame_app data handler

Implementation

@override
Uint8List pack() {
  if (_sprites.isEmpty) {
    throw Exception('_sprites is empty: call rasterize() before pack()');
  }

  int widthMsb = _width >> 8;
  int widthLsb = _width & 0xFF;

  // store the x (16-bit) and y (16-bit) offsets as pairs for each of the lines
  Uint8List offsets = Uint8List(_lineMetrics.length * 4);

  for (int i = 0; i < _lineMetrics.length; i++) {
    var lm = _lineMetrics[i];
    int xOffset = lm.left.toInt();
    int yOffset = (lm.baseline - lm.ascent).toInt();
    offsets[4 * i] = xOffset >> 8;
    offsets[4 * i + 1] = xOffset & 0xFF;
    offsets[4 * i + 2] = yOffset >> 8;
    offsets[4 * i + 3] = yOffset & 0xFF;
  }

  // special marker for Block header 0xFF, width of the block, max display rows, num lines, offsets within block for each line
  return Uint8List.fromList([
    0xFF,
    widthMsb,
    widthLsb,
    _maxDisplayRows & 0xFF,
    _sprites.length & 0xFF,
    ...offsets
  ]);
}