jdk/src/share/native/sun/font/layout/ThaiShaping.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 3935 afcdb712a9c5
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "LETypes.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "LEGlyphFilter.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "OpenTypeTables.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "LEGlyphStorage.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "ThaiShaping.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    CH_SPACE        = 0x0020,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    CH_YAMAKKAN     = 0x0E4E,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    CH_MAI_HANAKAT  = 0x0E31,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    CH_SARA_AA      = 0x0E32,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    CH_SARA_AM      = 0x0E33,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    CH_SARA_UEE     = 0x0E37,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    CH_MAITAIKHU    = 0x0E47,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    CH_NIKHAHIT     = 0x0E4D,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    CH_SARA_U       = 0x0E38,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    CH_PHINTHU      = 0x0E3A,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    CH_YO_YING      = 0x0E0D,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    CH_THO_THAN     = 0x0E10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    CH_DOTTED_CIRCLE = 0x25CC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    le_uint8 ThaiShaping::getCharClass(LEUnicode ch)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    le_uint8 charClass = NON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    if (ch >= 0x0E00 && ch <= 0x0E5B) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        charClass = classTable[ch - 0x0E00];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    return charClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
LEUnicode ThaiShaping::leftAboveVowel(LEUnicode vowel, le_uint8 glyphSet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    static const LEUnicode leftAboveVowels[][7] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        {0x0E61, 0x0E32, 0x0E33, 0x0E64, 0x0E65, 0x0E66, 0x0E67},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        {0xF710, 0x0E32, 0x0E33, 0xF701, 0xF702, 0xF703, 0xF704},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        {0xF884, 0x0E32, 0x0E33, 0xF885, 0xF886, 0xF887, 0xF788},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        {0x0E31, 0x0E32, 0x0E33, 0x0E34, 0x0E35, 0x0E36, 0x0E37}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    if (vowel >= CH_MAI_HANAKAT && vowel <= CH_SARA_UEE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return leftAboveVowels[glyphSet][vowel - CH_MAI_HANAKAT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    if (vowel == CH_YAMAKKAN && glyphSet == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return 0x0E7E;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    return vowel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
LEUnicode ThaiShaping::lowerRightTone(LEUnicode tone, le_uint8 glyphSet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    static const LEUnicode lowerRightTones[][7] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        {0x0E68, 0x0E69, 0x0E6A, 0x0E6B, 0x0E6C, 0x0E6D, 0x0E6E},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        {0x0E47, 0xF70A, 0xF70B, 0xF70C, 0xF70D, 0xF70E, 0x0E4D},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        {0x0E47, 0xF88B, 0xF88E, 0xF891, 0xF894, 0xF897, 0x0E4D},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        {0x0E47, 0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    if (tone >= CH_MAITAIKHU && tone <= CH_NIKHAHIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        return lowerRightTones[glyphSet][tone - CH_MAITAIKHU];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    return tone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
LEUnicode ThaiShaping::lowerLeftTone(LEUnicode tone, le_uint8 glyphSet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    static const LEUnicode lowerLeftTones[][7] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        {0x0E76, 0x0E77, 0x0E78, 0x0E79, 0x0E7A, 0x0E7B, 0x0E7C},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        {0xF712, 0xF705, 0xF706, 0xF707, 0xF708, 0xF709, 0xF711},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        {0xF889, 0xF88C, 0xF88F, 0xF892, 0xF895, 0xF898, 0xF899},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        {0x0E47, 0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    if (tone >= CH_MAITAIKHU && tone <= CH_NIKHAHIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return lowerLeftTones[glyphSet][tone - CH_MAITAIKHU];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    return tone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
LEUnicode ThaiShaping::upperLeftTone(LEUnicode tone, le_uint8 glyphSet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    static const LEUnicode upperLeftTones[][7] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        {0x0E6F, 0x0E70, 0x0E71, 0x0E72, 0x0E73, 0x0E74, 0x0E75},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        {0xF712, 0xF713, 0xF714, 0xF715, 0xF716, 0xF717, 0xF711},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        {0xF889, 0xF88A, 0xF88D, 0xF890, 0xF893, 0xF896, 0xF899},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        {0x0E47, 0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    if (tone >= CH_MAITAIKHU && tone <= CH_NIKHAHIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return upperLeftTones[glyphSet][tone - CH_MAITAIKHU];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    return tone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
LEUnicode ThaiShaping::lowerBelowVowel(LEUnicode vowel, le_uint8 glyphSet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    static const LEUnicode lowerBelowVowels[][3] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        {0x0E3C, 0x0E3D, 0x0E3E},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        {0xF718, 0xF719, 0xF71A},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        {0x0E38, 0x0E39, 0x0E3A},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        {0x0E38, 0x0E39, 0x0E3A}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    if (vowel >= CH_SARA_U && vowel <= CH_PHINTHU) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return lowerBelowVowels[glyphSet][vowel - CH_SARA_U];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    return vowel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
LEUnicode ThaiShaping::noDescenderCOD(LEUnicode cod, le_uint8 glyphSet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    static const LEUnicode noDescenderCODs[][4] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        {0x0E60, 0x0E0E, 0x0E0F, 0x0E63},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        {0xF70F, 0x0E0E, 0x0E0F, 0xF700},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        {0x0E0D, 0x0E0E, 0x0E0F, 0x0E10},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        {0x0E0D, 0x0E0E, 0x0E0F, 0x0E10}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    if (cod >= CH_YO_YING && cod <= CH_THO_THAN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return noDescenderCODs[glyphSet][cod - CH_YO_YING];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    return cod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
le_uint8 ThaiShaping::doTransition (StateTransition transition, LEUnicode currChar, le_int32 inputIndex, le_uint8 glyphSet,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        LEUnicode errorChar, LEUnicode *outputBuffer, LEGlyphStorage &glyphStorage, le_int32 &outputIndex)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    LEErrorCode success = LE_NO_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    switch (transition.action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    case tA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        glyphStorage.setCharIndex(outputIndex, inputIndex, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        outputBuffer[outputIndex++] = currChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    case tC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        glyphStorage.setCharIndex(outputIndex, inputIndex, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        outputBuffer[outputIndex++] = currChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    case tD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        glyphStorage.setCharIndex(outputIndex, inputIndex, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        outputBuffer[outputIndex++] = leftAboveVowel(currChar, glyphSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    case tE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        glyphStorage.setCharIndex(outputIndex, inputIndex, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        outputBuffer[outputIndex++] = lowerRightTone(currChar, glyphSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    case tF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        glyphStorage.setCharIndex(outputIndex, inputIndex, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        outputBuffer[outputIndex++] = lowerLeftTone(currChar, glyphSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    case tG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        glyphStorage.setCharIndex(outputIndex, inputIndex, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        outputBuffer[outputIndex++] = upperLeftTone(currChar, glyphSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    case tH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        LEUnicode cod = outputBuffer[outputIndex - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        LEUnicode coa = noDescenderCOD(cod, glyphSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (cod != coa) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            outputBuffer[outputIndex - 1] = coa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            glyphStorage.setCharIndex(outputIndex, inputIndex, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            outputBuffer[outputIndex++] = currChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        glyphStorage.setCharIndex(outputIndex, inputIndex, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        outputBuffer[outputIndex++] = lowerBelowVowel(currChar, glyphSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    case tR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        glyphStorage.setCharIndex(outputIndex, inputIndex, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        outputBuffer[outputIndex++] = errorChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        glyphStorage.setCharIndex(outputIndex, inputIndex, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        outputBuffer[outputIndex++] = currChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    case tS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (currChar == CH_SARA_AM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            glyphStorage.setCharIndex(outputIndex, inputIndex, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            outputBuffer[outputIndex++] = errorChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        glyphStorage.setCharIndex(outputIndex, inputIndex, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        outputBuffer[outputIndex++] = currChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        // FIXME: if we get here, there's an error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        // in the state table!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        glyphStorage.setCharIndex(outputIndex, inputIndex, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        outputBuffer[outputIndex++] = currChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     return transition.nextState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
le_uint8 ThaiShaping::getNextState(LEUnicode ch, le_uint8 prevState, le_int32 inputIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    le_uint8 glyphSet, LEUnicode errorChar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    le_uint8 &charClass, LEUnicode *output, LEGlyphStorage &glyphStorage, le_int32 &outputIndex)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    StateTransition transition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    charClass = getCharClass(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    transition = getTransition(prevState, charClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    return doTransition(transition, ch, inputIndex, glyphSet, errorChar, output, glyphStorage, outputIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
le_bool ThaiShaping::isLegalHere(LEUnicode ch, le_uint8 prevState)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    le_uint8 charClass = getCharClass(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    StateTransition transition = getTransition(prevState, charClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    switch (transition.action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    case tA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    case tC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    case tD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    case tE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    case tF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    case tG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    case tH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    case tR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    case tS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        // FIXME: if we get here, there's an error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        // in the state table!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
le_int32 ThaiShaping::compose(const LEUnicode *input, le_int32 offset, le_int32 charCount, le_uint8 glyphSet,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                          LEUnicode errorChar, LEUnicode *output, LEGlyphStorage &glyphStorage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    le_uint8 state = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    le_int32 inputIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    le_int32 outputIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    le_uint8 conState = 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    le_int32 conInput = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    le_int32 conOutput = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    for (inputIndex = 0; inputIndex < charCount; inputIndex += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        LEUnicode ch = input[inputIndex + offset];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        le_uint8 charClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        // Decompose SARA AM into NIKHAHIT + SARA AA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (ch == CH_SARA_AM && isLegalHere(ch, state)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            outputIndex = conOutput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            state = getNextState(CH_NIKHAHIT, conState, inputIndex, glyphSet, errorChar, charClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                output, glyphStorage, outputIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            for (int j = conInput + 1; j < inputIndex; j += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                ch = input[j + offset];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                state = getNextState(ch, state, j, glyphSet, errorChar, charClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    output, glyphStorage, outputIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            ch = CH_SARA_AA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        state = getNextState(ch, state, inputIndex, glyphSet, errorChar, charClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            output, glyphStorage, outputIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (charClass >= CON && charClass <= COD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            conState = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            conInput = inputIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            conOutput = outputIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    return outputIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
}