Top Description Inners Fields Constructors Methods
com.ibm.icu.text

public Class Bidi

extends Object
Class Inheritance
Imports
java.awt.font.NumericShaper, .TextAttribute, java.lang.reflect.Array, java.text.AttributedCharacterIterator, java.util.Arrays, com.ibm.icu.impl.UBiDiProps, com.ibm.icu.lang.UCharacter, .UCharacterDirection, .UProperty

Bidi algorithm for ICU

This is an implementation of the Unicode Bidirectional Algorithm. The algorithm is defined in the Unicode Standard Annex #9.

Note

Libraries that perform a bidirectional algorithm and reorder strings accordingly are sometimes called "Storage Layout Engines". ICU's Bidi and shaping (ArabicShaping) classes can be used at the core of such "Storage Layout Engines".

General remarks about the API:

The "limit" of a sequence of characters is the position just after their last character, i.e., one more than that position.

Some of the API methods provide access to "runs". Such a "run" is defined as a sequence of characters that are at the same embedding level after performing the Bidi algorithm.

Basic concept: paragraph

A piece of text can be divided into several paragraphs by characters with the Bidi class Block Separator. For handling of paragraphs, see:

Basic concept: text direction

The direction of a piece of text may be:

Basic concept: levels

Levels in this API represent embedding levels according to the Unicode Bidirectional Algorithm. Their low-order bit (even/odd value) indicates the visual direction.

Levels can be abstract values when used for the paraLevel and embeddingLevels arguments of setPara(); there:

The related constants are not real, valid level values. DEFAULT_XXX can be used to specify a default for the paragraph level for when the setPara() method shall determine it but there is no strongly typed character in the input.

Note that the value for LEVEL_DEFAULT_LTR is even and the one for LEVEL_DEFAULT_RTL is odd, just like with normal LTR and RTL level values - these special values are designed that way. Also, the implementation assumes that MAX_EXPLICIT_LEVEL is odd.

Note

The numeric values of the related constants will not change: They are tied to the use of 7-bit byte values (plus the override bit) and of the byte data type in this API.

See Also:

Basic concept: Reordering Mode

Reordering mode values indicate which variant of the Bidi algorithm to use. See Also:

Basic concept: Reordering Options

Reordering options can be applied during Bidi text transformations. See Also:

Sample code for the ICU Bidi API

Rendering a paragraph with the ICU Bidi API
This is (hypothetical) sample code that illustrates how the ICU Bidi API could be used to render a paragraph of text. Rendering code depends highly on the graphics system, therefore this sample code must make a lot of assumptions, which may or may not match any existing graphics system's properties.

