Package com.ibm.icu.text
Class BidiTransform
- java.lang.Object
-
- com.ibm.icu.text.BidiTransform
-
public class BidiTransform extends java.lang.Object
Bidi Layout Transformation Engine.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BidiTransform.Mirroring
indicates whether or not characters with the "mirrored" property in RTL runs should be replaced with their mirror-image counterparts.BidiTransform.Mirroring
static class
BidiTransform.Order
indicates the order of text.BidiTransform.Order
private static class
BidiTransform.ReorderingScheme
-
Field Summary
Fields Modifier and Type Field Description private Bidi
bidi
private int
reorderingOptions
private int
shapingOptions
private java.lang.String
text
-
Constructor Summary
Constructors Constructor Description BidiTransform()
default constructor.BidiTransform
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private BidiTransform.ReorderingScheme
findMatchingScheme(byte inLevel, BidiTransform.Order inOrder, byte outLevel, BidiTransform.Order outOrder)
Finds a valid
matching the caller-defined scheme.BidiTransform.ReorderingScheme
private static boolean
IsLogical(BidiTransform.Order order)
Is order logical? convenience methodprivate static boolean
IsLTR(byte level)
Is level LTR? convenience methodprivate static boolean
IsRTL(byte level)
Is level RTL? convenience methodprivate static boolean
IsVisual(BidiTransform.Order order)
Is order visual? convenience methodprivate 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 level, int options)
Performs bidi resolution of text.private void
resolveBaseDirection(byte[] levels)
When the direction option is
orBidi.LEVEL_DEFAULT_LTR
, resolves the base direction according to that of the first strong directional character in the text.Bidi.LEVEL_DEFAULT_RTL
private void
reverse()
Performs string reverse.private void
shapeArabic(int options)
Performs digit and letter shapingprivate void
shapeArabic(int digitsDir, int lettersDir)
Performs digit and letter shapingjava.lang.String
transform(java.lang.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.
-
-
-
Field Detail
-
bidi
private Bidi bidi
-
text
private java.lang.String text
-
reorderingOptions
private int reorderingOptions
-
shapingOptions
private int shapingOptions
-
-
Constructor Detail
-
BidiTransform
public BidiTransform()
default constructor.BidiTransform
-
-
Method Detail
-
transform
public java.lang.String transform(java.lang.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
class, such a transformation implies:Bidi
- calling
as needed (when the reordering mode is other than normal),Bidi.setReorderingMode(int)
- calling
as needed (when text should be transformed from a visual to a logical form),Bidi.setInverse(boolean)
- resolving embedding levels of each character in the input text by
calling
,Bidi.setPara(java.lang.String, byte, byte[])
- 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(int)
- performing Arabic digit and letter shaping on the output text by
calling
.ArabicShaping.shape(char[], int, int, char[], int, int)
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
already. Examples of the currently supported combinations:Bidi
- {Logical LTR, Visual LTR}: this is equivalent to calling
withBidi.setPara(java.lang.String, byte, byte[])
paraLevel ==
,Bidi.LTR
- {Logical RTL, Visual LTR}: this is equivalent to calling
withBidi.setPara(java.lang.String, byte, byte[])
paraLevel ==
,Bidi.RTL
- {Logical Default ("Auto") LTR, Visual LTR}: this is equivalent to
calling
withBidi.setPara(java.lang.String, byte, byte[])
paraLevel ==
,Bidi.LEVEL_DEFAULT_LTR
- {Logical Default ("Auto") RTL, Visual LTR}: this is equivalent to
calling
withBidi.setPara(java.lang.String, byte, byte[])
paraLevel ==
,Bidi.LEVEL_DEFAULT_RTL
- {Visual LTR, Logical LTR}: this is equivalent to
calling
and thenBidi.setInverse(boolean)
(true)
withBidi.setPara(java.lang.String, byte, byte[])
paraLevel ==
,Bidi.LTR
- {Visual LTR, Logical RTL}: this is equivalent to calling
and thenBidi.setInverse(boolean)
(true)
withBidi.setPara(java.lang.String, byte, byte[])
paraLevel ==
.Bidi.RTL
All combinations that involve the Visual RTL scheme are unsupported by
, for instance:Bidi
- {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
- An input character sequence that the Bidi layout transformations will be performed on.inParaLevel
- A base embedding level of the input as defined in
documentation for theBidi.setPara(String, byte, byte[])
paraLevel
parameter.inOrder
- An order of the input, which can be one of the
values.BidiTransform.Order
outParaLevel
- A base embedding level of the output as defined in
documentation for theBidi.setPara(String, byte, byte[])
paraLevel
parameter.outOrder
- An order of the output, which can be one of the
values.BidiTransform.Order
doMirroring
- Indicates whether or not to perform character mirroring, and can accept one of the
values.BidiTransform.Mirroring
shapingOptions
- Arabic digit and letter shaping options defined in the
documentation.ArabicShaping
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:
- The output string, which is the result of the layout transformation.
- Throws:
java.lang.IllegalArgumentException
- iftext
,inOrder
,outOrder
, ordoMirroring
parameter isnull
.
- calling
-
resolveBaseDirection
private void resolveBaseDirection(byte[] levels)
When the direction option is
orBidi.LEVEL_DEFAULT_LTR
, resolves the base direction according to that of the first strong directional character in the text.Bidi.LEVEL_DEFAULT_RTL
- Parameters:
levels
- Byte array, where levels[0] is an input level levels[1] is an output level. Resolved levels override these.
-
findMatchingScheme
private BidiTransform.ReorderingScheme findMatchingScheme(byte inLevel, BidiTransform.Order inOrder, byte outLevel, BidiTransform.Order outOrder)
Finds a valid
matching the caller-defined scheme.BidiTransform.ReorderingScheme
- Returns:
- A valid
ReorderingScheme
object or null
-
resolve
private void resolve(byte level, int options)
Performs bidi resolution of text.- Parameters:
level
- Base embedding leveloptions
- Reordering options
-
reorder
private void reorder()
Performs basic reordering of text (Logical LTR or RTL to Visual LTR).
-
reverse
private void reverse()
Performs string reverse.
-
mirror
private void mirror()
Performs character mirroring without reordering. When this method is called,
should be in a Logical form.text
-
shapeArabic
private void shapeArabic(int digitsDir, int lettersDir)
Performs digit and letter shaping- Parameters:
digitsDir
- Digit shaping option that indicates whether the text should be treated as logical or visual.lettersDir
- Letter shaping option that indicates whether the text should be treated as logical or visual form (can mismatch the digit option).
-
shapeArabic
private void shapeArabic(int options)
Performs digit and letter shaping- Parameters:
options
- Shaping options covering both letters and digits
-
IsLTR
private static boolean IsLTR(byte level)
Is level LTR? convenience method- Parameters:
level
- Embedding level
-
IsRTL
private static boolean IsRTL(byte level)
Is level RTL? convenience method- Parameters:
level
- Embedding level
-
IsLogical
private static boolean IsLogical(BidiTransform.Order order)
Is order logical? convenience method- Parameters:
level
- Order value
-
IsVisual
private static boolean IsVisual(BidiTransform.Order order)
Is order visual? convenience method- Parameters:
level
- Order value
-
-