Repository navigation
Draw Han in the UI language's own font - #1121
Merged
Merged
Conversation
Avalonia's embedded font collection, asked for a character its requested family lacks, answers with the first family of its own that has it. A composite family's first entry, Noto Sans, has no Han, so that answer was always Noto Sans JP and the chain's next entries were never reached: every language drew Han in Japanese shapes up to the first character the font lacks, which is why only some characters in a line looked wrong. FileeFontCollection now matches a letter only in the family asked for, so the order of SoftPalette's chain decides. zh-TW reaches the system's Traditional fonts this way, and Linux gets Noto Sans CJK TC in that list. Fixes #1095 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
macOS answers PingFang TC, which is right. The test only knew Windows' font and didn't skip there, as a system collection also lists the names it was asked for. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #1095
The reporter's trace holds, with one correction: the order that decides is Avalonia's sorted family list rather than the resource enumeration, and it isn't all Han that stays Japanese.
Cause
FontFamilies("zh-CN")isNoto Sans, Arabic, Devanagari, Thai, Noto Sans SC, ..., but the font manager never got past the first entry. For each composite entry it asks that family's collection to match the character, andFontCollectionBase.TryMatchCharacter, when the requested family lacks it, sweeps every other family in the collection. Noto Sans has no Han, so the sweep at entry 0 answered, and with no culture to score (TextBlock passes none) the first family won: Noto Sans JP, in every UI language.A run then stays in that font until it hits a character the font lacks. That is why only some characters looked wrong:
跟随系统was跟随系in JP and统in SC.Checked along the way:
NotoSansSC-Regular.otfis family "Noto Sans SC" and has all four characters, with outlines that differ from JP and KR (hashedSKFont.GetGlyphPath).Typeface.Defaultaren't affected: they end up in the system collection, whose platform match follows the UI culture (on this PC: YaHei UI, JhengHei UI, Yu Gothic UI).Fix
FileeFontCollectionnow wraps the embedded collection and matches a character only in the family asked for, so SoftPalette's order decides. It has to be a wrapper: the font manager calls an internal, non-virtual overload on anything derived fromFontCollectionBase, so overriding wouldn't run.将before将afterLatin stays in Noto Sans. Annotate's label fallback asks the same font manager, so it follows too.
zh-TW has no embedded font, so on Linux it would land on Noto Sans SC;
Noto Sans CJK TCjoins the system list for machines that have it. That name is untested, there's no Linux machine here.Limits
Avalonia keeps a run in the previous fallback font while that font has the character, so in a zh-CN UI a file name like
한글将draws将in Noto Sans KR. Only mixed foreign text is affected.Tests
LocalizationResourceTestsresolves the characters throughTryMatchCharacterand through a realTextLayout, in regular, semibold and bold. Without the fix 8 of the 16 fail (ja passes either way, its right answer was the accidental one); with itLocalizationResourceTests+LocalizationTestspass 232/232 andAnnotateWindowTests79/79. The tests skip if the fonts weren't fetched; CI fetches them.🤖 Generated with Claude Code