Repository navigation
Conversation
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
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: pengfeixx The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideImplementationUse the literal font family name for the QFontDatabase lookup, and remove its obsolete translated entry.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
pengfeixx
marked this pull request as draft
November 13, 2026 17:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause Analysis
CTextTool::initFontFamilyWidget()inctexttool.cpp:353usedQObject::tr("Source Han Sans CN")to look up the default font name. In zh_CN locale,tr()translates "Source Han Sans CN" to "思源黑体 CN" via the translation filedeepin-draw_zh_CN.ts. However,QFontDatabase::families()always returns original English font names, sofamilies().contains("思源黑体 CN")returns false, causing a fallback tofamilies().first()which may be a garbled name like "C059 [UKWN]".Fix
Replace
QObject::tr("Source Han Sans CN")withQStringLiteral("Source Han Sans CN")to use the literal font name for lookup. Remove the stale translation entry fromdeepin-draw_zh_CN.ts(lines 806-810) that mapped the font name to Chinese.Change Safety Assessment
Code Safety
initFontFamilyWidgetis only called byregisterAttributionWidgets, impact scope is limited to text tool font dropdown initializationtr()call has existed since code introduction with no subsequent fix commitsBusiness Impact Scope
Affects text tool's font family dropdown widget initialization. When users create a text box in the drawing tool, the default font name in the dropdown will now correctly show "Source Han Sans CN" instead of a garbled fallback name.
Verification Suggestion
Test text box creation with "Source Han Sans CN" font installed — verify the dropdown shows the correct font name. Also test without the font to confirm fallback behavior still works.
根因分析
ctexttool.cpp:353的CTextTool::initFontFamilyWidget()使用QObject::tr("Source Han Sans CN")查找默认字体名。在 zh_CN 环境下,tr()通过翻译文件deepin-draw_zh_CN.ts将 "Source Han Sans CN" 翻译为 "思源黑体 CN"。但QFontDatabase::families()始终返回原始英文字体名,导致families().contains("思源黑体 CN")返回 false,回退到families().first(),显示为乱码名 "C059 [UKWN]"。修复方案
将
QObject::tr("Source Han Sans CN")替换为QStringLiteral("Source Han Sans CN"),使用字面量字体名进行查找。同时移除deepin-draw_zh_CN.ts中对应的无用翻译条目(第 806-810 行)。改动安全评估
代码安全评估
initFontFamilyWidget仅被registerAttributionWidgets调用,影响范围仅限文本工具字体下拉框初始化tr()调用自代码引入以来一直存在,无后续修复提交业务影响范围
影响文本工具的字体下拉框组件初始化。用户在画板中创建文本框时,下拉框中的默认字体名将正确显示为 "Source Han Sans CN",而非乱码回退名。
验证建议
测试安装 "Source Han Sans CN" 字体后创建文本框——验证下拉框显示正确字体名。同时测试未安装该字体时的回退行为是否正常。
Summary by Sourcery
Use the literal Source Han Sans CN font name for reliable default font lookup in the text tool.
Bug Fixes:
Enhancements: