我没有找到通过 ESC/POS 命令实现它的任何方法。所以这是我对格式功能的实现:
procedure TNativePrint.DoAddLineWithTwoAlignments(const ALeftStr : string;
ALeftStrFont : TFontType;
ALeftStrFontStyle : TFontStyle;
const ARightStr : string;
ARightStrFont : TFontType;
ARightStrFontStyle : TFontStyle;
APrintAreaWidth : integer = 500);
const
vFomatLine = '';
var
vOffset : integer;
vCharSize : integer;
vLeftSize : integer;
vRightSize : integer;
begin
vCharSize := 12;
if (ALeftStrFont = ftFontA) then begin
vCharSize := 12;
end else if (ALeftStrFont = ftFontB) then begin
vCharSize := 9;
end;
if (ALeftStrFontStyle in [fsDoubleWidth, fsDoubleHW, fsBoldDoubleWidth, fsBoldDoubleHW]) then begin
vCharSize := vCharSize * 2;
end;
vLeftSize := length(ALeftStr) * vCharSize;
if (ARightStrFont = ftFontA) then begin
vCharSize := 12;
end else if (ARightStrFont = ftFontB) then begin
vCharSize := 9;
end;
if (ARightStrFontStyle in [fsDoubleWidth, fsDoubleHW, fsBoldDoubleWidth, fsBoldDoubleHW]) then begin
vCharSize := vCharSize * 2;
end;
vRightSize := length(ARightStr) * vCharSize;
vOffset := APrintAreaWidth - ( vLeftSize + vRightSize);
DoSetFont(ALeftStrFont, ALeftStrFontStyle);
DoAddLine(ALeftStr, false);
DoSetFont(ARightStrFont, ARightStrFontStyle);
DoAddLine(#$1B'\'+AnsiChar(vOffset)+#0, false);
DoAddLine(ARightStr);
end;
如您所见,我正在分析字体、字体样式和打印区域宽度,取决于它我计算偏移量