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

public Class BidiTransform

extends Object
Class Inheritance
Imports
com.ibm.icu.lang.UCharacter

Bidi Layout Transformation Engine.
Author
Lina Kemmel
ICU Status
Stable since ICU 58.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
BidiTransform.Mirroring

Mirroring indicates whether or not characters with the "mirrored" property in RTL runs should be replaced with their mirror-image counterparts.

public static enum
BidiTransform.Order

Order indicates the order of text.

private static enum

Field Summary

Modifier and TypeField and Description
private Bidi
private int
private int
private String

Constructor Summary

AccessConstructor and Description
public
BidiTransform()

BidiTransform default constructor.

Method Summary

Modifier and TypeMethod and Description
private BidiTransform.ReorderingScheme

Returns:

A valid ReorderingScheme object or null
findMatchingScheme
(byte inLevel, BidiTransform.Order inOrder, byte outLevel, BidiTransform.Order outOrder)

Finds a valid ReorderingScheme matching the caller-defined scheme.

private static boolean
IsLogical(BidiTransform.Order
Order value
order
)

Is order logical?

private static boolean
IsLTR(byte
Embedding level
level
)

Is level LTR?

private static boolean
IsRTL(byte
Embedding level
level
)

Is level RTL?

private static boolean
IsVisual(BidiTransform.Order
Order value
order
)

Is order visual?

private void
mirror()

Performs character mirroring without reordering.

private void
reorder()

Performs basic reordering of text (Logical LTR or RTL to Visual LTR).

private void
resolve(byte
Base embedding level
level
,
int
Reordering options
options
)

Performs bidi resolution of text.

private void
resolveBaseDirection(byte[]
Byte array, where levels[0] is an input level levels[1] is an output level. Resolved levels override these.
levels
)

When the direction option is Bidi#LEVEL_DEFAULT_LTR or Bidi#LEVEL_DEFAULT_RTL, resolves the base direction according to that of the first strong directional character in the text.

private void
reverse()

Performs string reverse.

private void
shapeArabic(int
Digit shaping option that indicates whether the text should be treated as logical or visual.
digitsDir
,
int
Letter shaping option that indicates whether the text should be treated as logical or visual form (can mismatch the digit option).
lettersDir
)

Performs digit and letter shaping

private void
shapeArabic(int
Shaping options covering both letters and digits
options
)

Performs digit and letter shaping

public String

Returns:

The output string, which is the result of the layout transformation.
transform
(CharSequence
An input character sequence that the Bidi layout transformations will be performed on.
text
,
byte
A base embedding level of the input as defined in Bidi#setPara(String, byte, byte[]) documentation for the paraLevel parameter.
inParaLevel
,
BidiTransform.Order
An order of the input, which can be one of the Order values.
inOrder
,
byte
A base embedding level of the output as defined in Bidi#setPara(String, byte, byte[]) documentation for the paraLevel parameter.
outParaLevel
,
BidiTransform.Order
An order of the output, which can be one of the Order values.
outOrder
,
BidiTransform.Mirroring
Indicates whether or not to perform character mirroring, and can accept one of the Mirroring values.
doMirroring
,
int
Arabic digit and letter shaping options defined in the ArabicShaping documentation.

Note

Direction indicator options are computed by the transformation engine based on the effective ordering schemes, so user-defined direction indicators will be ignored.

shapingOptions
)

Performs transformation of text from the bidi layout defined by the input ordering scheme to the bidi layout defined by the output ordering scheme, and applies character mirroring and Arabic shaping operations.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bidiback to summary
private Bidi bidi
reorderingOptionsback to summary
private int reorderingOptions
shapingOptionsback to summary
private int shapingOptions
textback to summary
private String text

Constructor Detail

BidiTransformback to summary
public BidiTransform()

BidiTransform default constructor.

ICU Status
Stable since ICU 58.

Method Detail

findMatchingSchemeback to summary
private BidiTransform.ReorderingScheme findMatchingScheme(byte inLevel, BidiTransform.Order inOrder, byte outLevel, BidiTransform.Order outOrder)

Finds a valid ReorderingScheme matching the caller-defined scheme.

Returns:BidiTransform.ReorderingScheme

A valid ReorderingScheme object or null

IsLogicalback to summary
private static boolean IsLogical(BidiTransform.Order order)

