Compare commits

...

3 Commits

Author SHA1 Message Date
ce4916d3a1 feat: Buffer 2024-03-14 08:36:10 +08:00
42af6d8906 feat: 中文 2024-03-13 22:44:10 +08:00
922d82e27c feat: 添加注释 2024-03-13 10:06:53 +08:00
5 changed files with 196 additions and 35 deletions

View File

@ -2,7 +2,23 @@
https://www.npmjs.com/package/@taoya7/print-help
示例
PDF文档
https://wiki.taoya.art/s/6712b96b-c67e-4e17-b3f7-ba12e7d146bf
> 注意
200 DPI: 1 mm = 8 dots
300 DPI: 1mm = 12 dots
在公制系统下, 在参数 m 与 “mm” 之间必须要有空格分隔
**示例**
```javascript
import { FONTMUL, FONTTYPE, LabelCommand, ROTATION } from '@/command/Label'
@ -12,7 +28,7 @@ function main() {
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));
console.log(label.getCommandStr(command)); // 转换命令字符串
}
main();
```

View File

@ -1,10 +1,10 @@
{
"name": "@taoya7/print-help",
"version": "1.0.3",
"version": "1.0.12",
"license": "MIT",
"type": "module",
"keywords": [
"佳博打印机"
"佳博打印机",
"打印机"
],
"exports": {
".": {
@ -25,10 +25,12 @@
"devDependencies": {
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.11.25",
"buffer": "^6.0.3",
"typescript": "^5.4.2",
"unbuild": "^2.0.0"
},
"dependencies": {
"iconv-lite": "^0.6.3",
"lodash-es": "^4.17.21",
"rollup-obfuscator": "^4.1.1"
}

View File

@ -5,6 +5,9 @@ settings:
excludeLinksFromLockfile: false
dependencies:
iconv-lite:
specifier: ^0.6.3
version: 0.6.3
lodash-es:
specifier: ^4.17.21
version: 4.17.21
@ -19,6 +22,9 @@ devDependencies:
'@types/node':
specifier: ^20.11.25
version: 20.11.25
buffer:
specifier: ^6.0.3
version: 6.0.3
typescript:
specifier: ^5.4.2
version: 5.4.2
@ -711,6 +717,10 @@ packages:
/balanced-match@1.0.2:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
/base64-js@1.5.1:
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
dev: true
/boolbase@1.0.0:
resolution: {integrity: sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==}
dev: true
@ -750,6 +760,13 @@ packages:
resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==}
dev: false
/buffer@6.0.3:
resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==}
dependencies:
base64-js: 1.5.1
ieee754: 1.2.1
dev: true
/builtin-modules@3.3.0:
resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==}
engines: {node: '>=6'}
@ -1351,6 +1368,17 @@ packages:
resolution: {integrity: sha512-Yc+BQe8SvoXH1643Qez1zqLRmbA5rCL+sSmk6TVos0LWVfNIB7PGncdlId77WzLGSIB5KaWgTaNTs2lNVEI6VQ==}
dev: true
/iconv-lite@0.6.3:
resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==}
engines: {node: '>=0.10.0'}
dependencies:
safer-buffer: 2.1.2
dev: false
/ieee754@1.2.1:
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
dev: true
/ignore@5.3.1:
resolution: {integrity: sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==}
engines: {node: '>= 4'}
@ -2145,6 +2173,10 @@ packages:
queue-microtask: 1.2.3
dev: true
/safer-buffer@2.1.2:
resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==}
dev: false
/scule@1.3.0:
resolution: {integrity: sha512-6FtHJEvt+pVMIB9IBY+IcCJ6Z5f1iQnytgyfKMhDKgmzYG+TeH/wx1y3l27rshSbLiSanrR9ffZDrEsmjlQF2g==}
dev: true

View File