The basic assumptions are:


 package com.ibm.icu.dev.test.bidi;

 import com.ibm.icu.text.Bidi;
 import com.ibm.icu.text.BidiRun;

 public class Sample {

     static final int styleNormal = 0;
     static final int styleSelected = 1;
     static final int styleBold = 2;
     static final int styleItalics = 4;
     static final int styleSuper=8;
     static final int styleSub = 16;

     static class StyleRun {
         int limit;
         int style;

         public StyleRun(int limit, int style) {
             this.limit = limit;
             this.style = style;
         }
     }

     static class Bounds {
         int start;
         int limit;

         public Bounds(int start, int limit) {
             this.start = start;
             this.limit = limit;
         }
     }

     static int getTextWidth(String text, int start, int limit,
                             StyleRun[] styleRuns, int styleRunCount) {
         // simplistic way to compute the width
         return limit - start;
     }

     // set limit and StyleRun limit for a line
     // from text[start] and from styleRuns[styleRunStart]
     // using Bidi.getLogicalRun(...)
     // returns line width
     static int getLineBreak(String text, Bounds line, Bidi para,
                             StyleRun styleRuns[], Bounds styleRun) {
         // dummy return
         return 0;
     }

     // render runs on a line sequentially, always from left to right

     // prepare rendering a new line
     static void startLine(byte textDirection, int lineWidth) {
         System.out.println();
     }

     // render a run of text and advance to the right by the run width
     // the text[start..limit-1] is always in logical order
     static void renderRun(String text, int start, int limit,
                           byte textDirection, int style) {
     }

     // We could compute a cross-product
     // from the style runs with the directional runs
     // and then reorder it.
     // Instead, here we iterate over each run type
     // and render the intersections -
     // with shortcuts in simple (and common) cases.
     // renderParagraph() is the main function.

     // render a directional run with
     // (possibly) multiple style runs intersecting with it
     static void renderDirectionalRun(String text, int start, int limit,
                                      byte direction, StyleRun styleRuns[],
                                      int styleRunCount) {
         int i;

         // iterate over style runs
         if (direction == Bidi.LTR) {
             int styleLimit;
             for (i = 0; i < styleRunCount; ++i) {
                 styleLimit = styleRuns[i].limit;
                 if (start < styleLimit) {
                     if (styleLimit > limit) {
                         styleLimit = limit;
                     }
                     renderRun(text, start, styleLimit,
                               direction, styleRuns[i].style);
                     if (styleLimit == limit) {
                         break;
                     }
                     start = styleLimit;
                 }
             }
         } else {
             int styleStart;

             for (i = styleRunCount-1; i >= 0; --i) {
                 if (i > 0) {
                     styleStart = styleRuns[i-1].limit;
                 } else {
                     styleStart = 0;
                 }
                 if (limit >= styleStart) {
                     if (styleStart < start) {
                         styleStart = start;
                     }
                     renderRun(text, styleStart, limit, direction,
                               styleRuns[i].style);
                     if (styleStart == start) {
                         break;
                     }
                     limit = styleStart;
                 }
             }
         }
     }

     // the line object represents text[start..limit-1]
     static void renderLine(Bidi line, String text, int start, int limit,
                            StyleRun styleRuns[], int styleRunCount) {
         byte direction = line.getDirection();
         if (direction != Bidi.MIXED) {
             // unidirectional
             if (styleRunCount <= 1) {
                 renderRun(text, start, limit, direction, styleRuns[0].style);
             } else {
                 renderDirectionalRun(text, start, limit, direction,
                                      styleRuns, styleRunCount);
             }
         } else {
             // mixed-directional
             int count, i;
             BidiRun run;

             try {
                 count = line.countRuns();
             } catch (IllegalStateException e) {
                 e.printStackTrace();
                 return;
             }
             if (styleRunCount <= 1) {
                 int style = styleRuns[0].style;

                 // iterate over directional runs
                 for (i = 0; i < count; ++i) {
                     run = line.getVisualRun(i);
                     renderRun(text, run.getStart(), run.getLimit(),
                               run.getDirection(), style);
                 }
             } else {
                 // iterate over both directional and style runs
                 for (i = 0; i < count; ++i) {
                     run = line.getVisualRun(i);
                     renderDirectionalRun(text, run.getStart(),
                                          run.getLimit(), run.getDirection(),
                                          styleRuns, styleRunCount);
                 }
             }
         }
     }

     static void renderParagraph(String text, byte textDirection,
                                 StyleRun styleRuns[], int styleRunCount,
                                 int lineWidth) {
         int length = text.length();
         Bidi para = new Bidi();
         try {
             para.setPara(text,
                          textDirection != 0 ? Bidi.LEVEL_DEFAULT_RTL
                                             : Bidi.LEVEL_DEFAULT_LTR,
                          null);
         } catch (Exception e) {
             e.printStackTrace();
             return;
         }
         byte paraLevel = (byte)(1 & para.getParaLevel());
         StyleRun styleRun = new StyleRun(length, styleNormal);

         if (styleRuns == null || styleRunCount <= 0) {
             styleRuns = new StyleRun[1];
             styleRunCount = 1;
             styleRuns[0] = styleRun;
         }
         // assume styleRuns[styleRunCount-1].limit>=length

         int width = getTextWidth(text, 0, length, styleRuns, styleRunCount);
         if (width <= lineWidth) {
             // everything fits onto one line

             // prepare rendering a new line from either left or right
             startLine(paraLevel, width);

             renderLine(para, text, 0, length, styleRuns, styleRunCount);
         } else {
             // we need to render several lines
             Bidi line = new Bidi(length, 0);
             int start = 0, limit;
             int styleRunStart = 0, styleRunLimit;

             for (;;) {
                 limit = length;
                 styleRunLimit = styleRunCount;
                 width = getLineBreak(text, new Bounds(start, limit),
                                      para, styleRuns,
                                      new Bounds(styleRunStart, styleRunLimit));
                 try {
                     line = para.setLine(start, limit);
                 } catch (Exception e) {
                     e.printStackTrace();
                     return;
                 }
                 // prepare rendering a new line
                 // from either left or right
                 startLine(paraLevel, width);

                 if (styleRunStart > 0) {
                     int newRunCount = styleRuns.length - styleRunStart;
                     StyleRun[] newRuns = new StyleRun[newRunCount];
                     System.arraycopy(styleRuns, styleRunStart, newRuns, 0,
                                      newRunCount);
                     renderLine(line, text, start, limit, newRuns,
                                styleRunLimit - styleRunStart);
                 } else {
                     renderLine(line, text, start, limit, styleRuns,
                                styleRunLimit - styleRunStart);
                 }
                 if (limit == length) {
                     break;
                 }
                 start = limit;
                 styleRunStart = styleRunLimit - 1;
                 if (start >= styleRuns[styleRunStart].limit) {
                     ++styleRunStart;
                 }
             }
         }
     }

     public static void main(String[] args)
     {
         renderParagraph("Some Latin text...", Bidi.LTR, null, 0, 80);
         renderParagraph("Some Hebrew text...", Bidi.RTL, null, 0, 60);
     }
 }