Is order logical? convenience method

Parameters
order:BidiTransform.Order

Order value

IsLTRback to summary
private static boolean IsLTR(byte level)

Is level LTR? convenience method

Parameters
level:byte

Embedding level

IsRTLback to summary
private static boolean IsRTL(byte level)

Is level RTL? convenience method

Parameters
level:byte

Embedding level

IsVisualback to summary
private static boolean IsVisual(BidiTransform.Order order)

Is order visual? convenience method

Parameters
order:BidiTransform.Order

Order value

mirrorback to summary
private void mirror()

Performs character mirroring without reordering. When this method is called, text should be in a Logical form.

reorderback to summary
private void reorder()

Performs basic reordering of text (Logical LTR or RTL to Visual LTR).

resolveback to summary
private void resolve(byte level, int options)

Performs bidi resolution of text.

Parameters
level:byte

Base embedding level

options:int

Reordering options

resolveBaseDirectionback to summary
private void resolveBaseDirection(byte[] levels)

When the direction option is Bidi#LEVEL_DEFAULT_LTR or Bidi#LEVEL_DEFAULT_RTL, resolves the base direction according to that of the first strong directional character in the text.

Parameters
levels:byte[]

Byte array, where levels[0] is an input level levels[1] is an output level. Resolved levels override these.

reverseback to summary
private void reverse()

Performs string reverse.

shapeArabicback to summary
private void shapeArabic(int digitsDir, int lettersDir)

Performs digit and letter shaping

Parameters
digitsDir:int

Digit shaping option that indicates whether the text should be treated as logical or visual.

lettersDir:int

Letter shaping option that indicates whether the text should be treated as logical or visual form (can mismatch the digit option).

shapeArabicback to summary
private void shapeArabic(int options)

Performs digit and letter shaping

Parameters
options:int

Shaping options covering both letters and digits

transformback to summary
public String transform(CharSequence text, byte inParaLevel, BidiTransform.Order inOrder, byte outParaLevel, BidiTransform.Order outOrder, BidiTransform.Mirroring doMirroring, int shapingOptions)

Performs transformation of text from the bidi layout defined by the input ordering scheme to the bidi layout defined by the output ordering scheme, and applies character mirroring and Arabic shaping operations.

In terms of Bidi class, such a transformation implies:

  • calling Bidi#setReorderingMode as needed (when the reordering mode is other than normal),
  • calling Bidi#setInverse as needed (when text should be transformed from a visual to a logical form),
  • resolving embedding levels of each character in the input text by calling Bidi#setPara,
  • reordering the characters based on the computed embedding levels, also performing character mirroring as needed, and streaming the result to the output, by calling Bidi#writeReordered,
  • performing Arabic digit and letter shaping on the output text by calling ArabicShaping#shape.

An "ordering scheme" encompasses the base direction and the order of text, and these characteristics must be defined by the caller for both input and output explicitly .

There are 36 possible combinations of {input, output} ordering schemes, which are partially supported by Bidi already. Examples of the currently supported combinations:

All combinations that involve the Visual RTL scheme are unsupported by Bidi, for instance:

  • {Logical LTR, Visual RTL},
  • {Visual RTL, Logical RTL}.

Example of usage of the transformation engine:

BidiTransform bidiTransform = new BidiTransform();
String in = "abc ۰123"; // "abc \\u06f0123"
// Run a transformation.
String out = bidiTransform.transform(in,
         Bidi.LTR, Order.VISUAL,
         Bidi.RTL, Order.LOGICAL,
         Mirroring.OFF,
         ArabicShaping.DIGITS_AN2EN | ArabicShaping.DIGIT_TYPE_AN_EXTENDED);
// Result: "0123 abc".
// Do something with out.
out = out.replace('0', '4');
// Result: "4123 abc".
// Run a reverse transformation.
String inNew = bidiTransform.transform(out,
         Bidi.RTL, Order.LOGICAL,
         Bidi.LTR, Order.VISUAL,
         Mirroring.OFF,
         ArabicShaping.DIGITS_EN2AN | ArabicShaping.DIGIT_TYPE_AN_EXTENDED);
// Result: "abc \\u06f4\\u06f1\\u06f2\\u06f3"
Parameters
text:CharSequence

An input character sequence that the Bidi layout transformations will be performed on.

inParaLevel:byte

