Skip to main content

disable bidi reordering in TextLayout

5 replies [Last post]
Anonymous

hi All,

I'm experiencing something interesting with TextLayout. If I render a string
that has runs LRL, where L is left-to-right and R is right-to-left, everything looks good. However, if I render a string that has runs RL, the R run is rendered at the end of the line.

I have a pretty tricked out Swing text view that breaks up lines in strange ways. I'd like to disable reordering altogether. Is there a graphics hint to do this? I'm also wondering if I'm totally off in thinking the TextLine is doing any reordering ... ?

Displaying right-to-left text is not important to me. Since I'm not playing right with Swing's bidi root stuff, I need to be able to hack the text layout into shape.

Thanks!
brien

---------------------------------
Pinpoint customers who are looking for what you sell.

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
[att1.html]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Phil Race

> since the base direction of the entire text is left-to-right.

So you have broken the text at some character index boundary,
and find that without access to the complete text (ie without
context) TextLayout isn't doing what you want.

I think you need to either run Bidi yourself (java.text.Bidi)
on the whole string, or simpler, and better, use the API that
was designed for this case : java.awt.font.TextMeasurer, or
java.awt.font.LineBreakMeasurer. It will return a succession
of TextLayouts representing the whole paragraph.

-phil.

Brien Colwell wrote:
> hi --
>
> By "end of line" I did mean the right side. I'm seeing this behavior
> with Arabic embedded in English. I would expect the Arabic to appear on
> the left, though, since the base direction of the entire text is
> left-to-right. The way I'm splitting isn't preserving that information,
> so I'll look into setting the base direction as Phil suggested.
>
> Thanks for the help!
>
> brien
>
>
> */java2d@JAVADESKTOP.ORG/* wrote:
>
> > However,
> > if I render a string that has runs RL, the R run
> > is rendered at the end of the line.
>
> Isn't this behavior the correct one? Your first part is RTL, so it
> is rendered at the right-hand side of the line (if this is what you
> mean by the "end of the line"). Your second part is LTR so it is
> rendered after it, but "after" is really "to the left of it" since
> the sentence begins with the RTL part.
>
> What RTL language are you using?
> [Message sent by forum member 'kirillcool' (kirillcool)]
>
> http://forums.java.net/jive/thread.jspa?messageID=230983
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in
> the body
> of the message "signoff JAVA2D-INTEREST". For general help, send
> email to
> listserv@java.sun.com and include in the body of the message "help".
>
>
> ------------------------------------------------------------------------
> Luggage? GPS? Comic books?
> Check out fitting gifts for grads
>
> at Yahoo! Search.
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body of the message "signoff JAVA2D-INTEREST". For general help, send
> email to listserv@java.sun.com and include in the body of the message
> "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

kirillcool
Offline
Joined: 2004-11-17

> However,
> if I render a string that has runs RL, the R run
> is rendered at the end of the line.

Isn't this behavior the correct one? Your first part is RTL, so it is rendered at the right-hand side of the line (if this is what you mean by the "end of the line"). Your second part is LTR so it is rendered after it, but "after" is really "to the left of it" since the sentence begins with the RTL part.

What RTL language are you using?

Brien Colwell

hi --

By "end of line" I did mean the right side. I'm seeing this behavior with Arabic embedded in English. I would expect the Arabic to appear on the left, though, since the base direction of the entire text is left-to-right. The way I'm splitting isn't preserving that information, so I'll look into setting the base direction as Phil suggested.

Thanks for the help!

brien

java2d@JAVADESKTOP.ORG wrote: > However,
> if I render a string that has runs RL, the R run
> is rendered at the end of the line.

Isn't this behavior the correct one? Your first part is RTL, so it is rendered at the right-hand side of the line (if this is what you mean by the "end of the line"). Your second part is LTR so it is rendered after it, but "after" is really "to the left of it" since the sentence begins with the RTL part.

What RTL language are you using?
[Message sent by forum member 'kirillcool' (kirillcool)]

http://forums.java.net/jive/thread.jspa?messageID=230983

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

---------------------------------
Luggage? GPS? Comic books?
Check out fitting gifts for grads at Yahoo! Search.

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
[att1.html]

kirillcool
Offline
Joined: 2004-11-17

I would say that it is the expected behavior. The first "chunk" should set the overall orientation, and if the sentence starts with an RTL chunk, it would start at the right-hand side. This is how it goes in Hebrew.

Phil Race

There won't be a Graphics hint to affect bidi behaviour since
that is completely un-related to the graphics.
A text layout only needs a graphics instance so it knows
where to send the already laid out text.

Perhaps what you want it to explicitly specify
java.awt.font.TextAttribute.RUN_DIRECTION_LTR as the value
for the attribute java.awt.font.TextAttribute.RUN_DIRECTION
to your text layout constructor.
This will over-ride the standard bidi behaviour.
(see java.text.Bidi)

-phil.

Brien Colwell wrote:
> hi All,
>
> I'm experiencing something interesting with TextLayout. If I render a
> string
> that has runs LRL, where L is left-to-right and R is
> right-to-left, everything looks good. However, if I render a string
> that has runs RL, the R run is rendered at the end of the line.
>
> I have a pretty tricked out Swing text view that breaks up lines in
> strange ways. I'd like to disable reordering altogether. Is there a
> graphics hint to do this? I'm also wondering if I'm totally off in
> thinking the TextLine is doing any reordering ... ?
>
> Displaying right-to-left text is not important to me. Since I'm not
> playing right with Swing's bidi root stuff, I need to be able to hack
> the text layout into shape.
>
>
> Thanks!
> brien
>
> ------------------------------------------------------------------------
> Pinpoint customers
> who
> are looking for what you sell.
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body of the message "signoff JAVA2D-INTEREST". For general help, send
> email to listserv@java.sun.com and include in the body of the message
> "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".