2
* @(#)IndicRearrangementProcessor.cpp 1.7 00/03/15
4
* (C) Copyright IBM Corp. 1998, 1999, 2000, 2001 - All Rights Reserved
9
#include "MorphTables.h"
10
#include "StateTables.h"
11
#include "MorphStateTables.h"
12
#include "SubtableProcessor.h"
13
#include "StateTableProcessor.h"
14
#include "IndicRearrangementProcessor.h"
19
IndicRearrangementProcessor::IndicRearrangementProcessor(const MorphSubtableHeader *morphSubtableHeader)
20
: StateTableProcessor(morphSubtableHeader)
22
indicRearrangementSubtableHeader = (const IndicRearrangementSubtableHeader *) morphSubtableHeader;
23
entryTable = (const IndicRearrangementStateEntry *) ((char *) &stateTableHeader->stHeader + entryTableOffset);
26
IndicRearrangementProcessor::~IndicRearrangementProcessor()
30
void IndicRearrangementProcessor::beginStateTable()
36
ByteOffset IndicRearrangementProcessor::processStateEntry(LEGlyphID *glyphs, le_int32 *charIndices, le_int32 &currGlyph,
37
le_int32 glyphCount, EntryTableIndex index)
39
const IndicRearrangementStateEntry *entry = &entryTable[index];
40
ByteOffset newState = SWAPW(entry->newStateOffset);
41
IndicRearrangementFlags flags = (IndicRearrangementFlags) SWAPW(entry->flags);
43
if (flags & irfMarkFirst) {
44
firstGlyph = currGlyph;
47
if (flags & irfMarkLast) {
48
lastGlyph = currGlyph;
51
doRearrangementAction(glyphs, charIndices, (IndicRearrangementVerb) (flags & irfVerbMask));
53
if (!(flags & irfDontAdvance)) {
54
// XXX: Should handle reverse too...
61
void IndicRearrangementProcessor::endStateTable()
65
void IndicRearrangementProcessor::doRearrangementAction(LEGlyphID *glyphs, le_int32 *charIndices, IndicRearrangementVerb verb) const
68
le_int32 ia, ib, ic, id, x;
76
a = glyphs[firstGlyph];
77
ia = charIndices[firstGlyph];
80
while (x <= lastGlyph) {
81
glyphs[x - 1] = glyphs[x];
82
charIndices[x - 1] = charIndices[x];
86
glyphs[lastGlyph] = a;
87
charIndices[lastGlyph] = ia;
91
d = glyphs[lastGlyph];
92
id = charIndices[lastGlyph];
95
while (x >= firstGlyph) {
96
glyphs[x + 1] = glyphs[x];
97
charIndices[x + 1] = charIndices[x];
101
glyphs[firstGlyph] = d;
102
charIndices[firstGlyph] = id;
106
a = glyphs[firstGlyph];
107
ia = charIndices[firstGlyph];
109
glyphs[firstGlyph] = glyphs[lastGlyph];
110
glyphs[lastGlyph] = a;
112
charIndices[firstGlyph] = charIndices[lastGlyph];
113
charIndices[lastGlyph] = ia;
117
a = glyphs[firstGlyph];
118
b = glyphs[firstGlyph + 1];
119
ia = charIndices[firstGlyph];
120
ib = charIndices[firstGlyph + 1];
123
while (x <= lastGlyph) {
124
glyphs[x - 2] = glyphs[x];
125
charIndices[x - 2] = charIndices[x];
129
glyphs[lastGlyph - 1] = a;
130
glyphs[lastGlyph] = b;
132
charIndices[lastGlyph - 1] = ia;
133
charIndices[lastGlyph] = ib;
137
a = glyphs[firstGlyph];
138
b = glyphs[firstGlyph + 1];
139
ia = charIndices[firstGlyph];
140
ib = charIndices[firstGlyph + 1];
143
while (x <= lastGlyph) {
144
glyphs[x - 2] = glyphs[x];
145
charIndices[x - 2] = charIndices[x];
149
glyphs[lastGlyph - 1] = b;
150
glyphs[lastGlyph] = a;
152
charIndices[lastGlyph - 1] = ib;
153
charIndices[lastGlyph] = ia;
157
c = glyphs[lastGlyph - 1];
158
d = glyphs[lastGlyph];
159
ic = charIndices[lastGlyph - 1];
160
id = charIndices[lastGlyph];
163
while (x >= lastGlyph) {
164
glyphs[x + 2] = glyphs[x];
165
charIndices[x + 2] = charIndices[x];
169
glyphs[firstGlyph] = c;
170
glyphs[firstGlyph + 1] = d;
172
charIndices[firstGlyph] = ic;
173
charIndices[firstGlyph + 1] = id;
177
c = glyphs[lastGlyph - 1];
178
d = glyphs[lastGlyph];
179
ic = charIndices[lastGlyph - 1];
180
id = charIndices[lastGlyph];
183
while (x >= lastGlyph) {
184
glyphs[x + 2] = glyphs[x];
185
charIndices[x + 2] = charIndices[x];
189
glyphs[firstGlyph] = d;
190
glyphs[firstGlyph + 1] = c;
192
charIndices[firstGlyph] = id;
193
charIndices[firstGlyph + 1] = ic;
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];
205
while (x > firstGlyph) {
206
glyphs[x + 1] = glyphs[x];
207
charIndices[x + 1] = charIndices[x];
211
glyphs[firstGlyph] = c;
212
glyphs[firstGlyph + 1] = d;
213
glyphs[lastGlyph] = a;
215
charIndices[firstGlyph] = ic;
216
charIndices[firstGlyph + 1] = id;
217
charIndices[lastGlyph] = ia;
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];
229
while (x > firstGlyph) {
230
glyphs[x + 1] = glyphs[x];
231
charIndices[x + 1] = charIndices[x];
235
glyphs[firstGlyph] = d;
236
glyphs[firstGlyph + 1] = c;
237
glyphs[lastGlyph] = a;
239
charIndices[firstGlyph] = id;
240
charIndices[firstGlyph + 1] = ic;
241
charIndices[lastGlyph] = ia;
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];
253
while (x < lastGlyph) {
254
glyphs[x - 2] = glyphs[x];
255
charIndices[x - 2] = charIndices[x];
259
glyphs[firstGlyph] = d;
260
glyphs[lastGlyph - 1] = a;
261
glyphs[lastGlyph] = b;
263
charIndices[firstGlyph] = id;
264
charIndices[lastGlyph - 1] = ia;
265
charIndices[lastGlyph] = ib;
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];
277
while (x < lastGlyph) {
278
glyphs[x - 2] = glyphs[x];
279
charIndices[x - 2] = charIndices[x];
283
glyphs[firstGlyph] = d;
284
glyphs[lastGlyph - 1] = b;
285
glyphs[lastGlyph] = a;
287
charIndices[firstGlyph] = id;
288
charIndices[lastGlyph - 1] = ib;
289
charIndices[lastGlyph] = ia;
293
a = glyphs[firstGlyph];
294
b = glyphs[firstGlyph + 1];
296
glyphs[firstGlyph] = glyphs[lastGlyph - 1];
297
glyphs[firstGlyph + 1] = glyphs[lastGlyph];
299
glyphs[lastGlyph - 1] = a;
300
glyphs[lastGlyph] = b;
302
ia = charIndices[firstGlyph];
303
ib = charIndices[firstGlyph + 1];
305
charIndices[firstGlyph] = charIndices[lastGlyph - 1];
306
charIndices[firstGlyph + 1] = charIndices[lastGlyph];
308
charIndices[lastGlyph - 1] = ia;
309
charIndices[lastGlyph] = ib;
313
a = glyphs[firstGlyph];
314
b = glyphs[firstGlyph + 1];
316
glyphs[firstGlyph] = glyphs[lastGlyph - 1];
317
glyphs[firstGlyph + 1] = glyphs[lastGlyph];
319
glyphs[lastGlyph - 1] = b;
320
glyphs[lastGlyph] = a;
322
ia = charIndices[firstGlyph];
323
ib = charIndices[firstGlyph + 1];
325
charIndices[firstGlyph] = charIndices[lastGlyph - 1];
326
charIndices[firstGlyph + 1] = charIndices[lastGlyph];
328
charIndices[lastGlyph - 1] = ib;
329
charIndices[lastGlyph] = ia;
333
a = glyphs[firstGlyph];
334
b = glyphs[firstGlyph + 1];
336
glyphs[firstGlyph] = glyphs[lastGlyph];
337
glyphs[firstGlyph + 1] = glyphs[lastGlyph - 1];
339
glyphs[lastGlyph - 1] = a;
340
glyphs[lastGlyph] = b;
342
ia = charIndices[firstGlyph];
343
ib = charIndices[firstGlyph + 1];
345
charIndices[firstGlyph] = charIndices[lastGlyph];
346
charIndices[firstGlyph + 1] = charIndices[lastGlyph - 1];
348
charIndices[lastGlyph - 1] = ia;
349
charIndices[lastGlyph] = ib;
353
a = glyphs[firstGlyph];
354
b = glyphs[firstGlyph + 1];
356
glyphs[firstGlyph] = glyphs[lastGlyph];
357
glyphs[firstGlyph + 1] = glyphs[lastGlyph - 1];
359
glyphs[lastGlyph - 1] = b;
360
glyphs[lastGlyph] = a;
362
ia = charIndices[firstGlyph];
363
ib = charIndices[firstGlyph + 1];
365
charIndices[firstGlyph] = charIndices[lastGlyph];
366
charIndices[firstGlyph + 1] = charIndices[lastGlyph - 1];
368
charIndices[lastGlyph - 1] = ib;
369
charIndices[lastGlyph] = ia;