3 * (C) Copyright IBM Corp. 1998-2013 - 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 "LEGlyphStorage.h"
18 StateTableProcessor::StateTableProcessor()
22 StateTableProcessor::StateTableProcessor(const LEReferenceTo
<MorphSubtableHeader
> &morphSubtableHeader
, LEErrorCode
&success
)
23 : SubtableProcessor(morphSubtableHeader
, success
), stateTableHeader(morphSubtableHeader
, success
),
24 stHeader(stateTableHeader
, success
, (const StateTableHeader
*)&stateTableHeader
->stHeader
)
26 if(LE_FAILURE(success
)) return;
27 stateSize
= SWAPW(stateTableHeader
->stHeader
.stateSize
);
28 classTableOffset
= SWAPW(stateTableHeader
->stHeader
.classTableOffset
);
29 stateArrayOffset
= SWAPW(stateTableHeader
->stHeader
.stateArrayOffset
);
30 entryTableOffset
= SWAPW(stateTableHeader
->stHeader
.entryTableOffset
);
32 classTable
= LEReferenceTo
<ClassTable
>(stateTableHeader
, success
, ((char *) &stateTableHeader
->stHeader
+ classTableOffset
));
33 if(LE_FAILURE(success
)) return;
34 firstGlyph
= SWAPW(classTable
->firstGlyph
);
35 lastGlyph
= firstGlyph
+ SWAPW(classTable
->nGlyphs
);
38 StateTableProcessor::~StateTableProcessor()
42 void StateTableProcessor::process(LEGlyphStorage
&glyphStorage
, LEErrorCode
&success
)
44 if (LE_FAILURE(success
)) return;
45 LE_STATE_PATIENCE_INIT();
48 // XXX: How do we know when to start at state 1?
49 ByteOffset currentState
= stateArrayOffset
;
52 le_int32 currGlyph
= 0;
53 le_int32 glyphCount
= glyphStorage
.getGlyphCount();
57 while (currGlyph
<= glyphCount
) {
58 if(LE_STATE_PATIENCE_DECR()) break; // patience exceeded.
59 ClassCode classCode
= classCodeOOB
;
60 if (currGlyph
== glyphCount
) {
61 // XXX: How do we handle EOT vs. EOL?
62 classCode
= classCodeEOT
;
64 TTGlyphID glyphCode
= (TTGlyphID
) LE_GET_GLYPH(glyphStorage
[currGlyph
]);
66 if (glyphCode
== 0xFFFF) {
67 classCode
= classCodeDEL
;
68 } else if ((glyphCode
>= firstGlyph
) && (glyphCode
< lastGlyph
)) {
69 classCode
= classTable
->classArray
[glyphCode
- firstGlyph
];
73 LEReferenceToArrayOf
<EntryTableIndex
> stateArray(stHeader
, success
, currentState
, LE_UNBOUNDED_ARRAY
);
74 EntryTableIndex entryTableIndex
= stateArray
.getObject((le_uint8
)classCode
, success
);
75 LE_STATE_PATIENCE_CURR(le_int32
, currGlyph
);
76 currentState
= processStateEntry(glyphStorage
, currGlyph
, entryTableIndex
);
77 LE_STATE_PATIENCE_INCR(currGlyph
);