How to render an Emoji with juce::Graphics

Hi!

I’m trying to figure out how to render an emoji with juce::Graphics. Basically if I have a valid UTF8 emoji character can I draw it in Juce? I"m on macOS but want something that works all three platforms.

I read various posts here about text layout and the like, but even an explicit attempt to draw with the apple emoji font doesn’t show me anything. Here’s the code I tried:

            std::string bee =  u8"\U0001F41D";
            auto showThis = bee;

            auto ace = juce::Font( "Apple Color Emoji", 9, 0);
            std::cout << bee << " " << ace.toString() << std::endl;
#if 0
            auto atts = juce::AttributedString(juce::CharPointer_UTF8(bee.c_str()));
            atts.setFont(ace);
            auto txtl = juce::TextLayout();
            txtl.createLayout(atts, getLocalBounds().getWidth());
            txtl.draw(g, getLocalBounds().toFloat());
#endif
            g.setFont(ace);
            g.drawText(juce::CharPointer_UTF8(label.c_str()), getLocalBounds(), juce::Justification::centred);

In my terminal I see “:honeybee: Apple Color Emoji; 9.0 Regular” so the UTF-8 is correct but the glyph resolution doesn’t work and, it seems, even calling the explicit emoji font (so there’s no fallback needed) doesn’t render.

There must be a way to do this. I’m porting off of VSTGUI and our users have patches with emojis and non-english characters in them all over the place so my use case isn’t just ‘draw a bee’. But I’m a bit stumped on how to proceed.

Any thoughts welcome (even if you have ode that does it win or lin i can follow from). Thank you.

Can’t you just use an emoji ttf font? Like this one GitHub - googlefonts/noto-emoji: Noto Emoji fonts

Thank you very much for the suggestion.

Unfortunately no; even with that typeface loaded from my binary i don’t seem to resolve the glyph properly with either that font or Apple Color Emoji. (replacing the ace above with a juce::font on the juce::typeface from the binary of that font).

From reading code last night seems there’s different glyph resolution paths also… i’ll continue to dig. but if anyone has made this work or sees something dumb would love to know

and thanks again for answering!

Unfortunately JUCE doesn’t currently include support for rendering emoji. It should, however, support rendering non-english characters, as long as the characters are monochrome and present in the requested typeface.

This issue is on our radar, but it will be a very large undertaking to do properly on all platforms. For this reason I’m unable to give a date when JUCE will support emoji rendering.

OK great. Thanks!

It’s a full time job drawing good looking Emoji at the rate these are added, surely!

The glyphs are in TTF files - I think (from reading the code) it is more about fallback font and glyph interpretation stuff and yeah it did look hard when I did a late night rabbit dive into the juce font code.

Anyway appreciate you all getting back to me! Thank you!