public final class ArabicShaping extends Object
ArabicShaping performs basic operations for "shaping" Arabic text. It is most useful for use with legacy data formats and legacy display technology (simple terminals). All operations are performed on Unicode characters.
Text-based shaping means that some character code points in the text are replaced by others depending on the context. It transforms one kind of text into another. In comparison, modern displays for Arabic text select appropriate, context-dependent font glyphs for each text element, which means that they transform text into a glyph vector.
Text transformations are necessary when modern display technology is not available or when text needs to be transformed to or from legacy formats that use "shaped" characters. Since the Arabic script is cursive, connecting adjacent letters to each other, computers select images for each letter based on the surrounding letters. This usually results in four images per Arabic letter: initial, middle, final, and isolated forms. In Unicode, on the other hand, letters are normally stored abstract, and a display system is expected to select the necessary glyphs. (This makes searching and other text processing easier because the same letter has only one code.) It is possible to mimic this with text transformations because there are characters in Unicode that are rendered as letters with a specific shape (or cursive connectivity). They were included for interoperability with legacy systems and codepages, and for unsophisticated display systems.
A second kind of text transformations is supported for Arabic digits: For compatibility with legacy codepages that only include European digits, it is possible to replace one set of digits by another, changing the character code points. These operations can be performed for either Arabic-Indic Digits (U+0660...U+0669) or Eastern (Extended) Arabic-Indic digits (U+06f0...U+06f9).
Some replacements may result in more or fewer characters (code points). By default, this means that the destination buffer may receive text with a length different from the source length. Some legacy systems rely on the length of the text to be constant. They expect extra spaces to be added or consumed either next to the affected character or at the end of the text.
Modifier and Type | Field and Description |
---|---|
static int |
DIGIT_TYPE_AN
Digit type option: Use Arabic-Indic digits (U+0660...U+0669).
|
static int |
DIGIT_TYPE_AN_EXTENDED
Digit type option: Use Eastern (Extended) Arabic-Indic digits (U+06f0...U+06f9).
|
static int |
DIGIT_TYPE_MASK
Bit mask for digit type options.
|
static int |
DIGITS_AN2EN
Digit shaping option: Replace Arabic-Indic digits by European digits (U+0030...U+0039).
|
static int |
DIGITS_EN2AN
Digit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits.
|
static int |
DIGITS_EN2AN_INIT_AL
Digit shaping option:
Replace European digits (U+0030...U+0039) by Arabic-Indic digits
if the most recent strongly directional character
is an Arabic letter (its Bidi direction value is RIGHT_TO_LEFT_ARABIC).
|
static int |
DIGITS_EN2AN_INIT_LR
Digit shaping option:
Replace European digits (U+0030...U+0039) by Arabic-Indic digits
if the most recent strongly directional character
is an Arabic letter (its Bidi direction value is RIGHT_TO_LEFT_ARABIC).
|
static int |
DIGITS_MASK
Bit mask for digit shaping options.
|
static int |
DIGITS_NOOP
Digit shaping option: do not perform digit shaping.
|
static int |
LAMALEF_AUTO
Memory option: the result must have the same length as the source.
|
static int |
LAMALEF_BEGIN
Memory option: the result must have the same length as the source.
|
static int |
LAMALEF_END
Memory option: the result must have the same length as the source.
|
static int |
LAMALEF_MASK
Bit mask for LamAlef memory options.
|
static int |
LAMALEF_NEAR
Memory option: the result must have the same length as the source.
|
static int |
LAMALEF_RESIZE
Memory option: allow the result to have a different length than the source.
|
static int |
LENGTH_FIXED_SPACES_AT_BEGINNING
Memory option: the result must have the same length as the source.
|
static int |
LENGTH_FIXED_SPACES_AT_END
Memory option: the result must have the same length as the source.
|
static int |
LENGTH_FIXED_SPACES_NEAR
Memory option: the result must have the same length as the source.
|
static int |
LENGTH_GROW_SHRINK
Memory option: allow the result to have a different length than the source.
|
static int |
LENGTH_MASK
Bit mask for memory options.
|
static int |
LETTERS_MASK
Bit mask for letter shaping options.
|
static int |
LETTERS_NOOP
Letter shaping option: do not perform letter shaping.
|
static int |
LETTERS_SHAPE
Letter shaping option: replace normative letter characters in the U+0600 (Arabic) block,
by shaped ones in the U+FE70 (Presentation Forms B) block.
|
static int |
LETTERS_SHAPE_TASHKEEL_ISOLATED
Letter shaping option: replace normative letter characters in the U+0600 (Arabic) block,
except for the TASHKEEL characters at U+064B...U+0652, by shaped ones in the U+Fe70
(Presentation Forms B) block.
|
static int |
LETTERS_UNSHAPE
Letter shaping option: replace shaped letter characters in the U+FE70 (Presentation Forms B) block
by normative ones in the U+0600 (Arabic) block.
|
static int |
SEEN_MASK
Bit mask for Seen memory options.
|
static int |
SEEN_TWOCELL_NEAR
Memory option: the result must have the same length as the source.
|
static int |
SHAPE_TAIL_NEW_UNICODE
If this option is used, shaping will use the new Unicode code point for TAIL (i.e. 0xFE73).
|
static int |
SHAPE_TAIL_TYPE_MASK
Bit mask for new Unicode Tail option
|
static int |
SPACES_RELATIVE_TO_TEXT_BEGIN_END
This option effects the meaning of BEGIN and END options. if this option is not used the default
for BEGIN and END will be as following:
The Default (for both Visual LTR, Visual RTL and Logical Text)
1.
|
static int |
SPACES_RELATIVE_TO_TEXT_MASK
Bit mask for swapping BEGIN and END for Visual LTR text
|
static int |
TASHKEEL_BEGIN
Memory option: the result must have the same length as the source.
|
static int |
TASHKEEL_END
Memory option: the result must have the same length as the source.
|
static int |
TASHKEEL_MASK
Bit mask for Tashkeel replacement with Space or Tatweel memory options.
|
static int |
TASHKEEL_REPLACE_BY_TATWEEL
Memory option: the result must have the same length as the source.
|
static int |
TASHKEEL_RESIZE
Memory option: allow the result to have a different length than the source.
|
static int |
TEXT_DIRECTION_LOGICAL
Direction indicator: the source is in logical (keyboard) order.
|
static int |
TEXT_DIRECTION_MASK
Bit mask for direction indicators.
|
static int |
TEXT_DIRECTION_VISUAL_LTR
Direction indicator: the source is in visual (display) order, that is,
the leftmost displayed character is stored first.
|
static int |
TEXT_DIRECTION_VISUAL_RTL
Direction indicator:the source is in visual RTL order,
the rightmost displayed character stored first.
|
static int |
YEHHAMZA_MASK
Bit mask for YehHamza memory options.
|
static int |
YEHHAMZA_TWOCELL_NEAR
Memory option: the result must have the same length as the source.
|
Constructor and Description |
---|
ArabicShaping(int options)
Construct ArabicShaping using the options flags.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object rhs) |
int |
hashCode() |
void |
shape(char[] source,
int start,
int length)
Convert a range of text in place.
|
int |
shape(char[] source,
int sourceStart,
int sourceLength,
char[] dest,
int destStart,
int destSize)
Convert a range of text in the source array, putting the result
into a range of text in the destination array, and return the number
of characters written.
|
String |
shape(String text)
Convert a string, returning the new string.
|
String |
toString() |
public static final int SEEN_TWOCELL_NEAR
public static final int SEEN_MASK
public static final int YEHHAMZA_TWOCELL_NEAR
public static final int YEHHAMZA_MASK
public static final int TASHKEEL_BEGIN
public static final int TASHKEEL_END
public static final int TASHKEEL_RESIZE
public static final int TASHKEEL_REPLACE_BY_TATWEEL
public static final int TASHKEEL_MASK
public static final int SPACES_RELATIVE_TO_TEXT_BEGIN_END
public static final int SPACES_RELATIVE_TO_TEXT_MASK
public static final int SHAPE_TAIL_NEW_UNICODE
public static final int SHAPE_TAIL_TYPE_MASK
public static final int LENGTH_GROW_SHRINK
public static final int LAMALEF_RESIZE
public static final int LENGTH_FIXED_SPACES_NEAR
public static final int LAMALEF_NEAR
public static final int LENGTH_FIXED_SPACES_AT_END
public static final int LAMALEF_END
public static final int LENGTH_FIXED_SPACES_AT_BEGINNING
public static final int LAMALEF_BEGIN
public static final int LAMALEF_AUTO
public static final int LENGTH_MASK
public static final int LAMALEF_MASK
public static final int TEXT_DIRECTION_LOGICAL
public static final int TEXT_DIRECTION_VISUAL_RTL
public static final int TEXT_DIRECTION_VISUAL_LTR
public static final int TEXT_DIRECTION_MASK
public static final int LETTERS_NOOP
public static final int LETTERS_SHAPE
public static final int LETTERS_UNSHAPE
public static final int LETTERS_SHAPE_TASHKEEL_ISOLATED
public static final int LETTERS_MASK
public static final int DIGITS_NOOP
public static final int DIGITS_EN2AN
public static final int DIGITS_AN2EN
public static final int DIGITS_EN2AN_INIT_LR
public static final int DIGITS_EN2AN_INIT_AL
public static final int DIGITS_MASK
public static final int DIGIT_TYPE_AN
public static final int DIGIT_TYPE_AN_EXTENDED
public static final int DIGIT_TYPE_MASK
public ArabicShaping(int options)
public int shape(char[] source, int sourceStart, int sourceLength, char[] dest, int destStart, int destSize) throws ArabicShapingException
source
- An array containing the input textsourceStart
- The start of the range of text to convertsourceLength
- The length of the range of text to convertdest
- The destination array that will receive the result.
It may be NULL
only if destSize
is 0.destStart
- The start of the range of the destination buffer to use.destSize
- The size (capacity) of the destination buffer.
If destSize
is 0, then no output is produced,
but the necessary buffer size is returned ("preflighting"). This
does not validate the text against the options, for example,
if letters are being unshaped, and spaces are being consumed
following lamalef, this will not detect a lamalef without a
corresponding space. An error will be thrown when the actual
conversion is attempted.ArabicShapingException
- if the text cannot be converted according to the options.public void shape(char[] source, int start, int length) throws ArabicShapingException
source
- An array containing the input textstart
- The start of the range of text to convertlength
- The length of the range of text to convertArabicShapingException
- if the text cannot be converted according to the options.public String shape(String text) throws ArabicShapingException
text
- the string to convertArabicShapingException
- if the string cannot be converted according to the options.Copyright © 2016 Unicode, Inc. and others.