2 *******************************************************************************
\r
3 * Copyright (C) 1998-2004, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
7 * Created on Dec 3, 2003
\r
9 *******************************************************************************
\r
11 package com.ibm.icu.dev.tool.layout;
\r
13 import com.ibm.icu.lang.UCharacter;
\r
14 import com.ibm.icu.lang.UProperty;
\r
16 public class ArabicShaping {
\r
18 // arabic shaping type code
\r
20 // shaping bit masks
\r
21 static final int MASK_SHAPE_RIGHT = 1; // if this bit set, shapes to right
\r
22 static final int MASK_SHAPE_LEFT = 2; // if this bit set, shapes to left
\r
23 static final int MASK_TRANSPARENT = 4; // if this bit set, is transparent (ignore other bits)
\r
24 static final int MASK_NOSHAPE = 8; // if this bit set, don't shape this char, i.e. tatweel
\r
27 public static final int VALUE_NONE = 0;
\r
28 public static final int VALUE_RIGHT = MASK_SHAPE_RIGHT;
\r
29 public static final int VALUE_LEFT = MASK_SHAPE_LEFT;
\r
30 public static final int VALUE_DUAL = MASK_SHAPE_RIGHT | MASK_SHAPE_LEFT;
\r
31 public static final int VALUE_TRANSPARENT = MASK_TRANSPARENT;
\r
32 public static final int VALUE_NOSHAPE_DUAL = MASK_NOSHAPE | VALUE_DUAL;
\r
33 public static final int VALUE_NOSHAPE_NONE = MASK_NOSHAPE;
\r
35 public static int getShapeType(char ch)
\r
37 int tt = UCharacter.getIntPropertyValue(ch, UProperty.JOINING_TYPE);
\r
40 case UCharacter.JoiningType.JOIN_CAUSING:
\r
41 return VALUE_NOSHAPE_DUAL;
\r
43 case UCharacter.JoiningType.LEFT_JOINING:
\r
46 case UCharacter.JoiningType.RIGHT_JOINING:
\r
49 case UCharacter.JoiningType.DUAL_JOINING:
\r
52 case UCharacter.JoiningType.TRANSPARENT:
\r
53 return VALUE_TRANSPARENT;
\r
55 case UCharacter.JoiningType.NON_JOINING:
\r
57 return VALUE_NOSHAPE_NONE;
\r
62 * Chars in logical order.
\r
63 * leftType is shaping code of char to logical left of range
\r
64 * rightType is shaping code of char to logical right of range
\r
67 public static void shape(char[] chars, int leftType, int rightType, ClassTable isolClassTable) {
\r
68 // iterate in logical order from left to right
\r
70 // the effective right char is the most recently encountered
\r
71 // non-transparent char
\r
73 // four boolean states:
\r
74 // the effective right char shapes
\r
75 // the effective right char causes right shaping
\r
76 // the current char shapes
\r
77 // the current char causes left shaping
\r
79 // if both cause shaping, then
\r
80 // right += 2 (isolate to initial, or final to medial)
\r
81 // cur += 1 (isolate to final)
\r
83 // ern is effective right logical index
\r
86 boolean rightShapes = false;
\r
87 boolean rightCauses = (rightType & MASK_SHAPE_LEFT) != 0;
\r
89 for (int n = 0; n < chars.length; n++) {
\r
91 int t = getShapeType(c);
\r
93 if ((t & MASK_TRANSPARENT) != 0) {
\r
97 boolean curShapes = (t & MASK_NOSHAPE) == 0;
\r
98 boolean curCauses = (t & MASK_SHAPE_RIGHT) != 0;
\r
100 if (rightCauses && curCauses) {
\r
106 chars[n] = (char) (isolClassTable.getGlyphClassID(c) + 1);
\r
110 chars[n] = (char) isolClassTable.getGlyphClassID(c);
\r
114 rightShapes = curShapes;
\r
115 rightCauses = (t & MASK_SHAPE_LEFT) != 0;
\r
119 if (rightShapes && rightCauses && (leftType & MASK_SHAPE_RIGHT) != 0) {
\r