-
Notifications
You must be signed in to change notification settings - Fork 449
Add emoji support to SpriteText
and TextBox
#6599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EYHN
wants to merge
18
commits into
ppy:master
Choose a base branch
from
EYHN:eyhn/emoji
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
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.
28795f9
to
a72fc89
Compare
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
Grapheme
structure 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
Grapheme
struct 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
Grapheme
struct's memory allocation by using directchar
storage for common characters andstring
storage only for complex graphemes, resulting in minimal heap allocations and negligible performance impact.Performance benchmarks show that using
Grapheme
instead ofchar
actually improves performance:Using
char
(original):Using
Grapheme
:Colored Font Rendering
I added a
Coloured
property toITexturedCharacterGlyph
. WhenColoured == true
:SpriteText
skips tinting during rendering to preserve original colorsTextBox Emoji Support
I refactored
TextBox
to work withGrapheme
instead of string indices. The component now maintains dual state:string text
andList<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