encodeHighLevel static method

String encodeHighLevel(
  1. String msg, [
  2. Encoding? priorityCharset,
  3. int fnc1 = -1,
  4. SymbolShapeHint shape = SymbolShapeHint.forceNone,
])

Performs message encoding of a DataMatrix message

@param msg the message @param priorityCharset The preferred {@link Charset}. When the value of the argument is null, the algorithm chooses charsets that leads to a minimal representation. Otherwise the algorithm will use the priority charset to encode any character in the input that can be encoded by it if the charset is among the supported charsets. @param fnc1 denotes the character in the input that represents the FNC1 character or -1 if this is not a GS1 bar code. If the value is not -1 then a FNC1 is also prepended. @param shape requested shape. @return the encoded message (the char values range from 0 to 255)

Implementation

static String encodeHighLevel(
  String msg, [
  Encoding? priorityCharset,
  int fnc1 = -1,
  SymbolShapeHint shape = SymbolShapeHint.forceNone,
]) {
  int macroId = 0;
  if (msg.startsWith(HighLevelEncoder.macro05Header) &&
      msg.endsWith(HighLevelEncoder.macroTrailer)) {
    macroId = 5;
    msg = msg.substring(
      HighLevelEncoder.macro05Header.length,
      msg.length - 2,
    );
  } else if (msg.startsWith(HighLevelEncoder.macro06Header) &&
      msg.endsWith(HighLevelEncoder.macroTrailer)) {
    macroId = 6;
    msg = msg.substring(
      HighLevelEncoder.macro06Header.length,
      msg.length - 2,
    );
  }
  final rst = encode(msg, priorityCharset, fnc1, shape, macroId);
  return latin1.decode(rst);
}