A base embedding level of the input as defined in Bidi#setPara(String, byte, byte[]) documentation for the paraLevel parameter.

inOrder:BidiTransform.Order

An order of the input, which can be one of the Order values.

outParaLevel:byte

A base embedding level of the output as defined in Bidi#setPara(String, byte, byte[]) documentation for the paraLevel parameter.

outOrder:BidiTransform.Order

An order of the output, which can be one of the Order values.

doMirroring:BidiTransform.Mirroring

Indicates whether or not to perform character mirroring, and can accept one of the Mirroring values.

shapingOptions:int

Arabic digit and letter shaping options defined in the ArabicShaping documentation.

Note

Direction indicator options are computed by the transformation engine based on the effective ordering schemes, so user-defined direction indicators will be ignored.

Returns:String

The output string, which is the result of the layout transformation.

Exceptions
IllegalArgumentException:
if text, inOrder, outOrder, or doMirroring parameter is null.
ICU Status
Stable since ICU 58.
com.ibm.icu.text back to summary

public final Enum BidiTransform.Mirroring

extends Enum<BidiTransform.Mirroring>
Class Inheritance

Mirroring indicates whether or not characters with the "mirrored" property in RTL runs should be replaced with their mirror-image counterparts.
ICU Status
Stable since ICU 58.
See Also
Bidi#DO_MIRRORING, Bidi#setReorderingOptions, Bidi#writeReordered, Bidi#writeReverse

Field Summary

Modifier and TypeField and Description
public static final BidiTransform.Mirroring
OFF

Constant indicating that character mirroring should not be performed.

public static final BidiTransform.Mirroring
ON

