scuffed-code/icu4c/source/layout/IndicRearrangementProcessor.cpp

399 lines
13 KiB
C++
Raw Normal View History

/*
*
* (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
*
*/
#include "LETypes.h"
#include "MorphTables.h"
#include "StateTables.h"
#include "MorphStateTables.h"
#include "SubtableProcessor.h"
#include "StateTableProcessor.h"
#include "IndicRearrangementProcessor.h"
#include "LEGlyphStorage.h"
#include "LESwaps.h"
U_NAMESPACE_BEGIN
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IndicRearrangementProcessor)
IndicRearrangementProcessor::IndicRearrangementProcessor(const MorphSubtableHeader *morphSubtableHeader)
: StateTableProcessor(morphSubtableHeader)
{
indicRearrangementSubtableHeader = (const IndicRearrangementSubtableHeader *) morphSubtableHeader;
entryTable = (const IndicRearrangementStateEntry *) ((char *) &stateTableHeader->stHeader + entryTableOffset);
}
IndicRearrangementProcessor::~IndicRearrangementProcessor()
{
}
void IndicRearrangementProcessor::beginStateTable()
{
firstGlyph = 0;
lastGlyph = 0;
}
ByteOffset IndicRearrangementProcessor::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex index)
{
const IndicRearrangementStateEntry *entry = &entryTable[index];
ByteOffset newState = SWAPW(entry->newStateOffset);
IndicRearrangementFlags flags = (IndicRearrangementFlags) SWAPW(entry->flags);
if (flags & irfMarkFirst) {
firstGlyph = currGlyph;
}
if (flags & irfMarkLast) {
lastGlyph = currGlyph;
}
doRearrangementAction(glyphStorage, (IndicRearrangementVerb) (flags & irfVerbMask));
if (!(flags & irfDontAdvance)) {
// XXX: Should handle reverse too...
currGlyph += 1;
}
return newState;
}
void IndicRearrangementProcessor::endStateTable()
{
}
void IndicRearrangementProcessor::doRearrangementAction(LEGlyphStorage &glyphStorage, IndicRearrangementVerb verb) const
{
LEGlyphID a, b, c, d;
le_int32 ia, ib, ic, id, ix, x;
2004-05-07 23:29:16 +00:00
LEErrorCode success = LE_NO_ERROR;
switch(verb)
{
case irvNoAction:
break;
case irvxA:
a = glyphStorage[firstGlyph];
2004-05-07 23:29:16 +00:00
ia = glyphStorage.getCharIndex(firstGlyph, success);
x = firstGlyph + 1;
while (x <= lastGlyph) {
glyphStorage[x - 1] = glyphStorage[x];
2004-05-07 23:29:16 +00:00
ix = glyphStorage.getCharIndex(x, success);
glyphStorage.setCharIndex(x - 1, ix, success);
x += 1;
}
glyphStorage[lastGlyph] = a;
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(lastGlyph, ia, success);
break;
case irvDx:
d = glyphStorage[lastGlyph];
2004-05-07 23:29:16 +00:00
id = glyphStorage.getCharIndex(lastGlyph, success);
x = lastGlyph - 1;
while (x >= firstGlyph) {
glyphStorage[x + 1] = glyphStorage[x];
2004-05-07 23:29:16 +00:00
ix = glyphStorage.getCharIndex(x, success);
glyphStorage.setCharIndex(x + 1, ix, success);
x -= 1;
}
glyphStorage[firstGlyph] = d;
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(firstGlyph, id, success);
break;
case irvDxA:
a = glyphStorage[firstGlyph];
2004-05-07 23:29:16 +00:00
ia = glyphStorage.getCharIndex(firstGlyph, success);
id = glyphStorage.getCharIndex(lastGlyph, success);
glyphStorage[firstGlyph] = glyphStorage[lastGlyph];
glyphStorage[lastGlyph] = a;
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(firstGlyph, id, success);
glyphStorage.setCharIndex(lastGlyph, ia, success);
break;
case irvxAB:
a = glyphStorage[firstGlyph];
b = glyphStorage[firstGlyph + 1];
2004-05-07 23:29:16 +00:00
ia = glyphStorage.getCharIndex(firstGlyph, success);
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
x = firstGlyph + 2;
while (x <= lastGlyph) {
glyphStorage[x - 2] = glyphStorage[x];
2004-05-07 23:29:16 +00:00
ix = glyphStorage.getCharIndex(x, success);
glyphStorage.setCharIndex(x - 2, ix, success);
x += 1;
}
glyphStorage[lastGlyph - 1] = a;
glyphStorage[lastGlyph] = b;
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
glyphStorage.setCharIndex(lastGlyph, ib, success);
break;
case irvxBA:
a = glyphStorage[firstGlyph];
b = glyphStorage[firstGlyph + 1];
ia = glyphStorage.getCharIndex(firstGlyph, success);
2004-05-07 23:29:16 +00:00
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
x = firstGlyph + 2;
while (x <= lastGlyph) {
glyphStorage[x - 2] = glyphStorage[x];
2004-05-07 23:29:16 +00:00
ix = glyphStorage.getCharIndex(x, success);
glyphStorage.setCharIndex(x - 2, ix, success);
x += 1;
}
glyphStorage[lastGlyph - 1] = b;
glyphStorage[lastGlyph] = a;
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
glyphStorage.setCharIndex(lastGlyph, ia, success);
break;
case irvCDx:
c = glyphStorage[lastGlyph - 1];
d = glyphStorage[lastGlyph];
2004-05-07 23:29:16 +00:00
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
id = glyphStorage.getCharIndex(lastGlyph, success);
x = lastGlyph - 2;
2003-12-18 16:39:17 +00:00
while (x >= firstGlyph) {
glyphStorage[x + 2] = glyphStorage[x];
2004-05-07 23:29:16 +00:00
ix = glyphStorage.getCharIndex(x, success);
glyphStorage.setCharIndex(x + 2, ix, success);
x -= 1;
}
glyphStorage[firstGlyph] = c;
glyphStorage[firstGlyph + 1] = d;
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(firstGlyph, ic, success);
glyphStorage.setCharIndex(firstGlyph + 1, id, success);
break;
case irvDCx:
c = glyphStorage[lastGlyph - 1];
d = glyphStorage[lastGlyph];
2004-05-07 23:29:16 +00:00
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
id = glyphStorage.getCharIndex(lastGlyph, success);
x = lastGlyph - 2;
2003-12-18 16:39:17 +00:00
while (x >= firstGlyph) {
glyphStorage[x + 2] = glyphStorage[x];
2004-05-07 23:29:16 +00:00
ix = glyphStorage.getCharIndex(x, success);
glyphStorage.setCharIndex(x + 2, ix, success);
x -= 1;
}
glyphStorage[firstGlyph] = d;
glyphStorage[firstGlyph + 1] = c;
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(firstGlyph, id, success);
glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
break;
case irvCDxA:
a = glyphStorage[firstGlyph];
c = glyphStorage[lastGlyph - 1];
d = glyphStorage[lastGlyph];
2004-05-07 23:29:16 +00:00
ia = glyphStorage.getCharIndex(firstGlyph, success);
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
id = glyphStorage.getCharIndex(lastGlyph, success);
x = lastGlyph - 2;
while (x > firstGlyph) {
glyphStorage[x + 1] = glyphStorage[x];
2004-05-07 23:29:16 +00:00
ix = glyphStorage.getCharIndex(x, success);
glyphStorage.setCharIndex(x + 1, ix, success);
x -= 1;
}
glyphStorage[firstGlyph] = c;
glyphStorage[firstGlyph + 1] = d;
glyphStorage[lastGlyph] = a;
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(firstGlyph, ic, success);
glyphStorage.setCharIndex(firstGlyph + 1, id, success);
glyphStorage.setCharIndex(lastGlyph, ia, success);
break;
case irvDCxA:
a = glyphStorage[firstGlyph];
c = glyphStorage[lastGlyph - 1];
d = glyphStorage[lastGlyph];
2004-05-07 23:29:16 +00:00
ia = glyphStorage.getCharIndex(firstGlyph, success);
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
id = glyphStorage.getCharIndex(lastGlyph, success);
x = lastGlyph - 2;
while (x > firstGlyph) {
glyphStorage[x + 1] = glyphStorage[x];
2004-05-07 23:29:16 +00:00
ix = glyphStorage.getCharIndex(x, success);
glyphStorage.setCharIndex(x + 1, ix, success);
x -= 1;
}
glyphStorage[firstGlyph] = d;
glyphStorage[firstGlyph + 1] = c;
glyphStorage[lastGlyph] = a;
glyphStorage.setCharIndex(firstGlyph, id, success);
glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
glyphStorage.setCharIndex(lastGlyph, ia, success);
break;
case irvDxAB:
a = glyphStorage[firstGlyph];
b = glyphStorage[firstGlyph + 1];
d = glyphStorage[lastGlyph];
2004-05-07 23:29:16 +00:00
ia = glyphStorage.getCharIndex(firstGlyph, success);
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
id = glyphStorage.getCharIndex(lastGlyph, success);
x = firstGlyph + 2;
while (x < lastGlyph) {
glyphStorage[x - 2] = glyphStorage[x];
2004-05-07 23:29:16 +00:00
ix = glyphStorage.getCharIndex(x, success);
glyphStorage.setCharIndex(x - 2, ix, success);
x += 1;
}
glyphStorage[firstGlyph] = d;
glyphStorage[lastGlyph - 1] = a;
glyphStorage[lastGlyph] = b;
glyphStorage.setCharIndex(firstGlyph, id, success);
glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
glyphStorage.setCharIndex(lastGlyph, ib, success);
break;
case irvDxBA:
a = glyphStorage[firstGlyph];
b = glyphStorage[firstGlyph + 1];
d = glyphStorage[lastGlyph];
2004-05-07 23:29:16 +00:00
ia = glyphStorage.getCharIndex(firstGlyph, success);
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
id = glyphStorage.getCharIndex(lastGlyph, success);
x = firstGlyph + 2;
while (x < lastGlyph) {
glyphStorage[x - 2] = glyphStorage[x];
2004-05-07 23:29:16 +00:00
ix = glyphStorage.getCharIndex(x, success);
glyphStorage.setCharIndex(x - 2, ix, success);
x += 1;
}
glyphStorage[firstGlyph] = d;
glyphStorage[lastGlyph - 1] = b;
glyphStorage[lastGlyph] = a;
glyphStorage.setCharIndex(firstGlyph, id, success);
glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
glyphStorage.setCharIndex(lastGlyph, ia, success);
break;
case irvCDxAB:
a = glyphStorage[firstGlyph];
b = glyphStorage[firstGlyph + 1];
glyphStorage[firstGlyph] = glyphStorage[lastGlyph - 1];
glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph];
glyphStorage[lastGlyph - 1] = a;
glyphStorage[lastGlyph] = b;
2004-05-07 23:29:16 +00:00
ia = glyphStorage.getCharIndex(firstGlyph, success);
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
2004-05-07 23:29:16 +00:00
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
id = glyphStorage.getCharIndex(lastGlyph, success);
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(firstGlyph, ic, success);
glyphStorage.setCharIndex(firstGlyph + 1, id, success);
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
glyphStorage.setCharIndex(lastGlyph, ib, success);
break;
case irvCDxBA:
a = glyphStorage[firstGlyph];
b = glyphStorage[firstGlyph + 1];
glyphStorage[firstGlyph] = glyphStorage[lastGlyph - 1];
glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph];
glyphStorage[lastGlyph - 1] = b;
glyphStorage[lastGlyph] = a;
2004-05-07 23:29:16 +00:00
ia = glyphStorage.getCharIndex(firstGlyph, success);
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
2004-05-07 23:29:16 +00:00
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
id = glyphStorage.getCharIndex(lastGlyph, success);
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(firstGlyph, ic, success);
glyphStorage.setCharIndex(firstGlyph + 1, id, success);
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
glyphStorage.setCharIndex(lastGlyph, ia, success);
break;
case irvDCxAB:
a = glyphStorage[firstGlyph];
b = glyphStorage[firstGlyph + 1];
glyphStorage[firstGlyph] = glyphStorage[lastGlyph];
glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph - 1];
glyphStorage[lastGlyph - 1] = a;
glyphStorage[lastGlyph] = b;
2004-05-07 23:29:16 +00:00
ia = glyphStorage.getCharIndex(firstGlyph, success);
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
2004-05-07 23:29:16 +00:00
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
id = glyphStorage.getCharIndex(lastGlyph, success);
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(firstGlyph, id, success);
glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
glyphStorage.setCharIndex(lastGlyph, ib, success);
break;
case irvDCxBA:
a = glyphStorage[firstGlyph];
b = glyphStorage[firstGlyph + 1];
glyphStorage[firstGlyph] = glyphStorage[lastGlyph];
glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph - 1];
glyphStorage[lastGlyph - 1] = b;
glyphStorage[lastGlyph] = a;
2004-05-07 23:29:16 +00:00
ia = glyphStorage.getCharIndex(firstGlyph, success);
ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
2004-05-07 23:29:16 +00:00
ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
id = glyphStorage.getCharIndex(lastGlyph, success);
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(firstGlyph, id, success);
glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
2004-05-07 23:29:16 +00:00
glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
glyphStorage.setCharIndex(lastGlyph, ia, success);
break;
default:
break;
}
}
U_NAMESPACE_END