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

8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
  1. export function generateZPL(elements,zplHOrP) {
  2. const zpl = ['^XA'];
  3. zpl.push(zplHOrP)
  4. elements.forEach(el => {
  5. const x = Math.round(el.x);
  6. const y = Math.round(el.y * 1.5); // 画布到 ZPL 像素转换
  7. switch (el.type) {
  8. case 'text':
  9. zpl.push(`^CI28^LH0,^JUS^CWJ,E:SIMSUN.FNT^CFJ,${el.fontSize},${el.fontSize}`);
  10. zpl.push(el.newline
  11. ? `^FO${x},${y}^FB${el.lineWidth},${el.lineRows},0^CFJ,${el.fontSize}^FD${el.data}^FS`
  12. : `^FO${x},${y}^FD${el.data}^FS`);
  13. if (el.bold) {
  14. zpl.push(el.newline
  15. ? `^FO${x+1},${y}^FB${el.lineWidth},${el.lineRows},0^CFJ,${el.fontSize}^FD${el.data}^FS`
  16. : `^FO${x+1},${y}^FD${el.data}^FS`);
  17. zpl.push(el.newline
  18. ? `^FO${x},${y+1}^FB${el.lineWidth},${el.lineRows},0^CFJ,${el.fontSize}^FD${el.data}^FS`
  19. : `^FO${x},${y+1}^FD${el.data}^FS`);
  20. zpl.push(el.newline
  21. ? `^FO${x+1},${y+1}^FB${el.lineWidth},${el.lineRows},0^CFJ,${el.fontSize}^FD${el.data}^FS`
  22. : `^FO${x+1},${y+1}^FD${el.data}^FS`);
  23. }
  24. break;
  25. case 'barcode':
  26. zpl.push(`^FO${x},${y}^BY${el.width}^BCN,${el.height},^FD${el.data}^FS`);
  27. break;
  28. case 'qrcode':
  29. zpl.push(`^FO${x},${y}^BQN,2,${el.height},^FDLA,${el.data}^FS`);
  30. break;
  31. case 'onecode':
  32. zpl.push(`^FO${x},${y}^BY${el.width}^BCN,${el.height},^FD${el.data}^FS`);
  33. break;
  34. case 'pic':
  35. if (el.data) {
  36. zpl.push(`^FO${x},${y}^GFA,${el.data}`);
  37. }
  38. break;
  39. case 'hLine':
  40. zpl.push(`^FO${x},${y}^GB${el.width},${el.height},3,B^FS`);
  41. break;
  42. case 'vLine':
  43. zpl.push(`^FO${x},${y}^GB1,${el.height},${el.width},B^FS`);
  44. break;
  45. }
  46. });
  47. zpl.push('^XZ');
  48. return zpl.join('\n');
  49. }