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* {
if (fixedLength != null) {
data = checkLength(data, fixedLength!);
} else {
if (zeroPrepend && ((data.length % 2 != 0) != addChecksum)) {
data = '0$data';
}
if (addChecksum) {
data += checkSumModulo10(data);
}
if (data.length % 2 != 0) {
throw BarcodeException(
'$name barcode can only encode an even number of digits.');
}
}
// Start
yield* add(BarcodeMaps.itfStart, 4);
final cu = data.codeUnits;
for (var i = 0; i < cu.length / 2; i++) {
final tuple = <int?>[
BarcodeMaps.itf[cu[i * 2]],
BarcodeMaps.itf[cu[i * 2 + 1]]
];
if (tuple[0] == null || tuple[1] == null) {
throw BarcodeException(
'Unable to encode "${String.fromCharCode(cu[i * 2])}${String.fromCharCode(cu[i * 2 + 1])}" to $name Barcode');
}
for (var n = 0; n < 10; n++) {
final v = (tuple[n % 2]! >> (n ~/ 2)) & 1;
final c = n % 2 == 0;
yield c;
if (v != 0) {
yield c;
yield c;
}
}
}
// End
yield* add(BarcodeMaps.itfEnd, 5);
}