APIdia Launch Partner
Top Description Fields Constructors Methods
java.text

public final Class Bidi

extends Object
Class Inheritance
Imports
jdk.internal.icu.text.BidiBase

This class implements the Unicode Bidirectional Algorithm.

A Bidi object provides information on the bidirectional reordering of the text used to create it. This is required, for example, to properly display Arabic or Hebrew text. These languages are inherently mixed directional, as they order numbers from left-to-right while ordering most other text from right-to-left.

Once created, a Bidi object can be queried to see if the text it represents is all left-to-right or all right-to-left. Such objects are very lightweight and this text is relatively easy to process.

If there are multiple runs of text, information about the runs can be accessed by indexing to get the start, limit, and level of a run. The level represents both the direction and the 'nesting level' of a directional run. Odd levels are right-to-left, while even levels are left-to-right. So for example level 0 represents left-to-right text, while level 1 represents right-to-left text, and level 2 represents left-to-right text embedded in a right-to-left run.

Since
1.4

Field Summary

Modifier and TypeField and Description
private BidiBase
public static final int
DIRECTION_DEFAULT_LEFT_TO_RIGHT

Constant indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm.

public static final int
DIRECTION_DEFAULT_RIGHT_TO_LEFT

Constant indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm.

public static final int
DIRECTION_LEFT_TO_RIGHT

Constant indicating base direction is left-to-right.

public static final int
DIRECTION_RIGHT_TO_LEFT

Constant indicating base direction is right-to-left.

Constructor Summary

AccessConstructor and Description
public
Bidi(String
a paragraph of text
paragraph
,
int
a collection of flags that control the algorithm. The algorithm understands the flags DIRECTION_LEFT_TO_RIGHT, DIRECTION_RIGHT_TO_LEFT, DIRECTION_DEFAULT_LEFT_TO_RIGHT, and DIRECTION_DEFAULT_RIGHT_TO_LEFT. Other values are reserved.
flags
)

Create Bidi from the given paragraph of text and base direction.

public
Bidi(AttributedCharacterIterator
a paragraph of text with optional character and paragraph attribute information
paragraph
)

Create Bidi from the given paragraph of text.

public
Bidi(char[]
an array containing the paragraph of text to process.
text
,
int
the index into the text array of the start of the paragraph.
textStart
,
byte[]
an array containing embedding values for each character in the paragraph. This can be null, in which case it is assumed that there is no external embedding information.
embeddings
,
int
the index into the embedding array of the start of the paragraph.
embStart
,
int
the length of the paragraph in the text and embeddings arrays.
paragraphLength
,
int
a collection of flags that control the algorithm. The algorithm understands the flags DIRECTION_LEFT_TO_RIGHT, DIRECTION_RIGHT_TO_LEFT, DIRECTION_DEFAULT_LEFT_TO_RIGHT, and DIRECTION_DEFAULT_RIGHT_TO_LEFT. Other values are reserved.
flags
)

Create Bidi from the given text, embedding, and direction information.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the base direction is left-to-right
baseIsLeftToRight
()

Return true if the base direction is left-to-right.

public Bidi

Returns:

a Bidi object
createLineBidi
(int
the offset from the start of the paragraph to the start of the line.
lineStart
,
int
the offset from the start of the paragraph to the limit of the line.
lineLimit
)

Create a Bidi object representing the bidi information on a line of text within the paragraph represented by the current Bidi.

public int

Returns:

the base level
getBaseLevel
()

Return the base level (0 if left-to-right, 1 if right-to-left).

public int

Returns:

the length of text in the line
getLength
()

Return the length of text in the line.

public int

Returns:

the resolved level of the character at offset
getLevelAt
(int
the index of the character for which to return the level
offset
)

Return the resolved level of the character at offset.

public int

Returns:

the number of level runs
getRunCount
()

Return the number of level runs.

public int

Returns:

the level of the run
getRunLevel
(int
the index of the run, between 0 and getRunCount()
run
)

Return the level of the nth logical run in this line.

public int

Returns:

limit the limit of the run
getRunLimit
(int
the index of the run, between 0 and getRunCount()
run
)

Return the index of the character past the end of the nth logical run in this line, as an offset from the start of the line.

public int

Returns:

the start of the run
getRunStart
(int
the index of the run, between 0 and getRunCount()
run
)

Return the index of the character at the start of the nth logical run in this line, as an offset from the start of the line.

public boolean

Returns:

true if the line is all left-to-right text and the base direction is left-to-right
isLeftToRight
()

