2 *******************************************************************************
\r
3 * Copyright (C) 2001-2010, International Business Machines
\r
4 * Corporation and others. All Rights Reserved.
\r
5 *******************************************************************************
\r
8 package com.ibm.icu.text;
\r
10 import java.io.IOException;
\r
11 import java.util.MissingResourceException;
\r
13 import com.ibm.icu.impl.UBiDiProps;
\r
14 import com.ibm.icu.lang.UCharacterDirection;
\r
17 * Shape Arabic text on a character basis.
\r
19 * <p>ArabicShaping performs basic operations for "shaping" Arabic text. It is most
\r
20 * useful for use with legacy data formats and legacy display technology
\r
21 * (simple terminals). All operations are performed on Unicode characters.</p>
\r
23 * <p>Text-based shaping means that some character code points in the text are
\r
24 * replaced by others depending on the context. It transforms one kind of text
\r
25 * into another. In comparison, modern displays for Arabic text select
\r
26 * appropriate, context-dependent font glyphs for each text element, which means
\r
27 * that they transform text into a glyph vector.</p>
\r
29 * <p>Text transformations are necessary when modern display technology is not
\r
30 * available or when text needs to be transformed to or from legacy formats that
\r
31 * use "shaped" characters. Since the Arabic script is cursive, connecting
\r
32 * adjacent letters to each other, computers select images for each letter based
\r
33 * on the surrounding letters. This usually results in four images per Arabic
\r
34 * letter: initial, middle, final, and isolated forms. In Unicode, on the other
\r
35 * hand, letters are normally stored abstract, and a display system is expected
\r
36 * to select the necessary glyphs. (This makes searching and other text
\r
37 * processing easier because the same letter has only one code.) It is possible
\r
38 * to mimic this with text transformations because there are characters in
\r
39 * Unicode that are rendered as letters with a specific shape
\r
40 * (or cursive connectivity). They were included for interoperability with
\r
41 * legacy systems and codepages, and for unsophisticated display systems.</p>
\r
43 * <p>A second kind of text transformations is supported for Arabic digits:
\r
44 * For compatibility with legacy codepages that only include European digits,
\r
45 * it is possible to replace one set of digits by another, changing the
\r
46 * character code points. These operations can be performed for either
\r
47 * Arabic-Indic Digits (U+0660...U+0669) or Eastern (Extended) Arabic-Indic
\r
48 * digits (U+06f0...U+06f9).</p>
\r
50 * <p>Some replacements may result in more or fewer characters (code points).
\r
51 * By default, this means that the destination buffer may receive text with a
\r
52 * length different from the source length. Some legacy systems rely on the
\r
53 * length of the text to be constant. They expect extra spaces to be added
\r
54 * or consumed either next to the affected character or at the end of the
\r
58 public final class ArabicShaping {
\r
59 private final int options;
\r
60 private boolean isLogical; // convenience
\r
61 private boolean spacesRelativeToTextBeginEnd;
\r
62 private char tailChar;
\r
65 * Convert a range of text in the source array, putting the result
\r
66 * into a range of text in the destination array, and return the number
\r
67 * of characters written.
\r
69 * @param source An array containing the input text
\r
70 * @param sourceStart The start of the range of text to convert
\r
71 * @param sourceLength The length of the range of text to convert
\r
72 * @param dest The destination array that will receive the result.
\r
73 * It may be <code>NULL</code> only if <code>destSize</code> is 0.
\r
74 * @param destStart The start of the range of the destination buffer to use.
\r
75 * @param destSize The size (capacity) of the destination buffer.
\r
76 * If <code>destSize</code> is 0, then no output is produced,
\r
77 * but the necessary buffer size is returned ("preflighting"). This
\r
78 * does not validate the text against the options, for example,
\r
79 * if letters are being unshaped, and spaces are being consumed
\r
80 * following lamalef, this will not detect a lamalef without a
\r
81 * corresponding space. An error will be thrown when the actual
\r
82 * conversion is attempted.
\r
83 * @return The number of chars written to the destination buffer.
\r
84 * If an error occurs, then no output was written, or it may be
\r
86 * @throws ArabicShapingException if the text cannot be converted according to the options.
\r
89 public int shape(char[] source, int sourceStart, int sourceLength,
\r
90 char[] dest, int destStart, int destSize) throws ArabicShapingException {
\r
91 if (source == null) {
\r
92 throw new IllegalArgumentException("source can not be null");
\r
94 if (sourceStart < 0 || sourceLength < 0 || sourceStart + sourceLength > source.length) {
\r
95 throw new IllegalArgumentException("bad source start (" + sourceStart +
\r
96 ") or length (" + sourceLength +
\r
97 ") for buffer of length " + source.length);
\r
99 if (dest == null && destSize != 0) {
\r
100 throw new IllegalArgumentException("null dest requires destSize == 0");
\r
102 if ((destSize != 0) &&
\r
103 (destStart < 0 || destSize < 0 || destStart + destSize > dest.length)) {
\r
104 throw new IllegalArgumentException("bad dest start (" + destStart +
\r
105 ") or size (" + destSize +
\r
106 ") for buffer of length " + dest.length);
\r
108 /* Validate input options */
\r
109 if ( ((options&TASHKEEL_MASK) > 0) &&
\r
110 !(((options & TASHKEEL_MASK)==TASHKEEL_BEGIN) ||
\r
111 ((options & TASHKEEL_MASK)==TASHKEEL_END ) ||
\r
112 ((options & TASHKEEL_MASK)==TASHKEEL_RESIZE )||
\r
113 ((options & TASHKEEL_MASK)==TASHKEEL_REPLACE_BY_TATWEEL)) ){
\r
114 throw new IllegalArgumentException("Wrong Tashkeel argument");
\r
118 //According to Steven Loomis, the code is unreachable when you OR all the constants within the if statements
\r
119 if(((options&LAMALEF_MASK) > 0)&&
\r
120 !(((options & LAMALEF_MASK)==LAMALEF_BEGIN) ||
\r
121 ((options & LAMALEF_MASK)==LAMALEF_END ) ||
\r
122 ((options & LAMALEF_MASK)==LAMALEF_RESIZE )||
\r
123 ((options & LAMALEF_MASK)==LAMALEF_AUTO) ||
\r
124 ((options & LAMALEF_MASK)==LAMALEF_NEAR))){
\r
125 throw new IllegalArgumentException("Wrong Lam Alef argument");
\r
129 /* Validate Tashkeel (Tashkeel replacement options should be enabled in shaping mode only)*/
\r
130 if(((options&TASHKEEL_MASK) > 0) && (options&LETTERS_MASK) == LETTERS_UNSHAPE) {
\r
131 throw new IllegalArgumentException("Tashkeel replacement should not be enabled in deshaping mode ");
\r
133 return internalShape(source, sourceStart, sourceLength, dest, destStart, destSize);
\r
137 * Convert a range of text in place. This may only be used if the Length option
\r
138 * does not grow or shrink the text.
\r
140 * @param source An array containing the input text
\r
141 * @param start The start of the range of text to convert
\r
142 * @param length The length of the range of text to convert
\r
143 * @throws ArabicShapingException if the text cannot be converted according to the options.
\r
146 public void shape(char[] source, int start, int length) throws ArabicShapingException {
\r
147 if ((options & LAMALEF_MASK) == LAMALEF_RESIZE) {
\r
148 throw new ArabicShapingException("Cannot shape in place with length option resize.");
\r
150 shape(source, start, length, source, start, length);
\r
154 * Convert a string, returning the new string.
\r
156 * @param text the string to convert
\r
157 * @return the converted string
\r
158 * @throws ArabicShapingException if the string cannot be converted according to the options.
\r
161 public String shape(String text) throws ArabicShapingException {
\r
162 char[] src = text.toCharArray();
\r
164 if (((options & LAMALEF_MASK) == LAMALEF_RESIZE) &&
\r
165 ((options & LETTERS_MASK) == LETTERS_UNSHAPE)) {
\r
167 dest = new char[src.length * 2]; // max
\r
169 int len = shape(src, 0, src.length, dest, 0, dest.length);
\r
171 return new String(dest, 0, len);
\r
175 * Construct ArabicShaping using the options flags.
\r
176 * The flags are as follows:<br>
\r
177 * 'LENGTH' flags control whether the text can change size, and if not,
\r
178 * how to maintain the size of the text when LamAlef ligatures are
\r
179 * formed or broken.<br>
\r
180 * 'TEXT_DIRECTION' flags control whether the text is read and written
\r
181 * in visual order or in logical order.<br>
\r
182 * 'LETTERS_SHAPE' flags control whether conversion is to or from
\r
183 * presentation forms.<br>
\r
184 * 'DIGITS' flags control whether digits are shaped, and whether from
\r
185 * European to Arabic-Indic or vice-versa.<br>
\r
186 * 'DIGIT_TYPE' flags control whether standard or extended Arabic-Indic
\r
187 * digits are used when performing digit conversion.
\r
190 public ArabicShaping(int options) {
\r
191 this.options = options;
\r
192 if ((options & DIGITS_MASK) > 0x80) {
\r
193 throw new IllegalArgumentException("bad DIGITS options");
\r
196 isLogical = ( (options & TEXT_DIRECTION_MASK) == TEXT_DIRECTION_LOGICAL );
\r
197 /* Validate options */
\r
198 spacesRelativeToTextBeginEnd = ( (options & SPACES_RELATIVE_TO_TEXT_MASK) == SPACES_RELATIVE_TO_TEXT_BEGIN_END );
\r
199 if ( (options&SHAPE_TAIL_TYPE_MASK) == SHAPE_TAIL_NEW_UNICODE){
\r
200 tailChar = NEW_TAIL_CHAR;
\r
202 tailChar = OLD_TAIL_CHAR;
\r
206 /* Seen Tail options */
\r
208 * Memory option: the result must have the same length as the source.
\r
209 * Shaping mode: The SEEN family character will expand into two characters using space near
\r
210 * the SEEN family character(i.e. the space after the character).
\r
211 * if there are no spaces found, ArabicShapingException will be thrown
\r
213 * De-shaping mode: Any Seen character followed by Tail character will be
\r
214 * replaced by one cell Seen and a space will replace the Tail.
\r
215 * Affects: Seen options
\r
217 public static final int SEEN_TWOCELL_NEAR = 0x200000;
\r
219 /** Bit mask for Seen memory options. */
\r
220 public static final int SEEN_MASK = 0x700000;
\r
222 /* YehHamza options */
\r
224 * Memory option: the result must have the same length as the source.
\r
225 * Shaping mode: The YEHHAMZA character will expand into two characters using space near it
\r
226 * (i.e. the space after the character)
\r
227 * if there are no spaces found, ArabicShapingException will be thrown
\r
229 * De-shaping mode: Any Yeh (final or isolated) character followed by Hamza character will be
\r
230 * replaced by one cell YehHamza and space will replace the Hamza.
\r
231 * Affects: YehHamza options
\r
233 public static final int YEHHAMZA_TWOCELL_NEAR = 0x1000000;
\r
236 /** Bit mask for YehHamza memory options. */
\r
237 public static final int YEHHAMZA_MASK = 0x3800000;
\r
239 /* New Tashkeel options */
\r
241 * Memory option: the result must have the same length as the source.
\r
242 * Shaping mode: Tashkeel characters will be replaced by spaces.
\r
243 * Spaces will be placed at beginning of the buffer
\r
245 * De-shaping mode: N/A
\r
246 * Affects: Tashkeel options
\r
248 public static final int TASHKEEL_BEGIN = 0x40000;
\r
251 * Memory option: the result must have the same length as the source.
\r
252 * Shaping mode: Tashkeel characters will be replaced by spaces.
\r
253 * Spaces will be placed at end of the buffer
\r
255 * De-shaping mode: N/A
\r
256 * Affects: Tashkeel options
\r
258 public static final int TASHKEEL_END = 0x60000;
\r
261 * Memory option: allow the result to have a different length than the source.
\r
262 * Shaping mode: Tashkeel characters will be removed, buffer length will shrink.
\r
263 * De-shaping mode: N/A
\r
265 * Affects: Tashkeel options
\r
267 public static final int TASHKEEL_RESIZE = 0x80000;
\r
270 * Memory option: the result must have the same length as the source.
\r
271 * Shaping mode: Tashkeel characters will be replaced by Tatweel if it is connected to adjacent
\r
272 * characters (i.e. shaped on Tatweel) or replaced by space if it is not connected.
\r
274 * De-shaping mode: N/A
\r
275 * Affects: YehHamza options
\r
277 public static final int TASHKEEL_REPLACE_BY_TATWEEL = 0xC0000;
\r
279 /** Bit mask for Tashkeel replacement with Space or Tatweel memory options. */
\r
280 public static final int TASHKEEL_MASK = 0xE0000;
\r
282 /* Space location Control options */
\r
284 * This option effects the meaning of BEGIN and END options. if this option is not used the default
\r
285 * for BEGIN and END will be as following:
\r
286 * The Default (for both Visual LTR, Visual RTL and Logical Text)
\r
287 * 1. BEGIN always refers to the start address of physical memory.
\r
288 * 2. END always refers to the end address of physical memory.
\r
290 * If this option is used it will swap the meaning of BEGIN and END only for Visual LTR text.
\r
292 * The affect on BEGIN and END Memory Options will be as following:
\r
293 * A. BEGIN For Visual LTR text: This will be the beginning (right side) of the visual text
\r
294 * (corresponding to the physical memory address end, same as END in default behavior)
\r
295 * B. BEGIN For Logical text: Same as BEGIN in default behavior.
\r
296 * C. END For Visual LTR text: This will be the end (left side) of the visual text. (corresponding to
\r
297 * the physical memory address beginning, same as BEGIN in default behavior)
\r
298 * D. END For Logical text: Same as END in default behavior.
\r
299 * Affects: All LamAlef BEGIN, END and AUTO options.
\r
301 public static final int SPACES_RELATIVE_TO_TEXT_BEGIN_END = 0x4000000;
\r
303 /** Bit mask for swapping BEGIN and END for Visual LTR text */
\r
304 public static final int SPACES_RELATIVE_TO_TEXT_MASK = 0x4000000;
\r
307 * If this option is used, shaping will use the new Unicode code point for TAIL (i.e. 0xFE73).
\r
308 * If this option is not specified (Default), old unofficial Unicode TAIL code point is used (i.e. 0x200B)
\r
309 * De-shaping will not use this option as it will always search for both the new Unicode code point for the
\r
310 * TAIL (i.e. 0xFE73) or the old unofficial Unicode TAIL code point (i.e. 0x200B) and de-shape the
\r
311 * Seen-Family letter accordingly.
\r
313 * Shaping Mode: Only shaping.
\r
314 * De-shaping Mode: N/A.
\r
315 * Affects: All Seen options
\r
317 public static final int SHAPE_TAIL_NEW_UNICODE = 0x8000000;
\r
319 /** Bit mask for new Unicode Tail option */
\r
320 public static final int SHAPE_TAIL_TYPE_MASK = 0x8000000;
\r
323 * Memory option: allow the result to have a different length than the source.
\r
326 public static final int LENGTH_GROW_SHRINK = 0;
\r
329 * Memory option: allow the result to have a different length than the source.
\r
330 * Affects: LamAlef options
\r
331 * This option is an alias to LENGTH_GROW_SHRINK
\r
333 public static final int LAMALEF_RESIZE = 0;
\r
336 * Memory option: the result must have the same length as the source.
\r
337 * If more room is necessary, then try to consume spaces next to modified characters.
\r
340 public static final int LENGTH_FIXED_SPACES_NEAR = 1;
\r
343 * Memory option: the result must have the same length as the source.
\r
344 * If more room is necessary, then try to consume spaces next to modified characters.
\r
345 * Affects: LamAlef options
\r
346 * This option is an alias to LENGTH_FIXED_SPACES_NEAR
\r
348 public static final int LAMALEF_NEAR = 1 ;
\r
351 * Memory option: the result must have the same length as the source.
\r
352 * If more room is necessary, then try to consume spaces at the end of the text.
\r
355 public static final int LENGTH_FIXED_SPACES_AT_END = 2;
\r
359 * Memory option: the result must have the same length as the source.
\r
360 * If more room is necessary, then try to consume spaces at the end of the text.
\r
361 * Affects: LamAlef options
\r
362 * This option is an alias to LENGTH_FIXED_SPACES_AT_END
\r
364 public static final int LAMALEF_END = 2;
\r
367 * Memory option: the result must have the same length as the source.
\r
368 * If more room is necessary, then try to consume spaces at the beginning of the text.
\r
371 public static final int LENGTH_FIXED_SPACES_AT_BEGINNING = 3;
\r
374 * Memory option: the result must have the same length as the source.
\r
375 * If more room is necessary, then try to consume spaces at the beginning of the text.
\r
376 * Affects: LamAlef options
\r
377 * This option is an alias to LENGTH_FIXED_SPACES_AT_BEGINNING
\r
379 public static final int LAMALEF_BEGIN = 3;
\r
382 * Memory option: the result must have the same length as the source.
\r
383 * Shaping Mode: For each LAMALEF character found, expand LAMALEF using space at end.
\r
384 * If there is no space at end, use spaces at beginning of the buffer. If there
\r
385 * is no space at beginning of the buffer, use spaces at the near (i.e. the space
\r
386 * after the LAMALEF character).
\r
388 * Deshaping Mode: Perform the same function as the flag equals LAMALEF_END.
\r
389 * Affects: LamAlef options
\r
391 public static final int LAMALEF_AUTO = 0x10000;
\r
394 * Bit mask for memory options.
\r
397 public static final int LENGTH_MASK = 0x10003;
\r
399 /** Bit mask for LamAlef memory options. */
\r
401 public static final int LAMALEF_MASK = 0x10003;
\r
404 * Direction indicator: the source is in logical (keyboard) order.
\r
407 public static final int TEXT_DIRECTION_LOGICAL = 0;
\r
410 * Direction indicator:the source is in visual RTL order,
\r
411 * the rightmost displayed character stored first.
\r
412 * This option is an alias to U_SHAPE_TEXT_DIRECTION_LOGICAL
\r
414 public static final int TEXT_DIRECTION_VISUAL_RTL = 0;
\r
417 * Direction indicator: the source is in visual (display) order, that is,
\r
418 * the leftmost displayed character is stored first.
\r
421 public static final int TEXT_DIRECTION_VISUAL_LTR = 4;
\r
424 * Bit mask for direction indicators.
\r
427 public static final int TEXT_DIRECTION_MASK = 4;
\r
431 * Letter shaping option: do not perform letter shaping.
\r
434 public static final int LETTERS_NOOP = 0;
\r
437 * Letter shaping option: replace normative letter characters in the U+0600 (Arabic) block,
\r
438 * by shaped ones in the U+FE70 (Presentation Forms B) block. Performs Lam-Alef ligature
\r
442 public static final int LETTERS_SHAPE = 8;
\r
445 * Letter shaping option: replace shaped letter characters in the U+FE70 (Presentation Forms B) block
\r
446 * by normative ones in the U+0600 (Arabic) block. Converts Lam-Alef ligatures to pairs of Lam and
\r
447 * Alef characters, consuming spaces if required.
\r
450 public static final int LETTERS_UNSHAPE = 0x10;
\r
453 * Letter shaping option: replace normative letter characters in the U+0600 (Arabic) block,
\r
454 * except for the TASHKEEL characters at U+064B...U+0652, by shaped ones in the U+Fe70
\r
455 * (Presentation Forms B) block. The TASHKEEL characters will always be converted to
\r
456 * the isolated forms rather than to their correct shape.
\r
459 public static final int LETTERS_SHAPE_TASHKEEL_ISOLATED = 0x18;
\r
462 * Bit mask for letter shaping options.
\r
465 public static final int LETTERS_MASK = 0x18;
\r
469 * Digit shaping option: do not perform digit shaping.
\r
472 public static final int DIGITS_NOOP = 0;
\r
475 * Digit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits.
\r
478 public static final int DIGITS_EN2AN = 0x20;
\r
481 * Digit shaping option: Replace Arabic-Indic digits by European digits (U+0030...U+0039).
\r
484 public static final int DIGITS_AN2EN = 0x40;
\r
487 * Digit shaping option:
\r
488 * Replace European digits (U+0030...U+0039) by Arabic-Indic digits
\r
489 * if the most recent strongly directional character
\r
490 * is an Arabic letter (its Bidi direction value is RIGHT_TO_LEFT_ARABIC).
\r
491 * The initial state at the start of the text is assumed to be not an Arabic,
\r
492 * letter, so European digits at the start of the text will not change.
\r
493 * Compare to DIGITS_ALEN2AN_INIT_AL.
\r
496 public static final int DIGITS_EN2AN_INIT_LR = 0x60;
\r
499 * Digit shaping option:
\r
500 * Replace European digits (U+0030...U+0039) by Arabic-Indic digits
\r
501 * if the most recent strongly directional character
\r
502 * is an Arabic letter (its Bidi direction value is RIGHT_TO_LEFT_ARABIC).
\r
503 * The initial state at the start of the text is assumed to be an Arabic,
\r
504 * letter, so European digits at the start of the text will change.
\r
505 * Compare to DIGITS_ALEN2AN_INT_LR.
\r
508 public static final int DIGITS_EN2AN_INIT_AL = 0x80;
\r
510 /** Not a valid option value. */
\r
511 //private static final int DIGITS_RESERVED = 0xa0;
\r
514 * Bit mask for digit shaping options.
\r
517 public static final int DIGITS_MASK = 0xe0;
\r
520 * Digit type option: Use Arabic-Indic digits (U+0660...U+0669).
\r
523 public static final int DIGIT_TYPE_AN = 0;
\r
526 * Digit type option: Use Eastern (Extended) Arabic-Indic digits (U+06f0...U+06f9).
\r
529 public static final int DIGIT_TYPE_AN_EXTENDED = 0x100;
\r
532 * Bit mask for digit type options.
\r
535 public static final int DIGIT_TYPE_MASK = 0x0100; // 0x3f00?
\r
540 private static final char HAMZAFE_CHAR = '\ufe80';
\r
541 private static final char HAMZA06_CHAR = '\u0621';
\r
542 private static final char YEH_HAMZA_CHAR = '\u0626';
\r
543 private static final char YEH_HAMZAFE_CHAR = '\uFE89';
\r
544 private static final char LAMALEF_SPACE_SUB = '\uffff';
\r
545 private static final char TASHKEEL_SPACE_SUB = '\ufffe';
\r
546 private static final char LAM_CHAR = '\u0644';
\r
547 private static final char SPACE_CHAR = '\u0020';
\r
548 private static final char SHADDA_CHAR = '\uFE7C';
\r
549 private static final char TATWEEL_CHAR = '\u0640';
\r
550 private static final char SHADDA_TATWEEL_CHAR = '\uFE7D';
\r
551 private static final char NEW_TAIL_CHAR = '\uFE73';
\r
552 private static final char OLD_TAIL_CHAR = '\u200B';
\r
553 private static final int SHAPE_MODE = 0;
\r
554 private static final int DESHAPE_MODE = 1;
\r
559 public boolean equals(Object rhs) {
\r
560 return rhs != null &&
\r
561 rhs.getClass() == ArabicShaping.class &&
\r
562 options == ((ArabicShaping)rhs).options;
\r
569 public int hashCode() {
\r
576 public String toString() {
\r
577 StringBuilder buf = new StringBuilder(super.toString());
\r
580 switch (options & LAMALEF_MASK) {
\r
581 case LAMALEF_RESIZE: buf.append("LamAlef resize"); break;
\r
582 case LAMALEF_NEAR: buf.append("LamAlef spaces at near"); break;
\r
583 case LAMALEF_BEGIN: buf.append("LamAlef spaces at begin"); break;
\r
584 case LAMALEF_END: buf.append("LamAlef spaces at end"); break;
\r
585 case LAMALEF_AUTO: buf.append("lamAlef auto"); break;
\r
587 switch (options & TEXT_DIRECTION_MASK) {
\r
588 case TEXT_DIRECTION_LOGICAL: buf.append(", logical"); break;
\r
589 case TEXT_DIRECTION_VISUAL_LTR: buf.append(", visual"); break;
\r
591 switch (options & LETTERS_MASK) {
\r
592 case LETTERS_NOOP: buf.append(", no letter shaping"); break;
\r
593 case LETTERS_SHAPE: buf.append(", shape letters"); break;
\r
594 case LETTERS_SHAPE_TASHKEEL_ISOLATED: buf.append(", shape letters tashkeel isolated"); break;
\r
595 case LETTERS_UNSHAPE: buf.append(", unshape letters"); break;
\r
597 switch (options & SEEN_MASK) {
\r
598 case SEEN_TWOCELL_NEAR: buf.append(", Seen at near"); break;
\r
600 switch (options & YEHHAMZA_MASK) {
\r
601 case YEHHAMZA_TWOCELL_NEAR: buf.append(", Yeh Hamza at near"); break;
\r
603 switch (options & TASHKEEL_MASK) {
\r
604 case TASHKEEL_BEGIN: buf.append(", Tashkeel at begin"); break;
\r
605 case TASHKEEL_END: buf.append(", Tashkeel at end"); break;
\r
606 case TASHKEEL_REPLACE_BY_TATWEEL: buf.append(", Tashkeel replace with tatweel"); break;
\r
607 case TASHKEEL_RESIZE: buf.append(", Tashkeel resize"); break;
\r
610 switch (options & DIGITS_MASK) {
\r
611 case DIGITS_NOOP: buf.append(", no digit shaping"); break;
\r
612 case DIGITS_EN2AN: buf.append(", shape digits to AN"); break;
\r
613 case DIGITS_AN2EN: buf.append(", shape digits to EN"); break;
\r
614 case DIGITS_EN2AN_INIT_LR: buf.append(", shape digits to AN contextually: default EN"); break;
\r
615 case DIGITS_EN2AN_INIT_AL: buf.append(", shape digits to AN contextually: default AL"); break;
\r
617 switch (options & DIGIT_TYPE_MASK) {
\r
618 case DIGIT_TYPE_AN: buf.append(", standard Arabic-Indic digits"); break;
\r
619 case DIGIT_TYPE_AN_EXTENDED: buf.append(", extended Arabic-Indic digits"); break;
\r
623 return buf.toString();
\r
631 private static final int IRRELEVANT = 4;
\r
632 private static final int LAMTYPE = 16;
\r
633 private static final int ALEFTYPE = 32;
\r
635 private static final int LINKR = 1;
\r
636 private static final int LINKL = 2;
\r
637 private static final int LINK_MASK = 3;
\r
639 private static final int irrelevantPos[] = {
\r
640 0x0, 0x2, 0x4, 0x6, 0x8, 0xA, 0xC, 0xE
\r
644 private static final char convertLamAlef[] = {
\r
656 private static final int tailFamilyIsolatedFinal[] = {
\r
673 private static final int tashkeelMedial[] = {
\r
692 private static final char yehHamzaToYeh[] =
\r
694 /* isolated*/ 0xFEEF,
\r
698 private static final char convertNormalizedLamAlef[] = {
\r
705 private static final int[] araLink = {
\r
706 1 + 32 + 256 * 0x11, /*0x0622*/
\r
707 1 + 32 + 256 * 0x13, /*0x0623*/
\r
708 1 + 256 * 0x15, /*0x0624*/
\r
709 1 + 32 + 256 * 0x17, /*0x0625*/
\r
710 1 + 2 + 256 * 0x19, /*0x0626*/
\r
711 1 + 32 + 256 * 0x1D, /*0x0627*/
\r
712 1 + 2 + 256 * 0x1F, /*0x0628*/
\r
713 1 + 256 * 0x23, /*0x0629*/
\r
714 1 + 2 + 256 * 0x25, /*0x062A*/
\r
715 1 + 2 + 256 * 0x29, /*0x062B*/
\r
716 1 + 2 + 256 * 0x2D, /*0x062C*/
\r
717 1 + 2 + 256 * 0x31, /*0x062D*/
\r
718 1 + 2 + 256 * 0x35, /*0x062E*/
\r
719 1 + 256 * 0x39, /*0x062F*/
\r
720 1 + 256 * 0x3B, /*0x0630*/
\r
721 1 + 256 * 0x3D, /*0x0631*/
\r
722 1 + 256 * 0x3F, /*0x0632*/
\r
723 1 + 2 + 256 * 0x41, /*0x0633*/
\r
724 1 + 2 + 256 * 0x45, /*0x0634*/
\r
725 1 + 2 + 256 * 0x49, /*0x0635*/
\r
726 1 + 2 + 256 * 0x4D, /*0x0636*/
\r
727 1 + 2 + 256 * 0x51, /*0x0637*/
\r
728 1 + 2 + 256 * 0x55, /*0x0638*/
\r
729 1 + 2 + 256 * 0x59, /*0x0639*/
\r
730 1 + 2 + 256 * 0x5D, /*0x063A*/
\r
731 0, 0, 0, 0, 0, /*0x063B-0x063F*/
\r
733 1 + 2 + 256 * 0x61, /*0x0641*/
\r
734 1 + 2 + 256 * 0x65, /*0x0642*/
\r
735 1 + 2 + 256 * 0x69, /*0x0643*/
\r
736 1 + 2 + 16 + 256 * 0x6D, /*0x0644*/
\r
737 1 + 2 + 256 * 0x71, /*0x0645*/
\r
738 1 + 2 + 256 * 0x75, /*0x0646*/
\r
739 1 + 2 + 256 * 0x79, /*0x0647*/
\r
740 1 + 256 * 0x7D, /*0x0648*/
\r
741 1 + 256 * 0x7F, /*0x0649*/
\r
742 1 + 2 + 256 * 0x81, /*0x064A*/
\r
743 4, 4, 4, 4, /*0x064B-0x064E*/
\r
744 4, 4, 4, 4, /*0x064F-0x0652*/
\r
745 4, 4, 4, 0, 0, /*0x0653-0x0657*/
\r
746 0, 0, 0, 0, /*0x0658-0x065B*/
\r
747 1 + 256 * 0x85, /*0x065C*/
\r
748 1 + 256 * 0x87, /*0x065D*/
\r
749 1 + 256 * 0x89, /*0x065E*/
\r
750 1 + 256 * 0x8B, /*0x065F*/
\r
751 0, 0, 0, 0, 0, /*0x0660-0x0664*/
\r
752 0, 0, 0, 0, 0, /*0x0665-0x0669*/
\r
753 0, 0, 0, 0, 0, 0, /*0x066A-0x066F*/
\r
760 1, 1, /*0x0676-0x0677*/
\r
761 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, /*0x0678-0x067D*/
\r
762 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, /*0x067E-0x0683*/
\r
763 1+2, 1+2, 1+2, 1+2, /*0x0684-0x0687*/
\r
764 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*0x0688-0x0691*/
\r
765 1, 1, 1, 1, 1, 1, 1, 1, /*0x0692-0x0699*/
\r
766 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, /*0x069A-0x06A3*/
\r
767 1+2, 1+2, 1+2, 1+2, /*0x069A-0x06A3*/
\r
768 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, /*0x06A4-0x06AD*/
\r
769 1+2, 1+2, 1+2, 1+2, /*0x06A4-0x06AD*/
\r
770 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, /*0x06AE-0x06B7*/
\r
771 1+2, 1+2, 1+2, 1+2, /*0x06AE-0x06B7*/
\r
772 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, /*0x06B8-0x06BF*/
\r
773 1+2, 1+2, /*0x06B8-0x06BF*/
\r
776 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*0x06C2-0x06CB*/
\r
779 1+2, 1+2, 1+2, 1+2, /*0x06CE-0x06D1*/
\r
780 1, 1 /*0x06D2-0x06D3*/
\r
783 private static final int[] presLink = {
\r
786 1 + 2, 0, 1+ 2, 0, 1+ 2, /*0xFE72-0xFE76*/
\r
788 1+ 2, 1 + 2, 1+2, 1 + 2, /*0xFE78-0xFE81*/
\r
789 1+ 2, 1 + 2, 1+2, 1 + 2, /*0xFE82-0xFE85*/
\r
790 0, 0 + 32, 1 + 32, 0 + 32, /*0xFE86-0xFE89*/
\r
791 1 + 32, 0, 1, 0 + 32, /*0xFE8A-0xFE8D*/
\r
792 1 + 32, 0, 2, 1 + 2, /*0xFE8E-0xFE91*/
\r
793 1, 0 + 32, 1 + 32, 0, /*0xFE92-0xFE95*/
\r
794 2, 1 + 2, 1, 0, /*0xFE96-0xFE99*/
\r
795 1, 0, 2, 1 + 2, /*0xFE9A-0xFE9D*/
\r
796 1, 0, 2, 1 + 2, /*0xFE9E-0xFEA1*/
\r
797 1, 0, 2, 1 + 2, /*0xFEA2-0xFEA5*/
\r
798 1, 0, 2, 1 + 2, /*0xFEA6-0xFEA9*/
\r
799 1, 0, 2, 1 + 2, /*0xFEAA-0xFEAD*/
\r
800 1, 0, 1, 0, /*0xFEAE-0xFEB1*/
\r
801 1, 0, 1, 0, /*0xFEB2-0xFEB5*/
\r
802 1, 0, 2, 1+2, /*0xFEB6-0xFEB9*/
\r
803 1, 0, 2, 1+2, /*0xFEBA-0xFEBD*/
\r
804 1, 0, 2, 1+2, /*0xFEBE-0xFEC1*/
\r
805 1, 0, 2, 1+2, /*0xFEC2-0xFEC5*/
\r
806 1, 0, 2, 1+2, /*0xFEC6-0xFEC9*/
\r
807 1, 0, 2, 1+2, /*0xFECA-0xFECD*/
\r
808 1, 0, 2, 1+2, /*0xFECE-0xFED1*/
\r
809 1, 0, 2, 1+2, /*0xFED2-0xFED5*/
\r
810 1, 0, 2, 1+2, /*0xFED6-0xFED9*/
\r
811 1, 0, 2, 1+2, /*0xFEDA-0xFEDD*/
\r
812 1, 0, 2, 1+2, /*0xFEDE-0xFEE1*/
\r
813 1, 0 + 16, 2 + 16, 1 + 2 +16, /*0xFEE2-0xFEE5*/
\r
814 1 + 16, 0, 2, 1+2, /*0xFEE6-0xFEE9*/
\r
815 1, 0, 2, 1+2, /*0xFEEA-0xFEED*/
\r
816 1, 0, 2, 1+2, /*0xFEEE-0xFEF1*/
\r
817 1, 0, 1, 0, /*0xFEF2-0xFEF5*/
\r
818 1, 0, 2, 1+2, /*0xFEF6-0xFEF9*/
\r
819 1, 0, 1, 0, /*0xFEFA-0xFEFD*/
\r
824 private static int[] convertFEto06 = {
\r
825 /***********0******1******2******3******4******5******6******7******8******9******A******B******C******D******E******F***/
\r
826 /*FE7*/ 0x64B, 0x64B, 0x64C, 0x64C, 0x64D, 0x64D, 0x64E, 0x64E, 0x64F, 0x64F, 0x650, 0x650, 0x651, 0x651, 0x652, 0x652,
\r
827 /*FE8*/ 0x621, 0x622, 0x622, 0x623, 0x623, 0x624, 0x624, 0x625, 0x625, 0x626, 0x626, 0x626, 0x626, 0x627, 0x627, 0x628,
\r
828 /*FE9*/ 0x628, 0x628, 0x628, 0x629, 0x629, 0x62A, 0x62A, 0x62A, 0x62A, 0x62B, 0x62B, 0x62B, 0x62B, 0x62C, 0x62C, 0x62C,
\r
829 /*FEA*/ 0x62C, 0x62D, 0x62D, 0x62D, 0x62D, 0x62E, 0x62E, 0x62E, 0x62E, 0x62F, 0x62F, 0x630, 0x630, 0x631, 0x631, 0x632,
\r
830 /*FEB*/ 0x632, 0x633, 0x633, 0x633, 0x633, 0x634, 0x634, 0x634, 0x634, 0x635, 0x635, 0x635, 0x635, 0x636, 0x636, 0x636,
\r
831 /*FEC*/ 0x636, 0x637, 0x637, 0x637, 0x637, 0x638, 0x638, 0x638, 0x638, 0x639, 0x639, 0x639, 0x639, 0x63A, 0x63A, 0x63A,
\r
832 /*FED*/ 0x63A, 0x641, 0x641, 0x641, 0x641, 0x642, 0x642, 0x642, 0x642, 0x643, 0x643, 0x643, 0x643, 0x644, 0x644, 0x644,
\r
833 /*FEE*/ 0x644, 0x645, 0x645, 0x645, 0x645, 0x646, 0x646, 0x646, 0x646, 0x647, 0x647, 0x647, 0x647, 0x648, 0x648, 0x649,
\r
834 /*FEF*/ 0x649, 0x64A, 0x64A, 0x64A, 0x64A, 0x65C, 0x65C, 0x65D, 0x65D, 0x65E, 0x65E, 0x65F, 0x65F
\r
837 private static final int shapeTable[][][] = {
\r
838 { {0,0,0,0}, {0,0,0,0}, {0,1,0,3}, {0,1,0,1} },
\r
839 { {0,0,2,2}, {0,0,1,2}, {0,1,1,2}, {0,1,1,3} },
\r
840 { {0,0,0,0}, {0,0,0,0}, {0,1,0,3}, {0,1,0,3} },
\r
841 { {0,0,1,2}, {0,0,1,2}, {0,1,1,2}, {0,1,1,3} }
\r
845 * This function shapes European digits to Arabic-Indic digits
\r
846 * in-place, writing over the input characters. Data is in visual
\r
849 private void shapeToArabicDigitsWithContext(char[] dest,
\r
853 boolean lastStrongWasAL) {
\r
856 bdp=UBiDiProps.getSingleton();
\r
857 } catch (IOException e) {
\r
859 // This is dependent on the UBiDiProps object
\r
860 throw new MissingResourceException(e.getMessage(), "(BidiProps)", "");
\r
863 digitBase -= '0'; // move common adjustment out of loop
\r
865 for(int i = start + length; --i >= start;) {
\r
867 switch (bdp.getClass(ch)) {
\r
868 case UCharacterDirection.LEFT_TO_RIGHT:
\r
869 case UCharacterDirection.RIGHT_TO_LEFT:
\r
870 lastStrongWasAL = false;
\r
872 case UCharacterDirection.RIGHT_TO_LEFT_ARABIC:
\r
873 lastStrongWasAL = true;
\r
875 case UCharacterDirection.EUROPEAN_NUMBER:
\r
876 if (lastStrongWasAL && ch <= '\u0039') {
\r
877 dest[i] = (char)(ch + digitBase);
\r
887 * Name : invertBuffer
\r
888 * Function: This function inverts the buffer, it's used
\r
889 * in case the user specifies the buffer to be
\r
890 * TEXT_DIRECTION_LOGICAL
\r
892 private static void invertBuffer(char[] buffer,
\r
896 for(int i = start, j = start + length - 1; i < j; i++, --j) {
\r
897 char temp = buffer[i];
\r
898 buffer[i] = buffer[j];
\r
904 * Name : changeLamAlef
\r
905 * Function: Converts the Alef characters into an equivalent
\r
906 * LamAlef location in the 0x06xx Range, this is an
\r
907 * intermediate stage in the operation of the program
\r
908 * later it'll be converted into the 0xFExx LamAlefs
\r
909 * in the shaping function.
\r
911 private static char changeLamAlef(char ch) {
\r
913 case '\u0622': return '\u065C';
\r
914 case '\u0623': return '\u065D';
\r
915 case '\u0625': return '\u065E';
\r
916 case '\u0627': return '\u065F';
\r
917 default: return '\u0000'; // not a lamalef
\r
922 * Name : specialChar
\r
923 * Function: Special Arabic characters need special handling in the shapeUnicode
\r
924 * function, this function returns 1 or 2 for these special characters
\r
926 private static int specialChar(char ch) {
\r
927 if ((ch > '\u0621' && ch < '\u0626') ||
\r
928 (ch == '\u0627') ||
\r
929 (ch > '\u062E' && ch < '\u0633') ||
\r
930 (ch > '\u0647' && ch < '\u064A') ||
\r
931 (ch == '\u0629')) {
\r
933 } else if (ch >= '\u064B' && ch<= '\u0652') {
\r
935 } else if (ch >= 0x0653 && ch <= 0x0655 ||
\r
937 ch >= 0xFE70 && ch <= 0xFE7F) {
\r
946 * Function: Resolves the link between the characters as
\r
947 * Arabic characters have four forms :
\r
948 * Isolated, Initial, Middle and Final Form
\r
950 private static int getLink(char ch) {
\r
951 if (ch >= '\u0622' && ch <= '\u06D3') {
\r
952 return araLink[ch - '\u0622'];
\r
953 } else if (ch == '\u200D') {
\r
955 } else if (ch >= '\u206D' && ch <= '\u206F') {
\r
957 } else if (ch >= '\uFE70' && ch <= '\uFEFC') {
\r
958 return presLink[ch - '\uFE70'];
\r
965 * Name : countSpaces
\r
966 * Function: Counts the number of spaces
\r
967 * at each end of the logical buffer
\r
969 private static int countSpacesLeft(char[] dest,
\r
972 for (int i = start, e = start + count; i < e; ++i) {
\r
973 if (dest[i] != SPACE_CHAR) {
\r
980 private static int countSpacesRight(char[] dest,
\r
984 for (int i = start + count; --i >= start;) {
\r
985 if (dest[i] != SPACE_CHAR) {
\r
986 return start + count - 1 - i;
\r
993 * Name : isTashkeelChar
\r
994 * Function: Returns true for Tashkeel characters else return false
\r
996 private static boolean isTashkeelChar(char ch) {
\r
997 return ( ch >='\u064B' && ch <= '\u0652' );
\r
1001 *Name : isSeenTailFamilyChar
\r
1002 *Function : returns 1 if the character is a seen family isolated character
\r
1003 * in the FE range otherwise returns 0
\r
1006 private static int isSeenTailFamilyChar(char ch) {
\r
1007 if (ch >= 0xfeb1 && ch < 0xfebf){
\r
1008 return tailFamilyIsolatedFinal [ch - 0xFEB1];
\r
1014 /* Name : isSeenFamilyChar
\r
1015 * Function : returns 1 if the character is a seen family character in the Unicode
\r
1016 * 06 range otherwise returns 0
\r
1019 private static int isSeenFamilyChar(char ch){
\r
1020 if (ch >= 0x633 && ch <= 0x636){
\r
1028 *Name : isTailChar
\r
1029 *Function : returns true if the character matches one of the tail characters
\r
1030 * (0xfe73 or 0x200b) otherwise returns false
\r
1033 private static boolean isTailChar(char ch) {
\r
1034 if(ch == OLD_TAIL_CHAR || ch == NEW_TAIL_CHAR){
\r
1042 *Name : isAlefMaksouraChar
\r
1043 *Function : returns true if the character is a Alef Maksoura Final or isolated
\r
1044 * otherwise returns false
\r
1046 private static boolean isAlefMaksouraChar(char ch) {
\r
1047 return ( (ch == 0xFEEF) || ( ch == 0xFEF0) || (ch == 0x0649));
\r
1051 * Name : isYehHamzaChar
\r
1052 * Function : returns true if the character is a yehHamza isolated or yehhamza
\r
1053 * final is found otherwise returns false
\r
1055 private static boolean isYehHamzaChar(char ch) {
\r
1056 if((ch==0xFE89)||(ch==0xFE8A)){
\r
1064 *Name : isTashkeelCharFE
\r
1065 *Function : Returns true for Tashkeel characters in FE range else return false
\r
1068 private static boolean isTashkeelCharFE(char ch) {
\r
1069 return ( ch!=0xFE75 &&(ch>=0xFE70 && ch<= 0xFE7F) );
\r
1073 * Name: isTashkeelOnTatweelChar
\r
1074 * Function: Checks if the Tashkeel Character is on Tatweel or not,if the
\r
1075 * Tashkeel on tatweel (FE range), it returns 1 else if the
\r
1076 * Tashkeel with shadda on tatweel (FC range)return 2 otherwise
\r
1079 private static int isTashkeelOnTatweelChar(char ch){
\r
1080 if (ch >= 0xfe70 && ch <= 0xfe7f && ch != NEW_TAIL_CHAR && ch != 0xFE75 && ch != SHADDA_TATWEEL_CHAR)
\r
1082 return tashkeelMedial [ch - 0xFE70];
\r
1083 } else if( (ch >= 0xfcf2 && ch <= 0xfcf4) || (ch == SHADDA_TATWEEL_CHAR)) {
\r
1091 * Name: isIsolatedTashkeelChar
\r
1092 * Function: Checks if the Tashkeel Character is in the isolated form
\r
1093 * (i.e. Unicode FE range) returns 1 else if the Tashkeel
\r
1094 * with shadda is in the isolated form (i.e. Unicode FC range)
\r
1095 * returns 1 otherwise returns 0
\r
1097 private static int isIsolatedTashkeelChar(char ch){
\r
1098 if (ch >= 0xfe70 && ch <= 0xfe7f && ch != NEW_TAIL_CHAR && ch != 0xFE75){
\r
1099 return (1 - tashkeelMedial [ch - 0xFE70]);
\r
1100 } else if(ch >= 0xfc5e && ch <= 0xfc63){
\r
1108 * Name : isAlefChar
\r
1109 * Function: Returns 1 for Alef characters else return 0
\r
1111 private static boolean isAlefChar(char ch) {
\r
1112 return ch == '\u0622' || ch == '\u0623' || ch == '\u0625' || ch == '\u0627';
\r
1116 * Name : isLamAlefChar
\r
1117 * Function: Returns true for LamAlef characters else return false
\r
1119 private static boolean isLamAlefChar(char ch) {
\r
1120 return ch >= '\uFEF5' && ch <= '\uFEFC';
\r
1123 private static boolean isNormalizedLamAlefChar(char ch) {
\r
1124 return ch >= '\u065C' && ch <= '\u065F';
\r
1128 * Name : calculateSize
\r
1129 * Function: This function calculates the destSize to be used in preflighting
\r
1130 * when the destSize is equal to 0
\r
1132 private int calculateSize(char[] source,
\r
1134 int sourceLength) {
\r
1136 int destSize = sourceLength;
\r
1138 switch (options & LETTERS_MASK) {
\r
1139 case LETTERS_SHAPE:
\r
1140 case LETTERS_SHAPE_TASHKEEL_ISOLATED:
\r
1142 for (int i = sourceStart, e = sourceStart + sourceLength - 1; i < e; ++i) {
\r
1143 if ((source[i] == LAM_CHAR && isAlefChar(source[i+1])) || isTashkeelCharFE(source[i])){
\r
1147 } else { // visual
\r
1148 for(int i = sourceStart + 1, e = sourceStart + sourceLength; i < e; ++i) {
\r
1149 if ((source[i] == LAM_CHAR && isAlefChar(source[i-1])) || isTashkeelCharFE(source[i])) {
\r
1156 case LETTERS_UNSHAPE:
\r
1157 for(int i = sourceStart, e = sourceStart + sourceLength; i < e; ++i) {
\r
1158 if (isLamAlefChar(source[i])) {
\r
1173 * Name : countSpaceSub
\r
1174 * Function: Counts number of times the subChar appears in the array
\r
1176 private static int countSpaceSub(char [] dest,int length, char subChar){
\r
1179 while (i < length) {
\r
1180 if (dest[i] == subChar) {
\r
1189 * Name : shiftArray
\r
1190 * Function: Shifts characters to replace space sub characters
\r
1192 private static void shiftArray(char [] dest,int start, int e, char subChar){
\r
1195 while (--r >= start) {
\r
1196 char ch = dest[r];
\r
1197 if (ch != subChar) {
\r
1207 * Name : flipArray
\r
1208 * Function: inverts array, so that start becomes end and vice versa
\r
1210 private static int flipArray(char [] dest, int start, int e, int w){
\r
1213 // shift, assume small buffer size so don't use arraycopy
\r
1217 dest[w++] = dest[r++];
\r
1226 * Name : handleTashkeelWithTatweel
\r
1227 * Function : Replaces Tashkeel as following:
\r
1228 * Case 1 :if the Tashkeel on tatweel, replace it with Tatweel.
\r
1229 * Case 2 :if the Tashkeel aggregated with Shadda on Tatweel, replace
\r
1230 * it with Shadda on Tatweel.
\r
1231 * Case 3: if the Tashkeel is isolated replace it with Space.
\r
1234 private static int handleTashkeelWithTatweel(char[] dest, int sourceLength) {
\r
1236 for(i = 0; i < sourceLength; i++){
\r
1237 if((isTashkeelOnTatweelChar(dest[i]) == 1)){
\r
1238 dest[i] = TATWEEL_CHAR;
\r
1239 }else if((isTashkeelOnTatweelChar(dest[i]) == 2)){
\r
1240 dest[i] = SHADDA_TATWEEL_CHAR;
\r
1241 }else if((isIsolatedTashkeelChar(dest[i])==1) && dest[i] != SHADDA_CHAR){
\r
1242 dest[i] = SPACE_CHAR;
\r
1245 return sourceLength;
\r
1249 *Name : handleGeneratedSpaces
\r
1250 *Function : The shapeUnicode function converts Lam + Alef into LamAlef + space,
\r
1251 * and Tashkeel to space.
\r
1252 * handleGeneratedSpaces function puts these generated spaces
\r
1253 * according to the options the user specifies. LamAlef and Tashkeel
\r
1254 * spaces can be replaced at begin, at end, at near or decrease the
\r
1257 * There is also Auto option for LamAlef and tashkeel, which will put
\r
1258 * the spaces at end of the buffer (or end of text if the user used
\r
1259 * the option SPACES_RELATIVE_TO_TEXT_BEGIN_END).
\r
1261 * If the text type was visual_LTR and the option
\r
1262 * SPACES_RELATIVE_TO_TEXT_BEGIN_END was selected the END
\r
1263 * option will place the space at the beginning of the buffer and
\r
1264 * BEGIN will place the space at the end of the buffer.
\r
1266 private int handleGeneratedSpaces(char[] dest,
\r
1270 int lenOptionsLamAlef = options & LAMALEF_MASK;
\r
1271 int lenOptionsTashkeel = options & TASHKEEL_MASK;
\r
1272 boolean lamAlefOn = false;
\r
1273 boolean tashkeelOn = false;
\r
1275 if (!isLogical & !spacesRelativeToTextBeginEnd) {
\r
1276 switch (lenOptionsLamAlef) {
\r
1277 case LAMALEF_BEGIN: lenOptionsLamAlef = LAMALEF_END; break;
\r
1278 case LAMALEF_END: lenOptionsLamAlef = LAMALEF_BEGIN; break;
\r
1281 switch (lenOptionsTashkeel){
\r
1282 case TASHKEEL_BEGIN: lenOptionsTashkeel = TASHKEEL_END; break;
\r
1283 case TASHKEEL_END: lenOptionsTashkeel = TASHKEEL_BEGIN; break;
\r
1289 if (lenOptionsLamAlef == LAMALEF_NEAR) {
\r
1290 for (int i = start, e = i + length; i < e; ++i) {
\r
1291 if (dest[i] == LAMALEF_SPACE_SUB) {
\r
1292 dest[i] = SPACE_CHAR;
\r
1298 final int e = start + length;
\r
1299 int wL = countSpaceSub(dest, length, LAMALEF_SPACE_SUB);
\r
1300 int wT = countSpaceSub(dest, length, TASHKEEL_SPACE_SUB);
\r
1302 if (lenOptionsLamAlef == LAMALEF_END){
\r
1305 if (lenOptionsTashkeel == TASHKEEL_END){
\r
1306 tashkeelOn = true;
\r
1310 if (lamAlefOn && (lenOptionsLamAlef == LAMALEF_END)) {
\r
1311 shiftArray(dest, start, e, LAMALEF_SPACE_SUB);
\r
1312 while (wL > start) {
\r
1313 dest[--wL] = SPACE_CHAR;
\r
1317 if (tashkeelOn && (lenOptionsTashkeel == TASHKEEL_END)){
\r
1318 shiftArray(dest, start, e, TASHKEEL_SPACE_SUB);
\r
1319 while (wT > start) {
\r
1320 dest[--wT] = SPACE_CHAR;
\r
1324 lamAlefOn = false;
\r
1325 tashkeelOn = false;
\r
1327 if (lenOptionsLamAlef == LAMALEF_RESIZE){
\r
1330 if (lenOptionsTashkeel == TASHKEEL_RESIZE){
\r
1331 tashkeelOn = true;
\r
1334 if (lamAlefOn && (lenOptionsLamAlef == LAMALEF_RESIZE)){
\r
1335 shiftArray(dest, start, e, LAMALEF_SPACE_SUB);
\r
1336 wL = flipArray(dest,start,e, wL);
\r
1337 length = wL - start;
\r
1339 if (tashkeelOn && (lenOptionsTashkeel == TASHKEEL_RESIZE)) {
\r
1340 shiftArray(dest, start, e, TASHKEEL_SPACE_SUB);
\r
1341 wT = flipArray(dest,start,e, wT);
\r
1342 length = wT - start;
\r
1345 lamAlefOn = false;
\r
1346 tashkeelOn = false;
\r
1348 if ((lenOptionsLamAlef == LAMALEF_BEGIN) ||
\r
1349 (lenOptionsLamAlef == LAMALEF_AUTO)){
\r
1352 if (lenOptionsTashkeel == TASHKEEL_BEGIN){
\r
1353 tashkeelOn = true;
\r
1356 if (lamAlefOn && ((lenOptionsLamAlef == LAMALEF_BEGIN)||
\r
1357 (lenOptionsLamAlef == LAMALEF_AUTO))) { // spaces at beginning
\r
1358 shiftArray(dest, start, e, LAMALEF_SPACE_SUB);
\r
1359 wL = flipArray(dest,start,e, wL);
\r
1361 dest[wL++] = SPACE_CHAR;
\r
1364 if(tashkeelOn && (lenOptionsTashkeel == TASHKEEL_BEGIN)){
\r
1365 shiftArray(dest, start, e, TASHKEEL_SPACE_SUB);
\r
1366 wT = flipArray(dest,start,e, wT);
\r
1368 dest[wT++] = SPACE_CHAR;
\r
1378 *Name :expandCompositCharAtBegin
\r
1379 *Function :Expands the LamAlef character to Lam and Alef consuming the required
\r
1380 * space from beginning of the buffer. If the text type was visual_LTR
\r
1381 * and the option SPACES_RELATIVE_TO_TEXT_BEGIN_END was selected
\r
1382 * the spaces will be located at end of buffer.
\r
1383 * If there are no spaces to expand the LamAlef, an exception is thrown.
\r
1385 private boolean expandCompositCharAtBegin(char[] dest,int start, int length,
\r
1387 boolean spaceNotFound = false;
\r
1389 if (lacount > countSpacesRight(dest, start, length)) {
\r
1390 spaceNotFound = true;
\r
1391 return spaceNotFound;
\r
1393 for (int r = start + length - lacount, w = start + length; --r >= start;) {
\r
1394 char ch = dest[r];
\r
1395 if (isNormalizedLamAlefChar(ch)) {
\r
1396 dest[--w] = LAM_CHAR;
\r
1397 dest[--w] = convertNormalizedLamAlef[ch - '\u065C'];
\r
1402 return spaceNotFound;
\r
1407 *Name : expandCompositCharAtEnd
\r
1408 *Function : Expands the LamAlef character to Lam and Alef consuming the
\r
1409 * required space from end of the buffer. If the text type was
\r
1410 * Visual LTR and the option SPACES_RELATIVE_TO_TEXT_BEGIN_END
\r
1411 * was used, the spaces will be consumed from begin of buffer. If
\r
1412 * there are no spaces to expand the LamAlef, an exception is thrown.
\r
1415 private boolean expandCompositCharAtEnd(char[] dest,int start, int length,
\r
1417 boolean spaceNotFound = false;
\r
1419 if (lacount > countSpacesLeft(dest, start, length)) {
\r
1420 spaceNotFound = true;
\r
1421 return spaceNotFound;
\r
1423 for (int r = start + lacount, w = start, e = start + length; r < e; ++r) {
\r
1424 char ch = dest[r];
\r
1425 if (isNormalizedLamAlefChar(ch)) {
\r
1426 dest[w++] = convertNormalizedLamAlef[ch - '\u065C'];
\r
1427 dest[w++] = LAM_CHAR;
\r
1432 return spaceNotFound;
\r
1436 *Name : expandCompositCharAtNear
\r
1437 *Function : Expands the LamAlef character into Lam + Alef, YehHamza character
\r
1438 * into Yeh + Hamza, SeenFamily character into SeenFamily character
\r
1439 * + Tail, while consuming the space next to the character.
\r
1442 private boolean expandCompositCharAtNear(char[] dest,int start, int length,
\r
1443 int yehHamzaOption, int seenTailOption, int lamAlefOption){
\r
1445 boolean spaceNotFound = false;
\r
1449 if (isNormalizedLamAlefChar(dest[start])) {
\r
1450 spaceNotFound = true;
\r
1451 return spaceNotFound;
\r
1453 for (int i = start + length; --i >=start;) {
\r
1454 char ch = dest[i];
\r
1455 if (lamAlefOption == 1 && isNormalizedLamAlefChar(ch)) {
\r
1456 if (i>start &&dest[i-1] == SPACE_CHAR) {
\r
1457 dest[i] = LAM_CHAR;
\r
1458 dest[--i] = convertNormalizedLamAlef[ch - '\u065C'];
\r
1460 spaceNotFound = true;
\r
1461 return spaceNotFound;
\r
1463 }else if(seenTailOption == 1 && isSeenTailFamilyChar(ch) == 1){
\r
1464 if(i>start &&dest[i-1] == SPACE_CHAR){
\r
1465 dest[i-1] = tailChar;
\r
1467 spaceNotFound = true;
\r
1468 return spaceNotFound;
\r
1470 }else if(yehHamzaOption == 1 && isYehHamzaChar(ch)){
\r
1472 if(i>start &&dest[i-1] == SPACE_CHAR){
\r
1473 dest[i] = yehHamzaToYeh[ch - YEH_HAMZAFE_CHAR];
\r
1474 dest[i-1] = HAMZAFE_CHAR;
\r
1476 spaceNotFound = true;
\r
1477 return spaceNotFound;
\r
1488 * Name : expandCompositChar
\r
1489 * Function: LamAlef needs special handling as the LamAlef is
\r
1490 * one character while expanding it will give two
\r
1491 * characters Lam + Alef, so we need to expand the LamAlef
\r
1492 * in near or far spaces according to the options the user
\r
1493 * specifies or increase the buffer size.
\r
1494 * Dest has enough room for the expansion if we are growing.
\r
1495 * lamalef are normalized to the 'special characters'
\r
1497 private int expandCompositChar(char[] dest,
\r
1501 int shapingMode) throws ArabicShapingException {
\r
1503 int lenOptionsLamAlef = options & LAMALEF_MASK;
\r
1504 int lenOptionsSeen = options & SEEN_MASK;
\r
1505 int lenOptionsYehHamza = options & YEHHAMZA_MASK;
\r
1506 boolean spaceNotFound = false;
\r
1508 if (!isLogical && !spacesRelativeToTextBeginEnd) {
\r
1509 switch (lenOptionsLamAlef) {
\r
1510 case LAMALEF_BEGIN: lenOptionsLamAlef = LAMALEF_END; break;
\r
1511 case LAMALEF_END: lenOptionsLamAlef = LAMALEF_BEGIN; break;
\r
1516 if(shapingMode == 1){
\r
1517 if(lenOptionsLamAlef == LAMALEF_AUTO){
\r
1519 spaceNotFound = expandCompositCharAtEnd(dest, start, length, lacount);
\r
1520 if(spaceNotFound){
\r
1521 spaceNotFound = expandCompositCharAtBegin(dest, start, length, lacount);
\r
1523 if(spaceNotFound){
\r
1524 spaceNotFound = expandCompositCharAtNear(dest, start, length,0,0,1);
\r
1526 if(spaceNotFound){
\r
1527 throw new ArabicShapingException("No spacefor lamalef");
\r
1530 spaceNotFound = expandCompositCharAtBegin(dest, start, length, lacount);
\r
1531 if(spaceNotFound){
\r
1532 spaceNotFound = expandCompositCharAtEnd(dest, start, length, lacount);
\r
1534 if(spaceNotFound){
\r
1535 spaceNotFound = expandCompositCharAtNear(dest, start, length,0,0,1);
\r
1537 if(spaceNotFound){
\r
1538 throw new ArabicShapingException("No spacefor lamalef");
\r
1541 }else if(lenOptionsLamAlef == LAMALEF_END){
\r
1542 spaceNotFound = expandCompositCharAtEnd(dest, start, length, lacount);
\r
1543 if(spaceNotFound){
\r
1544 throw new ArabicShapingException("No spacefor lamalef");
\r
1546 }else if(lenOptionsLamAlef == LAMALEF_BEGIN){
\r
1547 spaceNotFound = expandCompositCharAtBegin(dest, start, length, lacount);
\r
1548 if(spaceNotFound){
\r
1549 throw new ArabicShapingException("No spacefor lamalef");
\r
1551 }else if(lenOptionsLamAlef == LAMALEF_NEAR){
\r
1552 spaceNotFound = expandCompositCharAtNear(dest, start, length,0,0,1);
\r
1553 if(spaceNotFound){
\r
1554 throw new ArabicShapingException("No spacefor lamalef");
\r
1556 }else if(lenOptionsLamAlef == LAMALEF_RESIZE){
\r
1557 for (int r = start + length, w = r + lacount; --r >= start;) {
\r
1558 char ch = dest[r];
\r
1559 if (isNormalizedLamAlefChar(ch)) {
\r
1560 dest[--w] = '\u0644';
\r
1561 dest[--w] = convertNormalizedLamAlef[ch - '\u065C'];
\r
1566 length += lacount;
\r
1569 if(lenOptionsSeen == SEEN_TWOCELL_NEAR){
\r
1570 spaceNotFound = expandCompositCharAtNear(dest, start, length,0,1,0);
\r
1571 if(spaceNotFound){
\r
1572 throw new ArabicShapingException("No space for Seen tail expansion");
\r
1575 if(lenOptionsYehHamza == YEHHAMZA_TWOCELL_NEAR){
\r
1576 spaceNotFound = expandCompositCharAtNear(dest, start, length,1,0,0);
\r
1577 if(spaceNotFound){
\r
1578 throw new ArabicShapingException("No space for YehHamza expansion");
\r
1586 /* Convert the input buffer from FExx Range into 06xx Range
\r
1587 * to put all characters into the 06xx range
\r
1588 * even the lamalef is converted to the special region in
\r
1589 * the 06xx range. Return the number of lamalef chars found.
\r
1591 private int normalize(char[] dest, int start, int length) {
\r
1593 for (int i = start, e = i + length; i < e; ++i) {
\r
1594 char ch = dest[i];
\r
1595 if (ch >= '\uFE70' && ch <= '\uFEFC') {
\r
1596 if (isLamAlefChar(ch)) {
\r
1599 dest[i] = (char)convertFEto06[ch - '\uFE70'];
\r
1606 * Name : deshapeNormalize
\r
1607 * Function: Convert the input buffer from FExx Range into 06xx Range
\r
1608 * even the lamalef is converted to the special region in the 06xx range.
\r
1609 * According to the options the user enters, all seen family characters
\r
1610 * followed by a tail character are merged to seen tail family character and
\r
1611 * any yeh followed by a hamza character are merged to yehhamza character.
\r
1612 * Method returns the number of lamalef chars found.
\r
1614 private int deshapeNormalize(char[] dest, int start, int length) {
\r
1616 int yehHamzaComposeEnabled = 0;
\r
1617 int seenComposeEnabled = 0;
\r
1619 yehHamzaComposeEnabled = ((options&YEHHAMZA_MASK) == YEHHAMZA_TWOCELL_NEAR) ? 1 : 0;
\r
1620 seenComposeEnabled = ((options&SEEN_MASK) == SEEN_TWOCELL_NEAR)? 1 : 0;
\r
1622 for (int i = start, e = i + length; i < e; ++i) {
\r
1623 char ch = dest[i];
\r
1625 if( (yehHamzaComposeEnabled == 1) && ((ch == HAMZA06_CHAR) || (ch == HAMZAFE_CHAR))
\r
1626 && (i < (length - 1)) && isAlefMaksouraChar(dest[i+1] )) {
\r
1627 dest[i] = SPACE_CHAR;
\r
1628 dest[i+1] = YEH_HAMZA_CHAR;
\r
1629 } else if ( (seenComposeEnabled == 1) && (isTailChar(ch)) && (i< (length - 1))
\r
1630 && (isSeenTailFamilyChar(dest[i+1])==1) ) {
\r
1631 dest[i] = SPACE_CHAR;
\r
1633 else if (ch >= '\uFE70' && ch <= '\uFEFC') {
\r
1634 if (isLamAlefChar(ch)) {
\r
1637 dest[i] = (char)convertFEto06[ch - '\uFE70'];
\r
1644 * Name : shapeUnicode
\r
1645 * Function: Converts an Arabic Unicode buffer in 06xx Range into a shaped
\r
1646 * arabic Unicode buffer in FExx Range
\r
1648 private int shapeUnicode(char[] dest,
\r
1652 int tashkeelFlag)throws ArabicShapingException {
\r
1654 int lamalef_count = normalize(dest, start, length);
\r
1656 // resolve the link between the characters.
\r
1657 // Arabic characters have four forms: Isolated, Initial, Medial and Final.
\r
1658 // Tashkeel characters have two, isolated or medial, and sometimes only isolated.
\r
1659 // tashkeelFlag == 0: shape normally, 1: shape isolated, 2: don't shape
\r
1661 boolean lamalef_found = false, seenfam_found = false;
\r
1662 boolean yehhamza_found = false, tashkeel_found = false;
\r
1663 int i = start + length - 1;
\r
1664 int currLink = getLink(dest[i]);
\r
1668 //int prevPos = i;
\r
1674 // If high byte of currLink > 0 then there might be more than one shape
\r
1675 if ((currLink & '\uFF00') > 0 || isTashkeelChar(dest[i])) {
\r
1678 while (nx < 0) { // we need to know about next char
\r
1681 nx = Integer.MAX_VALUE;
\r
1683 nextLink = getLink(dest[nw]);
\r
1684 if ((nextLink & IRRELEVANT) == 0) {
\r
1692 if (((currLink & ALEFTYPE) > 0) && ((lastLink & LAMTYPE) > 0)) {
\r
1693 lamalef_found = true;
\r
1694 char wLamalef = changeLamAlef(dest[i]); // get from 0x065C-0x065f
\r
1695 if (wLamalef != '\u0000') {
\r
1696 // replace alef by marker, it will be removed later
\r
1697 dest[i] = '\uffff';
\r
1698 dest[lastPos] = wLamalef;
\r
1702 lastLink = prevLink;
\r
1703 currLink = getLink(wLamalef); // requires '\u0000', unfortunately
\r
1705 if ((i > 0) && (dest[i-1] == SPACE_CHAR))
\r
1707 if ( isSeenFamilyChar(dest[i]) == 1){
\r
1708 seenfam_found = true;
\r
1709 } else if (dest[i] == YEH_HAMZA_CHAR) {
\r
1710 yehhamza_found = true;
\r
1714 if ( isSeenFamilyChar(dest[i]) == 1){
\r
1715 seenfam_found = true;
\r
1716 } else if (dest[i] == YEH_HAMZA_CHAR) {
\r
1717 yehhamza_found = true;
\r
1722 // get the proper shape according to link ability of neighbors
\r
1723 // and of character; depends on the order of the shapes
\r
1724 // (isolated, initial, middle, final) in the compatibility area
\r
1726 int flag = specialChar(dest[i]);
\r
1728 int shape = shapeTable[nextLink & LINK_MASK]
\r
1729 [lastLink & LINK_MASK]
\r
1730 [currLink & LINK_MASK];
\r
1734 } else if (flag == 2) {
\r
1735 if (tashkeelFlag == 0 &&
\r
1736 ((lastLink & LINKL) != 0) &&
\r
1737 ((nextLink & LINKR) != 0) &&
\r
1738 dest[i] != '\u064C' &&
\r
1739 dest[i] != '\u064D' &&
\r
1740 !((nextLink & ALEFTYPE) == ALEFTYPE &&
\r
1741 (lastLink & LAMTYPE) == LAMTYPE)) {
\r
1749 if (tashkeelFlag == 2) {
\r
1750 dest[i] = TASHKEEL_SPACE_SUB;
\r
1751 tashkeel_found = true;
\r
1754 dest[i] = (char)('\uFE70' + irrelevantPos[dest[i] - '\u064B'] + shape);
\r
1756 // else leave tashkeel alone
\r
1758 dest[i] = (char)('\uFE70' + (currLink >> 8) + shape);
\r
1762 // move one notch forward
\r
1763 if ((currLink & IRRELEVANT) == 0) {
\r
1764 prevLink = lastLink;
\r
1765 lastLink = currLink;
\r
1766 //prevPos = lastPos;
\r
1772 currLink = nextLink;
\r
1774 } else if (i != -1) {
\r
1775 currLink = getLink(dest[i]);
\r
1779 // If we found a lam/alef pair in the buffer
\r
1780 // call handleGeneratedSpaces to remove the spaces that were added
\r
1782 destSize = length;
\r
1783 if (lamalef_found || tashkeel_found) {
\r
1784 destSize = handleGeneratedSpaces(dest, start, length);
\r
1786 if (seenfam_found || yehhamza_found){
\r
1787 destSize = expandCompositChar(dest, start, destSize, lamalef_count, SHAPE_MODE);
\r
1793 * Name : deShapeUnicode
\r
1794 * Function: Converts an Arabic Unicode buffer in FExx Range into unshaped
\r
1795 * arabic Unicode buffer in 06xx Range
\r
1797 private int deShapeUnicode(char[] dest,
\r
1800 int destSize) throws ArabicShapingException {
\r
1802 int lamalef_count = deshapeNormalize(dest, start, length);
\r
1804 // If there was a lamalef in the buffer call expandLamAlef
\r
1805 if (lamalef_count != 0) {
\r
1806 // need to adjust dest to fit expanded buffer... !!!
\r
1807 destSize = expandCompositChar(dest, start, length, lamalef_count,DESHAPE_MODE);
\r
1809 destSize = length;
\r
1815 private int internalShape(char[] source,
\r
1820 int destSize) throws ArabicShapingException {
\r
1822 if (sourceLength == 0) {
\r
1826 if (destSize == 0) {
\r
1827 if (((options & LETTERS_MASK) != LETTERS_NOOP) &&
\r
1828 ((options & LAMALEF_MASK) == LAMALEF_RESIZE)) {
\r
1830 return calculateSize(source, sourceStart, sourceLength);
\r
1832 return sourceLength; // by definition
\r
1836 // always use temp buffer
\r
1837 char[] temp = new char[sourceLength * 2]; // all lamalefs requiring expansion
\r
1838 System.arraycopy(source, sourceStart, temp, 0, sourceLength);
\r
1841 invertBuffer(temp, 0, sourceLength);
\r
1844 int outputSize = sourceLength;
\r
1846 switch (options & LETTERS_MASK) {
\r
1847 case LETTERS_SHAPE_TASHKEEL_ISOLATED:
\r
1848 outputSize = shapeUnicode(temp, 0, sourceLength, destSize, 1);
\r
1851 case LETTERS_SHAPE:
\r
1852 if( ((options&TASHKEEL_MASK)> 0) &&
\r
1853 ((options&TASHKEEL_MASK) !=TASHKEEL_REPLACE_BY_TATWEEL)) {
\r
1854 /* Call the shaping function with tashkeel flag == 2 for removal of tashkeel */
\r
1855 outputSize = shapeUnicode(temp, 0, sourceLength, destSize, 2);
\r
1857 //default Call the shaping function with tashkeel flag == 1 */
\r
1858 outputSize = shapeUnicode(temp, 0, sourceLength, destSize, 0);
\r
1860 /*After shaping text check if user wants to remove tashkeel and replace it with tatweel*/
\r
1861 if( (options&TASHKEEL_MASK) == TASHKEEL_REPLACE_BY_TATWEEL){
\r
1862 outputSize = handleTashkeelWithTatweel(temp,sourceLength);
\r
1867 case LETTERS_UNSHAPE:
\r
1868 outputSize = deShapeUnicode(temp, 0, sourceLength, destSize);
\r
1875 if (outputSize > destSize) {
\r
1876 throw new ArabicShapingException("not enough room for result data");
\r
1879 if ((options & DIGITS_MASK) != DIGITS_NOOP) {
\r
1880 char digitBase = '\u0030'; // European digits
\r
1881 switch (options & DIGIT_TYPE_MASK) {
\r
1882 case DIGIT_TYPE_AN:
\r
1883 digitBase = '\u0660'; // Arabic-Indic digits
\r
1886 case DIGIT_TYPE_AN_EXTENDED:
\r
1887 digitBase = '\u06f0'; // Eastern Arabic-Indic digits (Persian and Urdu)
\r
1894 switch (options & DIGITS_MASK) {
\r
1895 case DIGITS_EN2AN:
\r
1897 int digitDelta = digitBase - '\u0030';
\r
1898 for (int i = 0; i < outputSize; ++i) {
\r
1899 char ch = temp[i];
\r
1900 if (ch <= '\u0039' && ch >= '\u0030') {
\r
1901 temp[i] += digitDelta;
\r
1907 case DIGITS_AN2EN:
\r
1909 char digitTop = (char)(digitBase + 9);
\r
1910 int digitDelta = '\u0030' - digitBase;
\r
1911 for (int i = 0; i < outputSize; ++i) {
\r
1912 char ch = temp[i];
\r
1913 if (ch <= digitTop && ch >= digitBase) {
\r
1914 temp[i] += digitDelta;
\r
1920 case DIGITS_EN2AN_INIT_LR:
\r
1921 shapeToArabicDigitsWithContext(temp, 0, outputSize, digitBase, false);
\r
1924 case DIGITS_EN2AN_INIT_AL:
\r
1925 shapeToArabicDigitsWithContext(temp, 0, outputSize, digitBase, true);
\r
1934 invertBuffer(temp, 0, outputSize);
\r
1937 System.arraycopy(temp, 0, dest, destStart, outputSize);
\r
1939 return outputSize;
\r