drawText method
dynamic
drawText(
- String? text,
- PrinterOffset offset,
- PrinterSize size,
- PrinterTextStyle textStyle,
override
打印文字
text
内容
offset
偏移位置
size
大小
textStyle
文字样式
Implementation
@override
drawText(String? text, PrinterOffset offset, PrinterSize size, PrinterTextStyle textStyle) {
textStyle = textStyle.extendsStyle(this.config!.fontStyle!);
var fontHeight = getFontHeight(textStyle);
var height = fontHeight.toDouble() * (textStyle.lineHeight ?? 1);
if (text == null || text.trim().isEmpty) {
return offset.y! + height;
}
setFontBlod(textStyle.fontBlod ?? false);
setUnderline(textStyle.underline ?? false);
setFontSize(textStyle.fontSize ?? 1);
var textLeft = this.calcTextLeft(text, size.width!.toInt(), textStyle.align!,
textStyle);
if (textLeft < 0) {
text = splitLine(
text, size.width!.toInt(), textStyle)[0];
textLeft = this.calcTextLeft(text, size.width!.toInt(), textStyle.align!,
textStyle);
}
var x = offset.x! + textLeft;
var y = offset.y! + (height - fontHeight) ~/ 2;
if (text.trim().isNotEmpty) {
this.addCommand(
"T ${textStyle.fontType} 0 ${x.toInt()} ${y.toInt()} $text");
}
}