From f9755a4222fdb330fb52ae64276a630d63925bf3 Mon Sep 17 00:00:00 2001 From: aihe <961836564@qq.com> Date: Sun, 23 Jun 2024 01:06:21 +0800 Subject: [PATCH] uu --- .../print/tanexPrinterUniSdk.js | 38 ++++++++++++++++++- .../render-template-native.vue | 10 +++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/components/tpx-bluetooth-print/print/tanexPrinterUniSdk.js b/components/tpx-bluetooth-print/print/tanexPrinterUniSdk.js index daf5934..57cb987 100644 --- a/components/tpx-bluetooth-print/print/tanexPrinterUniSdk.js +++ b/components/tpx-bluetooth-print/print/tanexPrinterUniSdk.js @@ -82,8 +82,44 @@ var tanexPrinter = { r.push((~bits[i]) & 0xFF); } tanexPrinter.addCommand('\r\n') - // console.log('===>setBitmapCmd:',JSON.stringify(r)) + console.log('===>setBitmapCmd:', r) } + + tanexPrinter.addBitmap2 = function(x, y, res) { //添加图片,res为画布参数 + var w = res.width + var width = parseInt((res.width + 7) / 8 * 8 / 8) + var height = res.height; + // console.log(width + "--" + height) + data = `EG ${width} ${height} ${x} ${y} ` + // console.log(command) + var r = [] + var bits = new Uint8Array(height * width); + for (y = 0; y < height; y++) { + for (x = 0; x < w; x++) { + var color = res.data[(y * w + x) * 4 + 1]; + if (color > 128) { + bits[parseInt(y * width + x / 8)] |= (0x80 >> (x % 8)); + } + } + } + for (var i = 0; i < bits.length; i++) { + r.push((~bits[i]) & 0xFF); + } + let egIData = `` + r.map(v=> { + // 转成16位的ASCII + let a16 = (v).toString(16) + if(v < 16) { + a16 = `0${a16}` + } + a16 = a16.toUpperCase() + data += `${a16}` + }) + tanexPrinter.addCommand(data) + console.log("addBitmap2 EG data =====================", data) + tanexPrinter.addCommand('\r\n') + } + tanexPrinter.addText = function(text) { data = `TEXT 24 0 10 10 ${text}\r\n` tanexPrinter.addCommand(data) diff --git a/components/tpx-bluetooth-print/render-template-native.vue b/components/tpx-bluetooth-print/render-template-native.vue index 1445bbc..0cf2f3e 100644 --- a/components/tpx-bluetooth-print/render-template-native.vue +++ b/components/tpx-bluetooth-print/render-template-native.vue @@ -43,7 +43,7 @@ export default { imgData: '', percentage: 0, // 打印进度 imageUrl: '', - paperWidth: 320, + paperWidth: 560, } }, mounted () { @@ -65,10 +65,14 @@ export default { } let prtInstance = tanexPrinterUniSdk.createInstance() prtInstance.init(that.canvasHeight) - prtInstance.addBitmap(0, 0, that.imgData) + prtInstance.diyCode(`PAGE-WIDTH 600\r\n`) + // prtInstance.diyCode(`EG 2 16 90 45 F0F0F0F0F0F0F0F00F0F0F0F0F0F0F0F`) + // prtInstance.diyCode(`F0F0F0F0F0F0F0F00F0F0F0F0F0F0F0F\r\n`) + // prtInstance.addBitmap2(0, 0, that.imgData) + prtInstance.addBitmap2(0, 0, that.imgData) prtInstance.setPagePrint() let commond = prtInstance.getPrintCmd() - console.log("打印命令组装完成,开始打印=====") + console.log("打印命令组装完成,开始打印=====", commond) printModule.print(deviceId, commond, true) // printModule.printTestSimple(deviceId)