Home | History | Annotate | Download | only in layout
      1 //  2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html#License
      3 /*
      4  *******************************************************************************
      5  * Copyright (C) 1998-2010, International Business Machines Corporation and    *
      6  * others. All Rights Reserved.                                                *
      7  *******************************************************************************
      8  *
      9  * Created on Dec 09, 2003
     10  *
     11  *******************************************************************************
     12  */
     13 package com.ibm.icu.dev.tool.layout;
     14 
     15 import java.io.PrintStream;
     16 
     17 import com.ibm.icu.impl.Utility;
     18 
     19 public class ThaiCharacterClasses
     20 {
     21     public static final int NON    =  0;
     22     public static final int CON    =  1;
     23     public static final int COA    =  2;
     24     public static final int COD    =  3;
     25     public static final int LVO =  4;
     26     public static final int FV1    =  5;
     27     public static final int FV2    =  6;
     28     public static final int FV3    =  7;
     29     public static final int BV1    =  8;
     30     public static final int BV2    =  9;
     31     public static final int BDI = 10;
     32     public static final int TON    = 11;
     33     public static final int AD1    = 12;
     34     public static final int AD2    = 13;
     35     public static final int AD3    = 14;
     36     public static final int NIK    = 15;
     37     public static final int AV1    = 16;
     38     public static final int AV2    = 17;
     39     public static final int AV3    = 18;
     40     public static final int cCount = 19;
     41 
     42     // Indexed by unicode - '\u0E00'
     43     // FIXME: MS Fonts - Should 0E2E has no ascender (it does in WT font)
     44     // FIXME: MS Fonts - 0E47 (MAITAIKHU) and 0E4D (NIKHAHIT) only have vowel forms
     45     // FIXME: MS Fonts - 0E4E (YAMAKKAN) only has one form
     46     private static final int classTable[] = {
     47     //       0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F
     48     //       -------------------------------------------------------------------------------
     49     /*0E00*/ NON, CON, CON, CON, CON, CON, CON, CON, CON, CON, CON, CON, CON, COD, COD, COD,
     50     /*0E10*/ COD, CON, CON, CON, CON, CON, CON, CON, CON, CON, CON, COA, CON, COA, CON, COA,
     51     /*0E20*/ CON, CON, CON, CON, FV3, CON, FV3, CON, CON, CON, CON, CON, CON, CON, CON, NON,
     52     /*0E30*/ FV1, AV2, FV1, FV1, AV1, AV3, AV2, AV3, BV1, BV2, BDI, NON, NON, NON, NON, NON,
     53     /*0E40*/ LVO, LVO, LVO, LVO, LVO, FV2, NON, AD2, TON, TON, TON, TON, AD1, NIK, AD3, NON,
     54     /*0E50*/ NON, NON, NON, NON, NON, NON, NON, NON, NON, NON, NON, NON
     55     };
     56 
     57     private static String[] classNames =
     58     {
     59         "NON",
     60         "CON",
     61         "COA",
     62         "COD",
     63         "LVO",
     64         "FV1",
     65         "FV2",
     66         "FV3",
     67         "BV1",
     68         "BV2",
     69         "BDI",
     70         "TON",
     71         "AD1",
     72         "AD2",
     73         "AD3",
     74         "NIK",
     75         "AV1",
     76         "AV2",
     77         "AV3"
     78     };
     79 
     80     private static final char pairTable[][] = {
     81       //------------------------------------------------------------------------------------------------
     82       //  N    C    C    C    L    F    F    F    B    B    B    T    A    A    A    N    A    A    A
     83       //  O    O    O    O    V    V    V    V    V    V    D    O    D    D    D    I    V    V    V
     84       //  N    N    A    D    O    1    2    3    1    2    I    N    1    2    3    K    1    2    3
     85       //------------------------------------------------------------------------------------------------
     86 /*NON*/ {'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R'},
     87 /*CON*/ {'A', 'A', 'A', 'A', 'A', 'A', 'S', 'A', 'C', 'C', 'C', 'E', 'E', 'E', 'C', 'E', 'C', 'C', 'C'},
     88 /*COA*/ {'A', 'A', 'A', 'A', 'A', 'A', 'S', 'A', 'C', 'C', 'C', 'F', 'F', 'F', 'D', 'F', 'D', 'D', 'D'},
     89 /*COD*/ {'A', 'A', 'A', 'A', 'A', 'A', 'S', 'A', 'H', 'H', 'H', 'E', 'E', 'E', 'C', 'E', 'C', 'C', 'C'},
     90 /*LVO*/ {'S', 'A', 'A', 'A', 'S', 'S', 'S', 'S', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R'},
     91 /*FV1*/ {'S', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R'},
     92 /*FV2*/ {'A', 'A', 'A', 'A', 'A', 'A', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R'},
     93 /*FV3*/ {'A', 'A', 'A', 'A', 'A', 'S', 'A', 'S', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R'},
     94 /*BV1*/ {'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'E', 'E', 'R', 'R', 'E', 'R', 'R', 'R'},
     95 /*BV2*/ {'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'E', 'R', 'R', 'R', 'R', 'R', 'R', 'R'},
     96 /*BDI*/ {'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R'},
     97 /*TON*/ {'A', 'A', 'A', 'A', 'A', 'I', 'A', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R'},
     98 /*AD1*/ {'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R'},
     99 /*AD2*/ {'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R'},
    100 /*AD3*/ {'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R'},
    101 /*NIK*/ {'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'G', 'G', 'R', 'R', 'R', 'R', 'R', 'R'},
    102 /*AV1*/ {'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'G', 'G', 'R', 'R', 'G', 'R', 'R', 'R'},
    103 /*AV2*/ {'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'G', 'R', 'R', 'R', 'R', 'R', 'R', 'R'},
    104 /*AV3*/ {'A', 'A', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'G', 'R', 'G', 'R', 'R', 'R', 'R', 'R'}
    105     };
    106 
    107     public static int getCharClass(char ch)
    108     {
    109         int charClass = NON;
    110 
    111         if (ch >= '\u0E00' && ch <= '\u0E5B') {
    112             charClass = classTable[ch - '\u0E00'];
    113         }
    114 
    115         return charClass;
    116     }
    117 
    118     public static String getClassName(int classID)
    119     {
    120         if (classID < 0 || classID >= cCount) {
    121             return "***";
    122         }
    123 
    124         return classNames[classID];
    125     }
    126 
    127     public static char getPairAction(int prevClass, int currClass)
    128     {
    129         if (prevClass < 0 || prevClass >= cCount |
    130             currClass < 0 || currClass >= cCount) {
    131             return 'A';
    132         }
    133 
    134         return pairTable[prevClass][currClass];
    135     }
    136 
    137     private static String classTableHeader =
    138 "const le_uint8 ThaiShaping::classTable[] = {\n" +
    139 "    //       0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F\n" +
    140 "    //       -------------------------------------------------------------------------------";
    141 
    142     public static void writeClassTable(PrintStream output)
    143     {
    144         System.out.print("Writing class table...");
    145 
    146         output.print(classTableHeader);
    147 
    148         for (char ch = '\u0E00'; ch <= '\u0E5B'; ch += 1) {
    149             int charClass = getCharClass(ch);
    150 
    151             if ((ch & 0x000F) == 0) {
    152                 output.print("\n    /*" + Utility.hex(ch, 4) + "*/ ");
    153             }
    154 
    155             output.print(getClassName(charClass));
    156 
    157             if (ch < '\u0E5B') {
    158                 output.print(", ");
    159             } else {
    160                 output.print("\n};\n\n");
    161             }
    162         }
    163 
    164         System.out.println(" done.");
    165     }
    166 
    167 }
    168