16889
|
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. and others 1998-2013 - All Rights Reserved
|
|
29 |
*
|
|
30 |
*/
|
|
31 |
|
|
32 |
#include "LETypes.h"
|
|
33 |
#include "MorphTables.h"
|
|
34 |
#include "StateTables.h"
|
|
35 |
#include "MorphStateTables.h"
|
|
36 |
#include "SubtableProcessor2.h"
|
|
37 |
#include "StateTableProcessor2.h"
|
|
38 |
#include "IndicRearrangementProcessor2.h"
|
|
39 |
#include "LEGlyphStorage.h"
|
|
40 |
#include "LESwaps.h"
|
|
41 |
|
|
42 |
U_NAMESPACE_BEGIN
|
|
43 |
|
|
44 |
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IndicRearrangementProcessor2)
|
|
45 |
|
16891
|
46 |
IndicRearrangementProcessor2::IndicRearrangementProcessor2(
|
|
47 |
const LEReferenceTo<MorphSubtableHeader2> &morphSubtableHeader, LEErrorCode &success)
|
|
48 |
: StateTableProcessor2(morphSubtableHeader, success), indicRearrangementSubtableHeader(morphSubtableHeader, success),
|
|
49 |
entryTable(stHeader, success, entryTableOffset, LE_UNBOUNDED_ARRAY)
|
16889
|
50 |
{
|
|
51 |
}
|
|
52 |
|
|
53 |
IndicRearrangementProcessor2::~IndicRearrangementProcessor2()
|
|
54 |
{
|
|
55 |
}
|
|
56 |
|
|
57 |
void IndicRearrangementProcessor2::beginStateTable()
|
|
58 |
{
|
|
59 |
firstGlyph = 0;
|
|
60 |
lastGlyph = 0;
|
|
61 |
}
|
|
62 |
|
16891
|
63 |
le_uint16 IndicRearrangementProcessor2::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph,
|
|
64 |
EntryTableIndex2 index, LEErrorCode &success)
|
16889
|
65 |
{
|
16891
|
66 |
const IndicRearrangementStateEntry2 *entry = entryTable.getAlias(index, success);
|
|
67 |
if (LE_FAILURE(success)) return 0; // TODO - what to return in bad state?
|
16889
|
68 |
le_uint16 newState = SWAPW(entry->newStateIndex); // index to the new state
|
|
69 |
IndicRearrangementFlags flags = (IndicRearrangementFlags) SWAPW(entry->flags);
|
|
70 |
|
|
71 |
if (flags & irfMarkFirst) {
|
|
72 |
firstGlyph = currGlyph;
|
|
73 |
}
|
|
74 |
|
|
75 |
if (flags & irfMarkLast) {
|
|
76 |
lastGlyph = currGlyph;
|
|
77 |
}
|
|
78 |
|
|
79 |
doRearrangementAction(glyphStorage, (IndicRearrangementVerb) (flags & irfVerbMask));
|
|
80 |
|
|
81 |
if (!(flags & irfDontAdvance)) {
|
|
82 |
currGlyph += dir;
|
|
83 |
}
|
|
84 |
|
|
85 |
return newState; // index to new state
|
|
86 |
}
|
|
87 |
|
|
88 |
void IndicRearrangementProcessor2::endStateTable()
|
|
89 |
{
|
|
90 |
}
|
|
91 |
|
|
92 |
void IndicRearrangementProcessor2::doRearrangementAction(LEGlyphStorage &glyphStorage, IndicRearrangementVerb verb) const
|
|
93 |
{
|
|
94 |
LEGlyphID a, b, c, d;
|
|
95 |
le_int32 ia, ib, ic, id, ix, x;
|
|
96 |
LEErrorCode success = LE_NO_ERROR;
|
|
97 |
|
|
98 |
switch(verb)
|
|
99 |
{
|
|
100 |
case irvNoAction:
|
|
101 |
break;
|
|
102 |
|
|
103 |
case irvxA:
|
|
104 |
a = glyphStorage[firstGlyph];
|
|
105 |
ia = glyphStorage.getCharIndex(firstGlyph, success);
|
|
106 |
x = firstGlyph + 1;
|
|
107 |
|
|
108 |
while (x <= lastGlyph) {
|
|
109 |
glyphStorage[x - 1] = glyphStorage[x];
|
|
110 |
ix = glyphStorage.getCharIndex(x, success);
|
|
111 |
glyphStorage.setCharIndex(x - 1, ix, success);
|
|
112 |
x += 1;
|
|
113 |
}
|
|
114 |
|
|
115 |
glyphStorage[lastGlyph] = a;
|
|
116 |
glyphStorage.setCharIndex(lastGlyph, ia, success);
|
|
117 |
break;
|
|
118 |
|
|
119 |
case irvDx:
|
|
120 |
d = glyphStorage[lastGlyph];
|
|
121 |
id = glyphStorage.getCharIndex(lastGlyph, success);
|
|
122 |
x = lastGlyph - 1;
|
|
123 |
|
|
124 |
while (x >= firstGlyph) {
|
|
125 |
glyphStorage[x + 1] = glyphStorage[x];
|
|
126 |
ix = glyphStorage.getCharIndex(x, success);
|
|
127 |
glyphStorage.setCharIndex(x + 1, ix, success);
|
|
128 |
x -= 1;
|
|
129 |
}
|
|
130 |
|
|
131 |
glyphStorage[firstGlyph] = d;
|
|
132 |
glyphStorage.setCharIndex(firstGlyph, id, success);
|
|
133 |
break;
|
|
134 |
|
|
135 |
case irvDxA:
|
|
136 |
a = glyphStorage[firstGlyph];
|
|
137 |
ia = glyphStorage.getCharIndex(firstGlyph, success);
|
|
138 |
id = glyphStorage.getCharIndex(lastGlyph, success);
|
|
139 |
|
|
140 |
glyphStorage[firstGlyph] = glyphStorage[lastGlyph];
|
|
141 |
glyphStorage[lastGlyph] = a;
|
|
142 |
|
|
143 |
glyphStorage.setCharIndex(firstGlyph, id, success);
|
|
144 |
glyphStorage.setCharIndex(lastGlyph, ia, success);
|
|
145 |
break;
|
|
146 |
|
|
147 |
case irvxAB:
|
|
148 |
a = glyphStorage[firstGlyph];
|
|
149 |
b = glyphStorage[firstGlyph + 1];
|
|
150 |
ia = glyphStorage.getCharIndex(firstGlyph, success);
|
|
151 |
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
|
|
152 |
x = firstGlyph + 2;
|
|
153 |
|
|
154 |
while (x <= lastGlyph) {
|
|
155 |
glyphStorage[x - 2] = glyphStorage[x];
|
|
156 |
ix = glyphStorage.getCharIndex(x, success);
|
|
157 |
glyphStorage.setCharIndex(x - 2, ix, success);
|
|
158 |
x += 1;
|
|
159 |
}
|
|
160 |
|
|
161 |
glyphStorage[lastGlyph - 1] = a;
|
|
162 |
glyphStorage[lastGlyph] = b;
|
|
163 |
|
|
164 |
glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
|
|
165 |
glyphStorage.setCharIndex(lastGlyph, ib, success);
|
|
166 |
break;
|
|
167 |
|
|
168 |
case irvxBA:
|
|
169 |
a = glyphStorage[firstGlyph];
|
|
170 |
b = glyphStorage[firstGlyph + 1];
|
|
171 |
ia = glyphStorage.getCharIndex(firstGlyph, success);
|
|
172 |
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
|
|
173 |
x = firstGlyph + 2;
|
|
174 |
|
|
175 |
while (x <= lastGlyph) {
|
|
176 |
glyphStorage[x - 2] = glyphStorage[x];
|
|
177 |
ix = glyphStorage.getCharIndex(x, success);
|
|
178 |
glyphStorage.setCharIndex(x - 2, ix, success);
|
|
179 |
x += 1;
|
|
180 |
}
|
|
181 |
|
|
182 |
glyphStorage[lastGlyph - 1] = b;
|
|
183 |
glyphStorage[lastGlyph] = a;
|
|
184 |
|
|
185 |
glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
|
|
186 |
glyphStorage.setCharIndex(lastGlyph, ia, success);
|
|
187 |
break;
|
|
188 |
|
|
189 |
case irvCDx:
|
|
190 |
c = glyphStorage[lastGlyph - 1];
|
|
191 |
d = glyphStorage[lastGlyph];
|
|
192 |
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
|
|
193 |
id = glyphStorage.getCharIndex(lastGlyph, success);
|
|
194 |
x = lastGlyph - 2;
|
|
195 |
|
|
196 |
while (x >= firstGlyph) {
|
|
197 |
glyphStorage[x + 2] = glyphStorage[x];
|
|
198 |
ix = glyphStorage.getCharIndex(x, success);
|
|
199 |
glyphStorage.setCharIndex(x + 2, ix, success);
|
|
200 |
x -= 1;
|
|
201 |
}
|
|
202 |
|
|
203 |
glyphStorage[firstGlyph] = c;
|
|
204 |
glyphStorage[firstGlyph + 1] = d;
|
|
205 |
|
|
206 |
glyphStorage.setCharIndex(firstGlyph, ic, success);
|
|
207 |
glyphStorage.setCharIndex(firstGlyph + 1, id, success);
|
|
208 |
break;
|
|
209 |
|
|
210 |
case irvDCx:
|
|
211 |
c = glyphStorage[lastGlyph - 1];
|
|
212 |
d = glyphStorage[lastGlyph];
|
|
213 |
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
|
|
214 |
id = glyphStorage.getCharIndex(lastGlyph, success);
|
|
215 |
x = lastGlyph - 2;
|
|
216 |
|
|
217 |
while (x >= firstGlyph) {
|
|
218 |
glyphStorage[x + 2] = glyphStorage[x];
|
|
219 |
ix = glyphStorage.getCharIndex(x, success);
|
|
220 |
glyphStorage.setCharIndex(x + 2, ix, success);
|
|
221 |
x -= 1;
|
|
222 |
}
|
|
223 |
|
|
224 |
glyphStorage[firstGlyph] = d;
|
|
225 |
glyphStorage[firstGlyph + 1] = c;
|
|
226 |
|
|
227 |
glyphStorage.setCharIndex(firstGlyph, id, success);
|
|
228 |
glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
|
|
229 |
break;
|
|
230 |
|
|
231 |
case irvCDxA:
|
|
232 |
a = glyphStorage[firstGlyph];
|
|
233 |
c = glyphStorage[lastGlyph - 1];
|
|
234 |
d = glyphStorage[lastGlyph];
|
|
235 |
ia = glyphStorage.getCharIndex(firstGlyph, success);
|
|
236 |
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
|
|
237 |
id = glyphStorage.getCharIndex(lastGlyph, success);
|
|
238 |
x = lastGlyph - 2;
|
|
239 |
|
|
240 |
while (x > firstGlyph) {
|
|
241 |
glyphStorage[x + 1] = glyphStorage[x];
|
|
242 |
ix = glyphStorage.getCharIndex(x, success);
|
|
243 |
glyphStorage.setCharIndex(x + 1, ix, success);
|
|
244 |
x -= 1;
|
|
245 |
}
|
|
246 |
|
|
247 |
glyphStorage[firstGlyph] = c;
|
|
248 |
glyphStorage[firstGlyph + 1] = d;
|
|
249 |
glyphStorage[lastGlyph] = a;
|
|
250 |
|
|
251 |
glyphStorage.setCharIndex(firstGlyph, ic, success);
|
|
252 |
glyphStorage.setCharIndex(firstGlyph + 1, id, success);
|
|
253 |
glyphStorage.setCharIndex(lastGlyph, ia, success);
|
|
254 |
break;
|
|
255 |
|
|
256 |
case irvDCxA:
|
|
257 |
a = glyphStorage[firstGlyph];
|
|
258 |
c = glyphStorage[lastGlyph - 1];
|
|
259 |
d = glyphStorage[lastGlyph];
|
|
260 |
ia = glyphStorage.getCharIndex(firstGlyph, success);
|
|
261 |
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
|
|
262 |
id = glyphStorage.getCharIndex(lastGlyph, success);
|
|
263 |
x = lastGlyph - 2;
|
|
264 |
|
|
265 |
while (x > firstGlyph) {
|
|
266 |
glyphStorage[x + 1] = glyphStorage[x];
|
|
267 |
ix = glyphStorage.getCharIndex(x, success);
|
|
268 |
glyphStorage.setCharIndex(x + 1, ix, success);
|
|
269 |
x -= 1;
|
|
270 |
}
|
|
271 |
|
|
272 |
glyphStorage[firstGlyph] = d;
|
|
273 |
glyphStorage[firstGlyph + 1] = c;
|
|
274 |
glyphStorage[lastGlyph] = a;
|
|
275 |
|
|
276 |
glyphStorage.setCharIndex(firstGlyph, id, success);
|
|
277 |
glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
|
|
278 |
glyphStorage.setCharIndex(lastGlyph, ia, success);
|
|
279 |
break;
|
|
280 |
|
|
281 |
case irvDxAB:
|
|
282 |
a = glyphStorage[firstGlyph];
|
|
283 |
b = glyphStorage[firstGlyph + 1];
|
|
284 |
d = glyphStorage[lastGlyph];
|
|
285 |
ia = glyphStorage.getCharIndex(firstGlyph, success);
|
|
286 |
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
|
|
287 |
id = glyphStorage.getCharIndex(lastGlyph, success);
|
|
288 |
x = firstGlyph + 2;
|
|
289 |
|
|
290 |
while (x < lastGlyph) {
|
|
291 |
glyphStorage[x - 2] = glyphStorage[x];
|
|
292 |
ix = glyphStorage.getCharIndex(x, success);
|
|
293 |
glyphStorage.setCharIndex(x - 2, ix, success);
|
|
294 |
x += 1;
|
|
295 |
}
|
|
296 |
|
|
297 |
glyphStorage[firstGlyph] = d;
|
|
298 |
glyphStorage[lastGlyph - 1] = a;
|
|
299 |
glyphStorage[lastGlyph] = b;
|
|
300 |
|
|
301 |
glyphStorage.setCharIndex(firstGlyph, id, success);
|
|
302 |
glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
|
|
303 |
glyphStorage.setCharIndex(lastGlyph, ib, success);
|
|
304 |
break;
|
|
305 |
|
|
306 |
case irvDxBA:
|
|
307 |
a = glyphStorage[firstGlyph];
|
|
308 |
b = glyphStorage[firstGlyph + 1];
|
|
309 |
d = glyphStorage[lastGlyph];
|
|
310 |
ia = glyphStorage.getCharIndex(firstGlyph, success);
|
|
311 |
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
|
|
312 |
id = glyphStorage.getCharIndex(lastGlyph, success);
|
|
313 |
x = firstGlyph + 2;
|
|
314 |
|
|
315 |
while (x < lastGlyph) {
|
|
316 |
glyphStorage[x - 2] = glyphStorage[x];
|
|
317 |
ix = glyphStorage.getCharIndex(x, success);
|
|
318 |
glyphStorage.setCharIndex(x - 2, ix, success);
|
|
319 |
x += 1;
|
|
320 |
}
|
|
321 |
|
|
322 |
glyphStorage[firstGlyph] = d;
|
|
323 |
glyphStorage[lastGlyph - 1] = b;
|
|
324 |
glyphStorage[lastGlyph] = a;
|
|
325 |
|
|
326 |
glyphStorage.setCharIndex(firstGlyph, id, success);
|
|
327 |
glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
|
|
328 |
glyphStorage.setCharIndex(lastGlyph, ia, success);
|
|
329 |
break;
|
|
330 |
|
|
331 |
case irvCDxAB:
|
|
332 |
a = glyphStorage[firstGlyph];
|
|
333 |
b = glyphStorage[firstGlyph + 1];
|
|
334 |
|
|
335 |
glyphStorage[firstGlyph] = glyphStorage[lastGlyph - 1];
|
|
336 |
glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph];
|
|
337 |
|
|
338 |
glyphStorage[lastGlyph - 1] = a;
|
|
339 |
glyphStorage[lastGlyph] = b;
|
|
340 |
|
|
341 |
ia = glyphStorage.getCharIndex(firstGlyph, success);
|
|
342 |
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
|
|
343 |
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
|
|
344 |
id = glyphStorage.getCharIndex(lastGlyph, success);
|
|
345 |
|
|
346 |
glyphStorage.setCharIndex(firstGlyph, ic, success);
|
|
347 |
glyphStorage.setCharIndex(firstGlyph + 1, id, success);
|
|
348 |
|
|
349 |
glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
|
|
350 |
glyphStorage.setCharIndex(lastGlyph, ib, success);
|
|
351 |
break;
|
|
352 |
|
|
353 |
case irvCDxBA:
|
|
354 |
a = glyphStorage[firstGlyph];
|
|
355 |
b = glyphStorage[firstGlyph + 1];
|
|
356 |
|
|
357 |
glyphStorage[firstGlyph] = glyphStorage[lastGlyph - 1];
|
|
358 |
glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph];
|
|
359 |
|
|
360 |
glyphStorage[lastGlyph - 1] = b;
|
|
361 |
glyphStorage[lastGlyph] = a;
|
|
362 |
|
|
363 |
ia = glyphStorage.getCharIndex(firstGlyph, success);
|
|
364 |
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
|
|
365 |
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
|
|
366 |
id = glyphStorage.getCharIndex(lastGlyph, success);
|
|
367 |
|
|
368 |
glyphStorage.setCharIndex(firstGlyph, ic, success);
|
|
369 |
glyphStorage.setCharIndex(firstGlyph + 1, id, success);
|
|
370 |
|
|
371 |
glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
|
|
372 |
glyphStorage.setCharIndex(lastGlyph, ia, success);
|
|
373 |
break;
|
|
374 |
|
|
375 |
case irvDCxAB:
|
|
376 |
a = glyphStorage[firstGlyph];
|
|
377 |
b = glyphStorage[firstGlyph + 1];
|
|
378 |
|
|
379 |
glyphStorage[firstGlyph] = glyphStorage[lastGlyph];
|
|
380 |
glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph - 1];
|
|
381 |
|
|
382 |
glyphStorage[lastGlyph - 1] = a;
|
|
383 |
glyphStorage[lastGlyph] = b;
|
|
384 |
|
|
385 |
ia = glyphStorage.getCharIndex(firstGlyph, success);
|
|
386 |
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
|
|
387 |
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
|
|
388 |
id = glyphStorage.getCharIndex(lastGlyph, success);
|
|
389 |
|
|
390 |
glyphStorage.setCharIndex(firstGlyph, id, success);
|
|
391 |
glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
|
|
392 |
|
|
393 |
glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
|
|
394 |
glyphStorage.setCharIndex(lastGlyph, ib, success);
|
|
395 |
break;
|
|
396 |
|
|
397 |
case irvDCxBA:
|
|
398 |
a = glyphStorage[firstGlyph];
|
|
399 |
b = glyphStorage[firstGlyph + 1];
|
|
400 |
|
|
401 |
glyphStorage[firstGlyph] = glyphStorage[lastGlyph];
|
|
402 |
glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph - 1];
|
|
403 |
|
|
404 |
glyphStorage[lastGlyph - 1] = b;
|
|
405 |
glyphStorage[lastGlyph] = a;
|
|
406 |
|
|
407 |
ia = glyphStorage.getCharIndex(firstGlyph, success);
|
|
408 |
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
|
|
409 |
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
|
|
410 |
id = glyphStorage.getCharIndex(lastGlyph, success);
|
|
411 |
|
|
412 |
glyphStorage.setCharIndex(firstGlyph, id, success);
|
|
413 |
glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
|
|
414 |
|
|
415 |
glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
|
|
416 |
glyphStorage.setCharIndex(lastGlyph, ia, success);
|
|
417 |
break;
|
|
418 |
|
|
419 |
default:
|
|
420 |
break;
|
|
421 |
}
|
|
422 |
|
|
423 |
}
|
|
424 |
|
|
425 |
U_NAMESPACE_END
|