convert method
Actual barcode computation method, returns a stream of bool which represents the presence or absence of a bar
Implementation
@override
Iterable<bool> convert(String data) sync* {
// Start
yield* add(BarcodeMaps.code93StartStop, BarcodeMaps.code93Len);
final keys = BarcodeMaps.code93.keys.toList();
for (var code in data.codeUnits) {
final codeValue = BarcodeMaps.code93[code];
if (codeValue == null) {
throw BarcodeException(
'Unable to encode "${String.fromCharCode(code)}" to $name Barcode');
}
yield* add(codeValue, BarcodeMaps.code93Len);
}
// Checksum
var sumC = 0;
var sumK = 0;
var indexC = 1;
var indexK = 2;
for (var index = data.codeUnits.length - 1; index >= 0; index--) {
final code = data.codeUnits[index];
sumC += keys.indexOf(code) * indexC;
sumK += keys.indexOf(code) * indexK;
indexC++;
if (indexC > 20) {
indexC = 1;
}
indexK++;
if (indexK > 15) {
indexK = 1;
}
}
sumC = sumC % 47;
yield* add(BarcodeMaps.code93[keys[sumC]]!, BarcodeMaps.code93Len);
sumK = (sumK + sumC) % 47;
yield* add(BarcodeMaps.code93[keys[sumK]]!, BarcodeMaps.code93Len);
// Stop
yield* add(BarcodeMaps.code93StartStop, BarcodeMaps.code93Len);
// Termination Bar
yield true;
}