pack method
Corresponding parser should be called from frame_app data handler
Implementation
@override
Uint8List pack() {
if (_lines.isEmpty) {
throw Exception('_lines is empty: call rasterize() before pack()');
}
int widthMsb = _width >> 8;
int widthLsb = _width & 0xFF;
int heightMsb = _totalHeight >> 8;
int heightLsb = _totalHeight & 0xFF;
// store the x (16-bit) and y (16-bit) offsets as pairs for each of the lines
Uint8List offsets = Uint8List(_displayLineMetrics.length * 4);
for (int i = 0; i < _displayLineMetrics.length; i++) {
var lm = _displayLineMetrics[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, size of the block (WxH), num lines, offsets within block for each line
return Uint8List.fromList([
0xFF,
widthMsb,
widthLsb,
heightMsb,
heightLsb,
_lines.length & 0xFF,
...offsets
]);
}