Right-To-Left ?

BlitzMax Forums/Brucey's Modules/Right-To-Left ?

Brucey(Posted 2009) [#1]
Another weekend, another little project...

As we know, BlitzMax doesn't render right-to-left text properly. The problem is that BlitzMax simply sees a sequence of characters, so when you DrawText, you see... that same sequence of characters.
However, in languages such as Arabic and Hebrew, certain character sequences are actually written differently, so we need to apply a conversion to the text so we can see it properly.

So, here is Arabic :



As you can see, the default rendering from BlitzMax is a bit wrong. :-)


Brucey(Posted 2009) [#2]
BaH.RTL is now available for consumption - from the maxmods SVN repository.

I've tested it on Mac and Windows so far. (Linux next).

It uses the libfribidi library, which is LGPL, so I've shipped the appropriate .dylib/.dll file also. (I also had to create a makefile for Windows, so I've shipped the source too, if you ever feel the need to recompile the dll). LGPL means you can use the library in ANY app, free or otherwise.

Anyhoo, the API is possibly one of the easiest to use... there's ONE function, which takes a String, and returns another...
Function FormatStringRTL:String(text:String)

The returned string should be correctly formatted for displaying with DrawText, for example.

There's one example app provided, which renders the same text as in the image above.
You will need to copy the library (.dll / .dylib) from the lib folder into application folder. (For Mac, this is INSIDE the application bundle, in the same folder as the app binary, as usual).

Coincidentally, I believe this is the same formatter which Pango uses on Linux...


And yes, I know this is possibly about as niche as my modules get, but you never know... perhaps someone will find it useful !

As usual, comments and suggestions are always welcome.

:o)

Enjoy!


Brucey(Posted 2009) [#3]
Linux build is now working also.
You will need the libfribidi package installed on your system. (Note, for development you will also need the libfribidi-dev package).


Brucey(Posted 2009) [#4]
BaH.RTL (1.00) has been released, and can be downloaded here.

:o)

Enjoy.


Artemis(Posted 2009) [#5]
Nice, although I think I will never need it. ;-)


Space Fractal(Posted 2009) [#6]
I have not tested this one, but I have in last year have a simular request in my frontend launcher application to support Arabic which it seen I have do a very diffecent way.

I have a table with hex codes which make sure the letter also convert to the correct format (Isolated, Final, Medial and Initial).

After the convertning, I reserve the string and then calculate the postiion of it when I draw the text.

The user interface itself was also mirrored, so it look more correct.

The above was a project to addon Arabic support in my game launcher application I wrote for my arcade cabinet, and I have to say I dosent understand arabic, but was a fun project to do that.


Brucey(Posted 2009) [#7]
I would always look first for a library to do anything complex. (Perhaps I am just lazy ;-)

I don't understand Arabic either, but I investigated enough to understand at a basic level how characters change depending on their relative positions. Then I went out to find the best library to do the conversion for me.

The reason I went with fribidi (despite being LGPL), is because Pango (on Linux) uses it for it's right-to-left mapping. And since that is known to work well, it seemed a good choice.

Of course, to use these RTL Strings properly, you will need to right-align them correctly, but that's not a big issue (and something you can cache if required).

:o)