[reportlab-users] Right-to-Left languages

Ury Marshak reportlab-users@reportlab.com
Tue, 15 Oct 2002 14:25:28 +0200


Andy Robinson wrote:
>  I am VERY interested in this.  Thanks, Ury!  

I'm glad that you're interested; what I have right now is a somewhat
ugly hack, that is trying to touch as little as possible in the
base code. To make a more complete bidi-support it might be desirable
to introduce some changes in the framework (sounds pretty heavy, but
I'm talking about rather small changes, I'll outline my thoughts
below - warning! somewhat lengthy :)

> Can you send over
> some code?  
Sure, tell me where to send it. It's not really packaged into something
distributable though, so you must be prepared to help me to beat it into
shape ;)

> Also, since you do not use ME, I presume you
> are embedding fonts?  TrueType or Type 1? We'll need to know where
> to get hold of an appropriate font and to make some kind of reproducible
> test script.  

I tried it only on a windows machine with the TT fonts that came with it,
but I'm not doing anything special with the fonts, so T1 should be fine
as long as they are properly encoded.

> I would be delighted to make a checkin, even if we label it
> as 'experimental', so we and others can use it.
> 

I'm not very happy with my current version. Currently I have a low-level
that does the actual logical-to-visual translation and I wrote additional
classes like TableRTL, ParagraphRTL etc, that piggyback on the 
existing ones. What I would like to see is something ilke the following:

Flowables and containers get a 'direction' attribute,
which defaults to LTR. More precisely it defaults to 'use parent's'
direction and only the top level (Document?) defaults to LTR. This
means that there must be some way to pass that information from
container to contained element. Not sure what the best way to
pass that information would be though.

Alignment gets a new value 'SAME_AS_DIRECTION' which becomes a
default for the elements instead of 'LEFT'

The code will mostly stay the same. It will need to swap coordinates
according to the direction; the containers will need a way to figure
out if their elements support BiDi and pass adjusted coordinates to
them to stay compatible with user-written Flowables.

The good news is that all the processing (like formatting the paraghps
etc is done in the logical representation (i.e. with the string as it
is passed by the user) and only at the moment we output the string
we have to translate it to visual representation. The Unicode Consortium 
warns about some degenerate cases, but I think we can ignore it for
now. The only change that might be useful to introduce at the first
stage would be the determination of spaces - to use the unicode 
line-breaking properties. Still it might be left as is for now,
only factor out a 'isPossibleLineBreak(char)' function.

Well, i think I'll wrap this up for now, I'll wait for your comments on
possibility of such changes.

> You will have to be patient with us as me and my team can't read
> any right-to-left languages.  

That's not going to be a problem - the task at hand is to _write_
them ;)

> However, FriBiDi (which I had never heard
> of before tonight) has some really good docs and links to them:
>   http://fribidi.sourceforge.net/
>   http://www.langbox.com/bidimozilla/BiDi_API.html

Er, after wrapping it up for python I find it a bit lacking,
but nothing is perfect. Also I had to jump through some hoops
to compile it on windows - the CVS version provides windows
project files (although some methods are not exported),
but the CVS version has some severe memory problems, so I
ended up taking configuration files from the CVS version
and grafting them on the release library. Under *nix I
expect it to be much easier. (I also had a look at another
library - IBM's ICU, but it is a much bigger library that does
a lot of other things, and carrying around a 10MB library
just to use one function looks like an overkill)

> 
> Best Regards,
> 
> Andy Robinson
> 
> p.s. do all Israelis start coding at midnight?  The Twisted Matrix team
> usually get busy about now too...
> 

I'm trying to get rid of that habit, but not having much success,
and google search on "Anonymous Late-night Coders" brings no results ;)
As for others, possible reasons might include easier interaction with
US guys for example

Ury