1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.  Oracle designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * by Oracle in the LICENSE file that accompanied this code.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 /*
  27  *
  28  * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
  29  *
  30  */
  31 
  32 #ifndef __THAISHAPING_H
  33 #define __THAISHAPING_H
  34 
  35 /**
  36  * \file
  37  * \internal
  38  */
  39 
  40 #include "LETypes.h"
  41 #include "LEGlyphFilter.h"
  42 #include "OpenTypeTables.h"
  43 
  44 U_NAMESPACE_BEGIN
  45 
  46 class LEGlyphStorage;
  47 
  48 class ThaiShaping /* not : public UObject because all methods are static */ {
  49 public:
  50 
  51     enum {
  52         // Character classes
  53         NON =  0,
  54         CON =  1,
  55         COA =  2,
  56         COD =  3,
  57         LVO =  4,
  58         FV1 =  5,
  59         FV2 =  6,
  60         FV3 =  7,
  61         BV1 =  8,
  62         BV2 =  9,
  63         BDI = 10,
  64         TON = 11,
  65         AD1 = 12,
  66         AD2 = 13,
  67         AD3 = 14,
  68         NIK = 15,
  69         AV1 = 16,
  70         AV2 = 17,
  71         AV3 = 18,
  72         classCount = 19,
  73 
  74         // State Transition actions
  75         tA  =  0,
  76         tC  =  1,
  77         tD  =  2,
  78         tE  =  3,
  79         tF  =  4,
  80         tG  =  5,
  81         tH  =  6,
  82         tR  =  7,
  83         tS  =  8,
  84         stateCount = 52
  85     };
  86 
  87     struct StateTransition
  88     {
  89         le_uint8 nextState;
  90         le_uint8 action;
  91 
  92         le_uint8 getNextState() { return nextState; };
  93         le_uint8 getAction() { return action; };
  94     };
  95 
  96     static le_int32 compose(const LEUnicode *input, le_int32 offset, le_int32 charCount, le_uint8 glyphSet,
  97         LEUnicode errorChar, LEUnicode *output, LEGlyphStorage &glyphStorage);
  98 
  99 private:
 100     // forbid instantiation
 101     ThaiShaping();
 102 
 103     static const le_uint8 classTable[];
 104     static const StateTransition thaiStateTable[stateCount][classCount];
 105 
 106     inline static StateTransition getTransition(le_uint8 state, le_uint8 currClass);
 107 
 108     static le_uint8 doTransition(StateTransition transition, LEUnicode currChar, le_int32 inputIndex, le_uint8 glyphSet,
 109         LEUnicode errorChar, LEUnicode *outputBuffer, LEGlyphStorage &glyphStorage, le_int32 &outputIndex);
 110 
 111     static le_uint8 getNextState(LEUnicode ch, le_uint8 state, le_int32 inputIndex, le_uint8 glyphSet, LEUnicode errorChar,
 112         le_uint8 &charClass, LEUnicode *output, LEGlyphStorage &glyphStorage, le_int32 &outputIndex);
 113 
 114     static le_bool isLegalHere(LEUnicode ch, le_uint8 prevState);
 115     static le_uint8 getCharClass(LEUnicode ch);
 116 
 117     static LEUnicode noDescenderCOD(LEUnicode cod, le_uint8 glyphSet);
 118     static LEUnicode leftAboveVowel(LEUnicode vowel, le_uint8 glyphSet);
 119     static LEUnicode lowerBelowVowel(LEUnicode vowel, le_uint8 glyphSet);
 120     static LEUnicode lowerRightTone(LEUnicode tone, le_uint8 glyphSet);
 121     static LEUnicode lowerLeftTone(LEUnicode tone, le_uint8 glyphSet);
 122     static LEUnicode upperLeftTone(LEUnicode tone, le_uint8 glyphSet);
 123 
 124 };
 125 
 126 inline ThaiShaping::StateTransition ThaiShaping::getTransition(le_uint8 state, le_uint8 currClass)
 127 {
 128     return thaiStateTable[state][currClass];
 129 }
 130 
 131 U_NAMESPACE_END
 132 #endif