codeTableTestSheetBytes function
Uint8List
codeTableTestSheetBytes({
- required String cashregisterLabel,
- required DateTime time,
- required KeckPaperSize paper,
Das Testblatt als ESC/POS-Bytes. Jede Testzeile schaltet nach ihrer
Nummer einmal mit FS . + ESC t n auf ihre Tabelle und traegt deren
Bytes (encodeForCodeTable, also das echte €-Byte, wo die Tabelle es hat).
Die Nummer steht doppelt breit und hoch (GS !) und fett, die Vorlage als
Rasterbild (GS v 0).
Implementation
Uint8List codeTableTestSheetBytes({
required String cashregisterLabel,
required DateTime time,
required KeckPaperSize paper,
}) {
final (:blatt, vorlage: vorlageIndex) = _blattBauen(cashregisterLabel, time);
final vorlage = blatt.blocks[vorlageIndex];
if (vorlage is! SheetLine) throw StateError('Testblatt: Vorlage-Zeile fehlt (Block $vorlageIndex)');
// Der Erzeuger ist immer 58 mm (32 Spalten, Druckbereich 384 Punkte) und
// ohne globale Tabelle: nur die Testzeilen schalten um.
final gen = EscPosGenerator(EscPaperSize.mm58, CapabilityProfile());
final bytes = <int>[...gen.reset()];
if (paper == KeckPaperSize.mm80) bytes.addAll([0x1d, 0x4c, _rand80 & 0xff, _rand80 >> 8]);
var tabellen = 0;
for (final block in blatt.blocks) {
if (block is! SheetLine) continue;
if (identical(block, vorlage)) {
bytes.addAll(gen.imageRaster(codeTableReferenceImage().toRasterImage(), align: PosAlign.left));
continue;
}
final lead = block.doubleSizeLead;
if (lead == null) {
bytes.addAll(gen.text(block.text.trimRight(), styles: PosStyles(align: PosAlign.left, bold: block.bold)));
continue;
}
final tabelle = blatt.rows[tabellen];
tabellen += 1;
// Die Ziffer ist ASCII und steht in jeder Tabelle gleich: keine
// Umschaltung davor, die Zeile schaltet genau einmal, vor ihren Bytes.
bytes.addAll(gen.setStyles(const PosStyles(bold: true, width: PosTextSize.size2, height: PosTextSize.size2)));
bytes.addAll(encodeForCodeTable(block.text.substring(0, lead).trim(), CodeTableId.replacement));
bytes.addAll(gen.setStyles(PosStyles(codeTable: tabelle.codeTable.name)));
bytes.addAll(encodeForCodeTable(block.text.substring(lead).trimRight(), tabelle.codeTable));
bytes.add(0x0a);
}
// Endzustand wie ohne Wahl: Tabelle 16 (WPC1252) und auf 80 mm Rand 0.
// Ein Druck danach ohne `ESC @` stuende sonst in der Tabelle der letzten
// Testzeile und um den Rand verschoben.
bytes.addAll([0x1b, 0x74, _vorgabeEscT]);
if (paper == KeckPaperSize.mm80) bytes.addAll([0x1d, 0x4c, 0, 0]);
bytes.addAll(gen.cut());
return Uint8List.fromList(bytes);
}