Add Hans and Hant scripts; improve Hani sample #289
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.
This is a somewhat hacky fix to allow properly loading fallbacks for Chinese scripts on Windows.
The "Hans" and "Hant" (simplified and traditional Chinese) script identifiers were missing, and "Hani" included a character which is included in Yu Gothic UI, Windows' default Japanese font, which only contains kanji.
This means that selecting a "Hani" (all Han ideographs) fallback would select a Japanese-only font that's missing some ideographs that seem to be used in Chinese.
I do not actually speak Chinese; I found these characters by looking in gaps in Yu Gothic UI's coverage that Microsoft JhengHei UI fills. Someone more familiar with Chinese and/or Japanese could probably do a better job finding sample characters that are used only in Chinese and not Japanese.
We need to put the Chinese-only characters first in the "Hani" sample because of the way the DirectWrite fallback handling works--we call
IDWriteFontFallback::MapCharacters
repeatedly, advancing the "head" of the string one character at a time, until we get a match. However, the documentation forMapCharacters
says that it actually works by returning "the font that should be used to render the first mappedLength characters of the text"--that is, it returns a font that you can use to render the first bit of the string, then you advance and call it again on the next bit, repeat until all characters are mapped. This means that the way we do things, only one character in each sample (with preference given to earlier ones) needs to match in order for a fallback font to be selected.If things worked more like the fontconfig backend seems to, where there's a whole list of fallback families, this would be fine, but the DirectWrite backend only ever returns one fallback which may not cover all characters in the given sample string. That's a less-hacky longer-term solution.