From f18ad1ec93afde2b9c112b1b1f52a284b17e2bed Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Sun, 20 Sep 2026 13:29:16 +0800 Subject: [PATCH] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=AD=97=E4=BD=93=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20SIMSUN.TTF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/zplGenerator.js | 24 ++++++++++++------- .../labelSetting/components/PropertyForm.vue | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/utils/zplGenerator.js b/src/utils/zplGenerator.js index 85fab95..fff68b2 100644 --- a/src/utils/zplGenerator.js +++ b/src/utils/zplGenerator.js @@ -1,6 +1,7 @@ import { CoordinateTransformer } from './coordinateTransform.js' -const DEFAULT_FONT_FILE = 'ARIAL UNICODE MS.TTF' +const DEFAULT_FONT_FILE = 'SIMSUN.TTF' +// 前后端均保留字体槽位映射,默认字体统一使用宋体。 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 fontFile = DEFAULT_FONT_FILE - if (fontFamily && fontFamily !== 'default') { + if (fontFamily && fontFamily.toLowerCase() !== 'default') { fontFile = this.mapFontFamilyToFile(fontFamily) // 判断是否为中文字体 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}` // 添加调试信息 @@ -424,6 +425,11 @@ export class ZPLGenerator { * 映射字体族到字体文件 */ mapFontFamilyToFile(fontFamily) { + fontFamily = (fontFamily || '').trim() + if (!fontFamily || fontFamily.toLowerCase() === 'default') { + return DEFAULT_FONT_FILE + } + const fontMapping = { // 中文字体 'Microsoft YaHei': 'MSYH.TTF', @@ -444,10 +450,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 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', 'Times New Roman': 'TIMES.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 // 未识别字体回退宋体 } /** diff --git a/src/views/modules/labelSetting/components/PropertyForm.vue b/src/views/modules/labelSetting/components/PropertyForm.vue index 468a328..d69821b 100644 --- a/src/views/modules/labelSetting/components/PropertyForm.vue +++ b/src/views/modules/labelSetting/components/PropertyForm.vue @@ -660,7 +660,7 @@ const DEFAULT_FONT_OPTION = { name: 'default', value: 'default', category: 'system', - description: 'ARIAL UNICODE MS.TTF', + description: 'SIMSUN.TTF', supported: true }