@ -1,4 +1,5 @@
import _ from "lodash-es";
import { Buffer } from 'buffer'
export enum FOOT {
F2 = 0,
@ -169,16 +170,24 @@ export class LabelCommand {
public clrCommand() {
this.command = [];
}
private addStrToCommand(str: string): void {
addStrToCommand(str: string): void {
if (str !== "") {
let bs: Buffer = Buffer.from(str, "utf8");
const bs = Buffer.from(str, "utf8");
for (let i = 0; i < bs.length; ++i) {
this.command.push(bs[i]);
}
}
}
/**
*
* @param number
*/
public addToCommand(number: number[]) {
this.command = this.command.concat(number);
}
/**
*
* @param gap (mm)
*/
addGap(gap: number) {
let str = "GAP " + gap + " mm," + 0 + " mm\r\n";
@ -186,6 +195,8 @@ export class LabelCommand {
}
/**
* 使
* GAP 0,0
* @param bline (mm)
*/
addBline(bline: number) {
let str = "BLINE " + bline + " mm," + 0 + " mm\r\n";
@ -193,6 +204,8 @@ export class LabelCommand {
}
/**
*
* @param height (mm)
* @param width (mm)
*/
addSize(width: number, height: number): void {
const str = "SIZE " + width + " mm," + height + " mm\r\n";
@ -202,50 +215,102 @@ export class LabelCommand {
let str: string = `CASHDRAWER ${m},${t1},${t2}\r\n`;
this.addStrToCommand(str);
}
/**
* 使
*
*
* @param offset (mm)
*/
addOffset(offset: number): void {
let str: string = `OFFSET ${offset} mm\r\n`;
this.addStrToCommand(str);
}
/**
*
* @param speed
*/
addSpeed(speed: SPEED): void {
let str: string = `SPEED ${speed / 10}\r\n`;
this.addStrToCommand(str);
}
/**
*
* @param density
*/
addDensity(density: DENSITY): void {
let str: string = `DENSITY ${density}\r\n`;
this.addStrToCommand(str);
}
/**
* EEPROM
* @param direction 0- 1-
* @param mirror
*/
addDirection(direction: DIRECTION, mirror: MIRROR): void {
let str: string = `DIRECTION ${direction}, ${mirror}\r\n`;
this.addStrToCommand(str);
}
/**
*
* @param x dot
* @param y dot
*/
addReference(x: number, y: number): void {
let str: string = `REFERENCE ${x}, ${y}\r\n`;
this.addStrToCommand(str);
}
/**
*
* @param shift 1 inchdot
*/
addShift(shift: number): void {
let str: string = `SHIFT ${shift}\r\n`;
this.addStrToCommand(str);
}
/**
*
* SIZE
*/
addCls(): void {
let str: string = `CLS\r\n`;
this.addStrToCommand(str);
}
/**
* ()
* @param dot dot
*/
addFeed(dot: number): void {
let str: string = `FEED ${dot}\r\n`;
this.addStrToCommand(str);
}
/**
* ()
* @param dot dot
*/
addBackFeed(dot: number): void {
let str: string = `BACKFEED ${dot}\r\n`;
this.addStrToCommand(str);
}
/**
*
*/
addFormFeed(): void {
let str: string = `FORMFEED\r\n`;
this.addStrToCommand(str);
}
/**
* 使
*
*/
addHome(): void {
let str: string = `HOME\r\n`;
this.addStrToCommand(str);
}
/**
*
* @param m
* @param n
*/
addPrint(m: number, n?: number): void {
let str: string = n ? `PRINT ${m}, ${n}\r\n` : `PRINT ${m}\r\n`;
this.addStrToCommand(str);
@ -278,6 +343,13 @@ export class LabelCommand {
let str: string = `SELFTEST\r\n`;
this.addStrToCommand(str);
}
/**
* 线
* @param x 线 X dot
* @param y 线 Y dot
* @param width 线 dot
* @param height 线 dot
*/
addBar(x: number, y: number, width: number, height: number): void {
let str: string = `BAR ${x}, ${y}, ${width}, ${height}\r\n`;
this.addStrToCommand(str);
@ -312,6 +384,10 @@ export class LabelCommand {
'"\r\n';
this.addStrToCommand(str);
}
/**
*
* @param command
*/
addUserCommand(command: string): void {
this.addStrToCommand(command);
}
@ -410,16 +486,26 @@ export class LabelCommand {
*
*/
getCommandStr(command: number[]) {
let str = "";
for (let i = 0; i < command.length; i++) {
str += String.fromCharCode(command[i]);
}
// 创建一个Buffer实例来存储字节数组
const buffer = Buffer.from(command);
const str = buffer.toString('utf8'); // 指定utf8编码
return str;
}
addQueryPrinterType(): void {
let str: string = `~!T\r\n`;
this.addStrToCommand(str);
}
/**
* QRCODE
* @param x QRCODE X
* @param y QRCODE Y
* @param level
* @param cellwidth 1~10
* @param rotation
* @param data
*/
public addQRCode(
x: number,
y: number,
@ -431,10 +517,24 @@ export class LabelCommand {
let str: string = `QRCODE ${x}, ${y}, ${level}, ${cellwidth}, A, ${rotation}, "${data}"\r\n`;
this.addStrToCommand(str);
}
/**
*
* @param x X dot
* @param y Y dot
* @param xwidth dot
* @param yheight dot
*/
addReverse(x: number, y: number, xwidth: number, yheight: number): void {
let str = `REVERSE ${x}, ${y}, ${xwidth}, ${yheight}\r\n`;
this.addStrToCommand(str);
}
/**
*
* @param x X dot
* @param y Y dot
* @param xwidth dot
* @param yheight dot
*/
addErase(x: number, y: number, xwidth: number, yheight: number): void {
let str = `ERASE ${x},${y},${xwidth},${yheight}\r\n`;
this.addStrToCommand(str);
@ -449,6 +549,18 @@ export class LabelCommand {
let str = `DMATRIX ${x},${y},${width},${height},"${content}"\r\n`;
this.addStrToCommand(str);
}
/**
*
* @param x X
* @param y Y
* @param type
* @param height
* @param readable
* @param rotation
* @param narrow
* @param width
* @param content
*/
add1DBarcode(
x: number,
y: number,

View File

@ -1,27 +1,26 @@
export * from "./command";
import {
FONTMUL,
FONTTYPE,
LabelCommand,
ROTATION,
EEC,
} from "@/command/Label";
// import {
// FONTMUL,
// FONTTYPE,
// LabelCommand,
// ROTATION,
// } from "@/command/Label";
function main() {
let label = new LabelCommand(50, 30, 0);
label.addText(
0,
0,
FONTTYPE.FONT_1,
ROTATION.ROTATION_0,
FONTMUL.MUL_1,
FONTMUL.MUL_1,
"Hello World"
);
label.addQRCode(0, 0, EEC.LEVEL_L, 5, ROTATION.ROTATION_0, "taoya.art");
var command = label.getCommand();
console.log(command); // 获取字节码
console.log(label.getCommandStr(command));
}
main();
// 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();