encodeContent method

  1. @override
List<bool> encodeContent(
  1. String contents, [
  2. EncodeHint? hints
])
override

@param contents barcode contents to encode. It should not be encoded for extended characters. @return a {@code List

Implementation

@override
List<bool> encodeContent(
  String contents, [
  EncodeHint? hints,
]) {
  contents = convertToExtended(contents);
  final length = contents.length;
  if (length > 80) {
    throw ArgumentError(
      'Requested contents should be less than 80 digits long '
      'after converting to extended encoding, but got $length',
    );
  }

  //length of code + 2 start/stop characters + 2 checksums, each of 9 bits, plus a termination bar
  final codeWidth = (contents.length + 2 + 2) * 9 + 1;

  final result = List.filled(codeWidth, false);

  //start character (*)
  int pos = _appendPattern(result, 0, Code93Reader.asteriskEncoding);

  for (int i = 0; i < length; i++) {
    final indexInString = Code93Reader.alphabetString.indexOf(contents[i]);
    pos += _appendPattern(
      result,
      pos,
      Code93Reader.characterEncodings[indexInString],
    );
  }

  //add two checksums
  final check1 = _computeChecksumIndex(contents, 20);
  pos += _appendPattern(result, pos, Code93Reader.characterEncodings[check1]);

  //append the contents to reflect the first checksum added
  contents += Code93Reader.alphabetString[check1];

  final check2 = _computeChecksumIndex(contents, 15);
  pos += _appendPattern(result, pos, Code93Reader.characterEncodings[check2]);

  //end character (*)
  pos += _appendPattern(result, pos, Code93Reader.asteriskEncoding);

  //termination bar (single black bar)
  result[pos] = true;

  return result;
}