Return true if the line is all left-to-right text and the base direction is left-to-right.

public boolean

Returns:

true if the line is not left-to-right or right-to-left.
isMixed
()

Return true if the line is not left-to-right or right-to-left.

public boolean

Returns:

true if the line is all right-to-left text, and the base direction is right-to-left
isRightToLeft
()

Return true if the line is all right-to-left text, and the base direction is right-to-left.

public static void
reorderVisually(byte[]
an array representing the bidi level of each object
levels
,
int
the start position in the levels array
levelStart
,
Object[]
the array of objects to be reordered into visual order
objects
,
int
the start position in the objects array
objectStart
,
int
the number of objects to reorder
count
)

Reorder the objects in the array into visual order based on their levels.

public static boolean

Returns:

true if the range of characters requires bidi analysis
requiresBidi
(char[]
the text containing the characters to test
text
,
int
the start of the range of characters to test
start
,
int
the limit of the range of characters to test
limit
)

Return true if the specified text requires bidi analysis.

public String
toString()

Overrides java.lang.Object.toString.

Display the bidi internal state, used in debugging.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

bidiBaseback to summary
private BidiBase bidiBase
DIRECTION_DEFAULT_LEFT_TO_RIGHTback to summary
public static final int DIRECTION_DEFAULT_LEFT_TO_RIGHT

Constant indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm. If no strong directional character is present, the base direction is left-to-right.

DIRECTION_DEFAULT_RIGHT_TO_LEFTback to summary
public static final int DIRECTION_DEFAULT_RIGHT_TO_LEFT

Constant indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm. If no strong directional character is present, the base direction is right-to-left.

DIRECTION_LEFT_TO_RIGHTback to summary
public static final int DIRECTION_LEFT_TO_RIGHT

Constant indicating base direction is left-to-right.

DIRECTION_RIGHT_TO_LEFTback to summary
public static final int DIRECTION_RIGHT_TO_LEFT

Constant indicating base direction is right-to-left.

Constructor Detail

Bidiback to summary
public Bidi(String paragraph, int flags)

Create Bidi from the given paragraph of text and base direction.

Parameters
paragraph:String

a paragraph of text

flags:int

a collection of flags that control the algorithm. The algorithm understands the flags DIRECTION_LEFT_TO_RIGHT, DIRECTION_RIGHT_TO_LEFT, DIRECTION_DEFAULT_LEFT_TO_RIGHT, and DIRECTION_DEFAULT_RIGHT_TO_LEFT. Other values are reserved.

Bidiback to summary
public Bidi(AttributedCharacterIterator paragraph)

Create Bidi from the given paragraph of text.

The RUN_DIRECTION attribute in the text, if present, determines the base direction (left-to-right or right-to-left). If not present, the base direction is computed using the Unicode Bidirectional Algorithm, defaulting to left-to-right if there are no strong directional characters in the text. This attribute, if present, must be applied to all the text in the paragraph.

The BIDI_EMBEDDING attribute in the text, if present, represents embedding level information. Negative values from -1 to -62 indicate overrides at the absolute value of the level. Positive values from 1 to 62 indicate embeddings. Where values are zero or not defined, the base embedding level as determined by the base direction is assumed.

The NUMERIC_SHAPING attribute in the text, if present, converts European digits to other decimal digits before running the bidi algorithm. This attribute, if present, must be applied to all the text in the paragraph.

Parameters
paragraph:AttributedCharacterIterator

a paragraph of text with optional character and paragraph attribute information

Annotations
@SuppressWarnings:doclint:reference
See Also
java.desktop/java.awt.font.TextAttribute#BIDI_EMBEDDING, java.desktop/java.awt.font.TextAttribute#NUMERIC_SHAPING, java.desktop/java.awt.font.TextAttribute#RUN_DIRECTION
Bidiback to summary
public Bidi(char[] text, int textStart, byte[] embeddings, int embStart, int paragraphLength, int flags)

Create Bidi from the given text, embedding, and direction information. The embeddings array may be null. If present, the values represent embedding level information. Negative values from -1 to -61 indicate overrides at the absolute value of the level. Positive values from 1 to 61 indicate embeddings. Where values are zero, the base embedding level as determined by the base direction is assumed.

Parameters
text:char[]

an array containing the paragraph of text to process.

textStart:int

the index into the text array of the start of the paragraph.

embeddings:byte[]

an array containing embedding values for each character in the paragraph. This can be null, in which case it is assumed that there is no external embedding information.

