Skip to content

fix: use literal font name instead of tr() for font lookup - #293

Draft
pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/bugfix/373351
Draft

pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/bugfix/373351

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

CTextTool::initFontFamilyWidget() in ctexttool.cpp:353 used QObject::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 file deepin-draw_zh_CN.ts. However, QFontDatabase::families() always returns original English font names, so families().contains("思源黑体 CN") returns false, causing a fallback to families().first() which may be a garbled name like "C059 [UKWN]".

Fix

Replace QObject::tr("Source Han Sans CN") with QStringLiteral("Source Han Sans CN") to use the literal font name for lookup. Remove the stale translation entry from deepin-draw_zh_CN.ts (lines 806-810) that mapped the font name to Chinese.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • initFontFamilyWidget is only called by registerAttributionWidgets, impact scope is limited to text tool font dropdown initialization
  • No historical fix is being reverted; the tr() call has existed since code introduction with no subsequent fix commits
  • No function signature or control flow change — only the font name source changes from translated to literal

Business 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:

  • Fix default font selection so the text tool correctly recognizes and displays Source Han Sans CN when it is installed.

Enhancements:

  • Remove the obsolete Chinese translation for the font family name.

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
@deepin-ci-robot

Copy link
Copy Markdown

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Nov 13, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Use the literal font family name for the QFontDatabase lookup, and remove its obsolete translated entry.

  • src/drawshape/drawTools/ctexttool.cpp L353
  • translations/deepin-draw_zh_CN.ts L806 (removed lines)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@pengfeixx
pengfeixx marked this pull request as draft November 13, 2026 17:55

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants