JDK-8100148 : Add RTL support to Text node
  • Type: Sub-task
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 8
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2012-11-09
  • Updated: 2015-06-16
  • Resolved: 2012-12-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8Fixed
Related Reports
Blocks :  
Blocks :  
Blocks :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
The Text class should override getEffectiveNodeOrientation() to return a value based on the content's natural direction (using BIDI algorithm), rather than assume LTR by default.  This assumes that getEffectiveNodeOrientation() can be made non-final -- or better yet, be turned into a read-only property so that text input controls can listen to changes that are triggered by user input.

If the content is empty or contains only direction-neutral characters, then the effective orientation should be based on the nodeOrientation property, but only then.

If it is absolutely necessary to let applications set the orientation explicitly, then Text would need the ability to track whether nodeOrientation is set explicitly on the node. This is not possible currently. Note that it would not be enough to rely on nodeOrientation being INHERIT as that could also be used as an explicit value.

Comments
Verified on 8.0b114
05-11-2013

http://jfxsrc.us.oracle.com/javafx/8.0/scrum/graphics/rt-closed/rev/8323a36cbdf1 fixing final part
26-12-2012

Text needs to map horizontal in/out values. Since Text does not mirror it has to translate the coordinates by itself, this should affect any x in or out relative to the node: caret shape, selection shape, hit test.
07-12-2012

fixed http://jfxsrc.us.oracle.com/javafx/8.0/scrum/graphics/rt-closed/rev/7fe4eda3c61c http://jfxsrc.us.oracle.com/javafx/8.0/scrum/graphics/rt/rev/ef5f81064000
29-11-2012

the first patch has a bug in TextLayout when orientation is changed dynamically. This patch fixes it.
21-11-2012

Thanks for reviewing I will wait for RT-26140 so I can push the code to without the impl_transformChanged hack. Note: I will need to put the same code in TextFlow.
21-11-2012

Patches look good.
21-11-2012

Temporary patch for rt.closed
21-11-2012

temporary patch for rt
21-11-2012

For the record, an application can add a bidi sniffer and change the nodeOrientation and/or textAlignment using something like the following. Note that this can be a bit heavy if the text string is large or if the content changes frequently. text.nodeOrientationProperty().bind(new ObjectBinding<NodeOrientation>() { { bind(text.textProperty()); } @Override protected NodeOrientation computeValue() { Bidi bidi = new Bidi(text.getText(), (textParent.getEffectiveNodeOrientation() == NodeOrientation.LEFT_TO_RIGHT) ? Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT : Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT); return (bidi.baseIsLeftToRight() ? NodeOrientation.LEFT_TO_RIGHT : NodeOrientation.RIGHT_TO_LEFT); } });
20-11-2012

The going to do the work part in scene, part in prism. I'll prepare a patch and send it to you for review hopefully today.
20-11-2012

That's fine. I think that all we need for now is to override isAutomaticallyMirrored() and to match textAlignment with nodeOrientation (using a listener, not a bind). I can take ownership of this if you want.
20-11-2012

My vote is don't sniff for now. Review sniffing in a later JIRA.
20-11-2012

Leif, have we decided how the Text node should work ? Always sniff Never sniff My take is to never sniff Whichever decide we can always add API in the future to customize this behavior if needed.
20-11-2012

See also RT-26140, RT-26141 and RT-26142.
12-11-2012

Filed RT-26215
12-11-2012

is that new ? Are we keeping all the API: effecitveOrientation(), isAutomaticallyMirrored(), getNodeOrientation(), and setNodeOrientation(). Can we just called isMirrored() ? can we remove effectiveOrientation() and (one day) replace it by generic version that can take any property, similar to javascript window.getComputedStyle, see https://developer.mozilla.org/en-US/docs/DOM/window.getComputedStyle
12-11-2012

Text should just implement the following to avoid mirroring: @Override public boolean isAutomaticallyMirrored() { return false; }
12-11-2012

Yes, that is correct, if the application sets orientation directly on text node that is what happen. The difference between Text and other Nodes is what happen when the orientation is not set on it directly. Other Nodes will inherit from the parent. Text will determine the orientation based on its current text content (text node orientation equals direction of the first char with strong directionality). If the text content is empty (or all neutral chars), the orientation is inherit from the parent. effective orientation is what it means to any other node. text alignments is based on the effective orientation and it is reversed for RTL. In the implementation the text node is never mirrored. Not sure how this can be implemented using current design. I suspect it can't because getEffectiveOrientation() down in Node is what is used to decide mirroring ?
12-11-2012

It was my understanding that the application program needs to say up front which text nodes are expected to be handling RTL data. Is this wrong?
12-11-2012