Repository navigation
fix: pick a usable default font family on Linux CJK locales - #332
Merged
HMBSbige merged 2 commits intoOct 8, 2026
Merged
Conversation
Skia's fontconfig backend only accepts a match among the first 16 family aliases of the request. Under CJK locales (zh_CN, zh_TW, ja_JP, ...) fontconfig prefers Noto Sans CJK by language, but that family sits far behind the first 16 sans-serif aliases, so Skia rejects the match and SKTypeface.Default comes back with an empty family name. Avalonia then falls back to SystemFonts[0], the alphabetically first installed family (e.g. the decorative "Abydos"), and renders all Latin text with it. When SKTypeface.Default is empty, ask the font manager for a font that covers Latin text instead. That follows the locale the same way `fc-match sans-serif` does, and changes nothing where the default typeface already resolves.
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.
写字母显示成小型大写,例如

stun.miwifi.com→STUN.MIWIFI.COM、Unknown→UNKNOWN。中文字符不受影响,因为它们走的是按字符回退的路径。en_US/Clocale 下正常。原因
FontManagerImpl.GetDefaultFontFamilyName()直接返回SKTypeface.Default.FamilyName(FontManagerImpl.cs#L18-L22)。AnyMatching的maxId = 16,用于onMatchFamilyStyle)。fc-match sans-serif的结果也是它。但sans-serif展开后有一百多个别名,Noto Sans CJK SC 排在一百多位,于是 Skia 判定匹配失败,SKTypeface.Default变成空名字的空字体。SystemFonts[0],也就是按字母序排第一的已安装字体(FontManager.cs#L470-L473),所以结果完全取决于用户装了哪些字体。修改
仅当
SKTypeface.Default.FamilyName为空时,用SKFontManager.Default.MatchCharacter('A')取一个覆盖拉丁字符的字体,并通过FontManagerOptions.DefaultFamilyName交给 Avalonia。按字符匹配的路径不做上述 family 检查,并且同样遵循 locale,结果与fc-match sans-serif一致:fc-match sans-serifMatchCharacter('A')默认字体本来就正常的环境(Windows、macOS、Linux 的 en_US 等)不受影响,此时返回
null,Avalonia 照常走原来的逻辑。