From 42e445fda5c044522216bf64a89115a607d37405 Mon Sep 17 00:00:00 2001 From: xiepengfei Date: Sat, 14 Nov 2026 01:47:37 +0800 Subject: [PATCH] fix: use literal font name instead of tr() for font lookup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: QObject::tr("Source Han Sans CN") translates the font name to Chinese in zh_CN locale, which never matches any entry in QFontDatabase::families() that always returns English names 2. Fix: replace tr() with QStringLiteral to use the literal font name for lookup; remove the stale translation entry from zh_CN.ts 3. Impact: text box font dropdown shows correct font name instead of garbled fallback; no signature or control flow change Log: fix garbled font name in text box font dropdown Influence: 1. Test text box creation with "Source Han Sans CN" font installed 2. Test text box creation without the font to verify fallback 3. Verify font dropdown displays correct default font name fix: 文本框字体名使用字面量替代 tr() 翻译查找 1. 根因:QObject::tr("Source Han Sans CN") 在 zh_CN 下将字体名翻译 为中文,而 QFontDatabase::families() 始终返回英文原名,导致查找 失败回退到系统第一个字体(乱码名) 2. 方案:使用 QStringLiteral 替代 tr(),以原始字体名进行查找;移除 翻译文件中对应的无用条目 3. 影响:文本框字体下拉框正确显示字体名而非乱码回退值;不改变 函数签名或控制流 Log: 修复文本框字体名称显示为乱码的问题 Influence: 1. 测试安装"Source Han Sans CN"字体后创建文本框 2. 测试未安装该字体时的回退行为 3. 验证字体下拉框显示正确的默认字体名 PMS: BUG-373351 --- src/drawshape/drawTools/ctexttool.cpp | 2 +- translations/deepin-draw_zh_CN.ts | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/drawshape/drawTools/ctexttool.cpp b/src/drawshape/drawTools/ctexttool.cpp index 98e6a12e8..87b564e63 100644 --- a/src/drawshape/drawTools/ctexttool.cpp +++ b/src/drawshape/drawTools/ctexttool.cpp @@ -350,7 +350,7 @@ void CTextTool::initFontFamilyWidget(QComboBox *fontHeavy) // 设置默认的字体类型为思源宋黑体,没有该字体则选择系统第一个默认字体 QFontDatabase fontbase; - QString sourceHumFont = QObject::tr("Source Han Sans CN"); + QString sourceHumFont = QStringLiteral("Source Han Sans CN"); if (!fontbase.families().contains(sourceHumFont)) { qCDebug(drawShapeLog) << "Source Han Sans CN font not found, using first available font"; sourceHumFont = fontbase.families().first(); diff --git a/translations/deepin-draw_zh_CN.ts b/translations/deepin-draw_zh_CN.ts index 4e9a98817..ff80bea54 100644 --- a/translations/deepin-draw_zh_CN.ts +++ b/translations/deepin-draw_zh_CN.ts @@ -803,11 +803,6 @@ Please save it in another name or close that file and try again. File not saved 文件未保存 - - - Source Han Sans CN - 思源黑体 CN - Stroke