convert method

  1. @override
Iterable<bool> convert(
  1. String data
)
override

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* {
  data = checkLength(data, maxLength);

  // Start
  yield* add(BarcodeMaps.eanStartEnd, 3);

  var index = 0;
  final first = BarcodeMaps.eanFirst[data.codeUnits.first];
  if (first == null) {
    throw BarcodeException(
        'Unable to encode "${String.fromCharCode(data.codeUnits.first)}" to $name Barcode');
  }

  for (var code in data.codeUnits.sublist(1)) {
    final codes = BarcodeMaps.ean[code];

    if (codes == null) {
      throw BarcodeException(
          'Unable to encode "${String.fromCharCode(code)}" to $name Barcode');
    }

    if (index == 6) {
      yield* add(BarcodeMaps.eanCenter, 5);
    }

    if (index < 6) {
      yield* add(codes[(first >> index) & 1], 7);
    } else {
      yield* add(codes[2], 7);
    }

    index++;
  }

  // Stop
  yield* add(BarcodeMaps.eanStartEnd, 3);
}