On 28/10/2014, at 1:19 a.m., Jonathan Peirce <
jon.p...@gmail.com> wrote:
> PsychoPy merely puts the text on the screen. It doesn't care whether the person then reads it right-to-left or left-to-right. What is it that you're expecting to be done differently by PsychoPy when reading direction is reversed?
Hi Jon,
It took me a while to understand this issue, I didn't get it from the previous e-mails either until seeing it actually happen. Following on from Mark, the issue is that PsychoPy *doesn't* merely put the text on the screen. It (or more likely, some underlying libraries…) actually modifies what is entered in the dialog box in a text component, so that what is shown on screen does not match what was entered. Perhaps it isn't right to characterise this as an active modification, I think it is just what all non-fully Unicode compliant systems do when faced with right-to-left text systems.
In the case of Arabic/Farsi, there are two issues:
(1) The order of characters is reversed, so the first character (which should be right-most) becomes left-most. The equivalent situation in English would be that you entered this in the dialog box for a text component:
HELLO
but this was displayed on-screen:
OLLEH
(2) In Arabic, the letters are like cursive English script (but much more so), in that the shape of each character alters depending on its neighbours, as they sort of link and flow into each other, and I think characters can have different forms depending on their position in a word. What PsychoPy is currently doing is breaking up the characters so that they are all isolated, which gives them different shapes than intended. This is hard to represent in ASCII English, but would be like entering this:
Hello
and actually displaying this:
h ℇ L L 0
i.e. the character shapes have changed due to being isolated rather than taking their neighbours into account.
An example is in the attached screenshot. What is wanted to be displayed is the text in white. It reads right-to-left and the characters flow into each other. This looks exactly like what appears in the text component dialog box: when using an Arabic/Farsi text input setting, the characters appear in the field right-to-left when typed, and previous characters dynamically change shape as successive characters are typed.
But when actually displayed on screen, we get the output in red: e.g. the first four red characters that look like "IJJℇ" are the isolated forms of the four cursively-linked characters reading from the right in the white text (and yes, this is the same font).
A good place to start to get a handle on this is the blog post by Abdullah Diab on his "Python Arabic Text Reshaper", <
http://mpcabd.igeex.biz/python-arabic-text-reshaper/>, which is what I've been recommending people use as a workaround.
We could incorporate his reshaper library into PsychoPy, but I'd be reluctant to do that, as it would be a single language-specific workaround that wouldn't solve the general problem (for Hebrew and so on, and possibly Japanese and other East Asian languages?)
I'm guessing that the problem lies in underlying libraries like Pyglet that aren't fully Unicode compliant (whereas whatever handles the text input fields in Builder components works fine). i.e. Perhaps once Pyglet gets that issue updated, our problems disappear, and we automatically get a WYSIWYG correspondence between the Builder input and the drawn output?
The example text I used from that blog post is this (saying "Arabic is wonderful"):
اللغة العربية رائعة
It can simply be pasted into a Builder text component dialog. This was used to produce the attached screenshot. The "raw" red text is what PsychoPy will produce. The white text is what happens if instead you paste in that text after it has been "reshaped" by his algorithm (he has a simple online service to do that although it can also be done in Python). This "re-shaped" text looks just like what was entered in the dialog box.
For what its worth, this problem seems widespread in other Python libraries, e.g. I wrote this quick script to try the same thing using PIL, without any PsychoPy libraries, and it gives the same result:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from PIL import Image
from PIL import ImageFont, ImageDraw
image = Image.new("RGB",[320,320])
draw = ImageDraw.Draw(image)
a = u'Raw: اللغة العربية رائعة'
b = u'Reshaped: ﺔﻌﺋاﺭ ﺔﻴﺑﺮﻌﻟا ﺔﻐﻠﻟا'
font = ImageFont.truetype("/Library/Fonts/Arial Unicode.ttf",14)
draw.text((50, 50), a, font=font)
draw.text((50, 150), b, font=font)
image.save("a.png")
Cheers,
Mike