feat: init

This commit is contained in:
陶林 2024-03-11 16:32:51 +08:00
parent 66bca689d6
commit 65613ce895
3 changed files with 22 additions and 6 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
https://www.npmjs.com/package/@taoya7/print-help

View File

@ -164,8 +164,8 @@ export class LabelCommand {
command: number[] = []; command: number[] = [];
constructor(width: number, height: number, gap: number) { constructor(width: number, height: number, gap: number) {
this.command = new Array(); this.command = new Array();
this.addSize(width, height); // this.addSize(width, height);
this.addGap(gap); // this.addGap(gap);
} }
public clrCommand() { public clrCommand() {
this.command = []; this.command = [];
@ -271,8 +271,11 @@ export class LabelCommand {
let str: string = `BAR ${x}, ${y}, ${width}, ${height}\r\n`; let str: string = `BAR ${x}, ${y}, ${width}, ${height}\r\n`;
this.addStrToCommand(str); this.addStrToCommand(str);
} }
/***
*
*/
addText(x: number, y: number, font: FONTTYPE, rotation: ROTATION, Xscal: FONTMUL, Yscal: FONTMUL, text: string): void { 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); this.addStrToCommand(str);
} }
addUserCommand(command: string): void { addUserCommand(command: string): void {
@ -365,7 +368,14 @@ export class LabelCommand {
this.addStrToCommand(str); this.addStrToCommand(str);
} }
getCommand() { 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 { addQueryPrinterType(): void {
let str: string = `~!T\r\n`; let str: string = `~!T\r\n`;

View File

@ -1,9 +1,12 @@
export * from './command' export * from './command'
import { LabelCommand } from '@/command/Label' import { FONTMUL, FONTTYPE, LabelCommand, ROTATION } from '@/command/Label'
function main() { function main() {
let label = new LabelCommand(50, 30, 0); 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(); main();