feat: Buffer
This commit is contained in:
parent
42af6d8906
commit
ce4916d3a1
@ -1,8 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@taoya7/print-help",
|
"name": "@taoya7/print-help",
|
||||||
"version": "1.0.7",
|
"version": "1.0.12",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"佳博打印机",
|
"佳博打印机",
|
||||||
"打印机"
|
"打印机"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import _ from "lodash-es";
|
import _ from "lodash-es";
|
||||||
import iconv from "iconv-lite";
|
import { Buffer } from 'buffer'
|
||||||
|
|
||||||
export enum FOOT {
|
export enum FOOT {
|
||||||
F2 = 0,
|
F2 = 0,
|
||||||
F5 = 1,
|
F5 = 1,
|
||||||
@ -169,20 +170,20 @@ export class LabelCommand {
|
|||||||
public clrCommand() {
|
public clrCommand() {
|
||||||
this.command = [];
|
this.command = [];
|
||||||
}
|
}
|
||||||
private addStrToCommand(str: string): void {
|
addStrToCommand(str: string): void {
|
||||||
if (str !== "") {
|
if (str !== "") {
|
||||||
let bs;
|
const bs = Buffer.from(str, "utf8");
|
||||||
try {
|
|
||||||
bs = iconv.encode(str, "GB2312");
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
if (bs) {
|
|
||||||
for (let i = 0; i < bs.length; ++i) {
|
for (let i = 0; i < bs.length; ++i) {
|
||||||
this.command.push(bs[i]);
|
this.command.push(bs[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 追加编码
|
||||||
|
* @param number
|
||||||
|
*/
|
||||||
|
public addToCommand(number: number[]) {
|
||||||
|
this.command = this.command.concat(number);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 定义两张标签之间的间隙距离
|
* 定义两张标签之间的间隙距离
|
||||||
@ -488,8 +489,7 @@ export class LabelCommand {
|
|||||||
// 创建一个Buffer实例来存储字节数组
|
// 创建一个Buffer实例来存储字节数组
|
||||||
const buffer = Buffer.from(command);
|
const buffer = Buffer.from(command);
|
||||||
|
|
||||||
// 使用iconv-lite将Buffer从GB2312解码成字符串
|
const str = buffer.toString('utf8'); // 指定utf8编码
|
||||||
const str = iconv.decode(buffer, "GB2312");
|
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
25
src/index.ts
25
src/index.ts
@ -1 +1,26 @@
|
|||||||
export * from "./command";
|
export * from "./command";
|
||||||
|
|
||||||
|
// import {
|
||||||
|
// FONTMUL,
|
||||||
|
// FONTTYPE,
|
||||||
|
// LabelCommand,
|
||||||
|
// ROTATION,
|
||||||
|
// } from "@/command/Label";
|
||||||
|
|
||||||
|
// function main() {
|
||||||
|
// let label = new LabelCommand(50, 30, 0); // 长,宽,gap
|
||||||
|
// label.addText(
|
||||||
|
// 0,
|
||||||
|
// 0,
|
||||||
|
// FONTTYPE.FONT_1,
|
||||||
|
// ROTATION.ROTATION_0,
|
||||||
|
// FONTMUL.MUL_1,
|
||||||
|
// FONTMUL.MUL_1,
|
||||||
|
// "中国"
|
||||||
|
// );
|
||||||
|
// label.addToCommand([1, 2, 3]);
|
||||||
|
// var command = label.getCommand();
|
||||||
|
// console.log(command); // 获取字节码
|
||||||
|
// console.log(label.getCommandStr(command));
|
||||||
|
// }
|
||||||
|
// main();
|
||||||
|
Loading…
Reference in New Issue
Block a user