|
|
|
@ -1,5 +1,8 @@ |
|
|
|
import { CoordinateTransformer } from './coordinateTransform.js' |
|
|
|
|
|
|
|
const DEFAULT_FONT_FILE = 'ARIAL UNICODE MS.TTF' |
|
|
|
const DEFAULT_FONT_LETTER = 'J' |
|
|
|
|
|
|
|
/** |
|
|
|
* ZPL代码生成器 |
|
|
|
* 统一处理不同打印方向的ZPL代码生成 |
|
|
|
@ -331,6 +334,8 @@ export class ZPLGenerator { |
|
|
|
'新細明體': 'P', |
|
|
|
'DFKai-SB': 'Q', |
|
|
|
'標楷體': 'Q', |
|
|
|
'Arial Unicode MS': 'J', |
|
|
|
'Arial Unicode': 'J', |
|
|
|
'Arial': 'A', |
|
|
|
'Times New Roman': 'S', |
|
|
|
'Courier New': 'T', |
|
|
|
@ -364,14 +369,16 @@ export class ZPLGenerator { |
|
|
|
'Marker Felt': 'V', |
|
|
|
'Zapfino': 'W', |
|
|
|
'Snell Roundhand': 'X', |
|
|
|
'default': 'A', |
|
|
|
'Default': 'A' |
|
|
|
'default': 'J', |
|
|
|
'Default': 'J', |
|
|
|
'ARIAL UNICODE MS.TTF': 'J', |
|
|
|
'ARIALUNI.TTF': 'J' |
|
|
|
} |
|
|
|
|
|
|
|
// 根据字体族选择字体文件和字母
|
|
|
|
const fontFamily = element.fontFamily |
|
|
|
let fontLetter = 'A' |
|
|
|
let fontFile = 'ARIAL.TTF' |
|
|
|
let fontLetter = DEFAULT_FONT_LETTER |
|
|
|
let fontFile = DEFAULT_FONT_FILE |
|
|
|
if (fontFamily && fontFamily !== 'default') { |
|
|
|
fontFile = this.mapFontFamilyToFile(fontFamily) |
|
|
|
// 判断是否为中文字体
|
|
|
|
@ -382,7 +389,7 @@ export class ZPLGenerator { |
|
|
|
if (chineseFonts.includes(fontFamily)) { |
|
|
|
fontLetter = 'J' |
|
|
|
} else { |
|
|
|
fontLetter = fontLetterMapping[fontFamily] || 'A' |
|
|
|
fontLetter = fontLetterMapping[fontFamily] || 'J' |
|
|
|
if (!fontLetterMapping[fontFamily]) { |
|
|
|
// 尝试模糊匹配
|
|
|
|
const lowerFontFamily = fontFamily.toLowerCase() |
|
|
|
@ -397,9 +404,9 @@ export class ZPLGenerator { |
|
|
|
fontCmd += ` ^CW${fontLetter},E:${fontFile}` |
|
|
|
console.log(`ZPL字体映射: ${fontFamily} -> ${fontFile}, 字母: ${fontLetter}`) |
|
|
|
} else { |
|
|
|
fontCmd += ' ^CWJ,E:ARIAL.TTF' |
|
|
|
fontLetter = 'J' |
|
|
|
console.log('使用默认字体: ARIAL.TTF, 字母: J') |
|
|
|
fontCmd += ` ^CW${DEFAULT_FONT_LETTER},E:${DEFAULT_FONT_FILE}` |
|
|
|
fontLetter = DEFAULT_FONT_LETTER |
|
|
|
console.log(`使用默认字体: ${DEFAULT_FONT_FILE}, 字母: ${DEFAULT_FONT_LETTER}`) |
|
|
|
} |
|
|
|
|
|
|
|
// 设置字体大小
|
|
|
|
@ -437,6 +444,10 @@ export class ZPLGenerator { |
|
|
|
'標楷體': 'DFKAI.TTF', |
|
|
|
|
|
|
|
// 英文字体
|
|
|
|
'Arial Unicode MS': DEFAULT_FONT_FILE, |
|
|
|
'Arial Unicode': DEFAULT_FONT_FILE, |
|
|
|
'ARIAL UNICODE MS.TTF': DEFAULT_FONT_FILE, |
|
|
|
'ARIALUNI.TTF': DEFAULT_FONT_FILE, |
|
|
|
'Arial': 'ARIAL.TTF', |
|
|
|
'Times New Roman': 'TIMES.TTF', |
|
|
|
'Courier New': 'COUR.TTF', |
|
|
|
@ -476,8 +487,8 @@ export class ZPLGenerator { |
|
|
|
'Snell Roundhand': 'SNELLROUND.TTF', |
|
|
|
|
|
|
|
// 默认字体
|
|
|
|
'default': 'ARIAL.TTF', |
|
|
|
'Default': 'ARIAL.TTF' |
|
|
|
'default': DEFAULT_FONT_FILE, |
|
|
|
'Default': DEFAULT_FONT_FILE |
|
|
|
} |
|
|
|
|
|
|
|
// 如果找不到精确匹配,尝试模糊匹配
|
|
|
|
@ -490,7 +501,7 @@ export class ZPLGenerator { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return fontMapping[fontFamily] || 'ARIAL.TTF' // 默认返回ARIAL
|
|
|
|
return fontMapping[fontFamily] || DEFAULT_FONT_FILE // 默认返回Arial Unicode MS
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -620,7 +631,7 @@ export class ZPLGenerator { |
|
|
|
const fontSize = 15 // 根据二维码大小调整字体大小
|
|
|
|
|
|
|
|
// 设置中文字体支持
|
|
|
|
zpl += `\n^CI28^CWJ,E:ARIAL.TTF^CFJ,${fontSize}` |
|
|
|
zpl += `\n^CI28^CWJ,E:${DEFAULT_FONT_FILE}^CFJ,${fontSize}` |
|
|
|
|
|
|
|
// 计算文本宽度以实现居中对齐
|
|
|
|
const estimatedTextWidth = this.estimateTextWidth(data, fontSize) |
|
|
|
|