Displaying text in Arabic on psychtoolbox screen

Hi all,

I am trying to display an Arabic sentence on Psychtoolbox screen, this is the code that I have tried:
[windowPtr, screenRect]= Screen(‘OpenWindow’,0,,[100 100 1800 1000]);
Screen(‘FillRect’, windowPtr,[255 255 255]);
t=‘السلام عليكم’ ;
unicodetext = fliplr(double(t));
DrawFormattedText(windowPtr, unicodetext, ‘center’, ‘center’, [0 0 0]);

and this is the output I’m getting:

Psychtoolbox doesn’t report any error, the letters are in the correct order however the problem is that the letters are not connected (cursive). I tried reading the sentence from an excel sheet and from a text file, I also tried the DispText = double(native2unicode(t, ‘UTF-8’)); command but non of which worked.

I am using:
Psychtoolbox Version: 3.0.18 - Flavor: beta - Corresponds to SVN Revision 12862
Windows 11 platform

I would appreciate any support in solving this.

I am not sure, but i think that PTB’s text rendering engines do not support ligatures and alternative forms and such things needed to render arabic correctly. I hope i am wrong, else that’d be a lot of work to fix probably. You may be better of generating images of your text in another program and loading those in.

As Diederick stated, this is a limitation of our standard text renderer. It can’t handle ligatures (Ligature (writing) - Wikipedia), contextual shaping and similar advanced scripts automatically. Arabic text, apart from bidirectional writing order (another potential challenge) seems to have especially complex ones, according to Arabic alphabet - Wikipedia.

Implementing this properly would require integrating a full fledged text shaping and layout engine into our renderer, e.g., the open-source Pango + Harfbuzz libraries, a major undertaking in the >> 100 hours of work category. Due to the disappointing lack of financial support by the over 99% majority of our users, there isn’t any funding for this, so apart from taking substantial time to do so, somebody would have to contract us. I’d expect the likely costs for the work towards a basic implementation being at least upwards of 20.000 Euros. If anybody is interested in footing the bill and contracting us, feel free to cont(r)act us. This could be another crowd-funding opportunity in theory, although the first one we tried was total disaster.

One thing you may try, if you never intend your scripts to run on other operating systems than Windows, and sacrifice performance, various functionality like DrawFormattedText2() or potentially DrawFormattedText(), accept potential formatting and rendering bugs, and generally run on a completely unsupported implementation in case of trouble or further questions, is to use the old untested, unmaintained Windows GDI text renderer by adding…
Screen('Preference', 'TextRenderer', 0);
…at the top of your script.

For any further advice from myself: help PsychPaidSupportAndServices. Any serious lab should have a paid support membership anyway if you care about your research software. If you partake in our currently running user survey, mentioned at the top of this forum, it even comes with a small discount.