Add emoji support to SpriteText and TextBox#6599
Open
EYHN wants to merge 18 commits intoppy:masterfrom
Open
Conversation
Only the first test fails, but the second one needs consideration when migrating to Rune.
The bmfont format supports supplementary characters, but we were using `char` instead of the wider `int`/`Rune` for passing the values around.
The new tests now pass.
The font files were generated with the provided `.bmfc` config using `bmfont64_1.14b_beta`, and the latest Noto Emoji available from https://fonts.google.com/noto/specimen/Noto+Emoji.
Can't be fixed without considering the UX of typing, deleting and selecting.
Collaborator
Contributor
Author
28795f9 to
a72fc89
Compare
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.
This PR continues the work of @Susko3 in #5933, introducing comprehensive Unicode text handling improvements and colored font support. @Susko3's commits are already included in this PR, so only this PR needs to be merged.
I believe this PR is now ready for review. I've attempted to solve most of the major issues, including support for multi-codepoint emoji for flags and TextBox support for emoji. To achieve this, I introduced a new
Graphemestructure to replaceRune, and generated emoji resources from noto color emoji. Those changes that I think warrant discussion, so please share your thoughts.If you want to test the game yourself, please switch to https://github.com/EYHN/osu/tree/eyhn/emoji and use the local framework and resource from ppy/osu-resources#369
This fully emoji support feature is divided into three PRs.
Grapheme Implementation
I introduced the
Graphemestruct to represent a single grapheme cluster in Unicode text, efficiently handling both simple char and complex multi-character sequences (like emoji with skin tone modifiers, flags, or characters with combining marks).The key differences from existing types are:
char: Represents a single UTF-16 code unit, insufficient for complex Unicode charactersRune: Represents a Unicode scalar value, but doesn't handle grapheme clustersGrapheme: Represents complete user-perceived characters, including complex clustersI optimized the
Graphemestruct's memory allocation by using directcharstorage for common characters andstringstorage only for complex graphemes, resulting in minimal heap allocations and negligible performance impact.Performance benchmarks show that using
Graphemeinstead ofcharactually improves performance:Using
char(original):Using
Grapheme:Colored Font Rendering
I added a
Colouredproperty toITexturedCharacterGlyph. WhenColoured == true:SpriteTextskips tinting during rendering to preserve original colorsTextBox Emoji Support
I refactored
TextBoxto work withGraphemeinstead of string indices. The component now maintains dual state:string textandList<Grapheme> graphemes. I changed nearly all position-based variables to use grapheme positions, ensuring proper handling of complex Unicode characters in text input.Recording.2025-06-26.134618.mp4
Noto Color Emoji Resources
Resources: Available in ppy/osu-resources#369