os/textandloc/fontservices/textshaperplugin/IcuSource/layout/StateTableProcessor.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/layout/StateTableProcessor.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,77 @@
     1.4 +/*
     1.5 + *
     1.6 + * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
     1.7 + *
     1.8 + */
     1.9 +
    1.10 +#include "LETypes.h"
    1.11 +#include "MorphTables.h"
    1.12 +#include "StateTables.h"
    1.13 +#include "MorphStateTables.h"
    1.14 +#include "SubtableProcessor.h"
    1.15 +#include "StateTableProcessor.h"
    1.16 +#include "LEGlyphStorage.h"
    1.17 +#include "LESwaps.h"
    1.18 +
    1.19 +U_NAMESPACE_BEGIN
    1.20 +
    1.21 +StateTableProcessor::StateTableProcessor()
    1.22 +{
    1.23 +}
    1.24 +
    1.25 +StateTableProcessor::StateTableProcessor(const MorphSubtableHeader *morphSubtableHeader)
    1.26 +  : SubtableProcessor(morphSubtableHeader)
    1.27 +{
    1.28 +    stateTableHeader = (const MorphStateTableHeader *) morphSubtableHeader;
    1.29 +
    1.30 +    stateSize = SWAPW(stateTableHeader->stHeader.stateSize);
    1.31 +    classTableOffset = SWAPW(stateTableHeader->stHeader.classTableOffset);
    1.32 +    stateArrayOffset = SWAPW(stateTableHeader->stHeader.stateArrayOffset);
    1.33 +    entryTableOffset = SWAPW(stateTableHeader->stHeader.entryTableOffset);
    1.34 +
    1.35 +    classTable = (const ClassTable *) ((char *) &stateTableHeader->stHeader + classTableOffset);
    1.36 +    firstGlyph = SWAPW(classTable->firstGlyph);
    1.37 +    lastGlyph  = firstGlyph + SWAPW(classTable->nGlyphs);
    1.38 +}
    1.39 +
    1.40 +StateTableProcessor::~StateTableProcessor()
    1.41 +{
    1.42 +}
    1.43 +
    1.44 +void StateTableProcessor::process(LEGlyphStorage &glyphStorage)
    1.45 +{
    1.46 +    // Start at state 0
    1.47 +    // XXX: How do we know when to start at state 1?
    1.48 +    ByteOffset currentState = stateArrayOffset;
    1.49 +
    1.50 +    // XXX: reverse? 
    1.51 +    le_int32 currGlyph = 0;
    1.52 +    le_int32 glyphCount = glyphStorage.getGlyphCount();
    1.53 +
    1.54 +    beginStateTable();
    1.55 +
    1.56 +    while (currGlyph <= glyphCount) {
    1.57 +        ClassCode classCode = classCodeOOB;
    1.58 +        if (currGlyph == glyphCount) {
    1.59 +            // XXX: How do we handle EOT vs. EOL?
    1.60 +            classCode = classCodeEOT;
    1.61 +        } else {
    1.62 +            TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(glyphStorage[currGlyph]);
    1.63 +
    1.64 +            if (glyphCode == 0xFFFF) {
    1.65 +                classCode = classCodeDEL;
    1.66 +            } else if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) {
    1.67 +                classCode = classTable->classArray[glyphCode - firstGlyph];
    1.68 +            }
    1.69 +        }
    1.70 +
    1.71 +        const EntryTableIndex *stateArray = (const EntryTableIndex *) ((char *) &stateTableHeader->stHeader + currentState);
    1.72 +        EntryTableIndex entryTableIndex = stateArray[(le_uint8)classCode];
    1.73 +
    1.74 +        currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex);
    1.75 +    }
    1.76 +
    1.77 +    endStateTable();
    1.78 +}
    1.79 +
    1.80 +U_NAMESPACE_END