Constant indicating that character mirroring should be performed.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static BidiTransform.Mirroring
public static BidiTransform.Mirroring[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

OFFback to summary
public static final BidiTransform.Mirroring OFF

Constant indicating that character mirroring should not be performed.

ICU Status
Stable since ICU 58.
ONback to summary
public static final BidiTransform.Mirroring ON

Constant indicating that character mirroring should be performed.

This corresponds to calling Bidi#writeReordered or Bidi#writeReverse with the Bidi#DO_MIRRORING option bit set.

ICU Status
Stable since ICU 58.

Constructor Detail

Mirroringback to summary
private Mirroring()

Method Detail

valueOfback to summary
public static BidiTransform.Mirroring valueOf(String name)
valuesback to summary
public static BidiTransform.Mirroring[] values()
com.ibm.icu.text back to summary

public final Enum BidiTransform.Order

extends Enum<BidiTransform.Order>
Class Inheritance

Order indicates the order of text.

This bidi transformation engine supports all possible combinations (4 in total) of input and output text order:

ICU Status
Stable since ICU 58.
See Also
Bidi#setInverse, Bidi#setReorderingMode, Bidi#REORDER_DEFAULT, Bidi#REORDER_INVERSE_LIKE_DIRECT, Bidi#REORDER_RUNS_ONLY

Field Summary

Modifier and TypeField and Description
public static final BidiTransform.Order
LOGICAL

Constant indicating a logical order.

public static final BidiTransform.Order
VISUAL

Constant indicating a visual order.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static BidiTransform.Order
public static BidiTransform.Order[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

LOGICALback to summary
public static final BidiTransform.Order LOGICAL

Constant indicating a logical order.

ICU Status
Stable since ICU 58.
VISUALback to summary
public static final BidiTransform.Order VISUAL

Constant indicating a visual order.

ICU Status
Stable since ICU 58.

Constructor Detail

Orderback to summary
private Order()

Method Detail

valueOfback to summary
public static BidiTransform.Order valueOf(String name)
valuesback to summary
public static BidiTransform.Order[] values()
com.ibm.icu.text back to summary

private sealed Enum BidiTransform.ReorderingScheme

extends Enum<BidiTransform.ReorderingScheme>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final BidiTransform.ReorderingScheme
public static final BidiTransform.ReorderingScheme
public static final BidiTransform.ReorderingScheme
public static final BidiTransform.ReorderingScheme
public static final BidiTransform.ReorderingScheme
public static final BidiTransform.ReorderingScheme
public static final BidiTransform.ReorderingScheme
public static final BidiTransform.ReorderingScheme
public static final BidiTransform.ReorderingScheme
public static final BidiTransform.ReorderingScheme
public static final BidiTransform.ReorderingScheme
public static final BidiTransform.ReorderingScheme
public static final BidiTransform.ReorderingScheme
public static final BidiTransform.ReorderingScheme
public static final BidiTransform.ReorderingScheme
public static final BidiTransform.ReorderingScheme

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract void
doTransform(BidiTransform
Bidi transformation engine
transform
)

Performs a series of bidi layout transformations unique for the current scheme.

pack-priv abstract boolean

Returns:

true if it's a match, false otherwise
matches
(byte
Base level of the input text
inLevel
,
BidiTransform.Order
Order of the input text
inOrder
,
byte
Base level of the output text
outLevel
,
BidiTransform.Order
Order of the output text
outOrder
)

Indicates whether this scheme matches another one in terms of equality of base direction and ordering scheme.

public static BidiTransform.ReorderingScheme
public static BidiTransform.ReorderingScheme[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

LOG_LTR_TO_LOG_LTRback to summary
public static final BidiTransform.ReorderingScheme LOG_LTR_TO_LOG_LTR
LOG_LTR_TO_LOG_RTLback to summary
public static final BidiTransform.ReorderingScheme LOG_LTR_TO_LOG_RTL
LOG_LTR_TO_VIS_LTRback to summary
public static final BidiTransform.ReorderingScheme LOG_LTR_TO_VIS_LTR
LOG_LTR_TO_VIS_RTLback to summary
public static final BidiTransform.ReorderingScheme LOG_LTR_TO_VIS_RTL
LOG_RTL_TO_LOG_LTRback to summary
public static final BidiTransform.ReorderingScheme LOG_RTL_TO_LOG_LTR
LOG_RTL_TO_LOG_RTLback to summary
public static final BidiTransform.ReorderingScheme LOG_RTL_TO_LOG_RTL
LOG_RTL_TO_VIS_LTRback to summary
public static final BidiTransform.ReorderingScheme LOG_RTL_TO_VIS_LTR
LOG_RTL_TO_VIS_RTLback to summary
public static final BidiTransform.ReorderingScheme LOG_RTL_TO_VIS_RTL
VIS_LTR_TO_LOG_LTRback to summary
public static final BidiTransform.ReorderingScheme VIS_LTR_TO_LOG_LTR
VIS_LTR_TO_LOG_RTLback to summary
public static final BidiTransform.ReorderingScheme VIS_LTR_TO_LOG_RTL
VIS_LTR_TO_VIS_LTRback to summary
public static final BidiTransform.ReorderingScheme VIS_LTR_TO_VIS_LTR
VIS_LTR_TO_VIS_RTLback to summary
public static final BidiTransform.ReorderingScheme VIS_LTR_TO_VIS_RTL
VIS_RTL_TO_LOG_LTRback to summary
public static final BidiTransform.ReorderingScheme VIS_RTL_TO_LOG_LTR
VIS_RTL_TO_LOG_RTLback to summary
public static final BidiTransform.ReorderingScheme VIS_RTL_TO_LOG_RTL
VIS_RTL_TO_VIS_LTRback to summary
public static final BidiTransform.ReorderingScheme VIS_RTL_TO_VIS_LTR
VIS_RTL_TO_VIS_RTLback to summary
public static final BidiTransform.ReorderingScheme VIS_RTL_TO_VIS_RTL

Constructor Detail

ReorderingSchemeback to summary
private ReorderingScheme()

Method Detail

doTransformback to summary
pack-priv abstract void doTransform(BidiTransform transform)

Performs a series of bidi layout transformations unique for the current scheme.

Parameters
transform:BidiTransform

Bidi transformation engine

matchesback to summary
pack-priv abstract boolean matches(byte inLevel, BidiTransform.Order inOrder, byte outLevel, BidiTransform.Order outOrder)

Indicates whether this scheme matches another one in terms of equality of base direction and ordering scheme.

Parameters
inLevel:byte

Base level of the input text

inOrder:BidiTransform.Order

Order of the input text

outLevel:byte

Base level of the output text

outOrder:BidiTransform.Order

Order of the output text

Returns:boolean

true if it's a match, false otherwise

valueOfback to summary
public static BidiTransform.ReorderingScheme valueOf(String name)
valuesback to summary
public static BidiTransform.ReorderingScheme[] values()