Change draw direction from ltr to rtl

I have some persian text and I need to draw them from right to left, for example if my screen size is 1920 x 1080 and my text draw positions is like this :
textFace.drawStringAsShapes(text,100, 500);

I need it to start drawing from the point (1820, 500) and draw the rest of the text to the left side of screen. I used this functions (ofTranslate, ofRotate) but the problem is the text is upside down! how can I solve this? is there any better way?

1 Like

the nightly builds have some support for this, use a ofTtfSettings to initialize the font and then use direction RightToLeft.

unfortunately as I know the ofTrueTypeFont does not support persian text and unicode so I used ofxTrueTypeFontUC to draw my text . Is there any other solution?

1 Like

ofTrueTypeFont now supports unicode in the nightly builds and should support persian by selecting the right alphabet using ofTtfSetings too. We don’t have a specific range for persian but you can specify the correct unicode range if the ones there are not enough. Let me know if you need a different range than the ones already there and i’ll add it as well.

Not sure if persian will work without any problem though, i think it might need ligatures which are not still implemented but i don’t think ofxTrueTypeUC does ligatures either anyway

1 Like

thanks a lot, Is this new option available in raspberry nightly builds too?

1 Like

yes this works on every platform


I test the new nightly build and It works with Arabic unicode range but the problem is the letter are separated from each other, It should be:
but it is:
ن ی م ا
in the ofxTrueTypeFontUC the problem was the same but I used some reshape trick to fix this issue, I pass some thing like this text: “ﺎﻤﯿﻧ” as input and every things worked fine, but here when I pass the reshaped text It shows nothing, Is this a range issue?

yeah this is what i meant with ligatures. what is the reshaped text? i’ll take a look at ofxTTFUC to see how they do it.

1 Like

Reshape means to replace characters with their correct shapes according to their surroundings characters. It is a way to show Persian or Arabic text in applications that don’t support this kind of languages.

I think if you look at this library description you can find good clue in this problem.

ah ok that’s interesting i think we are just missing some unicode keypoints in the alphabet. looking at this:

it seems the contextual forms are in the range FE?? which in ofTTF is in ArabicPresFormsB, are you adding the range as ofUnicode::Arabic or ofAlphabet::Arabic? the latest should include the contextual forms too

if should be something like:

ofTtfSettings settings("font.ttf", size);
settings.direction = ofTttfSettings::RightToLeft;
1 Like

I used this ((ofUnicode::Arabic)), and you are right when I changed it to ((ofAlphabet::Arabic)) this fix the problem. and after the reshape every thing works fine. thanks a lot for your help.

1 Like

that’s great to hear, i though reshaping was a much more involved process but if it just means swapping some characters with others depending on their relative position in the word it might be easy to integrate into OF itself. i might ping you when it’s implemented so you can check if it works correctly if you don’t mind

1 Like

It’s a good news, I will be glad to check it .

Which nightly build have you been using? I’ve tested the of_v20170714_osx_release and had no success with stichting Arabic letters. Moreover, the ofTrueTypeFont.h and ofTrueTypeFont.cpp of that build do not appear to support OfTtfSettings.

Hej Nima,

I’ve been working more on using Arabic in OF. I now understood that you reshaped the text before loading it into OF. I’m using the python script from

However, the results in OF using ofTrueTypeFont does not yield the desired results. WhenI’m using OfxTrueTypeFontUC its better, but it needs manual adding of characters to ensure some show up properly.

I’m wondering if I have the right header and cpp file for ofTrueTypeFont, in the latest nightly build it does not offer ofTtfSettings functionality. I’ve found a header and cpp file that does, but this does not give the right results. Would you mind sharing your ofTrueTypeFont.h and .cpp?

Another possible error could be that i’m loading the text incorrectly. How do you feed your input string?

I’m hoping you have some time to help me out.
All the best,