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