feat: 添加注释
This commit is contained in:
parent
bc169183ba
commit
922d82e27c
20
README.md
20
README.md
@ -2,7 +2,23 @@
|
|||||||
|
|
||||||
https://www.npmjs.com/package/@taoya7/print-help
|
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
|
```javascript
|
||||||
import { FONTMUL, FONTTYPE, LabelCommand, ROTATION } from '@/command/Label'
|
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');
|
label.addText(0, 0, FONTTYPE.FONT_1, ROTATION.ROTATION_0, FONTMUL.MUL_1, FONTMUL.MUL_1, 'Hello World');
|
||||||
var command = label.getCommand();
|
var command = label.getCommand();
|
||||||
console.log(command);// 获取字节码
|
console.log(command);// 获取字节码
|
||||||
console.log(label.getCommandStr(command));
|
console.log(label.getCommandStr(command)); // 转换命令字符串
|
||||||
}
|
}
|
||||||
main();
|
main();
|
||||||
```
|
```
|
@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "@taoya7/print-help",
|
"name": "@taoya7/print-help",
|
||||||
"version": "1.0.3",
|
"version": "1.0.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"佳博打印机"
|
"佳博打印机",
|
||||||
|
"打印机"
|
||||||
],
|
],
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
|
@ -179,6 +179,7 @@ export class LabelCommand {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 定义两张标签之间的间隙距离
|
* 定义两张标签之间的间隙距离
|
||||||
|
* @param gap 定义标签间隙高度 (mm)
|
||||||
*/
|
*/
|
||||||
addGap(gap: number) {
|
addGap(gap: number) {
|
||||||
let str = "GAP " + gap + " mm," + 0 + " mm\r\n";
|
let str = "GAP " + gap + " mm," + 0 + " mm\r\n";
|
||||||
@ -186,6 +187,8 @@ export class LabelCommand {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 设定黑标高度及使用者定义标签印完后标签额外送出的长度
|
* 设定黑标高度及使用者定义标签印完后标签额外送出的长度
|
||||||
|
* 连续纸模式 GAP 0,0
|
||||||
|
* @param bline 额外送出纸张长度 (mm)
|
||||||
*/
|
*/
|
||||||
addBline(bline: number) {
|
addBline(bline: number) {
|
||||||
let str = "BLINE " + bline + " mm," + 0 + " mm\r\n";
|
let str = "BLINE " + bline + " mm," + 0 + " mm\r\n";
|
||||||
@ -193,6 +196,8 @@ export class LabelCommand {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 定义标签纸的宽度及高度
|
* 定义标签纸的宽度及高度
|
||||||
|
* @param height 定义标签纸的高度 (mm)
|
||||||
|
* @param width 定义标签纸的宽度 (mm)
|
||||||
*/
|
*/
|
||||||
addSize(width: number, height: number): void {
|
addSize(width: number, height: number): void {
|
||||||
const str = "SIZE " + width + " mm," + height + " mm\r\n";
|
const str = "SIZE " + width + " mm," + height + " mm\r\n";
|
||||||
@ -202,50 +207,102 @@ export class LabelCommand {
|
|||||||
let str: string = `CASHDRAWER ${m},${t1},${t2}\r\n`;
|
let str: string = `CASHDRAWER ${m},${t1},${t2}\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 定义标签于打印完后额外推出的长度,特別是在使用自动剥纸器或裁刀功能时,可用来
|
||||||
|
* 调校标签停止的位置,在打印下一张时打印机会将原先多推出或少推出的部分以回拉方
|
||||||
|
* 式补偿回来。此方式适用于剥离模式和裁刀模式。
|
||||||
|
* @param offset 偏移距离 (mm)
|
||||||
|
*/
|
||||||
addOffset(offset: number): void {
|
addOffset(offset: number): void {
|
||||||
let str: string = `OFFSET ${offset} mm\r\n`;
|
let str: string = `OFFSET ${offset} mm\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 设定打印机的打印速度
|
||||||
|
* @param speed
|
||||||
|
*/
|
||||||
addSpeed(speed: SPEED): void {
|
addSpeed(speed: SPEED): void {
|
||||||
let str: string = `SPEED ${speed / 10}\r\n`;
|
let str: string = `SPEED ${speed / 10}\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 设定打印机的打印浓度
|
||||||
|
* @param density
|
||||||
|
*/
|
||||||
addDensity(density: DENSITY): void {
|
addDensity(density: DENSITY): void {
|
||||||
let str: string = `DENSITY ${density}\r\n`;
|
let str: string = `DENSITY ${density}\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 设定打印方向,此设定将被记录于 EEPROM
|
||||||
|
* @param direction 0-翻转 1-顺序
|
||||||
|
* @param mirror
|
||||||
|
*/
|
||||||
addDirection(direction: DIRECTION, mirror: MIRROR): void {
|
addDirection(direction: DIRECTION, mirror: MIRROR): void {
|
||||||
let str: string = `DIRECTION ${direction}, ${mirror}\r\n`;
|
let str: string = `DIRECTION ${direction}, ${mirror}\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 定义标签纸上的相對于原点的参考点座标
|
||||||
|
* @param x 水平座标,单位 “dot”
|
||||||
|
* @param y 垂直座标,单位 “dot”
|
||||||
|
*/
|
||||||
addReference(x: number, y: number): void {
|
addReference(x: number, y: number): void {
|
||||||
let str: string = `REFERENCE ${x}, ${y}\r\n`;
|
let str: string = `REFERENCE ${x}, ${y}\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 该指令表示标签打印偏移量多少设置
|
||||||
|
* @param shift 最大值为 1 inch,以点(dot)为单位
|
||||||
|
*/
|
||||||
addShift(shift: number): void {
|
addShift(shift: number): void {
|
||||||
let str: string = `SHIFT ${shift}\r\n`;
|
let str: string = `SHIFT ${shift}\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 清除数据缓存
|
||||||
|
* 注意事项:此项指令必须置于 SIZE 指令之后
|
||||||
|
*/
|
||||||
addCls(): void {
|
addCls(): void {
|
||||||
let str: string = `CLS\r\n`;
|
let str: string = `CLS\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 将标签纸向前推送指定的长度 (送出纸)
|
||||||
|
* @param dot 单位:dot
|
||||||
|
*/
|
||||||
addFeed(dot: number): void {
|
addFeed(dot: number): void {
|
||||||
let str: string = `FEED ${dot}\r\n`;
|
let str: string = `FEED ${dot}\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 将标签纸向后回拉指定的长度 (回收纸)
|
||||||
|
* @param dot 单位:dot
|
||||||
|
*/
|
||||||
addBackFeed(dot: number): void {
|
addBackFeed(dot: number): void {
|
||||||
let str: string = `BACKFEED ${dot}\r\n`;
|
let str: string = `BACKFEED ${dot}\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 将标签向前推送至下一张标签的起始位置
|
||||||
|
*/
|
||||||
addFormFeed(): void {
|
addFormFeed(): void {
|
||||||
let str: string = `FORMFEED\r\n`;
|
let str: string = `FORMFEED\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 在使用含有间隙或黑标的标签纸时,若不能确定第一张标签纸是否在正确打印位置时,
|
||||||
|
* 此指令可将标签纸向前推送至下一张标签纸的起点开始打印
|
||||||
|
*/
|
||||||
addHome(): void {
|
addHome(): void {
|
||||||
let str: string = `HOME\r\n`;
|
let str: string = `HOME\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 将存于数据缓存的标签打印
|
||||||
|
* @param m 打印张数
|
||||||
|
* @param n 每张标签需重复打印的张数
|
||||||
|
*/
|
||||||
addPrint(m: number, n?: number): void {
|
addPrint(m: number, n?: number): void {
|
||||||
let str: string = n ? `PRINT ${m}, ${n}\r\n` : `PRINT ${m}\r\n`;
|
let str: string = n ? `PRINT ${m}, ${n}\r\n` : `PRINT ${m}\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
@ -278,6 +335,13 @@ export class LabelCommand {
|
|||||||
let str: string = `SELFTEST\r\n`;
|
let str: string = `SELFTEST\r\n`;
|
||||||
this.addStrToCommand(str);
|
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 {
|
addBar(x: number, y: number, width: number, height: number): void {
|
||||||
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);
|
||||||
@ -312,6 +376,10 @@ export class LabelCommand {
|
|||||||
'"\r\n';
|
'"\r\n';
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 添加自定义指令
|
||||||
|
* @param command 指令字符串
|
||||||
|
*/
|
||||||
addUserCommand(command: string): void {
|
addUserCommand(command: string): void {
|
||||||
this.addStrToCommand(command);
|
this.addStrToCommand(command);
|
||||||
}
|
}
|
||||||
@ -420,6 +488,15 @@ export class LabelCommand {
|
|||||||
let str: string = `~!T\r\n`;
|
let str: string = `~!T\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 绘制 QRCODE 二维条码
|
||||||
|
* @param x QRCODE 条码左上角 X 座标
|
||||||
|
* @param y QRCODE 条码左上角 Y 座标
|
||||||
|
* @param level 错误纠正能力等级
|
||||||
|
* @param cellwidth 1~10
|
||||||
|
* @param rotation 顺时针旋转角度
|
||||||
|
* @param data 条码资料内容
|
||||||
|
*/
|
||||||
public addQRCode(
|
public addQRCode(
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
@ -431,10 +508,24 @@ export class LabelCommand {
|
|||||||
let str: string = `QRCODE ${x}, ${y}, ${level}, ${cellwidth}, A, ${rotation}, "${data}"\r\n`;
|
let str: string = `QRCODE ${x}, ${y}, ${level}, ${cellwidth}, A, ${rotation}, "${data}"\r\n`;
|
||||||
this.addStrToCommand(str);
|
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 {
|
addReverse(x: number, y: number, xwidth: number, yheight: number): void {
|
||||||
let str = `REVERSE ${x}, ${y}, ${xwidth}, ${yheight}\r\n`;
|
let str = `REVERSE ${x}, ${y}, ${xwidth}, ${yheight}\r\n`;
|
||||||
this.addStrToCommand(str);
|
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 {
|
addErase(x: number, y: number, xwidth: number, yheight: number): void {
|
||||||
let str = `ERASE ${x},${y},${xwidth},${yheight}\r\n`;
|
let str = `ERASE ${x},${y},${xwidth},${yheight}\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
@ -449,6 +540,18 @@ export class LabelCommand {
|
|||||||
let str = `DMATRIX ${x},${y},${width},${height},"${content}"\r\n`;
|
let str = `DMATRIX ${x},${y},${width},${height},"${content}"\r\n`;
|
||||||
this.addStrToCommand(str);
|
this.addStrToCommand(str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 印制一维条码,
|
||||||
|
* @param x 明定条码左上角 X 座标
|
||||||
|
* @param y 明定条码左上角 Y 座标
|
||||||
|
* @param type
|
||||||
|
* @param height
|
||||||
|
* @param readable
|
||||||
|
* @param rotation
|
||||||
|
* @param narrow
|
||||||
|
* @param width
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
add1DBarcode(
|
add1DBarcode(
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
|
@ -9,7 +9,7 @@ import {
|
|||||||
} from "@/command/Label";
|
} from "@/command/Label";
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
let label = new LabelCommand(50, 30, 0);
|
let label = new LabelCommand(50, 30, 0); // 长,宽,gap
|
||||||
label.addText(
|
label.addText(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
Loading…
Reference in New Issue
Block a user