Compare commits
3 Commits
bc169183ba
...
ce4916d3a1
Author | SHA1 | Date | |
---|---|---|---|
ce4916d3a1 | |||
42af6d8906 | |||
922d82e27c |
20
README.md
20
README.md
@ -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();
|
||||
```
|
@ -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"
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 inch,以点(dot)为单位
|
||||
*/
|
||||
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,
|
||||
|
47
src/index.ts
47
src/index.ts
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user