embStart:int

the index into the embedding array of the start of the paragraph.

paragraphLength:int

the length of the paragraph in the text and embeddings arrays.

flags:int

a collection of flags that control the algorithm. The algorithm understands the flags DIRECTION_LEFT_TO_RIGHT, DIRECTION_RIGHT_TO_LEFT, DIRECTION_DEFAULT_LEFT_TO_RIGHT, and DIRECTION_DEFAULT_RIGHT_TO_LEFT. Other values are reserved.

Method Detail

baseIsLeftToRightback to summary
public boolean baseIsLeftToRight()

Return true if the base direction is left-to-right.

Returns:boolean

true if the base direction is left-to-right

createLineBidiback to summary
public Bidi createLineBidi(int lineStart, int lineLimit)

Create a Bidi object representing the bidi information on a line of text within the paragraph represented by the current Bidi. This call is not required if the entire paragraph fits on one line.

Parameters
lineStart:int

the offset from the start of the paragraph to the start of the line.

lineLimit:int

the offset from the start of the paragraph to the limit of the line.

Returns:Bidi

a Bidi object

getBaseLevelback to summary
public int getBaseLevel()

Return the base level (0 if left-to-right, 1 if right-to-left).

Returns:int

the base level

getLengthback to summary
public int getLength()

Return the length of text in the line.

Returns:int

the length of text in the line

getLevelAtback to summary
public int getLevelAt(int offset)

Return the resolved level of the character at offset. If offset is < 0 or ≥ the length of the line, return the base direction level.

Parameters
offset:int

the index of the character for which to return the level

Returns:int

the resolved level of the character at offset

getRunCountback to summary
public int getRunCount()

Return the number of level runs.

Returns:int

the number of level runs

getRunLevelback to summary
public int getRunLevel(int run)

Return the level of the nth logical run in this line.

Parameters
run:int

the index of the run, between 0 and getRunCount()

Returns:int

the level of the run

getRunLimitback to summary
public int getRunLimit(int run)

Return the index of the character past the end of the nth logical run in this line, as an offset from the start of the line. For example, this will return the length of the line for the last run on the line.

Parameters
run:int

the index of the run, between 0 and getRunCount()

Returns:int

limit the limit of the run

getRunStartback to summary
public int getRunStart(int run)

Return the index of the character at the start of the nth logical run in this line, as an offset from the start of the line.

Parameters
run:int

the index of the run, between 0 and getRunCount()

Returns:int

the start of the run

isLeftToRightback to summary
public boolean isLeftToRight()

Return true if the line is all left-to-right text and the base direction is left-to-right.

Returns:boolean

true if the line is all left-to-right text and the base direction is left-to-right

isMixedback to summary
public boolean isMixed()

Return true if the line is not left-to-right or right-to-left. This means it either has mixed runs of left-to-right and right-to-left text, or the base direction differs from the direction of the only run of text.

Returns:boolean

true if the line is not left-to-right or right-to-left.

isRightToLeftback to summary
public boolean isRightToLeft()

Return true if the line is all right-to-left text, and the base direction is right-to-left.

Returns:boolean

true if the line is all right-to-left text, and the base direction is right-to-left

reorderVisuallyback to summary
public static void reorderVisually(byte[] levels, int levelStart, Object[] objects, int objectStart, int count)

Reorder the objects in the array into visual order based on their levels. This is a utility function to use when you have a collection of objects representing runs of text in logical order, each run containing text at a single level. The elements at index from objectStart up to objectStart + count in the objects array will be reordered into visual order assuming each run of text has the level indicated by the corresponding element in the levels array (at index - objectStart + levelStart).

Parameters
levels:byte[]

an array representing the bidi level of each object

levelStart:int

the start position in the levels array

objects:Object[]

the array of objects to be reordered into visual order

objectStart:int

the start position in the objects array

count:int

the number of objects to reorder

requiresBidiback to summary
public static boolean requiresBidi(char[] text, int start, int limit)

Return true if the specified text requires bidi analysis. If this returns false, the text will display left-to-right. Clients can then avoid constructing a Bidi object. Text in the Arabic Presentation Forms area of Unicode is presumed to already be shaped and ordered for display, and so will not cause this function to return true.

Parameters
text:char[]

the text containing the characters to test

start:int

the start of the range of characters to test

limit:int

the limit of the range of characters to test

Returns:boolean

true if the range of characters requires bidi analysis

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Display the bidi internal state, used in debugging.