3  * (C) Copyright IBM Corp.  and others 1998-2013 - 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(const MorphSubtableHeader2 
*morphSubtableHeader
) 
  22   : StateTableProcessor2(morphSubtableHeader
) 
  24     indicRearrangementSubtableHeader 
= (const IndicRearrangementSubtableHeader2 
*) morphSubtableHeader
; 
  25     entryTable 
= (const IndicRearrangementStateEntry2 
*) ((char *) &stateTableHeader
->stHeader 
+ entryTableOffset
); 
  28 IndicRearrangementProcessor2::~IndicRearrangementProcessor2() 
  32 void IndicRearrangementProcessor2::beginStateTable() 
  38 le_uint16 
IndicRearrangementProcessor2::processStateEntry(LEGlyphStorage 
&glyphStorage
, le_int32 
&currGlyph
, EntryTableIndex2 index
) 
  40     const IndicRearrangementStateEntry2 
*entry 
= &entryTable
[index
]; 
  41     le_uint16 newState 
= SWAPW(entry
->newStateIndex
); // index to the new state 
  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
)) { 
  58     return newState
; // index to new state 
  61 void IndicRearrangementProcessor2::endStateTable() 
  65 void IndicRearrangementProcessor2::doRearrangementAction(LEGlyphStorage 
&glyphStorage
, IndicRearrangementVerb verb
) const 
  68     le_int32 ia
, ib
, ic
, id
, ix
, x
; 
  69     LEErrorCode success 
= LE_NO_ERROR
; 
  77         a 
= glyphStorage
[firstGlyph
]; 
  78         ia 
= glyphStorage
.getCharIndex(firstGlyph
, success
); 
  81         while (x 
<= lastGlyph
) { 
  82             glyphStorage
[x 
- 1] = glyphStorage
[x
]; 
  83             ix 
= glyphStorage
.getCharIndex(x
, success
); 
  84             glyphStorage
.setCharIndex(x 
- 1, ix
, success
); 
  88         glyphStorage
[lastGlyph
] = a
; 
  89         glyphStorage
.setCharIndex(lastGlyph
, ia
, success
); 
  93         d 
= glyphStorage
[lastGlyph
]; 
  94         id 
= glyphStorage
.getCharIndex(lastGlyph
, success
); 
  97         while (x 
>= firstGlyph
) { 
  98             glyphStorage
[x 
+ 1] = glyphStorage
[x
]; 
  99             ix 
= glyphStorage
.getCharIndex(x
, success
); 
 100             glyphStorage
.setCharIndex(x 
+ 1, ix
, success
); 
 104         glyphStorage
[firstGlyph
] = d
; 
 105         glyphStorage
.setCharIndex(firstGlyph
, id
, success
); 
 109         a 
= glyphStorage
[firstGlyph
]; 
 110         ia 
= glyphStorage
.getCharIndex(firstGlyph
, success
); 
 111         id 
= glyphStorage
.getCharIndex(lastGlyph
,  success
); 
 113         glyphStorage
[firstGlyph
] = glyphStorage
[lastGlyph
]; 
 114         glyphStorage
[lastGlyph
] = a
; 
 116         glyphStorage
.setCharIndex(firstGlyph
, id
, success
); 
 117         glyphStorage
.setCharIndex(lastGlyph
,  ia
, success
); 
 121         a 
= glyphStorage
[firstGlyph
]; 
 122         b 
= glyphStorage
[firstGlyph 
+ 1]; 
 123         ia 
= glyphStorage
.getCharIndex(firstGlyph
, success
); 
 124         ib 
= glyphStorage
.getCharIndex(firstGlyph 
+ 1, success
); 
 127         while (x 
<= lastGlyph
) { 
 128             glyphStorage
[x 
- 2] = glyphStorage
[x
]; 
 129             ix 
= glyphStorage
.getCharIndex(x
, success
); 
 130             glyphStorage
.setCharIndex(x 
- 2, ix
, success
); 
 134         glyphStorage
[lastGlyph 
- 1] = a
; 
 135         glyphStorage
[lastGlyph
] = b
; 
 137         glyphStorage
.setCharIndex(lastGlyph 
- 1, ia
, success
); 
 138         glyphStorage
.setCharIndex(lastGlyph
, ib
, success
); 
 142         a 
= glyphStorage
[firstGlyph
]; 
 143         b 
= glyphStorage
[firstGlyph 
+ 1]; 
 144         ia 
= glyphStorage
.getCharIndex(firstGlyph
, success
); 
 145         ib 
= glyphStorage
.getCharIndex(firstGlyph 
+ 1, success
); 
 148         while (x 
<= lastGlyph
) { 
 149             glyphStorage
[x 
- 2] = glyphStorage
[x
]; 
 150             ix 
= glyphStorage
.getCharIndex(x
, success
); 
 151             glyphStorage
.setCharIndex(x 
- 2, ix
, success
); 
 155         glyphStorage
[lastGlyph 
- 1] = b
; 
 156         glyphStorage
[lastGlyph
] = a
; 
 158         glyphStorage
.setCharIndex(lastGlyph 
- 1, ib
, success
); 
 159         glyphStorage
.setCharIndex(lastGlyph
, ia
, success
); 
 163         c 
= glyphStorage
[lastGlyph 
- 1]; 
 164         d 
= glyphStorage
[lastGlyph
]; 
 165         ic 
= glyphStorage
.getCharIndex(lastGlyph 
- 1, success
); 
 166         id 
= glyphStorage
.getCharIndex(lastGlyph
, success
); 
 169         while (x 
>= firstGlyph
) { 
 170             glyphStorage
[x 
+ 2] = glyphStorage
[x
]; 
 171             ix 
= glyphStorage
.getCharIndex(x
, success
); 
 172             glyphStorage
.setCharIndex(x 
+ 2, ix
, success
); 
 176         glyphStorage
[firstGlyph
] = c
; 
 177         glyphStorage
[firstGlyph 
+ 1] = d
; 
 179         glyphStorage
.setCharIndex(firstGlyph
, ic
, success
); 
 180         glyphStorage
.setCharIndex(firstGlyph 
+ 1, id
, success
); 
 184         c 
= glyphStorage
[lastGlyph 
- 1]; 
 185         d 
= glyphStorage
[lastGlyph
]; 
 186         ic 
= glyphStorage
.getCharIndex(lastGlyph 
- 1, success
); 
 187         id 
= glyphStorage
.getCharIndex(lastGlyph
, success
); 
 190         while (x 
>= firstGlyph
) { 
 191             glyphStorage
[x 
+ 2] = glyphStorage
[x
]; 
 192             ix 
= glyphStorage
.getCharIndex(x
, success
); 
 193             glyphStorage
.setCharIndex(x 
+ 2, ix
, success
); 
 197         glyphStorage
[firstGlyph
] = d
; 
 198         glyphStorage
[firstGlyph 
+ 1] = c
; 
 200         glyphStorage
.setCharIndex(firstGlyph
, id
, success
); 
 201         glyphStorage
.setCharIndex(firstGlyph 
+ 1, ic
, success
); 
 205         a 
= glyphStorage
[firstGlyph
]; 
 206         c 
= glyphStorage
[lastGlyph 
- 1]; 
 207         d 
= glyphStorage
[lastGlyph
]; 
 208         ia 
= glyphStorage
.getCharIndex(firstGlyph
, success
); 
 209         ic 
= glyphStorage
.getCharIndex(lastGlyph 
- 1, success
); 
 210         id 
= glyphStorage
.getCharIndex(lastGlyph
, success
); 
 213         while (x 
> firstGlyph
) { 
 214             glyphStorage
[x 
+ 1] = glyphStorage
[x
]; 
 215             ix 
= glyphStorage
.getCharIndex(x
, success
); 
 216             glyphStorage
.setCharIndex(x 
+ 1, ix
, success
); 
 220         glyphStorage
[firstGlyph
] = c
; 
 221         glyphStorage
[firstGlyph 
+ 1] = d
; 
 222         glyphStorage
[lastGlyph
] = a
; 
 224         glyphStorage
.setCharIndex(firstGlyph
, ic
, success
); 
 225         glyphStorage
.setCharIndex(firstGlyph 
+ 1, id
, success
); 
 226         glyphStorage
.setCharIndex(lastGlyph
, ia
, success
); 
 230         a 
= glyphStorage
[firstGlyph
]; 
 231         c 
= glyphStorage
[lastGlyph 
- 1]; 
 232         d 
= glyphStorage
[lastGlyph
]; 
 233         ia 
= glyphStorage
.getCharIndex(firstGlyph
, success
); 
 234         ic 
= glyphStorage
.getCharIndex(lastGlyph 
- 1, success
); 
 235         id 
= glyphStorage
.getCharIndex(lastGlyph
, success
); 
 238         while (x 
> firstGlyph
) { 
 239             glyphStorage
[x 
+ 1] = glyphStorage
[x
]; 
 240             ix 
= glyphStorage
.getCharIndex(x
, success
); 
 241             glyphStorage
.setCharIndex(x 
+ 1, ix
, success
); 
 245         glyphStorage
[firstGlyph
] = d
; 
 246         glyphStorage
[firstGlyph 
+ 1] = c
; 
 247         glyphStorage
[lastGlyph
] = a
; 
 249         glyphStorage
.setCharIndex(firstGlyph
, id
, success
); 
 250         glyphStorage
.setCharIndex(firstGlyph 
+ 1, ic
, success
); 
 251         glyphStorage
.setCharIndex(lastGlyph
, ia
, success
); 
 255         a 
= glyphStorage
[firstGlyph
]; 
 256         b 
= glyphStorage
[firstGlyph 
+ 1]; 
 257         d 
= glyphStorage
[lastGlyph
]; 
 258         ia 
= glyphStorage
.getCharIndex(firstGlyph
, success
); 
 259         ib 
= glyphStorage
.getCharIndex(firstGlyph 
+ 1, success
); 
 260         id 
= glyphStorage
.getCharIndex(lastGlyph
, success
); 
 263         while (x 
< lastGlyph
) { 
 264             glyphStorage
[x 
- 2] = glyphStorage
[x
]; 
 265             ix 
= glyphStorage
.getCharIndex(x
, success
); 
 266             glyphStorage
.setCharIndex(x 
- 2, ix
, success
); 
 270         glyphStorage
[firstGlyph
] = d
; 
 271         glyphStorage
[lastGlyph 
- 1] = a
; 
 272         glyphStorage
[lastGlyph
] = b
; 
 274         glyphStorage
.setCharIndex(firstGlyph
, id
, success
); 
 275         glyphStorage
.setCharIndex(lastGlyph 
- 1, ia
, success
); 
 276         glyphStorage
.setCharIndex(lastGlyph
, ib
, success
); 
 280         a 
= glyphStorage
[firstGlyph
]; 
 281         b 
= glyphStorage
[firstGlyph 
+ 1]; 
 282         d 
= glyphStorage
[lastGlyph
]; 
 283         ia 
= glyphStorage
.getCharIndex(firstGlyph
, success
); 
 284         ib 
= glyphStorage
.getCharIndex(firstGlyph 
+ 1, success
); 
 285         id 
= glyphStorage
.getCharIndex(lastGlyph
, success
); 
 288         while (x 
< lastGlyph
) { 
 289             glyphStorage
[x 
- 2] = glyphStorage
[x
]; 
 290             ix 
= glyphStorage
.getCharIndex(x
, success
); 
 291             glyphStorage
.setCharIndex(x 
- 2, ix
, success
); 
 295         glyphStorage
[firstGlyph
] = d
; 
 296         glyphStorage
[lastGlyph 
- 1] = b
; 
 297         glyphStorage
[lastGlyph
] = a
; 
 299         glyphStorage
.setCharIndex(firstGlyph
, id
, success
); 
 300         glyphStorage
.setCharIndex(lastGlyph 
- 1, ib
, success
); 
 301         glyphStorage
.setCharIndex(lastGlyph
, ia
, success
); 
 305         a 
= glyphStorage
[firstGlyph
]; 
 306         b 
= glyphStorage
[firstGlyph 
+ 1]; 
 308         glyphStorage
[firstGlyph
] = glyphStorage
[lastGlyph 
- 1]; 
 309         glyphStorage
[firstGlyph 
+ 1] = glyphStorage
[lastGlyph
]; 
 311         glyphStorage
[lastGlyph 
- 1] = a
; 
 312         glyphStorage
[lastGlyph
] = b
; 
 314         ia 
= glyphStorage
.getCharIndex(firstGlyph
, success
); 
 315         ib 
= glyphStorage
.getCharIndex(firstGlyph 
+ 1, success
); 
 316         ic 
= glyphStorage
.getCharIndex(lastGlyph 
- 1, success
); 
 317         id 
= glyphStorage
.getCharIndex(lastGlyph
, success
); 
 319         glyphStorage
.setCharIndex(firstGlyph
, ic
, success
); 
 320         glyphStorage
.setCharIndex(firstGlyph 
+ 1, id
, success
); 
 322         glyphStorage
.setCharIndex(lastGlyph 
- 1, ia
, success
); 
 323         glyphStorage
.setCharIndex(lastGlyph
, ib
, success
); 
 327         a 
= glyphStorage
[firstGlyph
]; 
 328         b 
= glyphStorage
[firstGlyph 
+ 1]; 
 330         glyphStorage
[firstGlyph
] = glyphStorage
[lastGlyph 
- 1]; 
 331         glyphStorage
[firstGlyph 
+ 1] = glyphStorage
[lastGlyph
]; 
 333         glyphStorage
[lastGlyph 
- 1] = b
; 
 334         glyphStorage
[lastGlyph
] = a
; 
 336         ia 
= glyphStorage
.getCharIndex(firstGlyph
, success
); 
 337         ib 
= glyphStorage
.getCharIndex(firstGlyph 
+ 1, success
); 
 338         ic 
= glyphStorage
.getCharIndex(lastGlyph 
- 1, success
); 
 339         id 
= glyphStorage
.getCharIndex(lastGlyph
, success
); 
 341         glyphStorage
.setCharIndex(firstGlyph
, ic
, success
); 
 342         glyphStorage
.setCharIndex(firstGlyph 
+ 1, id
, success
); 
 344         glyphStorage
.setCharIndex(lastGlyph 
- 1, ib
, success
); 
 345         glyphStorage
.setCharIndex(lastGlyph
, ia
, success
); 
 349         a 
= glyphStorage
[firstGlyph
]; 
 350         b 
= glyphStorage
[firstGlyph 
+ 1]; 
 352         glyphStorage
[firstGlyph
] = glyphStorage
[lastGlyph
]; 
 353         glyphStorage
[firstGlyph 
+ 1] = glyphStorage
[lastGlyph 
- 1]; 
 355         glyphStorage
[lastGlyph 
- 1] = a
; 
 356         glyphStorage
[lastGlyph
] = b
; 
 358         ia 
= glyphStorage
.getCharIndex(firstGlyph
, success
); 
 359         ib 
= glyphStorage
.getCharIndex(firstGlyph 
+ 1, success
); 
 360         ic 
= glyphStorage
.getCharIndex(lastGlyph 
- 1, success
); 
 361         id 
= glyphStorage
.getCharIndex(lastGlyph
, success
); 
 363         glyphStorage
.setCharIndex(firstGlyph
, id
, success
); 
 364         glyphStorage
.setCharIndex(firstGlyph 
+ 1, ic
, success
); 
 366         glyphStorage
.setCharIndex(lastGlyph 
- 1, ia
, success
); 
 367         glyphStorage
.setCharIndex(lastGlyph
, ib
, success
); 
 371         a 
= glyphStorage
[firstGlyph
]; 
 372         b 
= glyphStorage
[firstGlyph 
+ 1]; 
 374         glyphStorage
[firstGlyph
] = glyphStorage
[lastGlyph
]; 
 375         glyphStorage
[firstGlyph 
+ 1] = glyphStorage
[lastGlyph 
- 1]; 
 377         glyphStorage
[lastGlyph 
- 1] = b
; 
 378         glyphStorage
[lastGlyph
] = a
; 
 380         ia 
= glyphStorage
.getCharIndex(firstGlyph
, success
); 
 381         ib 
= glyphStorage
.getCharIndex(firstGlyph 
+ 1, success
); 
 382         ic 
= glyphStorage
.getCharIndex(lastGlyph 
- 1, success
); 
 383         id 
= glyphStorage
.getCharIndex(lastGlyph
, success
); 
 385         glyphStorage
.setCharIndex(firstGlyph
, id
, success
); 
 386         glyphStorage
.setCharIndex(firstGlyph 
+ 1, ic
, success
); 
 388         glyphStorage
.setCharIndex(lastGlyph 
- 1, ib
, success
); 
 389         glyphStorage
.setCharIndex(lastGlyph
, ia
, success
);