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.
59 lines
1.9 KiB
59 lines
1.9 KiB
export function generateZPL(elements,zplHOrP) {
|
|
const zpl = ['^XA'];
|
|
//zpl.push('^POI');
|
|
zpl.push(zplHOrP)
|
|
elements.forEach(el => {
|
|
const x = Math.round(el.y * 1.3);
|
|
const y = Math.round((750-el.x) * 1.5); // 你之前的转换比例保持不变
|
|
|
|
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}^BCB,${el.height},Y,N,N^FD${el.data}^FS`);
|
|
break;
|
|
|
|
case 'qrcode':
|
|
zpl.push(`^FO${x},${y}^BQB,2,${el.height},^FDLA,${el.data}^FS`);
|
|
break;
|
|
|
|
case 'onecode':
|
|
zpl.push(`^FO${x},${y}^BY${el.width}^BCB,${el.height},^FD${el.data}^FS`);
|
|
break;
|
|
|
|
case 'pic':
|
|
if (el.data) {
|
|
zpl.push(`^FO${x},${y}^GFA,${el.data}`);
|
|
}
|
|
break;
|
|
|
|
case 'hLine':
|
|
const y1 = Math.round(1200-el.x)-el.width;
|
|
zpl.push(`^FO${x},${y1}^FWR^GB${el.height},${el.width},3,B^FS`);
|
|
break;
|
|
case 'vLine':
|
|
zpl.push(`^FO${x},${y}^FWR^GB${el.height},${el.width},3,B^FS`);
|
|
break;
|
|
|
|
|
|
}
|
|
});
|
|
zpl.push('^XZ');
|
|
return zpl.join('\n');
|
|
}
|