1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
|
/*
* @(#)ThaiShaping.cpp 1.13 00/03/15
*
* (C) Copyright IBM Corp. 1998, 1999, 2000 - All Rights Reserved
*
*/
#include "LETypes.h"
#include "LEGlyphFilter.h"
#include "OpenTypeTables.h"
#include "ThaiShaping.h"
U_NAMESPACE_BEGIN
enum {
CH_SPACE = 0x0020,
CH_YAMAKKAN = 0x0E4E,
CH_MAI_HANAKAT = 0x0E31,
CH_SARA_AA = 0x0E32,
CH_SARA_AM = 0x0E33,
CH_SARA_UEE = 0x0E37,
CH_MAITAIKHU = 0x0E47,
CH_NIKHAHIT = 0x0E4D,
CH_SARA_U = 0x0E38,
CH_PHINTHU = 0x0E3A,
CH_YO_YING = 0x0E0D,
CH_THO_THAN = 0x0E10,
CH_DOTTED_CIRCLE = 0x25CC
};
le_uint8 ThaiShaping::getCharClass(LEUnicode ch)
{
le_uint8 charClass = NON;
if (ch >= 0x0E00 && ch <= 0x0E5B) {
charClass = classTable[ch - 0x0E00];
}
return charClass;
}
LEUnicode ThaiShaping::leftAboveVowel(LEUnicode vowel, le_uint8 glyphSet)
{
static LEUnicode leftAboveVowels[][7] = {
{0x0E61, 0x0E32, 0x0E33, 0x0E64, 0x0E65, 0x0E66, 0x0E67},
{0xF710, 0x0E32, 0x0E33, 0xF701, 0xF702, 0xF703, 0xF704},
{0xF884, 0x0E32, 0x0E33, 0xF885, 0xF886, 0xF887, 0xF788},
{0x0E31, 0x0E32, 0x0E33, 0x0E34, 0x0E35, 0x0E36, 0x0E37}
};
if (vowel >= CH_MAI_HANAKAT && vowel <= CH_SARA_UEE) {
return leftAboveVowels[glyphSet][vowel - CH_MAI_HANAKAT];
}
if (vowel == CH_YAMAKKAN && glyphSet == 0) {
return 0x0E7E;
}
return vowel;
}
LEUnicode ThaiShaping::lowerRightTone(LEUnicode tone, le_uint8 glyphSet)
{
static LEUnicode lowerRightTones[][7] = {
{0x0E68, 0x0E69, 0x0E6A, 0x0E6B, 0x0E6C, 0x0E6D, 0x0E6E},
{0x0E47, 0xF70A, 0xF70B, 0xF70C, 0xF70D, 0xF70E, 0x0E4D},
{0x0E47, 0xF88B, 0xF88E, 0xF891, 0xF894, 0xF897, 0x0E4D},
{0x0E47, 0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D}
};
if (tone >= CH_MAITAIKHU && tone <= CH_NIKHAHIT) {
return lowerRightTones[glyphSet][tone - CH_MAITAIKHU];
}
return tone;
}
LEUnicode ThaiShaping::lowerLeftTone(LEUnicode tone, le_uint8 glyphSet)
{
static LEUnicode lowerLeftTones[][7] = {
{0x0E76, 0x0E77, 0x0E78, 0x0E79, 0x0E7A, 0x0E7B, 0x0E7C},
{0xF712, 0xF705, 0xF706, 0xF707, 0xF708, 0xF709, 0xF711},
{0xF889, 0xF88C, 0xF88F, 0xF892, 0xF895, 0xF898, 0xF899},
{0x0E47, 0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D}
};
if (tone >= CH_MAITAIKHU && tone <= CH_NIKHAHIT) {
return lowerLeftTones[glyphSet][tone - CH_MAITAIKHU];
}
return tone;
}
LEUnicode ThaiShaping::upperLeftTone(LEUnicode tone, le_uint8 glyphSet)
{
static LEUnicode upperLeftTones[][7] = {
{0x0E6F, 0x0E70, 0x0E71, 0x0E72, 0x0E73, 0x0E74, 0x0E75},
{0xF712, 0xF713, 0xF714, 0xF715, 0xF716, 0xF717, 0xF711},
{0xF889, 0xF88A, 0xF88D, 0xF890, 0xF893, 0xF896, 0xF899},
{0x0E47, 0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D}
};
if (tone >= CH_MAITAIKHU && tone <= CH_NIKHAHIT) {
return upperLeftTones[glyphSet][tone - CH_MAITAIKHU];
}
return tone;
}
LEUnicode ThaiShaping::lowerBelowVowel(LEUnicode vowel, le_uint8 glyphSet)
{
static LEUnicode lowerBelowVowels[][3] = {
{0x0E3C, 0x0E3D, 0x0E3E},
{0xF718, 0xF719, 0xF71A},
{0x0E38, 0x0E39, 0x0E3A},
{0x0E38, 0x0E39, 0x0E3A}
};
if (vowel >= CH_SARA_U && vowel <= CH_PHINTHU) {
return lowerBelowVowels[glyphSet][vowel - CH_SARA_U];
}
return vowel;
}
LEUnicode ThaiShaping::noDescenderCOD(LEUnicode cod, le_uint8 glyphSet)
{
static LEUnicode noDescenderCODs[][4] = {
{0x0E60, 0x0E0E, 0x0E0F, 0x0E63},
{0xF70F, 0x0E0E, 0x0E0F, 0xF700},
{0x0E0D, 0x0E0E, 0x0E0F, 0x0E10},
{0x0E0D, 0x0E0E, 0x0E0F, 0x0E10}
};
if (cod >= CH_YO_YING && cod <= CH_THO_THAN) {
return noDescenderCODs[glyphSet][cod - CH_YO_YING];
}
return cod;
}
le_uint8 ThaiShaping::doTransition (StateTransition transition, LEUnicode currChar, le_int32 inputIndex, le_uint8 glyphSet,
LEUnicode errorChar, LEUnicode *outputBuffer, le_int32 *charIndicies, le_int32 &outputIndex)
{
switch (transition.action) {
case _A:
charIndicies[outputIndex] = inputIndex;
outputBuffer[outputIndex++] = currChar;
break;
case _C:
charIndicies[outputIndex] = inputIndex;
outputBuffer[outputIndex++] = currChar;
break;
case _D:
charIndicies[outputIndex] = inputIndex;
outputBuffer[outputIndex++] = leftAboveVowel(currChar, glyphSet);
break;
case _E:
charIndicies[outputIndex] = inputIndex;
outputBuffer[outputIndex++] = lowerRightTone(currChar, glyphSet);
break;
case _F:
charIndicies[outputIndex] = inputIndex;
outputBuffer[outputIndex++] = lowerLeftTone(currChar, glyphSet);
break;
case _G:
charIndicies[outputIndex] = inputIndex;
outputBuffer[outputIndex++] = upperLeftTone(currChar, glyphSet);
break;
case _H:
{
LEUnicode cod = outputBuffer[outputIndex - 1];
LEUnicode coa = noDescenderCOD(cod, glyphSet);
if (cod != coa) {
outputBuffer[outputIndex - 1] = coa;
charIndicies[outputIndex] = inputIndex;
outputBuffer[outputIndex++] = currChar;
break;
}
charIndicies[outputIndex] = inputIndex;
outputBuffer[outputIndex++] = lowerBelowVowel(currChar, glyphSet);
break;
}
case _R:
charIndicies[outputIndex] = inputIndex;
outputBuffer[outputIndex++] = errorChar;
charIndicies[outputIndex] = inputIndex;
outputBuffer[outputIndex++] = currChar;
break;
case _S:
if (currChar == CH_SARA_AM) {
charIndicies[outputIndex] = inputIndex;
outputBuffer[outputIndex++] = errorChar;
}
charIndicies[outputIndex] = inputIndex;
outputBuffer[outputIndex++] = currChar;
break;
default:
// FIXME: if we get here, there's an error
// in the state table!
charIndicies[outputIndex] = inputIndex;
outputBuffer[outputIndex++] = currChar;
break;
}
return transition.nextState;
}
le_uint8 ThaiShaping::getNextState(LEUnicode ch, le_uint8 prevState, le_int32 inputIndex, le_uint8 glyphSet, LEUnicode errorChar,
le_uint8 &charClass, LEUnicode *output, le_int32 *charIndicies, le_int32 &outputIndex)
{
StateTransition transition;
charClass = getCharClass(ch);
transition = getTransition(prevState, charClass);
return doTransition(transition, ch, inputIndex, glyphSet, errorChar, output, charIndicies, outputIndex);
}
le_bool ThaiShaping::isLegalHere(LEUnicode ch, le_uint8 prevState)
{
le_uint8 charClass = getCharClass(ch);
StateTransition transition = getTransition(prevState, charClass);
switch (transition.action) {
case _A:
case _C:
case _D:
case _E:
case _F:
case _G:
case _H:
return true;
case _R:
case _S:
return false;
default:
// FIXME: if we get here, there's an error
// in the state table!
return false;
}
}
le_int32 ThaiShaping::compose(const LEUnicode *input, le_int32 offset, le_int32 charCount, le_uint8 glyphSet,
LEUnicode errorChar, LEUnicode *output, le_int32 *charIndicies)
{
le_uint8 state = 0;
le_int32 inputIndex;
le_int32 outputIndex = 0;
le_uint8 conState = 0xFF;
le_int32 conInput = -1;
le_int32 conOutput = -1;
for (inputIndex = 0; inputIndex < charCount; inputIndex += 1) {
LEUnicode ch = input[inputIndex + offset];
le_uint8 charClass;
// Decompose SARA AM into NIKHAHIT + SARA AA
if (ch == CH_SARA_AM && isLegalHere(ch, state)) {
outputIndex = conOutput;
state = getNextState(CH_NIKHAHIT, conState, inputIndex, glyphSet, errorChar, charClass,
output, charIndicies, outputIndex);
for (int j = conInput + 1; j < inputIndex; j += 1) {
ch = input[j + offset];
state = getNextState(ch, state, j, glyphSet, errorChar, charClass,
output, charIndicies, outputIndex);
}
ch = CH_SARA_AA;
}
state = getNextState(ch, state, inputIndex, glyphSet, errorChar, charClass,
output, charIndicies, outputIndex);
if (charClass >= CON && charClass <= COD) {
conState = state;
conInput = inputIndex;
conOutput = outputIndex;
}
}
return outputIndex;
}
ThaiMarkFilter::ThaiMarkFilter(le_uint8 glyphSet)
: rangeList(NULL)
{
static MarkRange glyphSet0MarkRanges[] =
{
{0x0E31, 0x0E31}, {0x0E34, 0x0E3A}, {0x0E47, 0x0E4E}, {0x0E61, 0x0E61}, {0x0E64, 0x0E7C}, {0xFFFF, 0xFFFF}
};
static MarkRange glyphSet1MarkRanges[] =
{
{0x0E31, 0x0E31}, {0x0E34, 0x0E3A}, {0x0E47, 0x0E4E}, {0xF701, 0xF70E}, {0xF710, 0xF71A}, {0xFFFF, 0xFFFF}
};
static MarkRange glyphSet2MarkRanges[] =
{
{0x0E31, 0x0E31}, {0x0E34, 0x0E3A}, {0x0E47, 0x0E4E}, {0xF884, 0xF899}, {0xFFFF, 0xFFFF}
};
static MarkRange glyphSet3MarkRanges[] =
{
{0x0E31, 0x0E31}, {0x0E34, 0x0E3A}, {0x0E47, 0x0E4E}, {0xFFFF, 0xFFFF}
};
static MarkRange *rangeTable[] =
{glyphSet0MarkRanges, glyphSet1MarkRanges, glyphSet2MarkRanges, glyphSet3MarkRanges};
if (glyphSet <= 3) {
rangeList = rangeTable[glyphSet];
}
}
ThaiMarkFilter::~ThaiMarkFilter()
{
// nothing to do here...
}
le_bool ThaiMarkFilter::filter(LEGlyphID glyph)
{
le_int32 i;
if (rangeList != NULL) {
for (i = 0; rangeList[i].first <= glyph; i += 1) {
if (rangeList[i].last >= glyph) {
return true;
}
}
}
return false;
}
U_NAMESPACE_END
|