JavaFX Font support for Emojis
Scott Palmer
swpalmer at gmail.com
Sun Jan 1 19:02:12 UTC 2023
I’ve been experimenting, trying to figure out a cross-platform way of displaying emojis in a JavaFX application. It has been interesting.
I tested on macOS and Windows 11. On macOS I explicitly set the font to “Apple Color Emoji”, on Windows 11, I used “Segoe UI Emoji”. Those appear to be the standard fonts for emojis on the respective platforms.
On macOS with JavaFX, emojis render in monochrome with shades of grey, smaller than they should be and shifted down slightly, sometimes cropping off the bottom pixels. With Swing (via SwingPane) they render in full colour the same as native applications.
On Windows with JavaFX the emoji is rendered in black and white (no shading) for both JavaFX and Swing. This is the same as how WordPad renders them, but different than Microsoft Word, which will show the emojis in full colour. The emojis are the right size and not vertically shift as they are on macOS.
If I set the font to something else, I used “Fira Code” that I downloaded so it should be the exact same on both platforms, I get different behaviour.
On Windows 11 with JavaFX the \uFE0F combining character that indicates the previous character should be rendered as an emoji causes a blocked ? to print after a non-emoji heart character. (To get a “Red Heart” emoji I am using the standard Unicode heart “\u2764” followed by "\uFE0F”.)
Swing on macOS still renders full colour emojis, but on Windows 11 it claims it can’t render the emoji characters at all - sure enough java.awt.Font.canDisplay(codePoint) returns true on macOS and false on Windows 11, even though the font is the same.
If I use a logical font, e.g. “Monospaced”, Swing renders the emojis the same as when using the explicit emoji font on both platforms, as does JavaFX on macOS. However, JavaFX on Windows 11 still prints the blocked ? for \uFE0F.
So a few questions:
Can JavaFX render full colour emojis? Is the greyscale rendering on macOS intentional?
Presumably the smaller scale and vertical shift on macOS are bugs?
Can Swing on Windows render emojis in colour like it does on macOS?
(Btw, SwingPane on Windows 11 doesn’t paint at all until it is “provoked” with some sort of event, like dragging the window so it is partially obscured.)
And finally, is there any hope to get cross-platform support for full colour emojis in a JavaFX application via Text nodes, or would it be best to abandon the idea altogether and use Image nodes for them instead?
Regards,
Scott
More information about the openjfx-dev
mailing list