Emoji in TextField?

Hey folks - Anyone have any luck using emoji in a TextField? I can’t seem to find anything while searching. I’ve tried using emoji fonts (such as OpenSansEmoji) but all I get is white boxes - missing characters. (On iOS and OSX.)

I’ll keep looking into it, just thought I’d ask. Thanks!

1 Like

Is this more a matter of input, or the TextField displaying it properly? I wonder if its a matter of bitmap fonts vs vector shape fonts?

    var txt = new TextField();
    txt.text = "Hello \uD83D\uDE0A"
    txt.x = txt.y = 150;

Check the unicode tables for more information. And for better working with unicode there is also a Utf8 class: in the Std at haxe.Utf8;

And as said, be sure your font has the emoticon (for me flash by default shows them, html5 doesn’t but I didn’t spend a second on look for a proper font).

Thanks for the help, both of you! I’m sorry to just get back - I’ve been digging…

I’m mostly testing on OSX and iOS - using native and neko both. I am also attempting to use two free Emoji fonts: OpenSansEmoji (monochrome) and PhantomOpenEmoji (color). I don’t think I have any way of using Apple’s “Apple Color Emoji” font that is on both systems.

I can’t get emoji working with the string “\uD83D\uDE0A”. However, I can get the string “\xE2\x98\xBA” to work with OpenSansEmoji. It looks like OpenSansEmoji is just incomplete.

PhantomOpenEmoji won’t load for me - I get “Invalid field access - dirty” in CairoTextField.hx line 279. Neither will the other fonts in Google’s color-emoji repository.

On iOS when the keyboard is used to type a smiley, I get “\xED\xA0\xBD\xED\xB8\x80” which looks to be CESU-8 format for the emoji. So it looks like there are encoding issues with the software keyboard as well.

I think my best bet at this point is to translate all these different variations into emoji names and then load them as PNGs and insert them in gaps in the text. Another option might be to create native Cocoa textfields instead of Cairo textfields…?

Hello @kicks,

Did you try embedding the font? I think it makes sense to have a table with all emoticon codes / transformations and inline the value on build time based on the setup. Just an opinion, and it is some work to create such a generic library for each platform :smile:

If you go on and make that library open source please share it, I am sure it could be handy for more than one project :smiley: :yum:

Yes - the fonts are embedded. I will definitely open source any of my work - I just want to be sure to find a good answer, rather than one of my signature hacky codes. :stuck_out_tongue: Thanks, nudpiedo.