java.text

Class Bidi

public final class Bidi extends Object

Bidirectional Algorithm implementation. The full algorithm is Unicode Standard Annex #9: The Bidirectional Algorithm.

Since: 1.4

Field Summary
static intDIRECTION_DEFAULT_LEFT_TO_RIGHT
This indicates that a strongly directional character in the text should set the initial direction, but if no such character is found, then the initial direction will be left-to-right.
static intDIRECTION_DEFAULT_RIGHT_TO_LEFT
This indicates that a strongly directional character in the text should set the initial direction, but if no such character is found, then the initial direction will be right-to-left.
static intDIRECTION_LEFT_TO_RIGHT
This indicates that the initial direction should be left-to-right.
static intDIRECTION_RIGHT_TO_LEFT
This indicates that the initial direction should be right-to-left.
Constructor Summary
Bidi(AttributedCharacterIterator iter)
Create a new Bidi object given an attributed character iterator.
Bidi(char[] text, int offset, byte[] embeddings, int embedOffset, int length, int flags)
Create a new Bidi object with the indicated text and, possibly, explicit embedding settings.
Bidi(String text, int flags)
Create a new Bidi object using the contents of the given String as the text.
Method Summary
booleanbaseIsLeftToRight()
Return true if the paragraph base embedding is left-to-right, false otherwise.
BidicreateLineBidi(int start, int end)
Create a new Bidi object for a single line of text, taken from the text used when creating the current Bidi object.
intgetBaseLevel()
Return the base embedding level of the paragraph.
intgetLength()
Return the length of the paragraph, in characters.
intgetLevelAt(int offset)
Return the level at the indicated character.
intgetRunCount()
Return the number of runs in the result.
intgetRunLevel(int which)
Return the level of the indicated run.
intgetRunLimit(int which)
Return the index of the character just following the end of the indicated run.
intgetRunStart(int which)
Return the index of the first character in the indicated run.
booleanisLeftToRight()
Return true if the text is entirely left-to-right, and the base embedding is also left-to-right.
booleanisMixed()
Return true if the text consists of mixed left-to-right and right-to-left runs, or if the text consists of one kind of run which differs from the base embedding direction.
booleanisRightToLeft()
Return true if the text is entirely right-to-left, and the base embedding is also right-to-left.
static voidreorderVisually(byte[] levels, int levelOffset, Object[] objs, int objOffset, int count)
Reorder objects according to the levels passed in.
static booleanrequiresBidi(char[] text, int start, int end)
Returns false if all characters in the text between start and end are all left-to-right text.
StringtoString()
Return a String describing the internal state of this object.

Field Detail

DIRECTION_DEFAULT_LEFT_TO_RIGHT

public static final int DIRECTION_DEFAULT_LEFT_TO_RIGHT
This indicates that a strongly directional character in the text should set the initial direction, but if no such character is found, then the initial direction will be left-to-right.

DIRECTION_DEFAULT_RIGHT_TO_LEFT

public static final int DIRECTION_DEFAULT_RIGHT_TO_LEFT
This indicates that a strongly directional character in the text should set the initial direction, but if no such character is found, then the initial direction will be right-to-left.

DIRECTION_LEFT_TO_RIGHT

public static final int DIRECTION_LEFT_TO_RIGHT
This indicates that the initial direction should be left-to-right.

DIRECTION_RIGHT_TO_LEFT

public static final int DIRECTION_RIGHT_TO_LEFT
This indicates that the initial direction should be right-to-left.

Constructor Detail

Bidi

public Bidi(AttributedCharacterIterator iter)
Create a new Bidi object given an attributed character iterator. This constructor will examine various attributes of the text:

Parameters: iter the attributed character iterator to use

Bidi

public Bidi(char[] text, int offset, byte[] embeddings, int embedOffset, int length, int flags)
Create a new Bidi object with the indicated text and, possibly, explicit embedding settings. If the embeddings array is null, it is ignored. Otherwise it is taken to be explicit embedding settings corresponding to the text. Positive values from 1 to 61 are embedding levels, and negative values from -1 to -61 are embedding overrides. (FIXME: not at all clear what this really means.)

Parameters: text the text to use offset the offset of the first character of the text embeddings the explicit embeddings, or null if there are none embedOffset the offset of the first embedding value to use length the length of both the text and the embeddings flags a flag indicating the base embedding direction

Bidi

public Bidi(String text, int flags)
Create a new Bidi object using the contents of the given String as the text.

Parameters: text the text to use flags a flag indicating the base embedding direction

Method Detail

baseIsLeftToRight

public boolean baseIsLeftToRight()
Return true if the paragraph base embedding is left-to-right, false otherwise.

createLineBidi

public Bidi createLineBidi(int start, int end)
Create a new Bidi object for a single line of text, taken from the text used when creating the current Bidi object.

Parameters: start the index of the first character of the line end the index of the final character of the line

Returns: a new Bidi object for the indicated line of text

getBaseLevel

public int getBaseLevel()
Return the base embedding level of the paragraph.

getLength

public int getLength()
Return the length of the paragraph, in characters.

getLevelAt

public int getLevelAt(int offset)
Return the level at the indicated character. If the supplied index is less than zero or greater than the length of the text, then the paragraph's base embedding level will be returned.

Parameters: offset the character to examine

Returns: the level of that character

getRunCount

public int getRunCount()
Return the number of runs in the result. A run is a sequence of characters at the same embedding level.

getRunLevel

public int getRunLevel(int which)
Return the level of the indicated run.

Parameters: which the run to examine

Returns: the level of that run

getRunLimit

public int getRunLimit(int which)
Return the index of the character just following the end of the indicated run.

Parameters: which the run to examine

Returns: the index of the character after the final character of the run

getRunStart

public int getRunStart(int which)
Return the index of the first character in the indicated run.

Parameters: which the run to examine

Returns: the index of the first character of the run

isLeftToRight

public boolean isLeftToRight()
Return true if the text is entirely left-to-right, and the base embedding is also left-to-right.

isMixed

public boolean isMixed()
Return true if the text consists of mixed left-to-right and right-to-left runs, or if the text consists of one kind of run which differs from the base embedding direction.

isRightToLeft

public boolean isRightToLeft()
Return true if the text is entirely right-to-left, and the base embedding is also right-to-left.

reorderVisually

public static void reorderVisually(byte[] levels, int levelOffset, Object[] objs, int objOffset, int count)
Reorder objects according to the levels passed in. This implements reordering as defined by the Unicode bidirectional layout specification. The levels are integers from 0 to 62; even numbers represent left-to-right runs, and odd numbers represent right-to-left runs.

Parameters: levels the levels associated with each object levelOffset the index of the first level to use objs the objects to reorder according to the levels objOffset the index of the first object to use count the number of objects (and levels) to manipulate

requiresBidi

public static boolean requiresBidi(char[] text, int start, int end)
Returns false if all characters in the text between start and end are all left-to-right text. This implementation is just calls Character.getDirectionality(char) on all characters and makes sure all characters are either explicitly left-to-right or neutral in directionality (character types L, EN, ES, ET, AN, CS, S and WS).

toString

public String toString()
Return a String describing the internal state of this object. This is only useful for debugging.