fromUTF8 on Windows doesn't work as expected

Hello I am almost sure the problem is in my codec setting in Projucer project or in Visual Studio, but for long time I can’t figure it out how to fix it.

The problem is that:
Graphics::drawText(String::fromUTF8("\u00B0"), myRectangle, Justification::centred);

Prints me “0” (zero) instead deegree symbol.

But on OSX it works fine.

It also brought me to second even more interesting question concern more to C++.
I wonder if it decide what to print in compile time or in runtime?

If it is in runtime, so maybe it is some problem with my Windows settings.
If it is in compile time, then for sure it is problem with my project settings.

I have no idea.

For any help great thanks in advance.

the issue is probably the font not UTF8 per se

Try with TextLayout that support fallback font automatically

Hmm… I tried it and it doesn’t work for me. Maybe I use it in wrong manner. I use it like that:

AttributedString myAttString;
myAttString.setText(180+String::fromUTF8(\u00B0));
TextLayout myTextLayout;
myTextLayout.createLayout(myAttString, texBoxWidth, texBoxHeight);
Rectangle<float> textBounds;
textBounds.setBounds(0.0f, 0.0f, 100.0f, 40.0f);
myTextLayout.draw(g, textBounds);

So not sure if I could change here anything?

Have a look here

Great thanks.
Projucer-> menu ‘Tools’ → ‘UTF 8 String literal helper’
helped me

Thanks a lot.

Best Regards

1 Like