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-2005 - All Rights Reserved
|
|
29 |
*
|
|
30 |
* This file is a modification of the ICU file IndicReordering.cpp
|
|
31 |
* by Jens Herden and Javier Sola for Khmer language
|
|
32 |
*
|
|
33 |
*/
|
|
34 |
|
|
35 |
#include "LETypes.h"
|
|
36 |
#include "OpenTypeTables.h"
|
|
37 |
#include "KhmerReordering.h"
|
|
38 |
#include "LEGlyphStorage.h"
|
|
39 |
|
|
40 |
// Characters that get refered to by name...
|
|
41 |
enum
|
|
42 |
{
|
|
43 |
C_SIGN_ZWNJ = 0x200C,
|
|
44 |
C_SIGN_ZWJ = 0x200D,
|
|
45 |
C_DOTTED_CIRCLE = 0x25CC,
|
|
46 |
C_RO = 0x179A,
|
|
47 |
C_VOWEL_AA = 0x17B6,
|
|
48 |
C_SIGN_NIKAHIT = 0x17C6,
|
|
49 |
C_VOWEL_E = 0x17C1,
|
|
50 |
C_COENG = 0x17D2
|
|
51 |
};
|
|
52 |
|
|
53 |
|
|
54 |
enum
|
|
55 |
{
|
|
56 |
// simple classes, they are used in the statetable (in this file)
|
|
57 |
// to control the length of a syllable they are also used to know
|
|
58 |
// where a character should be placed (location in reference to
|
|
59 |
// the base character) and also to know if a character, when
|
|
60 |
// independtly displayed, should be displayed with a dotted-circle
|
|
61 |
// to indicate error in syllable construction
|
|
62 |
|
|
63 |
_xx = KhmerClassTable::CC_RESERVED,
|
|
64 |
_sa = KhmerClassTable::CC_SIGN_ABOVE | KhmerClassTable::CF_DOTTED_CIRCLE
|
|
65 |
| KhmerClassTable::CF_POS_ABOVE,
|
|
66 |
_sp = KhmerClassTable::CC_SIGN_AFTER | KhmerClassTable::CF_DOTTED_CIRCLE
|
|
67 |
| KhmerClassTable::CF_POS_AFTER,
|
|
68 |
_c1 = KhmerClassTable::CC_CONSONANT | KhmerClassTable::CF_CONSONANT,
|
|
69 |
_c2 = KhmerClassTable::CC_CONSONANT2 | KhmerClassTable::CF_CONSONANT,
|
|
70 |
_c3 = KhmerClassTable::CC_CONSONANT3 | KhmerClassTable::CF_CONSONANT,
|
|
71 |
_rb = KhmerClassTable::CC_ROBAT | KhmerClassTable::CF_POS_ABOVE
|
|
72 |
| KhmerClassTable::CF_DOTTED_CIRCLE,
|
|
73 |
_cs = KhmerClassTable::CC_CONSONANT_SHIFTER | KhmerClassTable::CF_DOTTED_CIRCLE
|
|
74 |
| KhmerClassTable::CF_SHIFTER,
|
|
75 |
_dl = KhmerClassTable::CC_DEPENDENT_VOWEL | KhmerClassTable::CF_POS_BEFORE
|
|
76 |
| KhmerClassTable::CF_DOTTED_CIRCLE,
|
|
77 |
_db = KhmerClassTable::CC_DEPENDENT_VOWEL | KhmerClassTable::CF_POS_BELOW
|
|
78 |
| KhmerClassTable::CF_DOTTED_CIRCLE,
|
|
79 |
_da = KhmerClassTable::CC_DEPENDENT_VOWEL | KhmerClassTable::CF_POS_ABOVE
|
|
80 |
| KhmerClassTable::CF_DOTTED_CIRCLE | KhmerClassTable::CF_ABOVE_VOWEL,
|
|
81 |
_dr = KhmerClassTable::CC_DEPENDENT_VOWEL | KhmerClassTable::CF_POS_AFTER
|
|
82 |
| KhmerClassTable::CF_DOTTED_CIRCLE,
|
|
83 |
_co = KhmerClassTable::CC_COENG | KhmerClassTable::CF_COENG
|
|
84 |
| KhmerClassTable::CF_DOTTED_CIRCLE,
|
|
85 |
|
|
86 |
// split vowel
|
|
87 |
_va = _da | KhmerClassTable::CF_SPLIT_VOWEL,
|
|
88 |
_vr = _dr | KhmerClassTable::CF_SPLIT_VOWEL
|
|
89 |
};
|
|
90 |
|
|
91 |
|
|
92 |
// Character class tables
|
|
93 |
|
|
94 |
// _xx character does not combine into syllable, such as numbers,
|
|
95 |
// puntuation marks, non-Khmer signs...
|
|
96 |
// _sa Sign placed above the base
|
|
97 |
// _sp Sign placed after the base
|
|
98 |
// _c1 Consonant of type 1 or independent vowel (independent vowels
|
|
99 |
// behave as type 1 consonants)
|
|
100 |
// _c2 Consonant of type 2 (only RO)
|
|
101 |
// _c3 Consonant of type 3
|
|
102 |
// _rb Khmer sign robat u17CC. combining mark for subscript consonants
|
|
103 |
// _cd Consonant-shifter
|
|
104 |
// _dl Dependent vowel placed before the base (left of the base)
|
|
105 |
// _db Dependent vowel placed below the base
|
|
106 |
// _da Dependent vowel placed above the base
|
|
107 |
// _dr Dependent vowel placed behind the base (right of the base)
|
|
108 |
// _co Khmer combining mark COENG u17D2, combines with the consonant
|
|
109 |
// or independent vowel following it to create a subscript consonant
|
|
110 |
// or independent vowel
|
|
111 |
// _va Khmer split vowel in wich the first part is before the base and
|
|
112 |
// the second one above the base
|
|
113 |
// _vr Khmer split vowel in wich the first part is before the base and
|
|
114 |
// the second one behind (right of) the base
|
|
115 |
|
|
116 |
static const KhmerClassTable::CharClass khmerCharClasses[] =
|
|
117 |
{
|
|
118 |
_c1, _c1, _c1, _c3, _c1, _c1, _c1, _c1, _c3, _c1, _c1, _c1, _c1, _c3, _c1, _c1, // 1780 - 178F
|
|
119 |
_c1, _c1, _c1, _c1, _c3, _c1, _c1, _c1, _c1, _c3, _c2, _c1, _c1, _c1, _c3, _c3, // 1790 - 179F
|
|
120 |
_c1, _c3, _c1, _c1, _c1, _c1, _c1, _c1, _c1, _c1, _c1, _c1, _c1, _c1, _c1, _c1, // 17A0 - 17AF
|
|
121 |
_c1, _c1, _c1, _c1, _dr, _dr, _dr, _da, _da, _da, _da, _db, _db, _db, _va, _vr, // 17B0 - 17BF
|
|
122 |
_vr, _dl, _dl, _dl, _vr, _vr, _sa, _sp, _sp, _cs, _cs, _sa, _rb, _sa, _sa, _sa, // 17C0 - 17CF
|
|
123 |
_sa, _sa, _co, _sa, _xx, _xx, _xx, _xx, _xx, _xx, _xx, _xx, _xx, _sa, _xx, _xx, // 17D0 - 17DF
|
|
124 |
};
|
|
125 |
|
|
126 |
|
|
127 |
//
|
|
128 |
// Khmer Class Tables
|
|
129 |
//
|
|
130 |
|
|
131 |
//
|
|
132 |
// The range of characters defined in the above table is defined
|
|
133 |
// here. FOr Khmer 1780 to 17DF Even if the Khmer range is bigger, all
|
|
134 |
// other characters are not combinable, and therefore treated as _xx
|
|
135 |
static const KhmerClassTable khmerClassTable = {0x1780, 0x17df, khmerCharClasses};
|
|
136 |
|
|
137 |
|
|
138 |
// Below we define how a character in the input string is either in
|
|
139 |
// the khmerCharClasses table (in which case we get its type back), a
|
|
140 |
// ZWJ or ZWNJ (two characters that may appear within the syllable,
|
|
141 |
// but are not in the table) we also get their type back, or an
|
|
142 |
// unknown object in which case we get _xx (CC_RESERVED) back
|
|
143 |
KhmerClassTable::CharClass KhmerClassTable::getCharClass(LEUnicode ch) const
|
|
144 |
{
|
|
145 |
if (ch == C_SIGN_ZWJ) {
|
|
146 |
return CC_ZERO_WIDTH_J_MARK;
|
|
147 |
}
|
|
148 |
|
|
149 |
if (ch == C_SIGN_ZWNJ) {
|
|
150 |
return CC_ZERO_WIDTH_NJ_MARK;
|
|
151 |
}
|
|
152 |
|
|
153 |
if (ch < firstChar || ch > lastChar) {
|
|
154 |
return CC_RESERVED;
|
|
155 |
}
|
|
156 |
|
|
157 |
return classTable[ch - firstChar];
|
|
158 |
}
|
|
159 |
|
|
160 |
const KhmerClassTable *KhmerClassTable::getKhmerClassTable()
|
|
161 |
{
|
|
162 |
return &khmerClassTable;
|
|
163 |
}
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
class ReorderingOutput {
|
|
168 |
private:
|
|
169 |
le_int32 fOutIndex;
|
|
170 |
LEUnicode *fOutChars;
|
|
171 |
|
|
172 |
LEGlyphStorage &fGlyphStorage;
|
|
173 |
|
|
174 |
public:
|
|
175 |
ReorderingOutput(LEUnicode *outChars, LEGlyphStorage &glyphStorage)
|
|
176 |
: fOutIndex(0), fOutChars(outChars), fGlyphStorage(glyphStorage)
|
|
177 |
{
|
|
178 |
// nothing else to do...
|
|
179 |
}
|
|
180 |
|
|
181 |
~ReorderingOutput()
|
|
182 |
{
|
|
183 |
// nothing to do here...
|
|
184 |
}
|
|
185 |
|
|
186 |
void writeChar(LEUnicode ch, le_uint32 charIndex, FeatureMask charFeatures)
|
|
187 |
{
|
|
188 |
LEErrorCode success = LE_NO_ERROR;
|
|
189 |
|
|
190 |
fOutChars[fOutIndex] = ch;
|
|
191 |
|
|
192 |
fGlyphStorage.setCharIndex(fOutIndex, charIndex, success);
|
|
193 |
fGlyphStorage.setAuxData(fOutIndex, charFeatures, success);
|
|
194 |
|
|
195 |
fOutIndex += 1;
|
|
196 |
}
|
|
197 |
|
|
198 |
le_int32 getOutputIndex()
|
|
199 |
{
|
|
200 |
return fOutIndex;
|
|
201 |
}
|
|
202 |
};
|
|
203 |
|
|
204 |
|
|
205 |
#define blwfFeatureTag LE_BLWF_FEATURE_TAG
|
|
206 |
#define pstfFeatureTag LE_PSTF_FEATURE_TAG
|
|
207 |
#define presFeatureTag LE_PRES_FEATURE_TAG
|
|
208 |
#define blwsFeatureTag LE_BLWS_FEATURE_TAG
|
|
209 |
#define abvsFeatureTag LE_ABVS_FEATURE_TAG
|
|
210 |
#define pstsFeatureTag LE_PSTS_FEATURE_TAG
|
|
211 |
|
|
212 |
#define blwmFeatureTag LE_BLWM_FEATURE_TAG
|
|
213 |
#define abvmFeatureTag LE_ABVM_FEATURE_TAG
|
|
214 |
#define distFeatureTag LE_DIST_FEATURE_TAG
|
|
215 |
|
|
216 |
#define prefFeatureTag LE_PREF_FEATURE_TAG
|
|
217 |
#define abvfFeatureTag LE_ABVF_FEATURE_TAG
|
|
218 |
#define cligFeatureTag LE_CLIG_FEATURE_TAG
|
|
219 |
#define mkmkFeatureTag LE_MKMK_FEATURE_TAG
|
|
220 |
|
|
221 |
#define prefFeatureMask 0x80000000UL
|
|
222 |
#define blwfFeatureMask 0x40000000UL
|
|
223 |
#define abvfFeatureMask 0x20000000UL
|
|
224 |
#define pstfFeatureMask 0x10000000UL
|
|
225 |
#define presFeatureMask 0x08000000UL
|
|
226 |
#define blwsFeatureMask 0x04000000UL
|
|
227 |
#define abvsFeatureMask 0x02000000UL
|
|
228 |
#define pstsFeatureMask 0x01000000UL
|
|
229 |
#define cligFeatureMask 0x00800000UL
|
|
230 |
#define distFeatureMask 0x00400000UL
|
|
231 |
#define blwmFeatureMask 0x00200000UL
|
|
232 |
#define abvmFeatureMask 0x00100000UL
|
|
233 |
#define mkmkFeatureMask 0x00080000UL
|
|
234 |
|
|
235 |
#define tagPref (prefFeatureMask | presFeatureMask | \
|
|
236 |
cligFeatureMask | distFeatureMask)
|
|
237 |
#define tagAbvf (abvfFeatureMask | abvsFeatureMask | \
|
|
238 |
cligFeatureMask | distFeatureMask | abvmFeatureMask | mkmkFeatureMask)
|
|
239 |
#define tagPstf (blwfFeatureMask | blwsFeatureMask | prefFeatureMask | \
|
|
240 |
presFeatureMask | pstfFeatureMask | pstsFeatureMask | cligFeatureMask | \
|
|
241 |
distFeatureMask | blwmFeatureMask)
|
|
242 |
#define tagBlwf (blwfFeatureMask | blwsFeatureMask | cligFeatureMask | \
|
|
243 |
distFeatureMask | blwmFeatureMask | mkmkFeatureMask)
|
|
244 |
#define tagDefault (prefFeatureMask | blwfFeatureMask | presFeatureMask | \
|
|
245 |
blwsFeatureMask | cligFeatureMask | distFeatureMask | abvmFeatureMask | \
|
|
246 |
blwmFeatureMask | mkmkFeatureMask)
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
// These are in the order in which the features need to be applied
|
|
251 |
// for correct processing
|
|
252 |
static const FeatureMap featureMap[] =
|
|
253 |
{
|
|
254 |
// Shaping features
|
|
255 |
{prefFeatureTag, prefFeatureMask},
|
|
256 |
{blwfFeatureTag, blwfFeatureMask},
|
|
257 |
{abvfFeatureTag, abvfFeatureMask},
|
|
258 |
{pstfFeatureTag, pstfFeatureMask},
|
|
259 |
{presFeatureTag, presFeatureMask},
|
|
260 |
{blwsFeatureTag, blwsFeatureMask},
|
|
261 |
{abvsFeatureTag, abvsFeatureMask},
|
|
262 |
{pstsFeatureTag, pstsFeatureMask},
|
|
263 |
{cligFeatureTag, cligFeatureMask},
|
|
264 |
|
|
265 |
// Positioning features
|
|
266 |
{distFeatureTag, distFeatureMask},
|
|
267 |
{blwmFeatureTag, blwmFeatureMask},
|
|
268 |
{abvmFeatureTag, abvmFeatureMask},
|
|
269 |
{mkmkFeatureTag, mkmkFeatureMask},
|
|
270 |
};
|
|
271 |
|
|
272 |
static const le_int32 featureMapCount = LE_ARRAY_SIZE(featureMap);
|
|
273 |
|
|
274 |
// The stateTable is used to calculate the end (the length) of a well
|
|
275 |
// formed Khmer Syllable.
|
|
276 |
//
|
|
277 |
// Each horizontal line is ordered exactly the same way as the values
|
|
278 |
// in KhmerClassTable CharClassValues in KhmerReordering.h This
|
|
279 |
// coincidence of values allows the follow up of the table.
|
|
280 |
//
|
|
281 |
// Each line corresponds to a state, which does not necessarily need
|
|
282 |
// to be a type of component... for example, state 2 is a base, with
|
|
283 |
// is always a first character in the syllable, but the state could be
|
|
284 |
// produced a consonant of any type when it is the first character
|
|
285 |
// that is analysed (in ground state).
|
|
286 |
//
|
|
287 |
// Differentiating 3 types of consonants is necessary in order to
|
|
288 |
// forbid the use of certain combinations, such as having a second
|
|
289 |
// coeng after a coeng RO.
|
|
290 |
// The inexistent possibility of having a type 3 after another type 3
|
|
291 |
// is permitted, eliminating it would very much complicate the table,
|
|
292 |
// and it does not create typing problems, as the case above.
|
|
293 |
//
|
|
294 |
// The table is quite complex, in order to limit the number of coeng
|
|
295 |
// consonants to 2 (by means of the table).
|
|
296 |
//
|
|
297 |
// There a peculiarity, as far as Unicode is concerned:
|
|
298 |
// - The consonant-shifter is considered in two possible different
|
|
299 |
// locations, the one considered in Unicode 3.0 and the one considered
|
|
300 |
// in Unicode 4.0. (there is a backwards compatibility problem in this
|
|
301 |
// standard).
|
|
302 |
|
|
303 |
|
|
304 |
// xx independent character, such as a number, punctuation sign or
|
|
305 |
// non-khmer char
|
|
306 |
//
|
|
307 |
// c1 Khmer consonant of type 1 or an independent vowel
|
|
308 |
// that is, a letter in which the subscript for is only under the
|
|
309 |
// base, not taking any space to the right or to the left
|
|
310 |
//
|
|
311 |
// c2 Khmer consonant of type 2, the coeng form takes space under
|
|
312 |
// and to the left of the base (only RO is of this type)
|
|
313 |
//
|
|
314 |
// c3 Khmer consonant of type 3. Its subscript form takes space under
|
|
315 |
// and to the right of the base.
|
|
316 |
//
|
|
317 |
// cs Khmer consonant shifter
|
|
318 |
//
|
|
319 |
// rb Khmer robat
|
|
320 |
//
|
|
321 |
// co coeng character (u17D2)
|
|
322 |
//
|
|
323 |
// dv dependent vowel (including split vowels, they are treated in the
|
|
324 |
// same way). even if dv is not defined above, the component that is
|
|
325 |
// really tested for is KhmerClassTable::CC_DEPENDENT_VOWEL, which is
|
|
326 |
// common to all dependent vowels
|
|
327 |
//
|
|
328 |
// zwj Zero Width joiner
|
|
329 |
//
|
|
330 |
// zwnj Zero width non joiner
|
|
331 |
//
|
|
332 |
// sa above sign
|
|
333 |
//
|
|
334 |
// sp post sign
|
|
335 |
//
|
|
336 |
// there are lines with equal content but for an easier understanding
|
|
337 |
// (and maybe change in the future) we did not join them
|
|
338 |
//
|
|
339 |
static const le_int8 khmerStateTable[][KhmerClassTable::CC_COUNT] =
|
|
340 |
{
|
|
341 |
|
|
342 |
// xx c1 c2 c3 zwnj cs rb co dv sa sp zwj
|
|
343 |
{ 1, 2, 2, 2, 1, 1, 1, 6, 1, 1, 1, 2}, // 0 - ground state
|
|
344 |
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // 1 - exit state (or sign to the right of the syllable)
|
|
345 |
{-1, -1, -1, -1, 3, 4, 5, 6, 16, 17, 1, -1}, // 2 - Base consonant
|
|
346 |
{-1, -1, -1, -1, -1, 4, -1, -1, 16, -1, -1, -1}, // 3 - First ZWNJ before a register shifter
|
|
347 |
// It can only be followed by a shifter or a vowel
|
|
348 |
{-1, -1, -1, -1, 15, -1, -1, 6, 16, 17, 1, 14}, // 4 - First register shifter
|
|
349 |
{-1, -1, -1, -1, -1, -1, -1, -1, 20, -1, 1, -1}, // 5 - Robat
|
|
350 |
{-1, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1}, // 6 - First Coeng
|
|
351 |
{-1, -1, -1, -1, 12, 13, -1, 10, 16, 17, 1, 14}, // 7 - First consonant of type 1 after coeng
|
|
352 |
{-1, -1, -1, -1, 12, 13, -1, -1, 16, 17, 1, 14}, // 8 - First consonant of type 2 after coeng
|
|
353 |
{-1, -1, -1, -1, 12, 13, -1, 10, 16, 17, 1, 14}, // 9 - First consonant or type 3 after ceong
|
|
354 |
{-1, 11, 11, 11, -1, -1, -1, -1, -1, -1, -1, -1}, // 10 - Second Coeng (no register shifter before)
|
|
355 |
{-1, -1, -1, -1, 15, -1, -1, -1, 16, 17, 1, 14}, // 11 - Second coeng consonant
|
|
356 |
// (or ind. vowel) no register shifter before
|
|
357 |
{-1, -1, 1, -1, -1, 13, -1, -1, 16, -1, -1, -1}, // 12 - Second ZWNJ before a register shifter
|
|
358 |
{-1, -1, -1, -1, 15, -1, -1, -1, 16, 17, 1, 14}, // 13 - Second register shifter
|
|
359 |
{-1, -1, -1, -1, -1, -1, -1, -1, 16, -1, -1, -1}, // 14 - ZWJ before vowel
|
|
360 |
{-1, -1, -1, -1, -1, -1, -1, -1, 16, -1, -1, -1}, // 15 - ZWNJ before vowel
|
|
361 |
{-1, -1, -1, -1, -1, -1, -1, -1, -1, 17, 1, 18}, // 16 - dependent vowel
|
|
362 |
{-1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, 18}, // 17 - sign above
|
|
363 |
{-1, -1, -1, -1, -1, -1, -1, 19, -1, -1, -1, -1}, // 18 - ZWJ after vowel
|
|
364 |
{-1, 1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1}, // 19 - Third coeng
|
|
365 |
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1}, // 20 - dependent vowel after a Robat
|
|
366 |
};
|
|
367 |
|
|
368 |
|
|
369 |
const FeatureMap *KhmerReordering::getFeatureMap(le_int32 &count)
|
|
370 |
{
|
|
371 |
count = featureMapCount;
|
|
372 |
|
|
373 |
return featureMap;
|
|
374 |
}
|
|
375 |
|
|
376 |
|
|
377 |
// Given an input string of characters and a location in which to start looking
|
|
378 |
// calculate, using the state table, which one is the last character of the syllable
|
|
379 |
// that starts in the starting position.
|
|
380 |
le_int32 KhmerReordering::findSyllable(const KhmerClassTable *classTable,
|
|
381 |
const LEUnicode *chars, le_int32 prev, le_int32 charCount)
|
|
382 |
{
|
|
383 |
le_int32 cursor = prev;
|
|
384 |
le_int8 state = 0;
|
|
385 |
|
|
386 |
while (cursor < charCount) {
|
|
387 |
KhmerClassTable::CharClass charClass = (classTable->getCharClass(chars[cursor])
|
|
388 |
& KhmerClassTable::CF_CLASS_MASK);
|
|
389 |
|
|
390 |
state = khmerStateTable[state][charClass];
|
|
391 |
|
|
392 |
if (state < 0) {
|
|
393 |
break;
|
|
394 |
}
|
|
395 |
|
|
396 |
cursor += 1;
|
|
397 |
}
|
|
398 |
|
|
399 |
return cursor;
|
|
400 |
}
|
|
401 |
|
|
402 |
|
|
403 |
// This is the real reordering function as applied to the Khmer language
|
|
404 |
|
|
405 |
le_int32 KhmerReordering::reorder(const LEUnicode *chars, le_int32 charCount,
|
|
406 |
le_int32 /*scriptCode*/, LEUnicode *outChars, LEGlyphStorage &glyphStorage)
|
|
407 |
{
|
|
408 |
const KhmerClassTable *classTable = KhmerClassTable::getKhmerClassTable();
|
|
409 |
|
|
410 |
ReorderingOutput output(outChars, glyphStorage);
|
|
411 |
KhmerClassTable::CharClass charClass;
|
|
412 |
le_int32 i, prev = 0, coengRo;
|
|
413 |
|
|
414 |
|
|
415 |
// This loop only exits when we reach the end of a run, which may contain
|
|
416 |
// several syllables.
|
|
417 |
while (prev < charCount) {
|
|
418 |
le_int32 syllable = findSyllable(classTable, chars, prev, charCount);
|
|
419 |
|
|
420 |
// write a pre vowel or the pre part of a split vowel first
|
|
421 |
// and look out for coeng + ro. RO is the only vowel of type 2, and
|
|
422 |
// therefore the only one that requires saving space before the base.
|
|
423 |
coengRo = -1; // There is no Coeng Ro, if found this value will change
|
|
424 |
for (i = prev; i < syllable; i += 1) {
|
|
425 |
charClass = classTable->getCharClass(chars[i]);
|
|
426 |
|
|
427 |
// if a split vowel, write the pre part. In Khmer the pre part
|
|
428 |
// is the same for all split vowels, same glyph as pre vowel C_VOWEL_E
|
|
429 |
if (charClass & KhmerClassTable::CF_SPLIT_VOWEL) {
|
|
430 |
output.writeChar(C_VOWEL_E, i, tagPref);
|
|
431 |
break; // there can be only one vowel
|
|
432 |
}
|
|
433 |
|
|
434 |
// if a vowel with pos before write it out
|
|
435 |
if (charClass & KhmerClassTable::CF_POS_BEFORE) {
|
|
436 |
output.writeChar(chars[i], i, tagPref);
|
|
437 |
break; // there can be only one vowel
|
|
438 |
}
|
|
439 |
|
|
440 |
// look for coeng + ro and remember position
|
|
441 |
// works because coeng + ro is always in front of a vowel (if there is a vowel)
|
|
442 |
// and because CC_CONSONANT2 is enough to identify it, as it is the only consonant
|
|
443 |
// with this flag
|
|
444 |
if ( (charClass & KhmerClassTable::CF_COENG) && (i + 1 < syllable) &&
|
|
445 |
( (classTable->getCharClass(chars[i + 1]) &
|
|
446 |
KhmerClassTable::CF_CLASS_MASK) == KhmerClassTable::CC_CONSONANT2) )
|
|
447 |
{
|
|
448 |
coengRo = i;
|
|
449 |
}
|
|
450 |
}
|
|
451 |
|
|
452 |
// write coeng + ro if found
|
|
453 |
if (coengRo > -1) {
|
|
454 |
output.writeChar(C_COENG, coengRo, tagPref);
|
|
455 |
output.writeChar(C_RO, coengRo + 1, tagPref);
|
|
456 |
}
|
|
457 |
|
|
458 |
// shall we add a dotted circle? If in the position in which
|
|
459 |
// the base should be (first char in the string) there is a
|
|
460 |
// character that has the Dotted circle flag (a character that
|
|
461 |
// cannot be a base) then write a dotted circle
|
|
462 |
if (classTable->getCharClass(chars[prev]) & KhmerClassTable::CF_DOTTED_CIRCLE) {
|
|
463 |
output.writeChar(C_DOTTED_CIRCLE, prev, tagDefault);
|
|
464 |
}
|
|
465 |
|
|
466 |
// copy what is left to the output, skipping before vowels and
|
|
467 |
// coeng Ro if they are present
|
|
468 |
for (i = prev; i < syllable; i += 1) {
|
|
469 |
charClass = classTable->getCharClass(chars[i]);
|
|
470 |
|
|
471 |
// skip a before vowel, it was already processed
|
|
472 |
if (charClass & KhmerClassTable::CF_POS_BEFORE) {
|
|
473 |
continue;
|
|
474 |
}
|
|
475 |
|
|
476 |
// skip coeng + ro, it was already processed
|
|
477 |
if (i == coengRo) {
|
|
478 |
i += 1;
|
|
479 |
continue;
|
|
480 |
}
|
|
481 |
|
|
482 |
switch (charClass & KhmerClassTable::CF_POS_MASK) {
|
|
483 |
case KhmerClassTable::CF_POS_ABOVE :
|
|
484 |
output.writeChar(chars[i], i, tagAbvf);
|
|
485 |
break;
|
|
486 |
|
|
487 |
case KhmerClassTable::CF_POS_AFTER :
|
|
488 |
output.writeChar(chars[i], i, tagPstf);
|
|
489 |
break;
|
|
490 |
|
|
491 |
case KhmerClassTable::CF_POS_BELOW :
|
|
492 |
output.writeChar(chars[i], i, tagBlwf);
|
|
493 |
break;
|
|
494 |
|
|
495 |
default:
|
|
496 |
// assign the correct flags to a coeng consonant
|
|
497 |
// Consonants of type 3 are taged as Post forms and those type 1 as below forms
|
|
498 |
if ( (charClass & KhmerClassTable::CF_COENG) && i + 1 < syllable ) {
|
|
499 |
if ( (classTable->getCharClass(chars[i + 1]) & KhmerClassTable::CF_CLASS_MASK)
|
|
500 |
== KhmerClassTable::CC_CONSONANT3) {
|
|
501 |
output.writeChar(chars[i], i, tagPstf);
|
|
502 |
i += 1;
|
|
503 |
output.writeChar(chars[i], i, tagPstf);
|
|
504 |
}
|
|
505 |
else {
|
|
506 |
output.writeChar(chars[i], i, tagBlwf);
|
|
507 |
i += 1;
|
|
508 |
output.writeChar(chars[i], i, tagBlwf);
|
|
509 |
}
|
|
510 |
break;
|
|
511 |
}
|
|
512 |
// if a shifter is followed by an above vowel change the shifter to below form,
|
|
513 |
// an above vowel can have two possible positions i + 1 or i + 3
|
|
514 |
// (position i+1 corresponds to unicode 3, position i+3 to Unicode 4)
|
|
515 |
// and there is an extra rule for C_VOWEL_AA + C_SIGN_NIKAHIT also for two
|
|
516 |
// different positions, right after the shifter or after a vowel (Unicode 4)
|
|
517 |
if ( (charClass & KhmerClassTable::CF_SHIFTER) && (i + 1 < syllable) ) {
|
|
518 |
if (classTable->getCharClass(chars[i + 1]) & KhmerClassTable::CF_ABOVE_VOWEL ) {
|
|
519 |
output.writeChar(chars[i], i, tagBlwf);
|
|
520 |
break;
|
|
521 |
}
|
|
522 |
if (i + 2 < syllable &&
|
|
523 |
( (classTable->getCharClass(chars[i + 1]) &
|
|
524 |
KhmerClassTable::CF_CLASS_MASK) == C_VOWEL_AA) &&
|
|
525 |
( (classTable->getCharClass(chars[i + 2]) &
|
|
526 |
KhmerClassTable::CF_CLASS_MASK) == C_SIGN_NIKAHIT) )
|
|
527 |
{
|
|
528 |
output.writeChar(chars[i], i, tagBlwf);
|
|
529 |
break;
|
|
530 |
}
|
|
531 |
if (i + 3 < syllable && (classTable->getCharClass(chars[i + 3]) &
|
|
532 |
KhmerClassTable::CF_ABOVE_VOWEL) )
|
|
533 |
{
|
|
534 |
output.writeChar(chars[i], i, tagBlwf);
|
|
535 |
break;
|
|
536 |
}
|
|
537 |
if (i + 4 < syllable &&
|
|
538 |
( (classTable->getCharClass(chars[i + 3]) &
|
|
539 |
KhmerClassTable::CF_CLASS_MASK) == C_VOWEL_AA) &&
|
|
540 |
( (classTable->getCharClass(chars[i + 4]) &
|
|
541 |
KhmerClassTable::CF_CLASS_MASK) == C_SIGN_NIKAHIT) )
|
|
542 |
{
|
|
543 |
output.writeChar(chars[i], i, tagBlwf);
|
|
544 |
break;
|
|
545 |
}
|
|
546 |
|
|
547 |
}
|
|
548 |
// default - any other characters
|
|
549 |
output.writeChar(chars[i], i, tagDefault);
|
|
550 |
break;
|
|
551 |
} // switch
|
|
552 |
} // for
|
|
553 |
|
|
554 |
prev = syllable; // move the pointer to the start of next syllable
|
|
555 |
}
|
|
556 |
|
|
557 |
return output.getOutputIndex();
|
|
558 |
}
|