]>
Commit | Line | Data |
---|---|---|
b75a7d8f | 1 | /* |
b75a7d8f | 2 | * |
57a6839d | 3 | * (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved |
b75a7d8f A |
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" | |
374ca955 | 13 | #include "LEGlyphStorage.h" |
b75a7d8f A |
14 | #include "LESwaps.h" |
15 | ||
16 | U_NAMESPACE_BEGIN | |
17 | ||
18 | StateTableProcessor::StateTableProcessor() | |
19 | { | |
20 | } | |
21 | ||
57a6839d A |
22 | StateTableProcessor::StateTableProcessor(const LEReferenceTo<MorphSubtableHeader> &morphSubtableHeader, LEErrorCode &success) |
23 | : SubtableProcessor(morphSubtableHeader, success), stateTableHeader(morphSubtableHeader, success), | |
24 | stHeader(stateTableHeader, success, (const StateTableHeader*)&stateTableHeader->stHeader) | |
b75a7d8f | 25 | { |
57a6839d | 26 | if(LE_FAILURE(success)) return; |
b75a7d8f A |
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 | ||
57a6839d A |
32 | classTable = LEReferenceTo<ClassTable>(stateTableHeader, success, ((char *) &stateTableHeader->stHeader + classTableOffset)); |
33 | if(LE_FAILURE(success)) return; | |
b75a7d8f A |
34 | firstGlyph = SWAPW(classTable->firstGlyph); |
35 | lastGlyph = firstGlyph + SWAPW(classTable->nGlyphs); | |
36 | } | |
37 | ||
38 | StateTableProcessor::~StateTableProcessor() | |
39 | { | |
40 | } | |
41 | ||
57a6839d | 42 | void StateTableProcessor::process(LEGlyphStorage &glyphStorage, LEErrorCode &success) |
b75a7d8f | 43 | { |
57a6839d A |
44 | if (LE_FAILURE(success)) return; |
45 | LE_STATE_PATIENCE_INIT(); | |
46 | ||
b75a7d8f A |
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; | |
374ca955 | 53 | le_int32 glyphCount = glyphStorage.getGlyphCount(); |
b75a7d8f A |
54 | |
55 | beginStateTable(); | |
56 | ||
57 | while (currGlyph <= glyphCount) { | |
57a6839d | 58 | if(LE_STATE_PATIENCE_DECR()) break; // patience exceeded. |
b75a7d8f A |
59 | ClassCode classCode = classCodeOOB; |
60 | if (currGlyph == glyphCount) { | |
61 | // XXX: How do we handle EOT vs. EOL? | |
62 | classCode = classCodeEOT; | |
63 | } else { | |
374ca955 | 64 | TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(glyphStorage[currGlyph]); |
b75a7d8f A |
65 | |
66 | if (glyphCode == 0xFFFF) { | |
67 | classCode = classCodeDEL; | |
68 | } else if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) { | |
69 | classCode = classTable->classArray[glyphCode - firstGlyph]; | |
70 | } | |
71 | } | |
72 | ||
57a6839d A |
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); | |
374ca955 | 76 | currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex); |
57a6839d | 77 | LE_STATE_PATIENCE_INCR(currGlyph); |
b75a7d8f A |
78 | } |
79 | ||
80 | endStateTable(); | |
81 | } | |
82 | ||
83 | U_NAMESPACE_END |