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