encodeContent method

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

Encode the contents to bool array expression of one-dimensional barcode. Start code and end code should be included in result, and side margins should not be included.

@param contents barcode contents to encode @return a {@code List

Implementation

@override
List<bool> encodeContent(
  String contents, [
  EncodeHint? hints,
]) {
  final length = contents.length;
  if (length % 2 != 0) {
    throw ArgumentError('The length of the input should be even');
  }
  if (length > 80) {
    throw ArgumentError(
      'Requested contents should be less than 80 '
      'digits long, but got $length',
    );
  }

  OneDimensionalCodeWriter.checkNumeric(contents);

  final result = List.filled(9 + 9 * length, false);
  int pos =
      OneDimensionalCodeWriter.appendPattern(result, 0, _startPattern, true);
  for (int i = 0; i < length; i += 2) {
    final one = int.parse(contents[i]);
    final two = int.parse(contents[i + 1]);
    final encoding = List.filled(10, 0);
    for (int j = 0; j < 5; j++) {
      encoding[2 * j] = _patterns[one][j];
      encoding[2 * j + 1] = _patterns[two][j];
    }
    pos +=
        OneDimensionalCodeWriter.appendPattern(result, pos, encoding, true);
  }
  OneDimensionalCodeWriter.appendPattern(result, pos, _endPattern, true);

  return result;
}