Author
Simon Montagu, Matitiahu Allouche (ported from C code written by Markus W. Scherer)
ICU Status
Stable since ICU 3.8.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
private static class
pack-priv static class
pack-priv static class
pack-priv static class
private static class
pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final short
private static final short
private static final short
private static final short
private static final short
private static final short
private static final short
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
B

pack-priv final UBiDiProps
pack-priv static final byte
public static final int
CLASS_DEFAULT

Value returned by BidiClassifier when there is no need to override the standard Bidi class for a given code point.

pack-priv int
private static final char
pack-priv static final byte
pack-priv BidiClassifier
pack-priv byte
pack-priv byte
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.

pack-priv static final int[]
pack-priv static final int[]
pack-priv static final int
pack-priv static final int[]
pack-priv byte[]
pack-priv byte[]
public static final short
DO_MIRRORING

option bit for writeReordered(): replace characters with the "mirrored" property in RTL runs by their mirror-image mappings

pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv String
pack-priv static final byte
pack-priv static final byte
pack-priv static final int
pack-priv int
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
private static final short[]
private static final short[]
private static final short[]
private static final short[]
private static final short[]
private static final Bidi.ImpTabPair
private static final Bidi.ImpTabPair
private static final Bidi.ImpTabPair
private static final Bidi.ImpTabPair
private static final Bidi.ImpTabPair
private static final Bidi.ImpTabPair
private static final Bidi.ImpTabPair
private static final Bidi.ImpTabPair
private static final byte[][]
private static final byte[][]
private static final byte[][]
private static final byte[][]
private static final byte[][]
private static final byte[][]
private static final int
private static final int
pack-priv Bidi.ImpTabPair
private static final short[][]
private static final int
private static final int
private static final byte[][]
private static final byte[][]
private static final byte[][]
private static final byte[][]
private static final byte[][]
public static final short
INSERT_LRM_FOR_NUMERIC

option bit for writeReordered(): surround the run with LRMs if necessary; this is part of the approximate "inverse Bidi" algorithm

This option does not imply corresponding adjustment of the index mappings.

pack-priv Bidi.InsertPoints
pack-priv boolean
pack-priv boolean
pack-priv static final int
pack-priv int
pack-priv Bidi.Isolate[]
public static final short
KEEP_BASE_COMBINING

option bit for writeReordered(): keep combining characters after their base characters in RTL runs

pack-priv static final byte
L

pack-priv int
pack-priv int
public static final byte
LEVEL_DEFAULT_LTR

Paragraph level setting

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 byte
LEVEL_DEFAULT_RTL

Paragraph level setting

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 byte
LEVEL_OVERRIDE

Bit flag for level input.

pack-priv byte[]
pack-priv byte[]
private static final char
pack-priv int[]
pack-priv static final int
pack-priv static final byte
pack-priv static final byte
pack-priv static final int
pack-priv static final int
pack-priv static final byte
public static final byte
LTR

