3 * (C) Copyright IBM Corp. and others 1998-2014 - All Rights Reserved
8 #include "MorphTables.h"
9 #include "StateTables.h"
10 #include "MorphStateTables.h"
11 #include "SubtableProcessor2.h"
12 #include "StateTableProcessor2.h"
13 #include "IndicRearrangementProcessor2.h"
14 #include "LEGlyphStorage.h"
19 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IndicRearrangementProcessor2
)
21 IndicRearrangementProcessor2::IndicRearrangementProcessor2(
22 const LEReferenceTo
<MorphSubtableHeader2
> &morphSubtableHeader
, LEErrorCode
&success
)
23 : StateTableProcessor2(morphSubtableHeader
, success
), entryTable(stHeader
, success
, entryTableOffset
, LE_UNBOUNDED_ARRAY
),
24 indicRearrangementSubtableHeader(morphSubtableHeader
, success
)
28 IndicRearrangementProcessor2::~IndicRearrangementProcessor2()
32 void IndicRearrangementProcessor2::beginStateTable()
38 le_uint16
IndicRearrangementProcessor2::processStateEntry(LEGlyphStorage
&glyphStorage
, le_int32
&currGlyph
,
39 EntryTableIndex2 index
, LEErrorCode
&success
)
41 const IndicRearrangementStateEntry2
*entry
= entryTable
.getAlias(index
, success
);
42 if (LE_FAILURE(success
)) return 0; // TODO - what to return in bad state?
43 le_uint16 newState
= SWAPW(entry
->newStateIndex
); // index to the new state
44 IndicRearrangementFlags flags
= (IndicRearrangementFlags
) SWAPW(entry
->flags
);
46 if (flags
& irfMarkFirst
) {
47 firstGlyph
= currGlyph
;
50 if (flags
& irfMarkLast
) {
51 lastGlyph
= currGlyph
;
54 doRearrangementAction(glyphStorage
, (IndicRearrangementVerb
) (flags
& irfVerbMask
));
56 if (!(flags
& irfDontAdvance
)) {
60 return newState
; // index to new state
63 void IndicRearrangementProcessor2::endStateTable()
67 void IndicRearrangementProcessor2::doRearrangementAction(LEGlyphStorage
&glyphStorage
, IndicRearrangementVerb verb
) const
70 le_int32 ia
, ib
, ic
, id
, ix
, x
;
71 LEErrorCode success
= LE_NO_ERROR
;
79 a
= glyphStorage
[firstGlyph
];
80 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
83 while (x
<= lastGlyph
) {
84 glyphStorage
[x
- 1] = glyphStorage
[x
];
85 ix
= glyphStorage
.getCharIndex(x
, success
);
86 glyphStorage
.setCharIndex(x
- 1, ix
, success
);
90 glyphStorage
[lastGlyph
] = a
;
91 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);
95 d
= glyphStorage
[lastGlyph
];
96 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
99 while (x
>= firstGlyph
) {
100 glyphStorage
[x
+ 1] = glyphStorage
[x
];
101 ix
= glyphStorage
.getCharIndex(x
, success
);
102 glyphStorage
.setCharIndex(x
+ 1, ix
, success
);
106 glyphStorage
[firstGlyph
] = d
;
107 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
111 a
= glyphStorage
[firstGlyph
];
112 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
113 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
115 glyphStorage
[firstGlyph
] = glyphStorage
[lastGlyph
];
116 glyphStorage
[lastGlyph
] = a
;
118 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
119 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);
123 a
= glyphStorage
[firstGlyph
];
124 b
= glyphStorage
[firstGlyph
+ 1];
125 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
126 ib
= glyphStorage
.getCharIndex(firstGlyph
+ 1, success
);
129 while (x
<= lastGlyph
) {
130 glyphStorage
[x
- 2] = glyphStorage
[x
];
131 ix
= glyphStorage
.getCharIndex(x
, success
);
132 glyphStorage
.setCharIndex(x
- 2, ix
, success
);
136 glyphStorage
[lastGlyph
- 1] = a
;
137 glyphStorage
[lastGlyph
] = b
;
139 glyphStorage
.setCharIndex(lastGlyph
- 1, ia
, success
);
140 glyphStorage
.setCharIndex(lastGlyph
, ib
, success
);
144 a
= glyphStorage
[firstGlyph
];
145 b
= glyphStorage
[firstGlyph
+ 1];
146 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
147 ib
= glyphStorage
.getCharIndex(firstGlyph
+ 1, success
);
150 while (x
<= lastGlyph
) {
151 glyphStorage
[x
- 2] = glyphStorage
[x
];
152 ix
= glyphStorage
.getCharIndex(x
, success
);
153 glyphStorage
.setCharIndex(x
- 2, ix
, success
);
157 glyphStorage
[lastGlyph
- 1] = b
;
158 glyphStorage
[lastGlyph
] = a
;
160 glyphStorage
.setCharIndex(lastGlyph
- 1, ib
, success
);
161 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);
165 c
= glyphStorage
[lastGlyph
- 1];
166 d
= glyphStorage
[lastGlyph
];
167 ic
= glyphStorage
.getCharIndex(lastGlyph
- 1, success
);
168 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
171 while (x
>= firstGlyph
) {
172 glyphStorage
[x
+ 2] = glyphStorage
[x
];
173 ix
= glyphStorage
.getCharIndex(x
, success
);
174 glyphStorage
.setCharIndex(x
+ 2, ix
, success
);
178 glyphStorage
[firstGlyph
] = c
;
179 glyphStorage
[firstGlyph
+ 1] = d
;
181 glyphStorage
.setCharIndex(firstGlyph
, ic
, success
);
182 glyphStorage
.setCharIndex(firstGlyph
+ 1, id
, success
);
186 c
= glyphStorage
[lastGlyph
- 1];
187 d
= glyphStorage
[lastGlyph
];
188 ic
= glyphStorage
.getCharIndex(lastGlyph
- 1, success
);
189 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
192 while (x
>= firstGlyph
) {
193 glyphStorage
[x
+ 2] = glyphStorage
[x
];
194 ix
= glyphStorage
.getCharIndex(x
, success
);
195 glyphStorage
.setCharIndex(x
+ 2, ix
, success
);
199 glyphStorage
[firstGlyph
] = d
;
200 glyphStorage
[firstGlyph
+ 1] = c
;
202 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
203 glyphStorage
.setCharIndex(firstGlyph
+ 1, ic
, success
);
207 a
= glyphStorage
[firstGlyph
];
208 c
= glyphStorage
[lastGlyph
- 1];
209 d
= glyphStorage
[lastGlyph
];
210 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
211 ic
= glyphStorage
.getCharIndex(lastGlyph
- 1, success
);
212 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
215 while (x
> firstGlyph
) {
216 glyphStorage
[x
+ 1] = glyphStorage
[x
];
217 ix
= glyphStorage
.getCharIndex(x
, success
);
218 glyphStorage
.setCharIndex(x
+ 1, ix
, success
);
222 glyphStorage
[firstGlyph
] = c
;
223 glyphStorage
[firstGlyph
+ 1] = d
;
224 glyphStorage
[lastGlyph
] = a
;
226 glyphStorage
.setCharIndex(firstGlyph
, ic
, success
);
227 glyphStorage
.setCharIndex(firstGlyph
+ 1, id
, success
);
228 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);
232 a
= glyphStorage
[firstGlyph
];
233 c
= glyphStorage
[lastGlyph
- 1];
234 d
= glyphStorage
[lastGlyph
];
235 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
236 ic
= glyphStorage
.getCharIndex(lastGlyph
- 1, success
);
237 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
240 while (x
> firstGlyph
) {
241 glyphStorage
[x
+ 1] = glyphStorage
[x
];
242 ix
= glyphStorage
.getCharIndex(x
, success
);
243 glyphStorage
.setCharIndex(x
+ 1, ix
, success
);
247 glyphStorage
[firstGlyph
] = d
;
248 glyphStorage
[firstGlyph
+ 1] = c
;
249 glyphStorage
[lastGlyph
] = a
;
251 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
252 glyphStorage
.setCharIndex(firstGlyph
+ 1, ic
, success
);
253 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);
257 a
= glyphStorage
[firstGlyph
];
258 b
= glyphStorage
[firstGlyph
+ 1];
259 d
= glyphStorage
[lastGlyph
];
260 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
261 ib
= glyphStorage
.getCharIndex(firstGlyph
+ 1, success
);
262 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
265 while (x
< lastGlyph
) {
266 glyphStorage
[x
- 2] = glyphStorage
[x
];
267 ix
= glyphStorage
.getCharIndex(x
, success
);
268 glyphStorage
.setCharIndex(x
- 2, ix
, success
);
272 glyphStorage
[firstGlyph
] = d
;
273 glyphStorage
[lastGlyph
- 1] = a
;
274 glyphStorage
[lastGlyph
] = b
;
276 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
277 glyphStorage
.setCharIndex(lastGlyph
- 1, ia
, success
);
278 glyphStorage
.setCharIndex(lastGlyph
, ib
, success
);
282 a
= glyphStorage
[firstGlyph
];
283 b
= glyphStorage
[firstGlyph
+ 1];
284 d
= glyphStorage
[lastGlyph
];
285 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
286 ib
= glyphStorage
.getCharIndex(firstGlyph
+ 1, success
);
287 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
290 while (x
< lastGlyph
) {
291 glyphStorage
[x
- 2] = glyphStorage
[x
];
292 ix
= glyphStorage
.getCharIndex(x
, success
);
293 glyphStorage
.setCharIndex(x
- 2, ix
, success
);
297 glyphStorage
[firstGlyph
] = d
;
298 glyphStorage
[lastGlyph
- 1] = b
;
299 glyphStorage
[lastGlyph
] = a
;
301 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
302 glyphStorage
.setCharIndex(lastGlyph
- 1, ib
, success
);
303 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);
307 a
= glyphStorage
[firstGlyph
];
308 b
= glyphStorage
[firstGlyph
+ 1];
310 glyphStorage
[firstGlyph
] = glyphStorage
[lastGlyph
- 1];
311 glyphStorage
[firstGlyph
+ 1] = glyphStorage
[lastGlyph
];
313 glyphStorage
[lastGlyph
- 1] = a
;
314 glyphStorage
[lastGlyph
] = b
;
316 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
317 ib
= glyphStorage
.getCharIndex(firstGlyph
+ 1, success
);
318 ic
= glyphStorage
.getCharIndex(lastGlyph
- 1, success
);
319 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
321 glyphStorage
.setCharIndex(firstGlyph
, ic
, success
);
322 glyphStorage
.setCharIndex(firstGlyph
+ 1, id
, success
);
324 glyphStorage
.setCharIndex(lastGlyph
- 1, ia
, success
);
325 glyphStorage
.setCharIndex(lastGlyph
, ib
, success
);
329 a
= glyphStorage
[firstGlyph
];
330 b
= glyphStorage
[firstGlyph
+ 1];
332 glyphStorage
[firstGlyph
] = glyphStorage
[lastGlyph
- 1];
333 glyphStorage
[firstGlyph
+ 1] = glyphStorage
[lastGlyph
];
335 glyphStorage
[lastGlyph
- 1] = b
;
336 glyphStorage
[lastGlyph
] = a
;
338 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
339 ib
= glyphStorage
.getCharIndex(firstGlyph
+ 1, success
);
340 ic
= glyphStorage
.getCharIndex(lastGlyph
- 1, success
);
341 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
343 glyphStorage
.setCharIndex(firstGlyph
, ic
, success
);
344 glyphStorage
.setCharIndex(firstGlyph
+ 1, id
, success
);
346 glyphStorage
.setCharIndex(lastGlyph
- 1, ib
, success
);
347 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);
351 a
= glyphStorage
[firstGlyph
];
352 b
= glyphStorage
[firstGlyph
+ 1];
354 glyphStorage
[firstGlyph
] = glyphStorage
[lastGlyph
];
355 glyphStorage
[firstGlyph
+ 1] = glyphStorage
[lastGlyph
- 1];
357 glyphStorage
[lastGlyph
- 1] = a
;
358 glyphStorage
[lastGlyph
] = b
;
360 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
361 ib
= glyphStorage
.getCharIndex(firstGlyph
+ 1, success
);
362 ic
= glyphStorage
.getCharIndex(lastGlyph
- 1, success
);
363 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
365 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
366 glyphStorage
.setCharIndex(firstGlyph
+ 1, ic
, success
);
368 glyphStorage
.setCharIndex(lastGlyph
- 1, ia
, success
);
369 glyphStorage
.setCharIndex(lastGlyph
, ib
, success
);
373 a
= glyphStorage
[firstGlyph
];
374 b
= glyphStorage
[firstGlyph
+ 1];
376 glyphStorage
[firstGlyph
] = glyphStorage
[lastGlyph
];
377 glyphStorage
[firstGlyph
+ 1] = glyphStorage
[lastGlyph
- 1];
379 glyphStorage
[lastGlyph
- 1] = b
;
380 glyphStorage
[lastGlyph
] = a
;
382 ia
= glyphStorage
.getCharIndex(firstGlyph
, success
);
383 ib
= glyphStorage
.getCharIndex(firstGlyph
+ 1, success
);
384 ic
= glyphStorage
.getCharIndex(lastGlyph
- 1, success
);
385 id
= glyphStorage
.getCharIndex(lastGlyph
, success
);
387 glyphStorage
.setCharIndex(firstGlyph
, id
, success
);
388 glyphStorage
.setCharIndex(firstGlyph
+ 1, ic
, success
);
390 glyphStorage
.setCharIndex(lastGlyph
- 1, ib
, success
);
391 glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);