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