Left-to-right text.

public static final int
MAP_NOWHERE

Special value which can be returned by the mapping methods when a logical index has no corresponding visual index or vice-versa.

pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
public static final byte
MAX_EXPLICIT_LEVEL

Maximum explicit embedding level.

pack-priv boolean
pack-priv boolean
public static final byte
MIXED

Mixed-directional text.

public static final byte
NEUTRAL

No strongly directional text.

pack-priv static final int
pack-priv static final byte
pack-priv static final byte
public static final int
OPTION_DEFAULT

Option value for setReorderingOptions: disable all the options which can be set with this method

public static final int
OPTION_INSERT_MARKS

Option bit for setReorderingOptions: insert Bidi marks (LRM or RLM) when needed to ensure correct result of a reordering to a Logical order

This option must be set or reset before calling setPara.

public static final int
OPTION_REMOVE_CONTROLS

Option bit for setReorderingOptions: remove Bidi control characters

This option must be set or reset before calling setPara.

public static final int
OPTION_STREAMING

Option bit for setReorderingOptions: process the output as part of a stream to be continued

This option must be set or reset before calling setPara.

pack-priv boolean
pack-priv int
public static final short
OUTPUT_REVERSE

option bit for writeReordered(): write the output in reverse order

This has the same effect as calling writeReordered() first without this option, and then calling writeReverse() without mirroring.

pack-priv Bidi
pack-priv int
pack-priv byte
pack-priv byte[]
pack-priv int[]
pack-priv static final byte
pack-priv static final byte
pack-priv String
pack-priv static final byte
R

public static final short
REMOVE_BIDI_CONTROLS

option bit for writeReordered(): remove Bidi control characters (this does not affect INSERT_LRM_FOR_NUMERIC)

This option does not imply corresponding adjustment of the index mappings.

pack-priv static final short
public static final short
REORDER_DEFAULT

Reordering mode: Regular Logical to Visual Bidi algorithm according to Unicode.

public static final short
REORDER_GROUP_NUMBERS_WITH_R

Reordering mode: Logical to Visual algorithm grouping numbers with adjacent R characters (reversible algorithm).

public static final short
REORDER_INVERSE_FOR_NUMBERS_SPECIAL

Reordering mode: Inverse Bidi (Visual to Logical) algorithm for the REORDER_NUMBERS_SPECIAL Bidi algorithm.

public static final short
REORDER_INVERSE_LIKE_DIRECT

Reordering mode: Visual to Logical algorithm equivalent to the regular Logical to Visual algorithm.

public static final short
REORDER_INVERSE_NUMBERS_AS_L

