[EMAIL PROTECTED] wrote:

> I'm actually done quite some progress in turning the gtk text widget
> bidi, but I'm far from done yet. I also have some fundamental questions
> what base direction to give lines that contain no strong characters.
> If the text was saved as unicode it would be possible to add the
> special characters RTM and LTM that indicate what direction the line
> is supposed to be. But if I'm saving as iso-8859-8 I don't have these
> characters and instead have to build some heuristics. Base dir according
> to last line? To the following line? Always LTR? How does your Motif
> widget solve this, Eli?

Well, most of the widgets (at least in Motif) have two resources for
specifying their main direction (XmNlayoutDirection and
XmNstringDirection). The trick of wrapping XDrawImageString(),
XDrawString(), XDrawText(), as well as platforms dependent functions
like _XomGenericDrawString() and _XomGenericDrawImageString(), is used
by me for about four years, but only for custom widgets which are not
subclassed from Motif widgets (but directly from the abstract widgets
Composite/Core). In these cases, I don't have the widget pointer
(because the only parameters are the Display, Window, Graphic Context,
location, and string attributes), but I have a smart trick which helps
me to find the widget and follow its main direction (if there is).

There are still many cases when the main direction is not available,
or that somebody asked to "guess" the main direction according to the
context. In these cases, I follow the ruling of Unicode, and use the
following algorithm (True = RTL, False = LTR, default = LTR, H_CLASS_L
is defined for a-z + A-Z + LRM, H_CLASS_R is defined for all the
Hebrew characters + RLM):

Boolean
HCheckStrong(str, len)
  char *str;
  int len;
{
    int i;
    unsigned char d;

    for (i = 0; i < len; i++)
        if ((d = HDirectionality(str[i])) == H_CLASS_L || d == H_CLASS_R)
            return(d == H_CLASS_R);
    return(False);
}

Of course, this rule (to decide according to the first "strong-
directionality" character in the text) is not perfect. You can find
easily cases when not only the text begins with the "wrong" strong
character, but even ends with, and even most of the characters are in
the opposite language (two examples are available at the following
slide: http://elmar.co.il/wwh/column/linux/1/5.html , which is part of
the article http://elmar.co.il/wwh/column/linux/1/ ).

There is also another algorithm to "guess" if the text is written in
Logical or in Visual.

-- 
Eli Marmor
[EMAIL PROTECTED]
El-Mar Software Ltd.
050-237338

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to