You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.8 KiB
56 lines
1.8 KiB
export function generateZPL(elements,zplHOrP) {
|
|
const zpl = ['^XA'];
|
|
zpl.push(zplHOrP)
|
|
elements.forEach(el => {
|
|
const x = Math.round(el.x);
|
|
const y = Math.round(el.y * 1.5); // 画布到 ZPL 像素转换
|
|
|
|
switch (el.type) {
|
|
case 'text':
|
|
zpl.push(`^CI28^LH0,^JUS^CWJ,E:SIMSUN.FNT^CFJ,${el.fontSize},${el.fontSize}`);
|
|
zpl.push(el.newline
|
|
? `^FO${x},${y}^FB${el.lineWidth},${el.lineRows},0^CFJ,${el.fontSize}^FD${el.data}^FS`
|
|
: `^FO${x},${y}^FD${el.data}^FS`);
|
|
if (el.bold) {
|
|
zpl.push(el.newline
|
|
? `^FO${x+1},${y}^FB${el.lineWidth},${el.lineRows},0^CFJ,${el.fontSize}^FD${el.data}^FS`
|
|
: `^FO${x+1},${y}^FD${el.data}^FS`);
|
|
zpl.push(el.newline
|
|
? `^FO${x},${y+1}^FB${el.lineWidth},${el.lineRows},0^CFJ,${el.fontSize}^FD${el.data}^FS`
|
|
: `^FO${x},${y+1}^FD${el.data}^FS`);
|
|
zpl.push(el.newline
|
|
? `^FO${x+1},${y+1}^FB${el.lineWidth},${el.lineRows},0^CFJ,${el.fontSize}^FD${el.data}^FS`
|
|
: `^FO${x+1},${y+1}^FD${el.data}^FS`);
|
|
}
|
|
break;
|
|
|
|
case 'barcode':
|
|
zpl.push(`^FO${x},${y}^BY${el.width}^BCN,${el.height},^FD${el.data}^FS`);
|
|
break;
|
|
|
|
case 'qrcode':
|
|
zpl.push(`^FO${x},${y}^BQN,2,${el.height},^FDLA,${el.data}^FS`);
|
|
break;
|
|
|
|
case 'onecode':
|
|
zpl.push(`^FO${x},${y}^BY${el.width}^BCN,${el.height},^FD${el.data}^FS`);
|
|
break;
|
|
|
|
case 'pic':
|
|
if (el.data) {
|
|
zpl.push(`^FO${x},${y}^GFA,${el.data}`);
|
|
}
|
|
break;
|
|
|
|
case 'hLine':
|
|
zpl.push(`^FO${x},${y}^GB${el.width},${el.height},3,B^FS`);
|
|
break;
|
|
|
|
case 'vLine':
|
|
zpl.push(`^FO${x},${y}^GB1,${el.height},${el.width},B^FS`);
|
|
break;
|
|
}
|
|
});
|
|
zpl.push('^XZ');
|
|
return zpl.join('\n');
|
|
}
|