~ubuntu-branches/ubuntu/gutsy/icu/gutsy-updates

« back to all changes in this revision

Viewing changes to source/layout/IndicRearrangementProcessor.cpp

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

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