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 (data.length <= 8) {
// Try to convert UPC-E to UPC-A
data = upceToUpca(data);
}
data = checkLength(data, maxLength);
final first = data.codeUnitAt(0);
final last = data.codeUnitAt(11);
try {
data = upcaToUpce(data);
} on BarcodeException {
if (fallback) {
yield* const BarcodeUpcA().convert(data);
return;
}
rethrow;
}
// Start
yield* add(BarcodeMaps.eanStartEnd, 3);
final parityRow = BarcodeMaps.upce[last];
final parity = first == 0x30 ? parityRow : parityRow! ^ 0x3f;
var index = 0;
for (var code in data.codeUnits) {
final codes = BarcodeMaps.ean[code];
if (codes == null) {
throw BarcodeException(
'Unable to encode "${String.fromCharCode(code)}" to $name Barcode');
}
yield* add(codes[(parity! >> index) & 1 == 0 ? 1 : 0], 7);
index++;
}
// Stop
yield* add(BarcodeMaps.eanEndUpcE, 6);
}