posSetFont static method

Uint8List? posSetFont(
  1. String str,
  2. int bold,
  3. int font,
  4. int widthsize,
  5. int heigthsize,
)

设置打印模式(选择字体(font:A font:B),加粗,字体倍高倍宽(最大4倍高宽)) @param str 打印的字符串 @param bold 加粗 @param font 选择字型 @param widthsize 倍宽 @param heigthsize 倍高 @return

Implementation

static Uint8List? posSetFont(
  String str,
  int bold,
  int font,
  int widthsize,
  int heigthsize,
) {
  if (str.isEmpty ||
      widthsize < 0 ||
      widthsize > 4 ||
      heigthsize < 0 ||
      heigthsize > 4 ||
      font < 0 ||
      font > 1) return null;

  final strData = Uint8List.fromList(str.codeUnits);

  final intToWidth = Uint8List.fromList([0x00, 0x10, 0x20, 0x30]);
  final intToHeight = Uint8List.fromList([0x00, 0x01, 0x02, 0x03]);

  final command = Uint8List(strData.length + 9);
  command[0] = 27;
  command[1] = 69;
  command[2] = bold;
  command[3] = 27;
  command[4] = 77;
  command[5] = font;
  command[6] = 29;
  command[7] = 33;
  command[8] = (intToWidth[widthsize] + intToHeight[heigthsize]);
  arraycopy(strData, 0, command, 9, strData.length);

  return command;
}