From 65613ce8951ba44b68b00450793ec5edc91f940f Mon Sep 17 00:00:00 2001 From: taoya7 <569781231@qq.com> Date: Mon, 11 Mar 2024 16:32:51 +0800 Subject: [PATCH] feat: init --- README.md | 3 +++ src/command/Label.ts | 18 ++++++++++++++---- src/index.ts | 7 +++++-- 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..f5d9b9d --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ + + +https://www.npmjs.com/package/@taoya7/print-help \ No newline at end of file diff --git a/src/command/Label.ts b/src/command/Label.ts index d0a7a76..da7926c 100644 --- a/src/command/Label.ts +++ b/src/command/Label.ts @@ -164,8 +164,8 @@ export class LabelCommand { command: number[] = []; constructor(width: number, height: number, gap: number) { this.command = new Array(); - this.addSize(width, height); - this.addGap(gap); + // this.addSize(width, height); + // this.addGap(gap); } public clrCommand() { this.command = []; @@ -271,8 +271,11 @@ export class LabelCommand { let str: string = `BAR ${x}, ${y}, ${width}, ${height}\r\n`; this.addStrToCommand(str); } + /*** + * 添加文本 + */ addText(x: number, y: number, font: FONTTYPE, rotation: ROTATION, Xscal: FONTMUL, Yscal: FONTMUL, text: string): void { - let str: string = `TEXT ${x}, ${y}, "${font}", ${rotation}, ${Xscal}, ${Yscal}, "${text}"\r\n`; + const str = "TEXT " + x + "," + y + ",\"" + font + "\"," + rotation + "," + Xscal + "," + Yscal + ",\"" + text + "\"\r\n"; this.addStrToCommand(str); } addUserCommand(command: string): void { @@ -365,7 +368,14 @@ export class LabelCommand { this.addStrToCommand(str); } getCommand() { - return this.command.join(','); + return this.command; + } + getCommandStr(command: number[]) { + let str = ""; + for (let i = 0; i < command.length; i++) { + str += String.fromCharCode(command[i]); + } + return str; } addQueryPrinterType(): void { let str: string = `~!T\r\n`; diff --git a/src/index.ts b/src/index.ts index bfefd26..de61ba6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,12 @@ export * from './command' -import { LabelCommand } from '@/command/Label' +import { FONTMUL, FONTTYPE, LabelCommand, ROTATION } from '@/command/Label' function main() { let label = new LabelCommand(50, 30, 0); - console.log(label.getCommand()); + label.addText(0, 0, FONTTYPE.FONT_1, ROTATION.ROTATION_0, FONTMUL.MUL_1, FONTMUL.MUL_1, 'Hello World'); + var command = label.getCommand(); + console.log(command);// 获取字节码 + console.log(label.getCommandStr(command)); } main(); \ No newline at end of file