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