getTextWidth method

int getTextWidth(
  1. String text,
  2. PrinterTextStyle style
)

获取文字宽度

text 文字

style 文字样式

Implementation

int getTextWidth(String text, PrinterTextStyle style) {
  int ascCharWidth = this.getFontAsciiWidth(style);
  int cnCharWidth = this.getFontWidth(style);
  int width = 0;
  int i = 0;
  List<int> codeUnits = text.codeUnits;
  for (int len = codeUnits.length; i < len; i++) {
    int charCode = codeUnits[i];
    width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
  }
  return width;
}