1 /*
2 *
3 * (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved
4 *
5 */
6
7 #include "LETypes.h"
8 #include "MorphTables.h"
9 #include "StateTables.h"
10 #include "MorphStateTables.h"
11 #include "SubtableProcessor.h"
12 #include "StateTableProcessor.h"
13 #include "LEGlyphStorage.h"
14 #include "LESwaps.h"
15
16 U_NAMESPACE_BEGIN
17
StateTableProcessor()18 StateTableProcessor::StateTableProcessor()
19 {
20 }
21
StateTableProcessor(const LEReferenceTo<MorphSubtableHeader> & morphSubtableHeader,LEErrorCode & success)22 StateTableProcessor::StateTableProcessor(const LEReferenceTo<MorphSubtableHeader> &morphSubtableHeader, LEErrorCode &success)
23 : SubtableProcessor(morphSubtableHeader, success), stateTableHeader(morphSubtableHeader, success),
24 stHeader(stateTableHeader, success, (const StateTableHeader*)&stateTableHeader->stHeader)
25 {
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);
31
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);
36 }
37
~StateTableProcessor()38 StateTableProcessor::~StateTableProcessor()
39 {
40 }
41
process(LEGlyphStorage & glyphStorage,LEErrorCode & success)42 void StateTableProcessor::process(LEGlyphStorage &glyphStorage, LEErrorCode &success)
43 {
44 if (LE_FAILURE(success)) return;
45 LE_STATE_PATIENCE_INIT();
46
47 // Start at state 0
48 // XXX: How do we know when to start at state 1?
49 ByteOffset currentState = stateArrayOffset;
50
51 // XXX: reverse?
52 le_int32 currGlyph = 0;
53 le_int32 glyphCount = glyphStorage.getGlyphCount();
54
55 beginStateTable();
56
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;
63 } else {
64 TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(glyphStorage[currGlyph]);
65
66 if (glyphCode == 0xFFFF) {
67 classCode = classCodeDEL;
68 } else if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) {
69 classCode = classTable->classArray[glyphCode - firstGlyph];
70 }
71 }
72
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);
78 }
79
80 endStateTable();
81 }
82
83 U_NAMESPACE_END
84