Constructor: |
public Bidi(AttributedCharacterIterator paragraph) {
if (paragraph == null) {
throw new IllegalArgumentException("paragraph is null");
}
bidiBase = new BidiBase(0, 0);
bidiBase.setPara(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 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. Parameters:
paragraph - a paragraph of text with optional character and paragraph attribute information
Also see:
- java.awt.font.TextAttribute#BIDI_EMBEDDING
- java.awt.font.TextAttribute#NUMERIC_SHAPING
- java.awt.font.TextAttribute#RUN_DIRECTION
|
public Bidi(String paragraph,
int flags) {
if (paragraph == null) {
throw new IllegalArgumentException("paragraph is null");
}
bidiBase = new BidiBase(paragraph.toCharArray(), 0, null, 0, paragraph.length(), flags);
}
Create Bidi from the given paragraph of text and base direction. Parameters:
paragraph - a paragraph of text
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.
|
public Bidi(char[] text,
int textStart,
byte[] embeddings,
int embStart,
int paragraphLength,
int flags) {
if (text == null) {
throw new IllegalArgumentException("text is null");
}
if (paragraphLength < 0) {
throw new IllegalArgumentException("bad length: " + paragraphLength);
}
if (textStart < 0 || paragraphLength > text.length - textStart) {
throw new IllegalArgumentException("bad range: " + textStart +
" length: " + paragraphLength +
" for text of length: " + text.length);
}
if (embeddings != null && (embStart < 0 || paragraphLength > embeddings.length - embStart)) {
throw new IllegalArgumentException("bad range: " + embStart +
" length: " + paragraphLength +
" for embeddings of length: " + text.length);
}
bidiBase = new BidiBase(text, textStart, embeddings, embStart, paragraphLength, 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 - 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 from java.text.Bidi Detail: |
public boolean baseIsLeftToRight() {
return bidiBase.baseIsLeftToRight();
}
Return true if the base direction is left-to-right. |
public Bidi createLineBidi(int lineStart,
int lineLimit) {
AttributedString astr = new AttributedString("");
Bidi newBidi = new Bidi(astr.getIterator());
return bidiBase.setLine(this, bidiBase, newBidi, newBidi.bidiBase,lineStart, 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. |
public int getBaseLevel() {
return bidiBase.getParaLevel();
}
Return the base level (0 if left-to-right, 1 if right-to-left). |
public int getLength() {
return bidiBase.getLength();
}
Return the length of text in the line. |
public int getLevelAt(int offset) {
return bidiBase.getLevelAt(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. |
public int getRunCount() {
return bidiBase.countRuns();
}
Return the number of level runs. |
public int getRunLevel(int run) {
return bidiBase.getRunLevel(run);
}
Return the level of the nth logical run in this line. |
public int getRunLimit(int run) {
return bidiBase.getRunLimit(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. |
public int getRunStart(int run) {
return bidiBase.getRunStart(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 isLeftToRight() {
return bidiBase.isLeftToRight();
}
Return true if the line is all left-to-right text and the base direction is left-to-right. |
public boolean isMixed() {
return bidiBase.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. |
public boolean isRightToLeft() {
return bidiBase.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[] levels,
int levelStart,
Object[] objects,
int objectStart,
int count) {
BidiBase.reorderVisually(levels, levelStart, objects, objectStart, 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 ). |
public static boolean requiresBidi(char[] text,
int start,
int limit) {
return BidiBase.requiresBidi(text, start, 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. |
public String toString() {
return bidiBase.toString();
}
Display the bidi internal state, used in debugging. |