skip to main content
Programmer's documentation > Advanced globalization > Bidirectional text > Base text direction: supported values
 
Base text direction: supported values
The following values describe base text direction:
LTR
Left-To-Right base text direction, which is the natural base text direction of most languages, including European, Asian, and Indic languages, with possible embedded runs of the opposite direction. For example:
this ia an english sentence using SDROW IDIB EMOS
RTL
Right-To-Left base text direction, which is the natural base text direction for languages such as Arabic, Hebrew, Urdu, and Farsi, with possible embedded runs of the opposite direction. For example:
some english words GNISU ECNETNES IDIB A SI SIHT
Contextual-RTL or Contextual-LTR
The base text direction is set according to the first strong character. This choice is appropriate when the main language of the string is not known at the time of setting the base direction.
If you know in advance that a GUI component will always display Hebrew or Arabic text, the base text direction for its content can safely be set to RTL. If it is known that it will always display English or Italian text, the base direction can safely be set to LTR.
You might not have such knowledge in advance. This information might only become available when the content is dynamically generated at run time, for example, by retrieving data from a database or because the user creates the data on the spot by selecting from a list or by keyboard entry. The contextual specifications are intended for such cases; the actual direction of the text for the current occurrence is set according to the analysis of the data by a given algorithm. The algorithm is described by the Unicode organization. See http://www.unicode.org/reports/tr9/#The_Paragraph_Level.
This Unicode documentation broadly indicates that if data contains letters from RTL scripts and no letters from an LTR script, the direction will be RTL. If the data contains letters from LTR scripts and no letters from an RTL script, the direction will be LTR. If the data contains characters of both types (RTL and LTR), then the first strong directional character in logical order will determine the direction.
If the data contains no letter from either LTR or RTL type in the text, which could happen, for example, in purely numeric content, a default must be set. This default should preferably be set by the author of the code and is the reason why two contextual values exist (Contextual-LTR and Contextual-RTL).
These two values give exactly the same results if the data contains at least one LTR or RTL letter; that is, if text includes at least one strong LTR or strong RTL character, the resulting display will be the same for Contextual-LTR or Contextual-RTL.
Only when there is no such letter do the results differ; Contextual-LTR resolves to LTR and Contextual-RTL resolves to RTL. The following example shows text where the display is different for Contextual-LTR and Contextual-RTL.
In logical order:
123 < 456
Contextual-LTR display order:
123 < 456
Contextual-RTL display order:
456 > 123
The less than sign (<) is mirrored in the display order of Contextual-RTL.
When contextual direction is selected for a GUI component, Contextual-LTR should be the default for an LTR-oriented (unmirrored) GUI and Contextual-RTL should be the default for an RTL-oriented (mirrored) GUI.
JViews provides the following constants to support base text direction.
INHERITED_DIRECTION
Implicit value: the default value that is assigned to every Java framework object that displays text. The actual value is looked up on the higher levels of the JViews object hierarchy (up to the root object). If no explicit value is found, the value COMPONENT_DIRECTION is used. If this value is assigned to an object without a parent, the value COMPONENT_DIRECTION is used.
COMPONENT_DIRECTION
Explicit value: the text direction follows the GUI direction (called ““component orientation ”” in the Java world). For a mirrored GUI, it will be RTL; for a GUI that is not mirrored, it will be LTR. The default contextual base text direction in the static context of Java controls is neutralized.
LEFT_TO_RIGHT
Explicit value: base text direction is Left To Right.
RIGHT_TO_LEFT
Explicit value: base text direction is Right To Left.
CONTEXTUAL_DIRECTION
Explicit value: contextual base text direction. For strings starting from Left To RIight strong characters, it is resolved to LTR base text direction; for strings starting from Right To Left strong characters, it is resolved to RTL base text direction.
If the string does not include any strong characters, the behavior is the same as the behavior for text direction set to COMPONENT_DIRECTION.
Namely:
*For a GUI with Left-To-Right direction and control showing text that does not include any strong character, supporting CONTEXTUAL_DIRECTION has the same effect as described for Contextual-LTR in Base text direction: supported values, that is, the same effect as the supported value LEFT_TO_RIGHT.
*For a GUI with Right-To-Left direction and control showing text that does not include any strong character, supporting CONTEXTUAL_DIRECTION has the same effect as described for Contextual-RTL in Base text direction: supported values, that is, the same effect as the supported value RIGHT_TO_LEFT.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.