3 * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
8 #include "MorphTables.h"
9 #include "StateTables.h"
10 #include "MorphStateTables.h"
11 #include "SubtableProcessor.h"
12 #include "StateTableProcessor.h"
13 #include "IndicRearrangementProcessor.h"
14 #include "LEGlyphStorage.h"
19 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IndicRearrangementProcessor
)
21 IndicRearrangementProcessor::IndicRearrangementProcessor(const MorphSubtableHeader
*morphSubtableHeader
)
22 : StateTableProcessor(morphSubtableHeader
)
24 indicRearrangementSubtableHeader
= (const IndicRearrangementSubtableHeader
*) morphSubtableHeader
;
25 entryTable
= (const IndicRearrangementStateEntry
*) ((char *) &stateTableHeader
->stHeader
+ entryTableOffset
);
28 IndicRearrangementProcessor::~IndicRearrangementProcessor()
32 void IndicRearrangementProcessor::beginStateTable()
38 ByteOffset
IndicRearrangementProcessor::processStateEntry(LEGlyphStorage
&glyphStorage
, le_int32
&currGlyph
, EntryTableIndex index
)
40 const IndicRearrangementStateEntry
*entry
= &entryTable
[index
];
41 ByteOffset newState
= SWAPW(entry
->newStateOffset
);
42 IndicRearrangementFlags flags
= (IndicRearrangementFlags
) SWAPW(entry
->flags
);
44 if (flags
& irfMarkFirst
) {
45 firstGlyph
= currGlyph
;
48 if (flags
& irfMarkLast
) {
49 lastGlyph
= currGlyph
;
52 doRearrangementAction(glyphStorage
, (IndicRearrangementVerb
) (flags
& irfVerbMask
));
54 if (!(flags
& irfDontAdvance
)) {
55 // XXX: Should handle reverse too...
62 void IndicRearrangementProcessor::endStateTable()
66 void IndicRearrangementProcessor::doRearrangementAction(LEGlyphStorage
&glyphStorage
, IndicRearrangementVerb verb
) const
69 le_int32 ia
, ib
, ic
, id
, ix
, x
;
70 LEErrorCode success
= LE_NO_ERROR
;
78 a
= glyphStorage
[firstGlyph
];
79 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
82 while (x
<= lastGlyph
) {
83 glyphStorage
[x
- 1] = glyphStorage
[x
];
84 ix
= glyphStorage
.getCharIndex(x
, success
);
85 glyphStorage
.setCharIndex(x
- 1, ix
, success
);
89 glyphStorage
[lastGlyph
] = a
;
90 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);
94 d
= glyphStorage
[lastGlyph
];
95 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
98 while (x
>= firstGlyph
) {
99 glyphStorage
[x
+ 1] = glyphStorage
[x
];
100 ix
= glyphStorage
.getCharIndex(x
, success
);
101 glyphStorage
.setCharIndex(x
+ 1, ix
, success
);
105 glyphStorage
[firstGlyph
] = d
;
106 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
110 a
= glyphStorage
[firstGlyph
];
111 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
112 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
114 glyphStorage
[firstGlyph
] = glyphStorage
[lastGlyph
];
115 glyphStorage
[lastGlyph
] = a
;
117 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
118 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);
122 a
= glyphStorage
[firstGlyph
];
123 b
= glyphStorage
[firstGlyph
+ 1];
124 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
125 ib
= glyphStorage
.getCharIndex(firstGlyph
+ 1, success
);
128 while (x
<= lastGlyph
) {
129 glyphStorage
[x
- 2] = glyphStorage
[x
];
130 ix
= glyphStorage
.getCharIndex(x
, success
);
131 glyphStorage
.setCharIndex(x
- 2, ix
, success
);
135 glyphStorage
[lastGlyph
- 1] = a
;
136 glyphStorage
[lastGlyph
] = b
;
138 glyphStorage
.setCharIndex(lastGlyph
- 1, ia
, success
);
139 glyphStorage
.setCharIndex(lastGlyph
, ib
, success
);
143 a
= glyphStorage
[firstGlyph
];
144 b
= glyphStorage
[firstGlyph
+ 1];
145 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
146 ib
= glyphStorage
.getCharIndex(firstGlyph
+ 1, success
);
149 while (x
<= lastGlyph
) {
150 glyphStorage
[x
- 2] = glyphStorage
[x
];
151 ix
= glyphStorage
.getCharIndex(x
, success
);
152 glyphStorage
.setCharIndex(x
- 2, ix
, success
);
156 glyphStorage
[lastGlyph
- 1] = b
;
157 glyphStorage
[lastGlyph
] = a
;
159 glyphStorage
.setCharIndex(lastGlyph
- 1, ib
, success
);
160 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);
164 c
= glyphStorage
[lastGlyph
- 1];
165 d
= glyphStorage
[lastGlyph
];
166 ic
= glyphStorage
.getCharIndex(lastGlyph
- 1, success
);
167 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
170 while (x
>= firstGlyph
) {
171 glyphStorage
[x
+ 2] = glyphStorage
[x
];
172 ix
= glyphStorage
.getCharIndex(x
, success
);
173 glyphStorage
.setCharIndex(x
+ 2, ix
, success
);
177 glyphStorage
[firstGlyph
] = c
;
178 glyphStorage
[firstGlyph
+ 1] = d
;
180 glyphStorage
.setCharIndex(firstGlyph
, ic
, success
);
181 glyphStorage
.setCharIndex(firstGlyph
+ 1, id
, success
);
185 c
= glyphStorage
[lastGlyph
- 1];
186 d
= glyphStorage
[lastGlyph
];
187 ic
= glyphStorage
.getCharIndex(lastGlyph
- 1, success
);
188 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
191 while (x
>= firstGlyph
) {
192 glyphStorage
[x
+ 2] = glyphStorage
[x
];
193 ix
= glyphStorage
.getCharIndex(x
, success
);
194 glyphStorage
.setCharIndex(x
+ 2, ix
, success
);
198 glyphStorage
[firstGlyph
] = d
;
199 glyphStorage
[firstGlyph
+ 1] = c
;
201 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
202 glyphStorage
.setCharIndex(firstGlyph
+ 1, ic
, success
);
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
);
214 while (x
> firstGlyph
) {
215 glyphStorage
[x
+ 1] = glyphStorage
[x
];
216 ix
= glyphStorage
.getCharIndex(x
, success
);
217 glyphStorage
.setCharIndex(x
+ 1, ix
, success
);
221 glyphStorage
[firstGlyph
] = c
;
222 glyphStorage
[firstGlyph
+ 1] = d
;
223 glyphStorage
[lastGlyph
] = a
;
225 glyphStorage
.setCharIndex(firstGlyph
, ic
, success
);
226 glyphStorage
.setCharIndex(firstGlyph
+ 1, id
, success
);
227 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);
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
);
239 while (x
> firstGlyph
) {
240 glyphStorage
[x
+ 1] = glyphStorage
[x
];
241 ix
= glyphStorage
.getCharIndex(x
, success
);
242 glyphStorage
.setCharIndex(x
+ 1, ix
, success
);
246 glyphStorage
[firstGlyph
] = d
;
247 glyphStorage
[firstGlyph
+ 1] = c
;
248 glyphStorage
[lastGlyph
] = a
;
250 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
251 glyphStorage
.setCharIndex(firstGlyph
+ 1, ic
, success
);
252 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);
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
);
264 while (x
< lastGlyph
) {
265 glyphStorage
[x
- 2] = glyphStorage
[x
];
266 ix
= glyphStorage
.getCharIndex(x
, success
);
267 glyphStorage
.setCharIndex(x
- 2, ix
, success
);
271 glyphStorage
[firstGlyph
] = d
;
272 glyphStorage
[lastGlyph
- 1] = a
;
273 glyphStorage
[lastGlyph
] = b
;
275 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
276 glyphStorage
.setCharIndex(lastGlyph
- 1, ia
, success
);
277 glyphStorage
.setCharIndex(lastGlyph
, ib
, success
);
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
);
289 while (x
< lastGlyph
) {
290 glyphStorage
[x
- 2] = glyphStorage
[x
];
291 ix
= glyphStorage
.getCharIndex(x
, success
);
292 glyphStorage
.setCharIndex(x
- 2, ix
, success
);
296 glyphStorage
[firstGlyph
] = d
;
297 glyphStorage
[lastGlyph
- 1] = b
;
298 glyphStorage
[lastGlyph
] = a
;
300 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
301 glyphStorage
.setCharIndex(lastGlyph
- 1, ib
, success
);
302 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);
306 a
= glyphStorage
[firstGlyph
];
307 b
= glyphStorage
[firstGlyph
+ 1];
309 glyphStorage
[firstGlyph
] = glyphStorage
[lastGlyph
- 1];
310 glyphStorage
[firstGlyph
+ 1] = glyphStorage
[lastGlyph
];
312 glyphStorage
[lastGlyph
- 1] = a
;
313 glyphStorage
[lastGlyph
] = b
;
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
);
320 glyphStorage
.setCharIndex(firstGlyph
, ic
, success
);
321 glyphStorage
.setCharIndex(firstGlyph
+ 1, id
, success
);
323 glyphStorage
.setCharIndex(lastGlyph
- 1, ia
, success
);
324 glyphStorage
.setCharIndex(lastGlyph
, ib
, success
);
328 a
= glyphStorage
[firstGlyph
];
329 b
= glyphStorage
[firstGlyph
+ 1];
331 glyphStorage
[firstGlyph
] = glyphStorage
[lastGlyph
- 1];
332 glyphStorage
[firstGlyph
+ 1] = glyphStorage
[lastGlyph
];
334 glyphStorage
[lastGlyph
- 1] = b
;
335 glyphStorage
[lastGlyph
] = 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
);
342 glyphStorage
.setCharIndex(firstGlyph
, ic
, success
);
343 glyphStorage
.setCharIndex(firstGlyph
+ 1, id
, success
);
345 glyphStorage
.setCharIndex(lastGlyph
- 1, ib
, success
);
346 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);
350 a
= glyphStorage
[firstGlyph
];
351 b
= glyphStorage
[firstGlyph
+ 1];
353 glyphStorage
[firstGlyph
] = glyphStorage
[lastGlyph
];
354 glyphStorage
[firstGlyph
+ 1] = glyphStorage
[lastGlyph
- 1];
356 glyphStorage
[lastGlyph
- 1] = a
;
357 glyphStorage
[lastGlyph
] = b
;
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
);
364 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
365 glyphStorage
.setCharIndex(firstGlyph
+ 1, ic
, success
);
367 glyphStorage
.setCharIndex(lastGlyph
- 1, ia
, success
);
368 glyphStorage
.setCharIndex(lastGlyph
, ib
, success
);
372 a
= glyphStorage
[firstGlyph
];
373 b
= glyphStorage
[firstGlyph
+ 1];
375 glyphStorage
[firstGlyph
] = glyphStorage
[lastGlyph
];
376 glyphStorage
[firstGlyph
+ 1] = glyphStorage
[lastGlyph
- 1];
378 glyphStorage
[lastGlyph
- 1] = b
;
379 glyphStorage
[lastGlyph
] = 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
);
386 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
387 glyphStorage
.setCharIndex(firstGlyph
+ 1, ic
, success
);
389 glyphStorage
.setCharIndex(lastGlyph
- 1, ib
, success
);
390 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);