Skip to content

fix(appearance): resolve Linux code fonts under CJK locales - #1305

Merged
leookun merged 4 commits into
baocode-dev:mainfrom
duyaofei:fix/linux-code-font-fallback
Nov 25, 2026
Merged

leookun merged 4 commits into
baocode-dev:mainfrom
duyaofei:fix/linux-code-font-fallback

Conversation

@duyaofei

Copy link
Copy Markdown
Contributor

Issue: #1304

What and why / 改了什么、为什么

Linux 使用 zh_CN.UTF-8 且未设置 FC_LANG 时,Flutter/Skia 可能把已安装的代码字体解析成其他字形,编辑器和终端也可能落到比例字体。

  • Linux runner 通过 Fontconfig 查找字体文件并核对字体族。命中的字体以私有别名注册,供编辑器、外观预览和终端共用;缺失的字体按顺序回退到等宽字体。
  • 在首帧前注册常用预设,避免切换预设时动态加载使 Flutter 字体缓存失效,导致旧字形长时间留在屏幕上。
  • 不修改用户的字体配置、中文 locale 或 FC_LANG。此实现只加载字体集合的第一个字面;任意自定义字体的热切换未做桌面验收。

How it was tested / 怎么测的

  • dart format、改动文件的 flutter analyze --no-pub 和 git diff --check 均通过。
  • flutter test --no-pub test/theme/linux_code_fonts_test.dart test/theme/code_font_test.dart:12 项通过。
  • flutter build linux --release --no-pub:构建成功。实际运行 Linux x64 Release,在 LANG=zh_CN.UTF-8、LANGUAGE=zh_CN:zh、无 FC_LANG 的环境,从外观页将 Consolas 切换到 Courier New。对照字形确认外观预览、已打开的编辑器和终端均在不重启的情况下更新,设置也成功保存。

Checklist / 检查

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

This pull request now follows CONTRIBUTING.md. Thanks!

这个 PR 现在符合 CONTRIBUTING.md 了,谢谢!

vic-7945hx and others added 4 commits November 25, 2026 14:08
…ts as the menu opens

- A family installed but not loadable (in a font collection, not its
  first face) is drawn by its own name, as before, instead of left out:
  codeFontFiles now tells whether each family is installed besides its
  files.
- Only the families set and the fallbacks are loaded before the first
  frame; the Appearance menu's presets are loaded as the menu opens, not
  at every start.
- The root cause is noted: Skia's Fontconfig StyleSet::matchStyle picks
  among an alias's faces without the family, fixed in Skia a4d18ba482
  (flutter/flutter#195102); this can go with a Flutter that has it.

Co-Authored-By: BaoCode <noreply@baocode.dev>
@kun6687
kun6687 force-pushed the fix/linux-code-font-fallback branch from d3fc78b to aed1932 Compare November 25, 2026 06:09
@leookun

leookun commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the fix and the clear write-up! I pushed a few changes on top, and rebased the branch onto main (that also resolves the conflict with the new heldModifiers method in linux/runner/my_application.cc):

  1. Root cause noted. Skia's Fontconfig StyleSet::matchStyle picks among all faces of an alias (including the CJK family a zh config puts first) by style and language only, not by family. Skia fixed it in google/skia@a4d18ba482 ([Linux] fontFamilyFallback: ["emoji"] picks a monochrome emoji font: family preference order is lost in SkFontMgr_fontconfig matchFamily/matchStyle flutter/flutter#195102); the Skia in Flutter 3.47.5 predates it, while beta and master have it. The doc comment in linux_code_fonts.dart says this workaround can go once we're on a Flutter with that Skia.
  2. Installed but unloadable families keep their names. codeFontFiles now answers {files, installed} per family. A family installed only as a non-first face of a collection (some Sarasa Mono SC packages, for example) was dropped from the stack; it is now passed by its own name, as before this PR, instead of disappearing.
  3. Presets load when the menu opens, not at every start. Before the first frame only the families set and the fallbacks are loaded; the Appearance menu's presets load when that menu opens.
  4. Doc comments adjusted to the repo's style; tests updated (test/theme/linux_code_fonts_test.dart, test/theme/code_font_test.dart: 12 pass).

Since the shape of the native answer changed, could you build it on your Linux machine once more and check that Consolas → Courier New under zh_CN.UTF-8 still switches the preview, the open editor and the terminal? I can't build for Linux here.

@leookun
leookun merged commit c880c29 into baocode-dev:main Nov 25, 2026
2 checks passed
@leookun

leookun commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Merged, thanks! If your Linux build of main shows anything off with the changes above, please open an issue and mention this PR.

leookun added a commit that referenced this pull request Nov 25, 2026
…1306)

g_steal_pointer() gives a gpointer in C++ there, which
fl_value_set_string_take() does not take: the Linux release builds
failed at my_application.cc:297 since #1305. The list is now a plain
pointer, taken by its entry.

Co-authored-by: leo <leokuncn@gmail.com>
Co-authored-by: BaoCode <noreply@baocode.dev>
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.

3 participants