001: /*
002: *******************************************************************************
003: * Copyright (C) 1998-2004, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: *
007: * Created on Dec 09, 2003
008: *
009: *******************************************************************************
010: */
011: package com.ibm.icu.dev.tool.layout;
012:
013: import com.ibm.icu.impl.Utility;
014: import java.io.PrintStream;
015:
016: public class ThaiCharacterClasses {
017: public static final int NON = 0;
018: public static final int CON = 1;
019: public static final int COA = 2;
020: public static final int COD = 3;
021: public static final int LVO = 4;
022: public static final int FV1 = 5;
023: public static final int FV2 = 6;
024: public static final int FV3 = 7;
025: public static final int BV1 = 8;
026: public static final int BV2 = 9;
027: public static final int BDI = 10;
028: public static final int TON = 11;
029: public static final int AD1 = 12;
030: public static final int AD2 = 13;
031: public static final int AD3 = 14;
032: public static final int NIK = 15;
033: public static final int AV1 = 16;
034: public static final int AV2 = 17;
035: public static final int AV3 = 18;
036: public static final int cCount = 19;
037:
038: // Indexed by unicode - '\u0E00'
039: // FIXME: MS Fonts - Should 0E2E has no ascender (it does in WT font)
040: // FIXME: MS Fonts - 0E47 (MAITAIKHU) and 0E4D (NIKHAHIT) only have vowel forms
041: // FIXME: MS Fonts - 0E4E (YAMAKKAN) only has one form
042: private static final int classTable[] = {
043: // 0 1 2 3 4 5 6 7 8 9 A B C D E F
044: // -------------------------------------------------------------------------------
045: /*0E00*/NON, CON, CON, CON, CON, CON, CON, CON, CON, CON,
046: CON, CON, CON, COD, COD, COD,
047: /*0E10*/COD, CON, CON, CON, CON, CON, CON, CON, CON, CON,
048: CON, COA, CON, COA, CON, COA,
049: /*0E20*/CON, CON, CON, CON, FV3, CON, FV3, CON, CON, CON,
050: CON, CON, CON, CON, CON, NON,
051: /*0E30*/FV1, AV2, FV1, FV1, AV1, AV3, AV2, AV3, BV1, BV2,
052: BDI, NON, NON, NON, NON, NON,
053: /*0E40*/LVO, LVO, LVO, LVO, LVO, FV2, NON, AD2, TON, TON,
054: TON, TON, AD1, NIK, AD3, NON,
055: /*0E50*/NON, NON, NON, NON, NON, NON, NON, NON, NON, NON,
056: NON, NON };
057:
058: private static String[] classNames = { "NON", "CON", "COA", "COD",
059: "LVO", "FV1", "FV2", "FV3", "BV1", "BV2", "BDI", "TON",
060: "AD1", "AD2", "AD3", "NIK", "AV1", "AV2", "AV3" };
061:
062: private static final char pairTable[][] = {
063: //------------------------------------------------------------------------------------------------
064: // N C C C L F F F B B B T A A A N A A A
065: // O O O O V V V V V V D O D D D I V V V
066: // N N A D O 1 2 3 1 2 I N 1 2 3 K 1 2 3
067: //------------------------------------------------------------------------------------------------
068: /*NON*/{ 'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R',
069: 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
070: /*CON*/{ 'A', 'A', 'A', 'A', 'A', 'A', 'S', 'A', 'C', 'C',
071: 'C', 'E', 'E', 'E', 'C', 'E', 'C', 'C', 'C' },
072: /*COA*/{ 'A', 'A', 'A', 'A', 'A', 'A', 'S', 'A', 'C', 'C',
073: 'C', 'F', 'F', 'F', 'D', 'F', 'D', 'D', 'D' },
074: /*COD*/{ 'A', 'A', 'A', 'A', 'A', 'A', 'S', 'A', 'H', 'H',
075: 'H', 'E', 'E', 'E', 'C', 'E', 'C', 'C', 'C' },
076: /*LVO*/{ 'S', 'A', 'A', 'A', 'S', 'S', 'S', 'S', 'R', 'R',
077: 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
078: /*FV1*/{ 'S', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R',
079: 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
080: /*FV2*/{ 'A', 'A', 'A', 'A', 'A', 'A', 'S', 'A', 'R', 'R',
081: 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
082: /*FV3*/{ 'A', 'A', 'A', 'A', 'A', 'S', 'A', 'S', 'R', 'R',
083: 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
084: /*BV1*/{ 'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R',
085: 'R', 'E', 'E', 'R', 'R', 'E', 'R', 'R', 'R' },
086: /*BV2*/{ 'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R',
087: 'R', 'E', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
088: /*BDI*/{ 'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R',
089: 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
090: /*TON*/{ 'A', 'A', 'A', 'A', 'A', 'I', 'A', 'A', 'R', 'R',
091: 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
092: /*AD1*/{ 'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R',
093: 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
094: /*AD2*/{ 'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R',
095: 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
096: /*AD3*/{ 'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R',
097: 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
098: /*NIK*/{ 'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R',
099: 'R', 'G', 'G', 'R', 'R', 'R', 'R', 'R', 'R' },
100: /*AV1*/{ 'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R',
101: 'R', 'G', 'G', 'R', 'R', 'G', 'R', 'R', 'R' },
102: /*AV2*/{ 'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R',
103: 'R', 'G', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
104: /*AV3*/{ 'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R',
105: 'R', 'G', 'R', 'G', 'R', 'R', 'R', 'R', 'R' } };
106:
107: public static int getCharClass(char ch) {
108: int charClass = NON;
109:
110: if (ch >= '\u0E00' && ch <= '\u0E5B') {
111: charClass = classTable[ch - '\u0E00'];
112: }
113:
114: return charClass;
115: }
116:
117: public static String getClassName(int classID) {
118: if (classID < 0 || classID >= cCount) {
119: return "***";
120: }
121:
122: return classNames[classID];
123: }
124:
125: public static char getPairAction(int prevClass, int currClass) {
126: if (prevClass < 0 || prevClass >= cCount | currClass < 0
127: || currClass >= cCount) {
128: return 'A';
129: }
130:
131: return pairTable[prevClass][currClass];
132: }
133:
134: private static String classTableHeader = "const le_uint8 ThaiShaping::classTable[] = {\n"
135: + " // 0 1 2 3 4 5 6 7 8 9 A B C D E F\n"
136: + " // -------------------------------------------------------------------------------";
137:
138: public static void writeClassTable(PrintStream output) {
139: System.out.print("Writing class table...");
140:
141: output.print(classTableHeader);
142:
143: for (char ch = '\u0E00'; ch <= '\u0E5B'; ch += 1) {
144: int charClass = getCharClass(ch);
145:
146: if ((ch & 0x000F) == 0) {
147: output.print("\n /*" + Utility.hex(ch, 4) + "*/ ");
148: }
149:
150: output.print(getClassName(charClass));
151:
152: if (ch < '\u0E5B') {
153: output.print(", ");
154: } else {
155: output.print("\n};\n\n");
156: }
157: }
158:
159: System.out.println(" done.");
160: }
161:
162: }
|