Class ArabicShaping
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Digit type option: Use Arabic-Indic digits (U+0660...U+0669).static final int
Digit type option: Use Eastern (Extended) Arabic-Indic digits (U+06f0...U+06f9).static final int
Bit mask for digit type options.static final int
Digit shaping option: Replace Arabic-Indic digits by European digits (U+0030...U+0039).static final int
Digit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits.static final int
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 final int
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 final int
Bit mask for digit shaping options.static final int
Digit shaping option: do not perform digit shaping.static final int
Memory option: the result must have the same length as the source.static final int
Memory option: the result must have the same length as the source.static final int
Memory option: the result must have the same length as the source.static final int
Bit mask for LamAlef memory options.static final int
Memory option: the result must have the same length as the source.static final int
Memory option: allow the result to have a different length than the source.static final int
Memory option: the result must have the same length as the source.static final int
Memory option: the result must have the same length as the source.static final int
Memory option: the result must have the same length as the source.static final int
Memory option: allow the result to have a different length than the source.static final int
Bit mask for memory options.static final int
Bit mask for letter shaping options.static final int
Letter shaping option: do not perform letter shaping.static final int
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 final int
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 final int
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 final int
Bit mask for Seen memory options.static final int
Memory option: the result must have the same length as the source.static final int
If this option is used, shaping will use the new Unicode code point for TAIL (i.e. 0xFE73).static final int
Bit mask for new Unicode Tail optionstatic final int
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 final int
Bit mask for swapping BEGIN and END for Visual LTR textstatic final int
Memory option: the result must have the same length as the source.static final int
Memory option: the result must have the same length as the source.static final int
Bit mask for Tashkeel replacement with Space or Tatweel memory options.static final int
Memory option: the result must have the same length as the source.static final int
Memory option: allow the result to have a different length than the source.static final int
Direction indicator: the source is in logical (keyboard) order.static final int
Bit mask for direction indicators.static final int
Direction indicator: the source is in visual (display) order, that is, the leftmost displayed character is stored first.static final int
Direction indicator:the source is in visual RTL order, the rightmost displayed character stored first.static final int
Bit mask for YehHamza memory options.static final int
Memory option: the result must have the same length as the source. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
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.Convert a string, returning the new string.toString()
-
Field Details
-
SEEN_TWOCELL_NEAR
public static final int SEEN_TWOCELL_NEARMemory option: the result must have the same length as the source. Shaping mode: The SEEN family character will expand into two characters using space near the SEEN family character(i.e. the space after the character). if there are no spaces found, ArabicShapingException will be thrown De-shaping mode: Any Seen character followed by Tail character will be replaced by one cell Seen and a space will replace the Tail. Affects: Seen options- See Also:
-
SEEN_MASK
public static final int SEEN_MASKBit mask for Seen memory options.- See Also:
-
YEHHAMZA_TWOCELL_NEAR
public static final int YEHHAMZA_TWOCELL_NEARMemory option: the result must have the same length as the source. Shaping mode: The YEHHAMZA character will expand into two characters using space near it (i.e. the space after the character) if there are no spaces found, ArabicShapingException will be thrown De-shaping mode: Any Yeh (final or isolated) character followed by Hamza character will be replaced by one cell YehHamza and space will replace the Hamza. Affects: YehHamza options- See Also:
-
YEHHAMZA_MASK
public static final int YEHHAMZA_MASKBit mask for YehHamza memory options.- See Also:
-
TASHKEEL_BEGIN
public static final int TASHKEEL_BEGINMemory option: the result must have the same length as the source. Shaping mode: Tashkeel characters will be replaced by spaces. Spaces will be placed at beginning of the buffer De-shaping mode: N/A Affects: Tashkeel options- See Also:
-
TASHKEEL_END
public static final int TASHKEEL_ENDMemory option: the result must have the same length as the source. Shaping mode: Tashkeel characters will be replaced by spaces. Spaces will be placed at end of the buffer De-shaping mode: N/A Affects: Tashkeel options- See Also:
-
TASHKEEL_RESIZE
public static final int TASHKEEL_RESIZEMemory option: allow the result to have a different length than the source. Shaping mode: Tashkeel characters will be removed, buffer length will shrink. De-shaping mode: N/A Affects: Tashkeel options- See Also:
-
TASHKEEL_REPLACE_BY_TATWEEL
public static final int TASHKEEL_REPLACE_BY_TATWEELMemory option: the result must have the same length as the source. Shaping mode: Tashkeel characters will be replaced by Tatweel if it is connected to adjacent characters (i.e. shaped on Tatweel) or replaced by space if it is not connected. De-shaping mode: N/A Affects: YehHamza options- See Also:
-
TASHKEEL_MASK
public static final int TASHKEEL_MASKBit mask for Tashkeel replacement with Space or Tatweel memory options.- See Also:
-
SPACES_RELATIVE_TO_TEXT_BEGIN_END
public static final int SPACES_RELATIVE_TO_TEXT_BEGIN_ENDThis 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. BEGIN always refers to the start address of physical memory. 2. END always refers to the end address of physical memory. If this option is used it will swap the meaning of BEGIN and END only for Visual LTR text. The affect on BEGIN and END Memory Options will be as following: A. BEGIN For Visual LTR text: This will be the beginning (right side) of the visual text (corresponding to the physical memory address end, same as END in default behavior) B. BEGIN For Logical text: Same as BEGIN in default behavior. C. END For Visual LTR text: This will be the end (left side) of the visual text. (corresponding to the physical memory address beginning, same as BEGIN in default behavior) D. END For Logical text: Same as END in default behavior. Affects: All LamAlef BEGIN, END and AUTO options.- See Also:
-
SPACES_RELATIVE_TO_TEXT_MASK
public static final int SPACES_RELATIVE_TO_TEXT_MASKBit mask for swapping BEGIN and END for Visual LTR text- See Also:
-
SHAPE_TAIL_NEW_UNICODE
public static final int SHAPE_TAIL_NEW_UNICODEIf this option is used, shaping will use the new Unicode code point for TAIL (i.e. 0xFE73). If this option is not specified (Default), old unofficial Unicode TAIL code point is used (i.e. 0x200B) De-shaping will not use this option as it will always search for both the new Unicode code point for the TAIL (i.e. 0xFE73) or the old unofficial Unicode TAIL code point (i.e. 0x200B) and de-shape the Seen-Family letter accordingly. Shaping Mode: Only shaping. De-shaping Mode: N/A. Affects: All Seen options- See Also:
-
SHAPE_TAIL_TYPE_MASK
public static final int SHAPE_TAIL_TYPE_MASKBit mask for new Unicode Tail option- See Also:
-
LENGTH_GROW_SHRINK
public static final int LENGTH_GROW_SHRINKMemory option: allow the result to have a different length than the source.- See Also:
-
LAMALEF_RESIZE
public static final int LAMALEF_RESIZEMemory option: allow the result to have a different length than the source. Affects: LamAlef options This option is an alias to LENGTH_GROW_SHRINK- See Also:
-
LENGTH_FIXED_SPACES_NEAR
public static final int LENGTH_FIXED_SPACES_NEARMemory option: the result must have the same length as the source. If more room is necessary, then try to consume spaces next to modified characters.- See Also:
-
LAMALEF_NEAR
public static final int LAMALEF_NEARMemory option: the result must have the same length as the source. If more room is necessary, then try to consume spaces next to modified characters. Affects: LamAlef options This option is an alias to LENGTH_FIXED_SPACES_NEAR- See Also:
-
LENGTH_FIXED_SPACES_AT_END
public static final int LENGTH_FIXED_SPACES_AT_ENDMemory option: the result must have the same length as the source. If more room is necessary, then try to consume spaces at the end of the text.- See Also:
-
LAMALEF_END
public static final int LAMALEF_ENDMemory option: the result must have the same length as the source. If more room is necessary, then try to consume spaces at the end of the text. Affects: LamAlef options This option is an alias to LENGTH_FIXED_SPACES_AT_END- See Also:
-
LENGTH_FIXED_SPACES_AT_BEGINNING
public static final int LENGTH_FIXED_SPACES_AT_BEGINNINGMemory option: the result must have the same length as the source. If more room is necessary, then try to consume spaces at the beginning of the text.- See Also:
-
LAMALEF_BEGIN
public static final int LAMALEF_BEGINMemory option: the result must have the same length as the source. If more room is necessary, then try to consume spaces at the beginning of the text. Affects: LamAlef options This option is an alias to LENGTH_FIXED_SPACES_AT_BEGINNING- See Also:
-
LAMALEF_AUTO
public static final int LAMALEF_AUTOMemory option: the result must have the same length as the source. Shaping Mode: For each LAMALEF character found, expand LAMALEF using space at end. If there is no space at end, use spaces at beginning of the buffer. If there is no space at beginning of the buffer, use spaces at the near (i.e. the space after the LAMALEF character). Deshaping Mode: Perform the same function as the flag equals LAMALEF_END. Affects: LamAlef options- See Also:
-
LENGTH_MASK
public static final int LENGTH_MASKBit mask for memory options.- See Also:
-
LAMALEF_MASK
public static final int LAMALEF_MASKBit mask for LamAlef memory options.- See Also:
-
TEXT_DIRECTION_LOGICAL
public static final int TEXT_DIRECTION_LOGICALDirection indicator: the source is in logical (keyboard) order.- See Also:
-
TEXT_DIRECTION_VISUAL_RTL
public static final int TEXT_DIRECTION_VISUAL_RTLDirection indicator:the source is in visual RTL order, the rightmost displayed character stored first. This option is an alias to U_SHAPE_TEXT_DIRECTION_LOGICAL- See Also:
-
TEXT_DIRECTION_VISUAL_LTR
public static final int TEXT_DIRECTION_VISUAL_LTRDirection indicator: the source is in visual (display) order, that is, the leftmost displayed character is stored first.- See Also:
-
TEXT_DIRECTION_MASK
public static final int TEXT_DIRECTION_MASKBit mask for direction indicators.- See Also:
-
LETTERS_NOOP
public static final int LETTERS_NOOPLetter shaping option: do not perform letter shaping.- See Also:
-
LETTERS_SHAPE
public static final int LETTERS_SHAPELetter shaping option: replace normative letter characters in the U+0600 (Arabic) block, by shaped ones in the U+FE70 (Presentation Forms B) block. Performs Lam-Alef ligature substitution.- See Also:
-
LETTERS_UNSHAPE
public static final int LETTERS_UNSHAPELetter shaping option: replace shaped letter characters in the U+FE70 (Presentation Forms B) block by normative ones in the U+0600 (Arabic) block. Converts Lam-Alef ligatures to pairs of Lam and Alef characters, consuming spaces if required.- See Also:
-
LETTERS_SHAPE_TASHKEEL_ISOLATED
public static final int LETTERS_SHAPE_TASHKEEL_ISOLATEDLetter 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. The TASHKEEL characters will always be converted to the isolated forms rather than to their correct shape.- See Also:
-
LETTERS_MASK
public static final int LETTERS_MASKBit mask for letter shaping options.- See Also:
-
DIGITS_NOOP
public static final int DIGITS_NOOPDigit shaping option: do not perform digit shaping.- See Also:
-
DIGITS_EN2AN
public static final int DIGITS_EN2ANDigit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits.- See Also:
-
DIGITS_AN2EN
public static final int DIGITS_AN2ENDigit shaping option: Replace Arabic-Indic digits by European digits (U+0030...U+0039).- See Also:
-
DIGITS_EN2AN_INIT_LR
public static final int DIGITS_EN2AN_INIT_LRDigit 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). The initial state at the start of the text is assumed to be not an Arabic, letter, so European digits at the start of the text will not change. Compare to DIGITS_ALEN2AN_INIT_AL.- See Also:
-
DIGITS_EN2AN_INIT_AL
public static final int DIGITS_EN2AN_INIT_ALDigit 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). The initial state at the start of the text is assumed to be an Arabic, letter, so European digits at the start of the text will change. Compare to DIGITS_ALEN2AN_INT_LR.- See Also:
-
DIGITS_MASK
public static final int DIGITS_MASKBit mask for digit shaping options.- See Also:
-
DIGIT_TYPE_AN
public static final int DIGIT_TYPE_ANDigit type option: Use Arabic-Indic digits (U+0660...U+0669).- See Also:
-
DIGIT_TYPE_AN_EXTENDED
public static final int DIGIT_TYPE_AN_EXTENDEDDigit type option: Use Eastern (Extended) Arabic-Indic digits (U+06f0...U+06f9).- See Also:
-
DIGIT_TYPE_MASK
public static final int DIGIT_TYPE_MASKBit mask for digit type options.- See Also:
-
-
Constructor Details
-
ArabicShaping
public ArabicShaping(int options) Construct ArabicShaping using the options flags. The flags are as follows:
'LENGTH' flags control whether the text can change size, and if not, how to maintain the size of the text when LamAlef ligatures are formed or broken.
'TEXT_DIRECTION' flags control whether the text is read and written in visual order or in logical order.
'LETTERS_SHAPE' flags control whether conversion is to or from presentation forms.
'DIGITS' flags control whether digits are shaped, and whether from European to Arabic-Indic or vice-versa.
'DIGIT_TYPE' flags control whether standard or extended Arabic-Indic digits are used when performing digit conversion.
-
-
Method Details
-
shape
public int shape(char[] source, int sourceStart, int sourceLength, char[] dest, int destStart, int destSize) throws ArabicShapingException 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.- Parameters:
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 beNULL
only ifdestSize
is 0.destStart
- The start of the range of the destination buffer to use.destSize
- The size (capacity) of the destination buffer. IfdestSize
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.- Returns:
- The number of chars written to the destination buffer. If an error occurs, then no output was written, or it may be incomplete.
- Throws:
ArabicShapingException
- if the text cannot be converted according to the options.
-
shape
Convert a range of text in place. This may only be used if the Length option does not grow or shrink the text.- Parameters:
source
- An array containing the input textstart
- The start of the range of text to convertlength
- The length of the range of text to convert- Throws:
ArabicShapingException
- if the text cannot be converted according to the options.
-
shape
Convert a string, returning the new string.- Parameters:
text
- the string to convert- Returns:
- the converted string
- Throws:
ArabicShapingException
- if the string cannot be converted according to the options.
-
equals
-
hashCode
public int hashCode() -
toString
-