Emoji support
1/28/2025
Kaloyan Geshev
Overview
With version 1.61, Gameface adds support for certain types of emoji fonts. Emojis and colored text glyphs can enhance the visual fidelity of any Web component that includes displaying text. Gameface can now load fonts that contain emoji characters and use them in any text context.
Gameface officially supports the following fonts:
If you require a different emoji font or want to create a custom one, the font file must be in the COLRV0
format, as curently Gameface supports emoji fonts only in this format.
For more details, check out the Emoji Support section of our documentation.
Usage
To showcase the functionality of emoji fonts, we’ll walk you through updating our Chat emojis sample from the UI tutorials.
The enhancements we will be doing, include:
- Rendering emojis directly from a supported emoji font - You’ll no longer need
SVGs
for emoji rendering. Instead, HTML character codes will render emojis directly, making it simpler to add new emojis to the emoji panel. - Native input field emoji support - Perhaps the most exciting enhancement is the ability to render emojis directly within input fields, whether added via JavaScript or pasted by users.
Previously, the Chat sample used a :emojicode:
pattern in input fields, which didn’t visually render the emojis:
With emoji fonts, this limitation is resolved. Users will see a real-time preview of emojis in the input field, improving the chat’s user experience:
- Simplified server-side processing - The server no longer needs to match
:emojicode:
patterns and replace them withSVGs
. Messages will now display emojis rendered directly by the font.
Importing an emoji font
To enable usage of certain emojis, you need first to import a COLRV0
font file. For this guide, we’ll use the OpenMojiCOLRv0.ttf font built using the https://openmoji.org/ graphics:
- Download the font on your machine.
- Use the
@font-face
CSS rule to import the font. - Link the font file using the
src
property and assign it afont-family
. For example, we’ll name our custom fontOpenMoji
. - Apply the font to relevant HTML elements (
html
,body
,button
, andinput
) to ensure consistency. Note thatbutton
andinput
elements use the system font by default, so explicitly applying the custom font is necessary.
**Note: You need to set the default font-family for Gameface to ‘Droid Sans’, as the OpenMoji font lacks numeric symbols. This ensures numbers properly fall back to the default font. **
Now you’re ready to add emojis to the UI.
Updating the emoji panel button
To migrate the SVG
icon for the emoji panel button, replace it with a direct emoji character in the HTML and remove the associated CSS background image styles.
Additionally, use the coh-font-fit
property to adjust the emoji’s size to automatically fit within the button element. Previously, the background-image
style used the contain
property for this purpose.
You can read more about the coh-font-fit
custom CSS
property here .
Making the emojis panel to work with the font
In the Chat sample, we initially implemented a panel where users could select emojis to include in their messages. Previously, emojis were displayed using SVG
icons. Now, we’ll enhance this feature by switching to emoji fonts.
To render the emojis in the panel, we initially defined an array containing the paths to the SVG
icons for each emoji. Then, using data-bind-for
and data-bind-style-background-image-url
attributes, we displayed all available emojis in the panel.
Now, we will adjust the array and update the panel in the HTML
to use emoji fonts.
Click here to see the new JS file without the differences
In the HTML
, we’ll also update the rendering logic to use the new emoji font approach.
This change enables direct rendering of emoji Unicode characters using the data-bind-html
attribute. Additionally, the iter
variable now passes the emoji character code directly and this eliminates the need to pass the index
when clicking an emoji.
Adding emoji to the message input
When a user selects an emoji from the panel, it will be inserted at the current caret position in the input field. Since we are now using fonts, we no longer need to insert the pattern :emojicode:
. Instead, we can directly add the emoji character code, which will be rendered automatically.
Here’s the revised addEmoji
method:
Refactoring the server
The Chat sample uses a server to handle message delivery via WebSockets. Previously, the server replaced :emojicode:
patterns with corresponding SVG
elements before broadcasting messages. With the new font-based approach, this step is no longer necessary.
Here’s the updated server logic:
By eliminating the need for SVG
replacements, we simplify the server logic and improve performance.
Conclusion
These updates enhance the Chat sample by leveraging emoji fonts for rendering emojis in both the panel and the message input. The server logic is also simplified, as it no longer needs to process emoji patterns.
The emoji font support in Gameface is a great feature that can be used in many ways to enhance the visual fidelity of the UI components, including displaying text.
Where you can find the enhanced sample?
The updated Chat sample is available in the Samples/uiresources/UITutorials/ChatEmojisWithFonts
folder of the Gameface package.
The original sample using SVG
emojis can be found in the Samples/uiresources/UITutorials/ChatEmojis
folder.