]> git.saurik.com Git - apple/icu.git/blob - icuSources/layout/ContextualGlyphSubstProc.cpp
ICU-6.2.22.tar.gz
[apple/icu.git] / icuSources / layout / ContextualGlyphSubstProc.cpp
1 /*
2 *
3 * (C) Copyright IBM Corp. 1998-2004 - 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 "ContextualGlyphSubstProc.h"
14 #include "LEGlyphStorage.h"
15 #include "LESwaps.h"
16
17 U_NAMESPACE_BEGIN
18
19 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ContextualGlyphSubstitutionProcessor)
20
21 ContextualGlyphSubstitutionProcessor::ContextualGlyphSubstitutionProcessor(const MorphSubtableHeader *morphSubtableHeader)
22 : StateTableProcessor(morphSubtableHeader)
23 {
24 contextualGlyphSubstitutionHeader = (const ContextualGlyphSubstitutionHeader *) morphSubtableHeader;
25 substitutionTableOffset = SWAPW(contextualGlyphSubstitutionHeader->substitutionTableOffset);
26
27 entryTable = (const ContextualGlyphSubstitutionStateEntry *) ((char *) &stateTableHeader->stHeader + entryTableOffset);
28 }
29
30 ContextualGlyphSubstitutionProcessor::~ContextualGlyphSubstitutionProcessor()
31 {
32 }
33
34 void ContextualGlyphSubstitutionProcessor::beginStateTable()
35 {
36 markGlyph = 0;
37 }
38
39 ByteOffset ContextualGlyphSubstitutionProcessor::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex index)
40 {
41 const ContextualGlyphSubstitutionStateEntry *entry = &entryTable[index];
42 ByteOffset newState = SWAPW(entry->newStateOffset);
43 le_int16 flags = SWAPW(entry->flags);
44 WordOffset markOffset = SWAPW(entry->markOffset);
45 WordOffset currOffset = SWAPW(entry->currOffset);
46
47 if (markOffset != 0) {
48 const le_int16 *table = (const le_int16 *) ((char *) &stateTableHeader->stHeader + markOffset * 2);
49 LEGlyphID mGlyph = glyphStorage[markGlyph];
50 TTGlyphID newGlyph = SWAPW(table[LE_GET_GLYPH(mGlyph)]);
51
52 glyphStorage[markGlyph] = LE_SET_GLYPH(mGlyph, newGlyph);
53 }
54
55 if (currOffset != 0) {
56 const le_int16 *table = (const le_int16 *) ((char *) &stateTableHeader->stHeader + currOffset * 2);
57 LEGlyphID thisGlyph = glyphStorage[currGlyph];
58 TTGlyphID newGlyph = SWAPW(table[LE_GET_GLYPH(thisGlyph)]);
59
60 glyphStorage[currGlyph] = LE_SET_GLYPH(thisGlyph, newGlyph);
61 }
62
63 if (flags & cgsSetMark) {
64 markGlyph = currGlyph;
65 }
66
67 if (!(flags & cgsDontAdvance)) {
68 // should handle reverse too!
69 currGlyph += 1;
70 }
71
72 return newState;
73 }
74
75 void ContextualGlyphSubstitutionProcessor::endStateTable()
76 {
77 }
78
79 U_NAMESPACE_END