Reordering mode: Visual to Logical algorithm which handles numbers like L (same algorithm as selected by setInverse(true).

pack-priv static final short
public static final short
REORDER_NUMBERS_SPECIAL

Reordering mode: Logical to Visual algorithm which handles numbers in a way which mimicks the behavior of Windows XP.

public static final short
REORDER_RUNS_ONLY

Reordering mode: Reorder runs only to transform a Logical LTR string to the logical RTL string with the same display, or vice-versa.

pack-priv int
pack-priv int
pack-priv int
pack-priv static final byte
pack-priv static final byte
pack-priv static final int
pack-priv static final int
pack-priv static final byte
public static final byte
RTL

Right-to-left text.

pack-priv int
pack-priv BidiRun[]
pack-priv BidiRun[]
pack-priv static final byte
S

pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv BidiRun[]
pack-priv char[]
pack-priv int
pack-priv static final byte

Constructor Summary

AccessConstructor and Description
public
Bidi()

Allocate a Bidi object.

public
Bidi(int
is the maximum text or line length that internal memory will be preallocated for. An attempt to associate this object with a longer text will fail, unless this value is 0, which leaves the allocation up to the implementation.
maxLength
,
int
is the maximum anticipated number of same-level runs that internal memory will be preallocated for. An attempt to access visual runs on an object that was not preallocated for as many runs as the text was actually resolved to will fail, unless this value is 0, which leaves the allocation up to the implementation.

The number of runs depends on the actual text and maybe anywhere between 1 and maxLength. It is typically small.
maxRunCount
)

Allocate a Bidi object with preallocated memory for internal structures.

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
private void
addPoint(int pos, int flag)

private void
public boolean

Returns:

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

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

pack-priv int
Bidi_Abs(int x)

pack-priv int
Bidi_Min(int x, int y)

private void
bracketAddOpening(Bidi.BracketData bd, char match, int position)

private void
private void
private void
bracketProcessBoundary(Bidi.BracketData bd, int lastCcPos, byte contextLevel, byte embeddingLevel)

private void
private byte
bracketProcessClosing(Bidi.BracketData bd, int openIdx, int position)

private void
private void
private byte
checkExplicitLevels()

Use a pre-specified embedding levels array:

Adjust the directional properties for overrides (->LEVEL_OVERRIDE), ignore all explicit codes (X9), and check all the preset levels.

private void
public int

Returns:

The number of paragraphs.
countParagraphs
()

Get the number of paragraphs.

public int

Returns:

The number of runs.
countRuns
()

Get the number of runs.

public Bidi
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.

private byte
pack-priv static final byte
DirFromStrong(byte strong)

pack-priv static int
DirPropFlag(byte dir)

pack-priv static final int
DirPropFlagE(byte level)

pack-priv static final int
DirPropFlagLR(byte level)

pack-priv static final int
DirPropFlagO(byte level)

private byte
firstL_R_AL()

Returns the directionality of the first strong character after the last B in prologue, if any.

private byte
firstL_R_AL_EN_AN()

Returns the directionality of the first strong character, or digit, in the epilogue, if any.

private void
fixN0c(Bidi.BracketData bd, int openingIndex, int newPropPosition, byte newProp)

private static short
GetAction(byte cell)

private static short
GetActionProps(short cell)

public static byte

Returns:

LTR, RTL, NEUTRAL
getBaseDirection
(CharSequence
the text whose paragraph level direction is needed.
paragraph
)

Get the base direction of the text provided according to the Unicode Bidirectional Algorithm.

public int

Returns:

the base level
getBaseLevel
()

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

public BidiClassifier

Returns:

An instance of class BidiClassifier
getCustomClassifier
()

Gets the current custom class classifier used for Bidi class determination.

public int

Returns:

The Bidi class for the character c that is in effect for this Bidi instance.
getCustomizedClass
(int
The code point to get a Bidi class for.
c
)

Retrieves the Bidi class for a given code point.

public byte

Returns:

a value of LTR, RTL or MIXED that indicates if the entire text represented by this object is unidirectional, and which direction, or if it is mixed-directional.
getDirection
()

Get the directionality of the text.

private void
private void
getDirPropsMemory(boolean mayAllocate, int len)

pack-priv void
private void
private void
private void
public int

Returns:

The length of the text that the Bidi object was created for.
getLength
()

Get the length of the text.

public byte

Returns:

The level for the character at charIndex.
getLevelAt
(int
the index of a character.
charIndex
)

Get the level for one character.

public byte[]

Returns:

The levels array for the text, or null if an error occurs.
getLevels
()

Get an array of levels for each character.

private void
getLevelsMemory(boolean mayAllocate, int len)

pack-priv void
getLevelsMemory(int len)

public int

Returns:

The index of this character in the text.
getLogicalIndex
(int
is the visual position of a character.
visualIndex
)

Get the logical text position from a visual position.

public int[]

Returns:

an array of getProcessedLength() indexes which will reflect the reordering of the characters.

The index map will result in indexMap[logicalIndex]==visualIndex, where indexMap represents the returned array.
getLogicalMap
()

Get a logical-to-visual index map (array) for the characters in the Bidi (paragraph or line) object.

public BidiRun

Returns:

a BidiRun object filled with start containing the first character of the run, limit containing the limit of the run, and embeddingLevel containing the level of the run.
getLogicalRun
(int
is a logical position within the source text.
logicalPosition
)

Get a logical run.

pack-priv void
getLogicalToVisualRunsMap()

Compute the logical to visual run mapping

pack-priv static byte
GetLRFromLevel(byte level)

private Object
getMemory(String label, Object array, Class<?> arrayClass, boolean mayAllocate, int sizeNeeded)

public BidiRun

Returns:

a BidiRun object with the details of the paragraph:
start will receive the index of the first character of the paragraph in the text.
limit will receive the limit of the paragraph.
embeddingLevel will receive the level of the paragraph.
getParagraph
(int
is the index of a character within the text, in the range [0..getProcessedLength()-1].
charIndex
)

Get a paragraph, given a position within the text.

public BidiRun

Returns:

a BidiRun object with the details of the paragraph:
start will receive the index of the first character of the paragraph in the text.
limit will receive the limit of the paragraph.
embeddingLevel will receive the level of the paragraph.
getParagraphByIndex
(int
is the number of the paragraph, in the range [0..countParagraphs()-1].
paraIndex
)

Get a paragraph, given the index of this paragraph.

public int

Returns:

The index of the paragraph containing the specified position, starting from 0.
getParagraphIndex
(int
is the index of a character within the text, in the range [0..getProcessedLength()-1].
charIndex
)

Get the index of a paragraph, given a position within the text.

public byte

Returns:

The paragraph level. If there are multiple paragraphs, their level may vary if the required paraLevel is LEVEL_DEFAULT_LTR or LEVEL_DEFAULT_RTL. In that case, the level of the first paragraph is returned.
getParaLevel
()

Get the paragraph level of the text.

pack-priv byte
GetParaLevelAt(int pindex)

public int

Returns:

The length of the part of the source text processed by the last call to setPara.
getProcessedLength
()

Get the length of the source text processed by the last call to setPara().

public int

Returns:

the current reordering mode of the Bidi object
getReorderingMode
()

What is the requested reordering mode for a given Bidi object?

public int

Returns:

the current reordering options of the Bidi object
getReorderingOptions
()

What are the reordering options applied to a given Bidi object?

public int

Returns:

The length of the reordered text resulting from the last call to setPara.
getResultLength
()

Get the length of the reordered text resulting from the last call to setPara().

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 countRuns()-1
run
)

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

