]> git.saurik.com Git - apple/icu.git/blame - icuSources/layout/IndicRearrangementProcessor.cpp
ICU-491.11.1.tar.gz
[apple/icu.git] / icuSources / layout / IndicRearrangementProcessor.cpp
CommitLineData
b75a7d8f 1/*
b75a7d8f 2 *
374ca955 3 * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
b75a7d8f
A
4 *
5 */
6
7#include "LETypes.h"
8#include "MorphTables.h"
9#include "StateTables.h"
10#include "MorphStateTables.h"
11#include "SubtableProcessor.h"
12#include "StateTableProcessor.h"
13#include "IndicRearrangementProcessor.h"
374ca955 14#include "LEGlyphStorage.h"
b75a7d8f
A
15#include "LESwaps.h"
16
17U_NAMESPACE_BEGIN
18
374ca955 19UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IndicRearrangementProcessor)
b75a7d8f
A
20
21IndicRearrangementProcessor::IndicRearrangementProcessor(const MorphSubtableHeader *morphSubtableHeader)
22 : StateTableProcessor(morphSubtableHeader)
23{
24 indicRearrangementSubtableHeader = (const IndicRearrangementSubtableHeader *) morphSubtableHeader;
25 entryTable = (const IndicRearrangementStateEntry *) ((char *) &stateTableHeader->stHeader + entryTableOffset);
26}
27
28IndicRearrangementProcessor::~IndicRearrangementProcessor()
29{
30}
31
32void IndicRearrangementProcessor::beginStateTable()
33{
34 firstGlyph = 0;
35 lastGlyph = 0;
36}
37
374ca955 38ByteOffset IndicRearrangementProcessor::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex index)
b75a7d8f
A
39{
40 const IndicRearrangementStateEntry *entry = &entryTable[index];
41 ByteOffset newState = SWAPW(entry->newStateOffset);
42 IndicRearrangementFlags flags = (IndicRearrangementFlags) SWAPW(entry->flags);
43
44 if (flags & irfMarkFirst) {
45 firstGlyph = currGlyph;
46 }
47
48 if (flags & irfMarkLast) {
49 lastGlyph = currGlyph;
50 }
51
374ca955 52 doRearrangementAction(glyphStorage, (IndicRearrangementVerb) (flags & irfVerbMask));
b75a7d8f
A
53
54 if (!(flags & irfDontAdvance)) {
55 // XXX: Should handle reverse too...
56 currGlyph += 1;
57 }
58
59 return newState;
60}
61
62void IndicRearrangementProcessor::endStateTable()
63{
64}
65
374ca955 66void IndicRearrangementProcessor::doRearrangementAction(LEGlyphStorage &glyphStorage, IndicRearrangementVerb verb) const
b75a7d8f
A
67{
68 LEGlyphID a, b, c, d;
374ca955
A
69 le_int32 ia, ib, ic, id, ix, x;
70 LEErrorCode success = LE_NO_ERROR;
b75a7d8f
A
71
72 switch(verb)
73 {
74 case irvNoAction:
75 break;
76
77 case irvxA:
374ca955
A
78 a = glyphStorage[firstGlyph];
79 ia = glyphStorage.getCharIndex(firstGlyph, success);
b75a7d8f
A
80 x = firstGlyph + 1;
81
82 while (x <= lastGlyph) {
374ca955
A
83 glyphStorage[x - 1] = glyphStorage[x];
84 ix = glyphStorage.getCharIndex(x, success);
85 glyphStorage.setCharIndex(x - 1, ix, success);
b75a7d8f
A
86 x += 1;
87 }
88
374ca955
A
89 glyphStorage[lastGlyph] = a;
90 glyphStorage.setCharIndex(lastGlyph, ia, success);
b75a7d8f
A
91 break;
92
93 case irvDx:
374ca955
A
94 d = glyphStorage[lastGlyph];
95 id = glyphStorage.getCharIndex(lastGlyph, success);
b75a7d8f
A
96 x = lastGlyph - 1;
97
98 while (x >= firstGlyph) {
374ca955
A
99 glyphStorage[x + 1] = glyphStorage[x];
100 ix = glyphStorage.getCharIndex(x, success);
101 glyphStorage.setCharIndex(x + 1, ix, success);
b75a7d8f
A
102 x -= 1;
103 }
104
374ca955
A
105 glyphStorage[firstGlyph] = d;
106 glyphStorage.setCharIndex(firstGlyph, id, success);
b75a7d8f
A
107 break;
108
109 case irvDxA:
374ca955
A
110 a = glyphStorage[firstGlyph];
111 ia = glyphStorage.getCharIndex(firstGlyph, success);
112 id = glyphStorage.getCharIndex(lastGlyph, success);
b75a7d8f 113
374ca955
A
114 glyphStorage[firstGlyph] = glyphStorage[lastGlyph];
115 glyphStorage[lastGlyph] = a;
b75a7d8f 116
374ca955
A
117 glyphStorage.setCharIndex(firstGlyph, id, success);
118 glyphStorage.setCharIndex(lastGlyph, ia, success);
b75a7d8f
A
119 break;
120
121 case irvxAB:
374ca955
A
122 a = glyphStorage[firstGlyph];
123 b = glyphStorage[firstGlyph + 1];
124 ia = glyphStorage.getCharIndex(firstGlyph, success);
125 ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
b75a7d8f
A
126 x = firstGlyph + 2;
127
128 while (x <= lastGlyph) {
374ca955
A
129 glyphStorage[x - 2] = glyphStorage[x];
130 ix = glyphStorage.getCharIndex(x, success);
131 glyphStorage.setCharIndex(x - 2, ix, success);
b75a7d8f
A
132 x += 1;
133 }
134
374ca955
A
135 glyphStorage[lastGlyph - 1] = a;
136 glyphStorage[lastGlyph] = b;
b75a7d8f 137
374ca955
A
138 glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
139 glyphStorage.setCharIndex(lastGlyph, ib, success);
b75a7d8f
A
140 break;
141
142 case irvxBA:
374ca955
A
143 a = glyphStorage[firstGlyph];
144 b = glyphStorage[firstGlyph + 1];
145 ia = glyphStorage.getCharIndex(firstGlyph, success);
146 ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
b75a7d8f
A
147 x = firstGlyph + 2;
148
149 while (x <= lastGlyph) {
374ca955
A
150 glyphStorage[x - 2] = glyphStorage[x];
151 ix = glyphStorage.getCharIndex(x, success);
152 glyphStorage.setCharIndex(x - 2, ix, success);
b75a7d8f
A
153 x += 1;
154 }
155
374ca955
A
156 glyphStorage[lastGlyph - 1] = b;
157 glyphStorage[lastGlyph] = a;
b75a7d8f 158
374ca955
A
159 glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
160 glyphStorage.setCharIndex(lastGlyph, ia, success);
b75a7d8f
A
161 break;
162
163 case irvCDx:
374ca955
A
164 c = glyphStorage[lastGlyph - 1];
165 d = glyphStorage[lastGlyph];
166 ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
167 id = glyphStorage.getCharIndex(lastGlyph, success);
b75a7d8f
A
168 x = lastGlyph - 2;
169
374ca955
A
170 while (x >= firstGlyph) {
171 glyphStorage[x + 2] = glyphStorage[x];
172 ix = glyphStorage.getCharIndex(x, success);
173 glyphStorage.setCharIndex(x + 2, ix, success);
b75a7d8f
A
174 x -= 1;
175 }
176
374ca955
A
177 glyphStorage[firstGlyph] = c;
178 glyphStorage[firstGlyph + 1] = d;
b75a7d8f 179
374ca955
A
180 glyphStorage.setCharIndex(firstGlyph, ic, success);
181 glyphStorage.setCharIndex(firstGlyph + 1, id, success);
b75a7d8f
A
182 break;
183
184 case irvDCx:
374ca955
A
185 c = glyphStorage[lastGlyph - 1];
186 d = glyphStorage[lastGlyph];
187 ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
188 id = glyphStorage.getCharIndex(lastGlyph, success);
b75a7d8f
A
189 x = lastGlyph - 2;
190
374ca955
A
191 while (x >= firstGlyph) {
192 glyphStorage[x + 2] = glyphStorage[x];
193 ix = glyphStorage.getCharIndex(x, success);
194 glyphStorage.setCharIndex(x + 2, ix, success);
b75a7d8f
A
195 x -= 1;
196 }
197
374ca955
A
198 glyphStorage[firstGlyph] = d;
199 glyphStorage[firstGlyph + 1] = c;
b75a7d8f 200
374ca955
A
201 glyphStorage.setCharIndex(firstGlyph, id, success);
202 glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
b75a7d8f
A
203 break;
204
205 case irvCDxA:
374ca955
A
206 a = glyphStorage[firstGlyph];
207 c = glyphStorage[lastGlyph - 1];
208 d = glyphStorage[lastGlyph];
209 ia = glyphStorage.getCharIndex(firstGlyph, success);
210 ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
211 id = glyphStorage.getCharIndex(lastGlyph, success);
b75a7d8f
A
212 x = lastGlyph - 2;
213
214 while (x > firstGlyph) {
374ca955
A
215 glyphStorage[x + 1] = glyphStorage[x];
216 ix = glyphStorage.getCharIndex(x, success);
217 glyphStorage.setCharIndex(x + 1, ix, success);
b75a7d8f
A
218 x -= 1;
219 }
220
374ca955
A
221 glyphStorage[firstGlyph] = c;
222 glyphStorage[firstGlyph + 1] = d;
223 glyphStorage[lastGlyph] = a;
b75a7d8f 224
374ca955
A
225 glyphStorage.setCharIndex(firstGlyph, ic, success);
226 glyphStorage.setCharIndex(firstGlyph + 1, id, success);
227 glyphStorage.setCharIndex(lastGlyph, ia, success);
b75a7d8f
A
228 break;
229
230 case irvDCxA:
374ca955
A
231 a = glyphStorage[firstGlyph];
232 c = glyphStorage[lastGlyph - 1];
233 d = glyphStorage[lastGlyph];
234 ia = glyphStorage.getCharIndex(firstGlyph, success);
235 ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
236 id = glyphStorage.getCharIndex(lastGlyph, success);
b75a7d8f
A
237 x = lastGlyph - 2;
238
239 while (x > firstGlyph) {
374ca955
A
240 glyphStorage[x + 1] = glyphStorage[x];
241 ix = glyphStorage.getCharIndex(x, success);
242 glyphStorage.setCharIndex(x + 1, ix, success);
b75a7d8f
A
243 x -= 1;
244 }
245
374ca955
A
246 glyphStorage[firstGlyph] = d;
247 glyphStorage[firstGlyph + 1] = c;
248 glyphStorage[lastGlyph] = a;
b75a7d8f 249
374ca955
A
250 glyphStorage.setCharIndex(firstGlyph, id, success);
251 glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
252 glyphStorage.setCharIndex(lastGlyph, ia, success);
b75a7d8f
A
253 break;
254
255 case irvDxAB:
374ca955
A
256 a = glyphStorage[firstGlyph];
257 b = glyphStorage[firstGlyph + 1];
258 d = glyphStorage[lastGlyph];
259 ia = glyphStorage.getCharIndex(firstGlyph, success);
260 ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
261 id = glyphStorage.getCharIndex(lastGlyph, success);
b75a7d8f
A
262 x = firstGlyph + 2;
263
264 while (x < lastGlyph) {
374ca955
A
265 glyphStorage[x - 2] = glyphStorage[x];
266 ix = glyphStorage.getCharIndex(x, success);
267 glyphStorage.setCharIndex(x - 2, ix, success);
b75a7d8f
A
268 x += 1;
269 }
270
374ca955
A
271 glyphStorage[firstGlyph] = d;
272 glyphStorage[lastGlyph - 1] = a;
273 glyphStorage[lastGlyph] = b;
b75a7d8f 274
374ca955
A
275 glyphStorage.setCharIndex(firstGlyph, id, success);
276 glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
277 glyphStorage.setCharIndex(lastGlyph, ib, success);
b75a7d8f
A
278 break;
279
280 case irvDxBA:
374ca955
A
281 a = glyphStorage[firstGlyph];
282 b = glyphStorage[firstGlyph + 1];
283 d = glyphStorage[lastGlyph];
284 ia = glyphStorage.getCharIndex(firstGlyph, success);
285 ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
286 id = glyphStorage.getCharIndex(lastGlyph, success);
b75a7d8f
A
287 x = firstGlyph + 2;
288
289 while (x < lastGlyph) {
374ca955
A
290 glyphStorage[x - 2] = glyphStorage[x];
291 ix = glyphStorage.getCharIndex(x, success);
292 glyphStorage.setCharIndex(x - 2, ix, success);
b75a7d8f
A
293 x += 1;
294 }
295
374ca955
A
296 glyphStorage[firstGlyph] = d;
297 glyphStorage[lastGlyph - 1] = b;
298 glyphStorage[lastGlyph] = a;
b75a7d8f 299
374ca955
A
300 glyphStorage.setCharIndex(firstGlyph, id, success);
301 glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
302 glyphStorage.setCharIndex(lastGlyph, ia, success);
b75a7d8f
A
303 break;
304
305 case irvCDxAB:
374ca955
A
306 a = glyphStorage[firstGlyph];
307 b = glyphStorage[firstGlyph + 1];
b75a7d8f 308
374ca955
A
309 glyphStorage[firstGlyph] = glyphStorage[lastGlyph - 1];
310 glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph];
b75a7d8f 311
374ca955
A
312 glyphStorage[lastGlyph - 1] = a;
313 glyphStorage[lastGlyph] = b;
b75a7d8f 314
374ca955
A
315 ia = glyphStorage.getCharIndex(firstGlyph, success);
316 ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
317 ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
318 id = glyphStorage.getCharIndex(lastGlyph, success);
b75a7d8f 319
374ca955
A
320 glyphStorage.setCharIndex(firstGlyph, ic, success);
321 glyphStorage.setCharIndex(firstGlyph + 1, id, success);
b75a7d8f 322
374ca955
A
323 glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
324 glyphStorage.setCharIndex(lastGlyph, ib, success);
b75a7d8f
A
325 break;
326
327 case irvCDxBA:
374ca955
A
328 a = glyphStorage[firstGlyph];
329 b = glyphStorage[firstGlyph + 1];
b75a7d8f 330
374ca955
A
331 glyphStorage[firstGlyph] = glyphStorage[lastGlyph - 1];
332 glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph];
b75a7d8f 333
374ca955
A
334 glyphStorage[lastGlyph - 1] = b;
335 glyphStorage[lastGlyph] = a;
b75a7d8f 336
374ca955
A
337 ia = glyphStorage.getCharIndex(firstGlyph, success);
338 ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
339 ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
340 id = glyphStorage.getCharIndex(lastGlyph, success);
b75a7d8f 341
374ca955
A
342 glyphStorage.setCharIndex(firstGlyph, ic, success);
343 glyphStorage.setCharIndex(firstGlyph + 1, id, success);
b75a7d8f 344
374ca955
A
345 glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
346 glyphStorage.setCharIndex(lastGlyph, ia, success);
b75a7d8f
A
347 break;
348
349 case irvDCxAB:
374ca955
A
350 a = glyphStorage[firstGlyph];
351 b = glyphStorage[firstGlyph + 1];
b75a7d8f 352
374ca955
A
353 glyphStorage[firstGlyph] = glyphStorage[lastGlyph];
354 glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph - 1];
b75a7d8f 355
374ca955
A
356 glyphStorage[lastGlyph - 1] = a;
357 glyphStorage[lastGlyph] = b;
b75a7d8f 358
374ca955
A
359 ia = glyphStorage.getCharIndex(firstGlyph, success);
360 ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
361 ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
362 id = glyphStorage.getCharIndex(lastGlyph, success);
b75a7d8f 363
374ca955
A
364 glyphStorage.setCharIndex(firstGlyph, id, success);
365 glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
b75a7d8f 366
374ca955
A
367 glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
368 glyphStorage.setCharIndex(lastGlyph, ib, success);
b75a7d8f
A
369 break;
370
371 case irvDCxBA:
374ca955
A
372 a = glyphStorage[firstGlyph];
373 b = glyphStorage[firstGlyph + 1];
b75a7d8f 374
374ca955
A
375 glyphStorage[firstGlyph] = glyphStorage[lastGlyph];
376 glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph - 1];
b75a7d8f 377
374ca955
A
378 glyphStorage[lastGlyph - 1] = b;
379 glyphStorage[lastGlyph] = a;
b75a7d8f 380
374ca955
A
381 ia = glyphStorage.getCharIndex(firstGlyph, success);
382 ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
383 ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
384 id = glyphStorage.getCharIndex(lastGlyph, success);
b75a7d8f 385
374ca955
A
386 glyphStorage.setCharIndex(firstGlyph, id, success);
387 glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
b75a7d8f 388
374ca955
A
389 glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
390 glyphStorage.setCharIndex(lastGlyph, ia, success);
b75a7d8f
A
391 break;
392
393 default:
394 break;
395 }
396}
397
398U_NAMESPACE_END