ofTrueTypeFont to draw English and Chinese

Hello
I’m trying to draw Chinese words like “你好” but I don’t find the solution using fontExample on OF 0.9.0
Is it possible to draw Chinese using ofTrueTypeFont?
Thanks for the help

Hola David!

Make sure you load the a font that has the ranges you need (for example a unicode font). Then tell ofTrueTypeFont that you want to load those ranges:

ofTtfSettings settings("ArialUni.ttf", 14);
settings.antialiased = true;
settings.addRange(ofUnicode::Latin1Supplement);
settings.addRange(ofUnicode::Hiragana);
settings.addRange(ofUnicode::Katakana);
settings.addRange(ofUnicode::CJKUnified);
arialUni.load(settings);
arialUni.setLineHeight(18.0f);
arialUni.setLetterSpacing(1.037);

Then draw as usual and make sure you include long characters:

arialUni.drawString("Hola! \xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e", 10, 10);

(you can also tell your IDE that your text file includes long chars… then you can write directly).

Other options:
IMGUI

FTGL (old)

ofxTrueTypeFontUC (old)

Relevant threads (bydate, mostly old):



Nos vemos!

1 Like

this will only work on OF master or the nightly builds though

1 Like

Hi, I am also trying to draw special characters using ofTrueTypeFont. I am on Windows 10, Visual Studio 2015. I downloaded the nightly build for VS. On setup(), I have:

ofTtfSettings settings("fonts/verdana.ttf", 24);
	settings.antialiased = true;
	settings.addRange(ofUnicode::Latin1Supplement);
	settings.addRange(ofUnicode::Latin);
	settings.addRange(ofUnicode::LatinExtendedAdditional);
	font.load(settings);

And on draw():

font.drawString("éãóáíêô", 50, 50);

But none of these characters are drawn.

Any ideas why?

I can only think of two cases:

  1. the font you are using does not have those ranges. Solution, try a Unicode font. But I guess Verdana has them.
  2. you are setting special characters in your code. If you haven’t enabled Unicode in your IDE, those chars will not be read. Actually, I don-t know exactly what happens in that case… To fix that in VS you have to right click on your project, at Configuration Properties/General look for Character Set, and set it to “Use Unicode Character Set”.

Hey Jordi and Arturo!
Long time we don’t coincide!
One question, ofTtfSettings settings(“ArialUni.ttf”, 14); of_0.9.8 don’t recognise it, I’m missing something.
Thanks for the answer! Maybe I will try the nightly builds as Arturo suggest.
Hugs!

Hi
I’m already using the nightly builds, and now ofTtfSettings is recognised. Now my issue is that only squares are drawn, and the frameRate drops to 2 fps :sweat_smile:
This is the code I’m using:
ofTtfSettings settings(“ArialUni.ttf”, 80);
//settings.antialiased = true;
settings.addRange(ofUnicode::Latin1Supplement);
settings.addRange(ofUnicode::Hiragana);
settings.addRange(ofUnicode::Katakana);
settings.addRange(ofUnicode::CJKUnified);
myFont.load(settings);

EDIT found a solution! Depending on the version of OF you’re using, you may need to use this slightly different syntax to change your ofTrueTypeFont settings:

instead of ofTtfSettings, use:
setup()
{

ofTrueTypeFont::Settings settings( “yourfont.ttf”, 14);
settings.antialiased = true;
settings.addRange(ofUnicode::CJKUnified);
font.load(settings);

}