public int

Returns:

the limit of the run
getRunLimit
(int
the index of the run, between 0 and countRuns()
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.

private void
getRunsMemory(boolean mayAllocate, int len)

pack-priv void
getRunsMemory(int len)

public int

Returns:

the start of the run
getRunStart
(int
the index of the run, between 0 and countRuns()
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.

private static short
GetState(byte cell)

private static short
GetStateProps(short cell)

public char[]

Returns:

A char array containing the text that the Bidi object was created for.
getText
()

Get the text.

public String

Returns:

A String containing the text that the Bidi object was created for.
getTextAsString
()

Get the text.

public int

Returns:

The visual position of this character.
getVisualIndex
(int
is the index of a character in the text.
logicalIndex
)

Get the visual position from a logical text position.

public int[]

Returns:

an array of getResultLength() indexes which will reflect the reordering of the characters.

The index map will result in indexMap[visualIndex]==logicalIndex, where indexMap represents the returned array.
getVisualMap
()

Get a visual-to-logical index map (array) for the characters in the Bidi (paragraph or line) object.

public BidiRun

Returns:

a BidiRun object containing the details of the run. The directionality of the run is LTR==0 or RTL==1, never MIXED.
getVisualRun
(int
is the number of the run in visual order, in the range [0..countRuns()-1].
runIndex
)

Get a BidiRun object according to its index.

public static int[]

Returns:

an array representing the inverse map. This array has a number of elements equal to 1 + the highest value in srcMap. For elements of the result array which have no matching elements in the source array, the corresponding elements in the inverse map will receive a value equal to MAP_NOWHERE. If element with index i in srcMap has a value k different from MAP_NOWHERE, this means that element i of the source array maps to element k in the destination array. The inverse map will have value i in its k-th element. For all elements of the destination array which do not map to an element in the source array, the corresponding element in the inverse map will have a value equal to MAP_NOWHERE.
invertMap
(int[]
is an array whose elements define the original mapping from a source array to a destination array. Some elements of the source array may have no mapping in the destination array. In that case, their value will be the special value MAP_NOWHERE. All elements must be >=0 or equal to MAP_NOWHERE. Some elements in the source map may have a value greater than the srcMap.length if the destination array has more elements than the source array. There must be no duplicate indexes (two or more elements with the same value except MAP_NOWHERE).
srcMap
)

Invert an index map.

pack-priv static boolean
pack-priv static boolean
IsDefaultLevel(byte level)

public boolean

Returns:

true if the Bidi object is set to perform the inverse Bidi algorithm by handling numbers as L.
isInverse
()

Is this Bidi object set to perform the inverse Bidi algorithm?

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 Bidi object is set to allocate level 0 to block separators.
isOrderParagraphsLTR
()

Is this Bidi object set to allocate level 0 to block separators so that successive paragraphs progress from left to right?

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

private byte
lastL_R_AL()

Returns the directionality of the last strong character at the end of the prologue, if any.

pack-priv static final byte
NoOverride(byte level)

public void
orderParagraphsLTR(boolean
specifies whether paragraph separators (B) must receive level 0, so that successive paragraphs progress from left to right.
ordarParaLTR
)

Specify whether block separators must be allocated level zero, so that successive paragraphs will progress from left to right.

private void
processPropertySeq(Bidi.LevState levState, short _prop, int start, int limit)

public static int[]

Returns:

an array of levels.length indexes which will reflect the reordering of the characters.

The index map will result in indexMap[logicalIndex]==visualIndex, where indexMap represents the returned array.

reorderLogical
(byte[]
is an array of levels that have been determined by the application.
levels
)

This is a convenience method that does not use a Bidi object.

public static int[]

Returns:

an array of levels.length indexes which will reflect the reordering of the characters.

The index map will result in indexMap[visualIndex]==logicalIndex, where indexMap represents the returned array.

reorderVisual
(byte[]
is an array of levels that have been determined by the application.
levels
)

This is a convenience method that does not use a Bidi object.

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.

private byte
private void
resolveImplicitLevels(int start, int limit, short sor, short eor)

public void
setContext(String
is the text which precedes the text that will be specified in a coming call to setPara(). If there is no prologue to consider, this parameter can be null.
prologue
,
String
is the text which follows the text that will be specified in a coming call to setPara(). If there is no epilogue to consider, this parameter can be null.
epilogue
)

Set the context before a call to setPara().

public void
setCustomClassifier(BidiClassifier
A new custom classifier. This can be null.
classifier
)

Set a custom Bidi classifier used by the UBA implementation for Bidi class determination.

public void
setInverse(boolean
specifies "forward" or "inverse" Bidi operation.
isInverse
)

Modify the operation of the Bidi algorithm such that it approximates an "inverse Bidi" algorithm.

private void
setLevelsOutsideIsolates(int start, int limit, byte level)

public Bidi

Returns:

a Bidi object that will now represent a line of the text.
setLine
(int
is the line's first index into the text.
start
,
int
is just behind the line's last index into the text (its last index +1).
limit
)

setLine() returns a Bidi object to contain the reordering information, especially the resolved levels, for all the characters in a line of text.

public void
setPara(String
contains the text that the Bidi algorithm will be performed on. This text can be retrieved with getText() or getTextAsString.
text
,
byte
specifies the default level for the text; it is typically 0 (LTR) or 1 (RTL). If the method shall determine the paragraph level from the text, then paraLevel can be set to either LEVEL_DEFAULT_LTR or LEVEL_DEFAULT_RTL; if the text contains multiple paragraphs, the paragraph level shall be determined separately for each paragraph; if a paragraph does not include any strongly typed character, then the desired default is used (0 for LTR or 1 for RTL). Any other value between 0 and MAX_EXPLICIT_LEVEL is also valid, with odd levels indicating RTL.
paraLevel
,
byte[]
(in) may be used to preset the embedding and override levels, ignoring characters like LRE and PDF in the text. A level overrides the directional property of its corresponding (same index) character if the level has the LEVEL_OVERRIDE bit set.

Aside from that bit, it must be paraLevel<=embeddingLevels[]<=MAX_EXPLICIT_LEVEL, except that level 0 is always allowed. Level 0 for a paragraph separator prevents reordering of paragraphs; this only works reliably if LEVEL_OVERRIDE is also set for paragraph separators. Level 0 for other characters is treated as a wildcard and is lifted up to the resolved level of the surrounding paragraph

Caution

A reference to this array, not a copy of the levels, will be stored in the Bidi object; the embeddingLevels should not be modified to avoid unexpected results on subsequent Bidi operations. However, the setPara() and setLine() methods may modify some or all of the levels.

Note: the embeddingLevels array must have one entry for each character in text.

embeddingLevels
)

Perform the Unicode Bidi algorithm.

public void
setPara(char[]
contains the text that the Bidi algorithm will be performed on. This text can be retrieved with getText() or getTextAsString.
chars
,
byte
specifies the default level for the text; it is typically 0 (LTR) or 1 (RTL). If the method shall determine the paragraph level from the text, then paraLevel can be set to either LEVEL_DEFAULT_LTR or LEVEL_DEFAULT_RTL; if the text contains multiple paragraphs, the paragraph level shall be determined separately for each paragraph; if a paragraph does not include any strongly typed character, then the desired default is used (0 for LTR or 1 for RTL). Any other value between 0 and MAX_EXPLICIT_LEVEL is also valid, with odd levels indicating RTL.
paraLevel
,
byte[]
(in) may be used to preset the embedding and override levels, ignoring characters like LRE and PDF in the text. A level overrides the directional property of its corresponding (same index) character if the level has the LEVEL_OVERRIDE bit set.

Aside from that bit, it must be paraLevel<=embeddingLevels[]<=MAX_EXPLICIT_LEVEL, except that level 0 is always allowed. Level 0 for a paragraph separator prevents reordering of paragraphs; this only works reliably if LEVEL_OVERRIDE is also set for paragraph separators. Level 0 for other characters is treated as a wildcard and is lifted up to the resolved level of the surrounding paragraph

Caution

A reference to this array, not a copy of the levels, will be stored in the Bidi object; the embeddingLevels should not be modified to avoid unexpected results on subsequent Bidi operations. However, the setPara() and setLine() methods may modify some or all of the levels.

Note: the embeddingLevels array must have one entry for each character in text.

embeddingLevels
)

Perform the Unicode Bidi algorithm.

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

Perform the Unicode Bidi algorithm on a given paragraph, as defined in the Unicode Standard Annex #9, version 13, also described in The Unicode Standard, Version 4.0 .

pack-priv void
setParaRunsOnly(char[] parmText, byte parmParaLevel)

private void
public void
setReorderingMode(int
specifies the required variant of the Bidi algorithm.
reorderingMode
)

Modify the operation of the Bidi algorithm such that it implements some variant to the basic Bidi algorithm or approximates an "inverse Bidi" algorithm, depending on different values of the "reordering mode".

public void
setReorderingOptions(int
A combination of zero or more of the following reordering options: OPTION_DEFAULT, OPTION_INSERT_MARKS, OPTION_REMOVE_CONTROLS, OPTION_STREAMING.
options
)

Specify which of the reordering options should be applied during Bidi transformations.

pack-priv boolean
testDirPropFlagAt(int flag, int index)

pack-priv void
verifyRange(int index, int start, int limit)

pack-priv void
pack-priv void
public String

Returns:

The reordered text. If the INSERT_LRM_FOR_NUMERIC option is set, then the length of the returned string could be as large as getLength()+2*countRuns().
If the REMOVE_BIDI_CONTROLS option is set, then the length of the returned string may be less than getLength().
If none of these options is set, then the length of the returned string will be exactly getProcessedLength().
writeReordered
(int
A bit set of options for the reordering that control how the reordered text is written. The options include mirroring the characters on a code point basis and inserting LRM characters, which is used especially for transforming visually stored text to logically stored text (although this is still an imperfect implementation of an "inverse Bidi" algorithm because it uses the "forward Bidi" algorithm at its core). The available options are: DO_MIRRORING, INSERT_LRM_FOR_NUMERIC, KEEP_BASE_COMBINING, OUTPUT_REVERSE, REMOVE_BIDI_CONTROLS, STREAMING
options
)

Take a Bidi object containing the reordering information for a piece of text (one or more paragraphs) set by setPara() or for a line of text set by setLine() and return a string containing the reordered text.

public static String

Returns:

The reordered text. If the REMOVE_BIDI_CONTROLS option is set, then the length of the returned string may be less than src.length(). If this option is not set, then the length of the returned string will be exactly src.length().
writeReverse
(String
The RTL run text.
src
,
int
A bit set of options for the reordering that control how the reordered text is written. See the options parameter in writeReordered().
options
)

Reverse a Right-To-Left run of Unicode text.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait