Godot: Most emojis don't work on Windows

Created on 17 Oct 2018  ·  11Comments  ·  Source: godotengine/godot

Godot version:

Godot 3.1 master https://github.com/godotengine/godot/commit/0d8284d3d4f439e074bf498af81e8c73be23cc67

OS/device including version:

Window 10

Issue description:

In theory, emoji support was added with this PR https://github.com/godotengine/godot/pull/15780 but I've been testing it and I can't get it to work. I tested it with the NotoColorEmoji.ttf font. That's the font I think @volzhs used for both that PR and this issue https://github.com/godotengine/godot/issues/10873 but I couldn't make it work. The font doesn't work on windows (opening it with the font viewer throws an error) because Windows doesn't support the type of color font https://github.com/googlei18n/noto-emoji/issues/43 But I'm not sure if it has anything to do with the issue.

Steps to reproduce:

  1. Download the font https://www.google.com/get/noto/#emoji-zsye-color
  2. Use it in a label with an emoji like 😄
bug windows core

Most helpful comment

Most emotes have char codes > 0xFFFF.

Godot string is based on wchar_t which is 16-bit on Windows, convention from UTF-8 replaces chars with codes above 0xFFFF with spaces, ustring.cpp#L1497 and Godot doesn't support UTF-16 surrogate pairs (and Windows copy-paste probably use UTF-16).

On Linux an macOS wchar_t is 32-bit and all emotes should work fine.

All 11 comments

did you compile with builtin_freetype option?
scons platform=windows builtin_freetype=yes

I didn't specify builtin_freetype=yes explicitly but it's on by default. I tried just in case and still nothing. When I c&p an emoji from the internet this is how it shows in the inspector but nothing shows in the actual label.

https://i.imgur.com/hgcysYG.png

I tried a couple of other emojis and some did work like ✔

https://i.imgur.com/xj8AS79.png

I also tried using a PoolByteArray and push the utf-8 bytes in there but no luck either. I tried:

func _ready():
    var bytes = PoolByteArray()
    bytes.push_back(0xF0)
    bytes.push_back(0x9F)
    bytes.push_back(0x98)
    bytes.push_back(0x84)
    text = bytes.get_string_from_utf8()

Which should be this one https://apps.timwhitlock.info/unicode/inspect?s=%F0%9F%98%84

Most emotes have char codes > 0xFFFF.

Godot string is based on wchar_t which is 16-bit on Windows, convention from UTF-8 replaces chars with codes above 0xFFFF with spaces, ustring.cpp#L1497 and Godot doesn't support UTF-16 surrogate pairs (and Windows copy-paste probably use UTF-16).

On Linux an macOS wchar_t is 32-bit and all emotes should work fine.

Oh well, I updated the title of the issue to reflect that information. Thanks @bruvzg

To be precise Unicode supplementary planes have much more stuff, not just emojis.

BiDi/Shaping PR (#21791) I'm working on, should fix rendering of > 0xFFFF chars on all platforms, but wchar_t size difference still cause some input problems on Windows and excessive encoding conversions on Linux/macOS.

How a bout switch to char32_t?

How a bout switch to char32_t?

char32_t and char16_t are C++11 types and Godot currently targets C++03.

And it's probably better to switch to UTF-16 instead for several reasons:

  • Windows APIs (and JavaScript APIs IIRC) use UTF-16 (input, copy-paste, filesystem), Linux/macOS APIs use UTF-8, none use UTF-32.
  • ICU required for #21791 use UTF-16.
  • UTF-32 is space inefficient, non BMP chars are rare and in average UTF-16 is using two times less memory than UTF-32.

I wrote some code to handle utf code conversion in c++ somewhere. I can take a look for it. wchar on windows is really quite a pain in the butt, but it can be worked with.

update: I would love to be able to 😏 people in game :^)

Godot is gonna support C++11 soon so what's the status on this? Are we using UTF-16?

It's time to switch to char16_t or something else, as Godot now targets C++11.

The same goes for Godots ord() where nearly all emojis return 32 (32 is actually the space " "), meaning that the emojis aren't recognized at all. ☹

Was this page helpful?
0 / 5 - 0 ratings