|
JavaTM 2 Platform Std. Ed. v1.4.2 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.text.Bidi
This class implements the Unicode Version 3.0 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.
Field Summary | |
static 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. |
static 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. |
static int |
DIRECTION_LEFT_TO_RIGHT
Constant indicating base direction is left-to-right. |
static int |
DIRECTION_RIGHT_TO_LEFT
Constant indicating base direction is right-to-left. |
Constructor Summary | |
Bidi(AttributedCharacterIterator paragraph)
Create Bidi from the given paragraph of text. |
|
Bidi(char[] text,
int textStart,
byte[] embeddings,
int embStart,
int paragraphLength,
int flags)
Create Bidi from the given text, embedding, and direction information. |
|
Bidi(String paragraph,
int flags)
Create Bidi from the given paragraph of text and base direction. |
Method Summary | |
boolean |
baseIsLeftToRight()
Return true if the base direction is left-to-right. |
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. |
int |
getBaseLevel()
Return the base level (0 if left-to-right, 1 if right-to-left). |
int |
getLength()
Return the length of text in the line. |
int |
getLevelAt(int offset)
Return the resolved level of the character at offset. |
int |
getRunCount()
Return the number of level runs. |
int |
getRunLevel(int run)
Return the level of the nth logical run in this line. |
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. |
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. |
boolean |
isLeftToRight()
Return true if the line is all left-to-right text and the base direction is left-to-right. |
boolean |
isMixed()
Return true if the line is not left-to-right or right-to-left. |
boolean |
isRightToLeft()
Return true if the line is all right-to-left text, and the base direction is right-to-left. |
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. |
static boolean |
requiresBidi(char[] text,
int start,
int limit)
Return true if the specified text requires bidi analysis. |
String |
toString()
Display the bidi internal state, used in debugging. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int DIRECTION_LEFT_TO_RIGHT
public static final int DIRECTION_RIGHT_TO_LEFT
public static final int DIRECTION_DEFAULT_LEFT_TO_RIGHT
public static final int DIRECTION_DEFAULT_RIGHT_TO_LEFT
Constructor Detail |
public Bidi(String paragraph, int flags)
paragraph
- a paragraph of textflags
- 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.public Bidi(AttributedCharacterIterator paragraph)
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 computes 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.
paragraph
- a paragraph of text with optional character and paragraph attribute informationTextAttribute.BIDI_EMBEDDING
,
TextAttribute.NUMERIC_SHAPING
,
TextAttribute.RUN_DIRECTION
public Bidi(char[] text, int textStart, byte[] embeddings, int embStart, int paragraphLength, int flags)
text
- an array containing the paragraph of text to process.textStart
- the index into the text array of the start of the paragraph.embeddings
- 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
- the index into the embedding array of the start of the paragraph.paragraphLength
- the length of the paragraph in the text and embeddings arrays.flags
- 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 |
public Bidi createLineBidi(int lineStart, int lineLimit)
lineStart
- the offset from the start of the paragraph to the start of the line.lineLimit
- the offset from the start of the paragraph to the limit of the line.public boolean isMixed()
public boolean isLeftToRight()
public boolean isRightToLeft()
public int getLength()
public boolean baseIsLeftToRight()
public int getBaseLevel()
public int getLevelAt(int offset)
offset
- the index of the character for which to return the level
public int getRunCount()
public int getRunLevel(int run)
run
- the index of the run, between 0 and getRunCount()
public int getRunStart(int run)
run
- the index of the run, between 0 and getRunCount()
public int getRunLimit(int run)
run
- the index of the run, between 0 and getRunCount()
public static boolean requiresBidi(char[] text, int start, int limit)
text
- the text containing the characters to teststart
- the start of the range of characters to testlimit
- the limit of the range of characters to test
public static void reorderVisually(byte[] levels, int levelStart, Object[] objects, int objectStart, int count)
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
).
levels
- an array representing the bidi level of each objectlevelStart
- the start position in the levels arrayobjects
- the array of objects to be reordered into visual orderobjectStart
- the start position in the objects arraycount
- the number of objects to reorderpublic String toString()
toString
in class Object
|
JavaTM 2 Platform Std. Ed. v1.4.2 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.