Custom font with unsupported characters

Hi,

When developing for iOS using a UILabel (for example), if you set a custom font, it automatically uses a default system font for characters that your font does not support (e. g. emojis and special characters).

Currently, I`m creating a TTF Label (via cocos studio) with a custom font and it is showing some empty squares instead of the emojis user inputs on keyboard. If I use a system font (e. g. “Arial”), it works as expected.

Is there any way to achieve the same behaviour with cocos2d-x, like setting a fallback font?

Thank you

EDIT:

A code snippet to demonstrate how I’m testing it right now (behaves similarly for any custom font). Label ttf2 works perfectly, while ttf1 displays some weird characters instead of emojis. If I create a Label using “arial.ttf” file (instead of using a system font name), the same problem occurs.

Label* ttf1 = Label::createWithTTF("emoji test 😀😬", "fonts/pixelart.ttf", 100);
ttf1->setColor(Color3B::WHITE);
ttf1->setPosition(800.0,700.0);

Label* ttf2 = Label::createWithSystemFont("emoji test 😀😬", "Arial", 100);
ttf2->setColor(Color3B::WHITE);
ttf2->setPosition(800.0,400.0);

Scene* s = Scene::create();
s->addChild(ttf1);
s->addChild(ttf2);
Director::getInstance()->runWithScene(s);
1 Like

Now i’m working with this problem! Anyone please support us!

I have this issue too. Right now, the only solution I have is to build my own custom font with all the characters of languages I am supporting, but that adds about 20MB of fonts in the build. Not something I want to do.

If cocos2dx can provide a way to allow fallback to a system font if the glyphs in the text are not available in the given font, that would be great.

@slackmoehrle do you know anyone who can help here? I’m looking at the source code to see if I can add support for this myself.

Sorry. Elaborate more. What’s the exact issue.

@slackmoehrle

An example is posted in the original post by @renatoaf.

If you use Label::createWithTTF with a custom ttf that does not support east asian characters, it renders empty boxes like this:
05%20AM

If you use Label::createWithSystemFont, it will work well for East Asian characters, but Latin characters will be in an ugly default font.

Basically, we want support for fallback to a system font in Label::createWithTTF. This feature existed in the older label CCLabelTTF::create. (it supported fallbacks correctly, but it was very buggy.)

Makes sense the empty boxes. I wonder if there is a way to test the ttf for the characters and if they don’t exist use system font.

What about using a different ttf?

There should be a way because the older CCLabelTTF used to support it.

To support all CJK languages, with a custom font, I have to add about 20MB of TTF files to the build. I basically used FontForge to merge my custom font with an East Asian Font (Source Hans Sans), which works great, but I am not happy with the extra 20MB added to the build. Perhaps I could live with it and make only people in East Asia download the extra fonts.