Add font glyph fallback mechanism to the tiles build #36326
Merged
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.
Summary
SUMMARY: Interface "Fallback fonts can now be specified for the tiles build"
Purpose of change
The font currently shipped with the game (unifont) has the merit of wide unicode support, but its pixelated glyphs doesn't actually look pretty. Other fonts with prettier glyphs, however, often support only a very limited subset of unicode glyphs. This PR implements font fallback mechanism for the tiles build, so the user can specify the main font to display the most common glyphs, and fallback fonts to display rare glyphs correctly when the main font doesn't provide these glyphs.
Describe the solution
The "typeface" value in
config/fonts.json
can now be an array specifying multiple typefaces. A new child class ofFont
,FontFallbackList
, is added, which loads the specified typefaces and checks if a given glyph is provided with the typefaces. The first typeface from the array that provides the glyph is used to render the glyph.Testing
Changed the typeface list and started the game, observed that glyphs not provided with the main font are correctly rendered with the glyphs from the fallback font.
Additional context
This is only for the tiles build. For the curses build, font fallback probably can only be achieved by configuring the terminal software.
In the above screen shot, the Latin/Cyrillic characters are rendered with
UbuntuMono (bold)
, and the CJK characters are rendered withunifont
as the fallback font.