posPrintText static method

Uint8List? posPrintText(
  1. String pszString, {
  2. int nWidthTimes = 0,
  3. int nHeightTimes = 0,
  4. int codepage = 0,
  5. int nFontType = 0,
  6. PosAlign align = PosAlign.left,
})

打印文本文档 @param pszString 要打印的字符串 @param codepage 设置代码页(0--255) @param nWidthTimes 倍宽(0--4) @param nHeightTimes 倍高(0--4) @param nFontType 字体类型(只对Ascii码有效)(0,1 48,49)

Implementation

static Uint8List? posPrintText(
  String pszString, {
  int nWidthTimes = 0,
  int nHeightTimes = 0,
  int codepage = 0,
  int nFontType = 0,
  PosAlign align = PosAlign.left,
}) {
  if (codepage < 0 || codepage > 255 || pszString.isEmpty) {
    return null;
  }

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

  final dataSize = (intToWidth[nWidthTimes] + intToHeight[nHeightTimes]);

  Command.gsExclamationMark[2] = dataSize;
  Command.esct[2] = codepage;
  Command.escM[2] = nFontType;
  Command.escAlign[2] = align.value;

  if (codepage == 0) {
    return Uint8List.fromList(
      Command.escAlign +
          Command.gsExclamationMark +
          Command.esct +
          Command.fsAnd +
          Command.escM +
          pbString +
          Command.escInit,
    );
  }

  return Uint8List.fromList(
    Command.escAlign +
        Command.gsExclamationMark +
        Command.esct +
        Command.fsDot +
        Command.escM +
        pbString +
        Command.escInit,
  );
}