diff --git a/src/utils/zplGenerator.js b/src/utils/zplGenerator.js index 1bc03d8..64e771d 100644 --- a/src/utils/zplGenerator.js +++ b/src/utils/zplGenerator.js @@ -119,20 +119,20 @@ export class ZPLGenerator { */ generateTextZPL(element, x, y) { const zpl = [] - + // 生成字体命令 const fontCommand = this.generateFontCommand(element) zpl.push(fontCommand) - + if (element.isChecked) { zpl.push(`^FO${x-60},${y}^GB45,45,2,B,0^FS ^FO${x-50},${y+10}^AJN,35,35^FD√^FS `) } - + const lineWidth = Math.max(1, Math.round((element.lineWidth || 200) * this.dpi / 25.4)) - + // 处理文本对齐 const alignmentParam = this.getTextAlignmentParam(element.textAlign) - + // 基础文本 const textCommand = element.newline ? `^FO${x},${y}^FB${lineWidth},${element.lineRows},0,${alignmentParam}^CFJ,${element.fontSize}^FD${element.data}^FS` @@ -170,7 +170,7 @@ export class ZPLGenerator { */ generateFontCommand(element) { let fontCmd = '^CI28' // 设置字符编码 - + // 根据字体族选择字体文件 const fontFamily = element.fontFamily if (fontFamily && fontFamily !== 'default') { @@ -179,22 +179,22 @@ export class ZPLGenerator { fontCmd += ` ^CWJ,E:${fontFile}` console.log(`ZPL字体映射: ${fontFamily} -> ${fontFile}`) } else { - fontCmd += ' ^CWJ,E:MSYH.TTF' // 默认字体 + fontCmd += ' ^CWJ,E:ARIAL.TTF' // 默认字体 console.warn(`未找到字体映射: ${fontFamily},使用默认字体`) } } else { - fontCmd += ' ^CWJ,E:MSYH.TTF' // 默认字体 - console.log('使用默认字体: MSYH.TTF') + fontCmd += ' ^CWJ,E:ARIAL.TTF' // 默认字体 + console.log('使用默认字体: ARIAL.TTF') } - + // 设置字体大小 const fontSize = element.fontSize || 30 fontCmd += ` ^CFJ,${fontSize}` - + // 添加调试信息 console.log(`生成字体命令: ${fontCmd}`) console.log(`字体族: ${fontFamily}, 字体大小: ${fontSize}`) - + return fontCmd } @@ -220,7 +220,7 @@ export class ZPLGenerator { '新細明體': 'PMINGLIU.TTF', 'DFKai-SB': 'DFKAI.TTF', '標楷體': 'DFKAI.TTF', - + // 英文字体 'Arial': 'ARIAL.TTF', 'Times New Roman': 'TIMES.TTF', @@ -243,7 +243,7 @@ export class ZPLGenerator { 'Futura': 'FUTURA.TTF', 'Bodoni': 'BODONI.TTF', 'Didot': 'DIDOT.TTF', - + // 等宽字体 'Consolas': 'CONSOLAS.TTF', 'Monaco': 'MONACO.TTF', @@ -251,7 +251,7 @@ export class ZPLGenerator { 'Source Code Pro': 'SOURCECODE.TTF', 'Fira Code': 'FIRACODE.TTF', 'JetBrains Mono': 'JETBRAINS.TTF', - + // 装饰字体 'Brush Script MT': 'BRUSHSCRIPT.TTF', 'Papyrus': 'PAPYRUS.TTF', @@ -259,12 +259,12 @@ export class ZPLGenerator { 'Marker Felt': 'MARKERFELT.TTF', 'Zapfino': 'ZAPFINO.TTF', 'Snell Roundhand': 'SNELLROUND.TTF', - + // 默认字体 - 'default': 'MSYH.TTF', - 'Default': 'MSYH.TTF' + 'default': 'ARIAL.TTF', + 'Default': 'ARIAL.TTF' } - + // 如果找不到精确匹配,尝试模糊匹配 if (!fontMapping[fontFamily]) { const lowerFontFamily = fontFamily.toLowerCase() @@ -274,8 +274,8 @@ export class ZPLGenerator { } } } - - return fontMapping[fontFamily] || 'MSYH.TTF' // 默认返回微软雅黑 + + return fontMapping[fontFamily] || 'ARIAL.TTF' // 默认返回ARIAL } /** @@ -295,11 +295,11 @@ export class ZPLGenerator { */ estimateTextWidth(text, fontSize) { if (!text) return 0 - + // 简单估算:中文字符按字体大小计算,英文字符按字体大小的0.6倍计算 let chineseCount = 0 let englishCount = 0 - + for (let i = 0; i < text.length; i++) { const char = text.charAt(i) if (char.match(/[\u4e00-\u9fff]/)) { @@ -308,7 +308,7 @@ export class ZPLGenerator { englishCount++ } } - + return Math.round(chineseCount * fontSize + englishCount * fontSize * 0.6) } @@ -436,22 +436,22 @@ export class ZPLGenerator { */ generateSerialNumberZPL(element, x, y) { const zpl = [] - + // 生成字体命令 const fontCommand = this.generateFontCommand(element) zpl.push(fontCommand) - + const bold = element.bold || false const base = `^FO${x},${y}^FD${element.data}^FS` zpl.push(base) - + // 可选:加粗效果(重复打印) if (bold) { zpl.push(`^FO${x + 1},${y}^FD${element.data}^FS`) zpl.push(`^FO${x},${y + 1}^FD${element.data}^FS`) zpl.push(`^FO${x + 1},${y + 1}^FD${element.data}^FS`) } - + return zpl.join('\n') } } diff --git a/src/views/modules/labelSetting/components/PaperSelector.vue b/src/views/modules/labelSetting/components/PaperSelector.vue index 900047b..d07f9a1 100644 --- a/src/views/modules/labelSetting/components/PaperSelector.vue +++ b/src/views/modules/labelSetting/components/PaperSelector.vue @@ -11,12 +11,13 @@