|
|
|
@ -171,25 +171,98 @@ export class ZPLGenerator { |
|
|
|
generateFontCommand(element) { |
|
|
|
let fontCmd = '^CI28' // 设置字符编码
|
|
|
|
|
|
|
|
// 根据字体族选择字体文件
|
|
|
|
// 字体族与ZPL字体字母映射表
|
|
|
|
const fontLetterMapping = { |
|
|
|
'Microsoft YaHei': 'J', |
|
|
|
'微软雅黑': 'J', |
|
|
|
'SimSun': 'K', |
|
|
|
'宋体': 'K', |
|
|
|
'SimHei': 'L', |
|
|
|
'黑体': 'L', |
|
|
|
'KaiTi': 'M', |
|
|
|
'楷体': 'M', |
|
|
|
'FangSong': 'N', |
|
|
|
'仿宋': 'N', |
|
|
|
'Microsoft JhengHei': 'O', |
|
|
|
'微軟正黑體': 'O', |
|
|
|
'PMingLiU': 'P', |
|
|
|
'新細明體': 'P', |
|
|
|
'DFKai-SB': 'Q', |
|
|
|
'標楷體': 'Q', |
|
|
|
'Arial': 'A', |
|
|
|
'Times New Roman': 'S', |
|
|
|
'Courier New': 'T', |
|
|
|
'Helvetica': 'U', |
|
|
|
'Verdana': 'V', |
|
|
|
'Georgia': 'W', |
|
|
|
'Tahoma': 'X', |
|
|
|
'Trebuchet MS': 'Y', |
|
|
|
'Lucida Console': 'Z', |
|
|
|
'Impact': 'A', |
|
|
|
'Comic Sans MS': 'B', |
|
|
|
'Palatino': 'C', |
|
|
|
'Garamond': 'D', |
|
|
|
'Bookman': 'E', |
|
|
|
'Century Gothic': 'F', |
|
|
|
'Franklin Gothic': 'G', |
|
|
|
'Gill Sans': 'H', |
|
|
|
'Optima': 'I', |
|
|
|
'Futura': 'J', |
|
|
|
'Bodoni': 'K', |
|
|
|
'Didot': 'L', |
|
|
|
'Consolas': 'M', |
|
|
|
'Monaco': 'N', |
|
|
|
'Menlo': 'O', |
|
|
|
'Source Code Pro': 'P', |
|
|
|
'Fira Code': 'Q', |
|
|
|
'JetBrains Mono': 'R', |
|
|
|
'Brush Script MT': 'S', |
|
|
|
'Papyrus': 'T', |
|
|
|
'Chalkboard': 'U', |
|
|
|
'Marker Felt': 'V', |
|
|
|
'Zapfino': 'W', |
|
|
|
'Snell Roundhand': 'X', |
|
|
|
'default': 'A', |
|
|
|
'Default': 'A' |
|
|
|
} |
|
|
|
|
|
|
|
// 根据字体族选择字体文件和字母
|
|
|
|
const fontFamily = element.fontFamily |
|
|
|
let fontLetter = 'A' |
|
|
|
let fontFile = 'ARIAL.TTF' |
|
|
|
if (fontFamily && fontFamily !== 'default') { |
|
|
|
const fontFile = this.mapFontFamilyToFile(fontFamily) |
|
|
|
if (fontFile) { |
|
|
|
fontCmd += ` ^CWJ,E:${fontFile}` |
|
|
|
console.log(`ZPL字体映射: ${fontFamily} -> ${fontFile}`) |
|
|
|
fontFile = this.mapFontFamilyToFile(fontFamily) |
|
|
|
// 判断是否为中文字体
|
|
|
|
const chineseFonts = [ |
|
|
|
'Microsoft YaHei', '微软雅黑', 'SimSun', '宋体', 'SimHei', '黑体', 'KaiTi', '楷体', 'FangSong', '仿宋', |
|
|
|
'Microsoft JhengHei', '华文宋体', '华文仿宋', '新細明體', '华文楷体', '新宋体' |
|
|
|
] |
|
|
|
if (chineseFonts.includes(fontFamily)) { |
|
|
|
fontLetter = 'J' |
|
|
|
} else { |
|
|
|
fontCmd += ' ^CWJ,E:ARIAL.TTF' // 默认字体
|
|
|
|
console.warn(`未找到字体映射: ${fontFamily},使用默认字体`) |
|
|
|
fontLetter = fontLetterMapping[fontFamily] || 'A' |
|
|
|
if (!fontLetterMapping[fontFamily]) { |
|
|
|
// 尝试模糊匹配
|
|
|
|
const lowerFontFamily = fontFamily.toLowerCase() |
|
|
|
for (const [key, value] of Object.entries(fontLetterMapping)) { |
|
|
|
if (key.toLowerCase().includes(lowerFontFamily) || lowerFontFamily.includes(key.toLowerCase())) { |
|
|
|
fontLetter = value |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
fontCmd += ` ^CW${fontLetter},E:${fontFile}` |
|
|
|
console.log(`ZPL字体映射: ${fontFamily} -> ${fontFile}, 字母: ${fontLetter}`) |
|
|
|
} else { |
|
|
|
fontCmd += ' ^CWJ,E:ARIAL.TTF' // 默认字体
|
|
|
|
console.log('使用默认字体: ARIAL.TTF') |
|
|
|
fontCmd += ' ^CWA,E:ARIAL.TTF' |
|
|
|
fontLetter = 'A' |
|
|
|
console.log('使用默认字体: ARIAL.TTF, 字母: J') |
|
|
|
} |
|
|
|
|
|
|
|
// 设置字体大小
|
|
|
|
const fontSize = element.fontSize || 30 |
|
|
|
fontCmd += ` ^CFJ,${fontSize}` |
|
|
|
fontCmd += ` ^CF${fontLetter},${fontSize}` |
|
|
|
|
|
|
|
// 添加调试信息
|
|
|
|
console.log(`生成字体命令: ${fontCmd}`) |
|
|
|
@ -206,8 +279,8 @@ export class ZPLGenerator { |
|
|
|
// 中文字体
|
|
|
|
'Microsoft YaHei': 'MSYH.TTF', |
|
|
|
'微软雅黑': 'MSYH.TTF', |
|
|
|
'SimSun': 'SIMSUN.TTC', |
|
|
|
'宋体': 'SIMSUN.TTC', |
|
|
|
'SimSun': 'SIMSUN.TTF', |
|
|
|
'宋体': 'SIMSUN.TTF', |
|
|
|
'SimHei': 'SIMHEI.TTF', |
|
|
|
'黑体': 'SIMHEI.TTF', |
|
|
|
'KaiTi': 'KAITI.TTF', |
|
|
|
|