import { columnsText, fontSize as fs, AlginType, FontSize, getLength } from './print_common'; import HardwareKit from 'qm-hardwarekit'; let Purong = HardwareKit.Purong; const PAGE_ROW_SIZE: number = 44; function startPrint(_: any) { return new Promise(async resolve => { if (Purong) { await Purong.create(); await Purong.setLineSpace(5); } resolve(null); }); } function printText(text: String, fontSize: FontSize = 'middle', algin: AlginType = 0) { if (!Purong) return; fontSize = typeof fontSize === 'number' ? fontSize : fs(fontSize); return new Promise(async resolve => { switch (algin) { case 0: await Purong.printAlignLeft(); break; case 1: await Purong.printAlignCenter(); break; case 2: await Purong.printAlignRight(); break; } await Purong.printText(text); resolve(null); }); } function printlnText(text: String, fontSize: FontSize = 'middle', algin: AlginType = 0) { return printText(text + '\n', fontSize, algin); } function printColumnsText( texts: Array, weights: Array, algins: Array, zoom: boolean = true, ) { return new Promise(async resolve => { if (Purong) await Purong.reset(); let cos = columnsText(texts, weights, algins, PAGE_ROW_SIZE, zoom); for (let text of cos) { await printlnText(text); } resolve(null); }); } const printQrCode = text => { if (Purong) Purong.printQrCode(text); }; const printBarCode = text => { return new Promise(async resolve => { if (Purong) await Purong.printBarCode(text); resolve(null); }); }; const line = () => { var l = ''; for (var i = 0; i < PAGE_ROW_SIZE; ++i) { l += '-'; } return new Promise(async resolve => { if (Purong) await Purong.printlnText(l); resolve(null); }); }; const lineWrap = (nums: number) => { return new Promise(async resolve => { if (Purong) { await Purong.lineWrap(nums); } resolve(null); }); }; const endPrint = () => { return new Promise(async resolve => { lineWrap(5); if (Purong) { await Purong.cut(); //打印完成还原 await Purong.reset(); await Purong.clean(); } resolve(null); }); }; export { printText, printlnText, printQrCode, printBarCode, printColumnsText, lineWrap, line, startPrint, endPrint };