2 Commits

  1. 24
      src/utils/zplGenerator.js
  2. 2
      src/views/modules/labelSetting/components/PropertyForm.vue

24
src/utils/zplGenerator.js

@ -1,6 +1,7 @@
import { CoordinateTransformer } from './coordinateTransform.js' import { CoordinateTransformer } from './coordinateTransform.js'
const DEFAULT_FONT_FILE = 'ARIAL UNICODE MS.TTF'
const DEFAULT_FONT_FILE = 'SIMSUN.TTF'
// 前后端均保留字体槽位映射,默认字体统一使用宋体。
const DEFAULT_FONT_LETTER = 'J' const DEFAULT_FONT_LETTER = 'J'
/** /**
@ -376,10 +377,10 @@ export class ZPLGenerator {
} }
// 根据字体族选择字体文件和字母 // 根据字体族选择字体文件和字母
const fontFamily = element.fontFamily
const fontFamily = (element.fontFamily || '').trim()
let fontLetter = DEFAULT_FONT_LETTER let fontLetter = DEFAULT_FONT_LETTER
let fontFile = DEFAULT_FONT_FILE let fontFile = DEFAULT_FONT_FILE
if (fontFamily && fontFamily !== 'default') {
if (fontFamily && fontFamily.toLowerCase() !== 'default') {
fontFile = this.mapFontFamilyToFile(fontFamily) fontFile = this.mapFontFamilyToFile(fontFamily)
// 判断是否为中文字体 // 判断是否为中文字体
const chineseFonts = [ const chineseFonts = [
@ -410,7 +411,7 @@ export class ZPLGenerator {
} }
// 设置字体大小 // 设置字体大小
const fontSize = element.fontSize || 30
const fontSize = Number(element.fontSize) > 0 ? Number(element.fontSize) : 30
fontCmd += ` ^CF${fontLetter},${fontSize}` fontCmd += ` ^CF${fontLetter},${fontSize}`
// 添加调试信息 // 添加调试信息
@ -424,6 +425,11 @@ export class ZPLGenerator {
* 映射字体族到字体文件 * 映射字体族到字体文件
*/ */
mapFontFamilyToFile(fontFamily) { mapFontFamilyToFile(fontFamily) {
fontFamily = (fontFamily || '').trim()
if (!fontFamily || fontFamily.toLowerCase() === 'default') {
return DEFAULT_FONT_FILE
}
const fontMapping = { const fontMapping = {
// 中文字体 // 中文字体
'Microsoft YaHei': 'MSYH.TTF', 'Microsoft YaHei': 'MSYH.TTF',
@ -444,10 +450,10 @@ export class ZPLGenerator {
'標楷體': 'DFKAI.TTF', '標楷體': '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 Unicode MS': 'ARIAL UNICODE MS.TTF',
'Arial Unicode': 'ARIAL UNICODE MS.TTF',
'ARIAL UNICODE MS.TTF': 'ARIAL UNICODE MS.TTF',
'ARIALUNI.TTF': 'ARIAL UNICODE MS.TTF',
'Arial': 'ARIAL.TTF', 'Arial': 'ARIAL.TTF',
'Times New Roman': 'TIMES.TTF', 'Times New Roman': 'TIMES.TTF',
'Courier New': 'COUR.TTF', 'Courier New': 'COUR.TTF',
@ -501,7 +507,7 @@ export class ZPLGenerator {
} }
} }
return fontMapping[fontFamily] || DEFAULT_FONT_FILE // 默认返回Arial Unicode MS
return fontMapping[fontFamily] || DEFAULT_FONT_FILE // 未识别字体回退宋体
} }
/** /**

2
src/views/modules/labelSetting/components/PropertyForm.vue

@ -660,7 +660,7 @@ const DEFAULT_FONT_OPTION = {
name: 'default', name: 'default',
value: 'default', value: 'default',
category: 'system', category: 'system',
description: 'ARIAL UNICODE MS.TTF',
description: 'SIMSUN.TTF',
supported: true supported: true
} }

Loading…
Cancel
Save