]>
Commit | Line | Data |
---|---|---|
51004dcb A |
1 | /* |
2 | * | |
3 | * (C) Copyright IBM Corp. and others 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 "SubtableProcessor2.h" | |
12 | #include "StateTableProcessor2.h" | |
13 | #include "ContextualGlyphSubstProc2.h" | |
14 | #include "LEGlyphStorage.h" | |
15 | #include "LESwaps.h" | |
51004dcb A |
16 | |
17 | U_NAMESPACE_BEGIN | |
18 | ||
19 | UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ContextualGlyphSubstitutionProcessor2) | |
20 | ||
57a6839d A |
21 | ContextualGlyphSubstitutionProcessor2::ContextualGlyphSubstitutionProcessor2( |
22 | const LEReferenceTo<MorphSubtableHeader2> &morphSubtableHeader, LEErrorCode &success) | |
23 | : StateTableProcessor2(morphSubtableHeader, success), contextualGlyphHeader(morphSubtableHeader, success) | |
51004dcb | 24 | { |
57a6839d | 25 | if(LE_FAILURE(success)) return; |
51004dcb | 26 | le_uint32 perGlyphTableOffset = SWAPL(contextualGlyphHeader->perGlyphTableOffset); |
57a6839d A |
27 | perGlyphTable = LEReferenceToArrayOf<le_uint32> (stHeader, success, perGlyphTableOffset, LE_UNBOUNDED_ARRAY); |
28 | entryTable = LEReferenceToArrayOf<ContextualGlyphStateEntry2>(stHeader, success, entryTableOffset, LE_UNBOUNDED_ARRAY); | |
51004dcb A |
29 | } |
30 | ||
31 | ContextualGlyphSubstitutionProcessor2::~ContextualGlyphSubstitutionProcessor2() | |
32 | { | |
33 | } | |
34 | ||
35 | void ContextualGlyphSubstitutionProcessor2::beginStateTable() | |
36 | { | |
37 | markGlyph = 0; | |
38 | } | |
39 | ||
57a6839d A |
40 | le_uint16 ContextualGlyphSubstitutionProcessor2::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, |
41 | EntryTableIndex2 index, LEErrorCode &success) | |
51004dcb | 42 | { |
57a6839d A |
43 | if(LE_FAILURE(success)) return 0; |
44 | const ContextualGlyphStateEntry2 *entry = entryTable.getAlias(index, success); | |
45 | if(LE_FAILURE(success)) return 0; | |
51004dcb A |
46 | le_uint16 newState = SWAPW(entry->newStateIndex); |
47 | le_uint16 flags = SWAPW(entry->flags); | |
48 | le_int16 markIndex = SWAPW(entry->markIndex); | |
49 | le_int16 currIndex = SWAPW(entry->currIndex); | |
50 | ||
51 | if (markIndex != -1) { | |
57a6839d | 52 | le_uint32 offset = SWAPL(perGlyphTable(markIndex, success)); |
51004dcb | 53 | LEGlyphID mGlyph = glyphStorage[markGlyph]; |
57a6839d | 54 | TTGlyphID newGlyph = lookup(offset, mGlyph, success); |
51004dcb A |
55 | glyphStorage[markGlyph] = LE_SET_GLYPH(mGlyph, newGlyph); |
56 | } | |
57 | ||
58 | if (currIndex != -1) { | |
57a6839d | 59 | le_uint32 offset = SWAPL(perGlyphTable(currIndex, success)); |
51004dcb | 60 | LEGlyphID thisGlyph = glyphStorage[currGlyph]; |
57a6839d | 61 | TTGlyphID newGlyph = lookup(offset, thisGlyph, success); |
51004dcb A |
62 | glyphStorage[currGlyph] = LE_SET_GLYPH(thisGlyph, newGlyph); |
63 | } | |
64 | ||
65 | if (flags & cgsSetMark) { | |
66 | markGlyph = currGlyph; | |
67 | } | |
68 | ||
69 | if (!(flags & cgsDontAdvance)) { | |
70 | currGlyph += dir; | |
71 | } | |
72 | ||
73 | return newState; | |
74 | } | |
75 | ||
57a6839d | 76 | TTGlyphID ContextualGlyphSubstitutionProcessor2::lookup(le_uint32 offset, LEGlyphID gid, LEErrorCode &success) |
51004dcb | 77 | { |
51004dcb | 78 | TTGlyphID newGlyph = 0xFFFF; |
57a6839d A |
79 | if(LE_FAILURE(success)) return newGlyph; |
80 | LEReferenceTo<LookupTable> lookupTable(perGlyphTable, success, offset); | |
81 | if(LE_FAILURE(success)) return newGlyph; | |
82 | le_int16 format = SWAPW(lookupTable->format); | |
51004dcb A |
83 | |
84 | switch (format) { | |
85 | case ltfSimpleArray: { | |
86 | #ifdef TEST_FORMAT | |
87 | // Disabled pending for design review | |
57a6839d A |
88 | LEReferenceTo<SimpleArrayLookupTable> lookupTable0(lookupTable, success); |
89 | LEReferenceToArrayOf<LookupValue> valueArray(lookupTable0, success, &lookupTable0->valueArray[0], LE_UNBOUNDED_ARRAY); | |
90 | if(LE_FAILURE(success)) return newGlyph; | |
51004dcb | 91 | TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid); |
57a6839d | 92 | newGlyph = SWAPW(lookupTable0->valueArray(glyphCode, success)); |
51004dcb A |
93 | #endif |
94 | break; | |
95 | } | |
96 | case ltfSegmentSingle: { | |
97 | #ifdef TEST_FORMAT | |
98 | // Disabled pending for design review | |
57a6839d | 99 | LEReferenceTo<SegmentSingleLookupTable> lookupTable2 = (SegmentSingleLookupTable *) lookupTable; |
51004dcb A |
100 | const LookupSegment *segment = lookupTable2->lookupSegment(lookupTable2->segments, gid); |
101 | if (segment != NULL) { | |
102 | newGlyph = SWAPW(segment->value); | |
103 | } | |
104 | #endif | |
105 | break; | |
106 | } | |
107 | case ltfSegmentArray: { | |
57a6839d | 108 | //printf("Context Lookup Table Format4: specific interpretation needed!\n"); |
51004dcb A |
109 | break; |
110 | } | |
111 | case ltfSingleTable: | |
112 | { | |
113 | #ifdef TEST_FORMAT | |
114 | // Disabled pending for design review | |
57a6839d A |
115 | LEReferenceTo<SingleTableLookupTable> lookupTable6 = (SingleTableLookupTable *) lookupTable; |
116 | const LEReferenceTo<LookupSingle> segment = lookupTable6->lookupSingle(lookupTable6->entries, gid); | |
51004dcb A |
117 | if (segment != NULL) { |
118 | newGlyph = SWAPW(segment->value); | |
119 | } | |
120 | #endif | |
121 | break; | |
122 | } | |
123 | case ltfTrimmedArray: { | |
57a6839d A |
124 | LEReferenceTo<TrimmedArrayLookupTable> lookupTable8(lookupTable, success); |
125 | if (LE_FAILURE(success)) return newGlyph; | |
51004dcb | 126 | TTGlyphID firstGlyph = SWAPW(lookupTable8->firstGlyph); |
57a6839d A |
127 | TTGlyphID glyphCount = SWAPW(lookupTable8->glyphCount); |
128 | TTGlyphID lastGlyph = firstGlyph + glyphCount; | |
51004dcb A |
129 | TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid); |
130 | if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) { | |
57a6839d A |
131 | LEReferenceToArrayOf<LookupValue> valueArray(lookupTable8, success, &lookupTable8->valueArray[0], glyphCount); |
132 | newGlyph = SWAPW(valueArray(glyphCode - firstGlyph, success)); | |
51004dcb A |
133 | } |
134 | } | |
135 | default: | |
136 | break; | |
137 | } | |
138 | return newGlyph; | |
139 | } | |
140 | ||
141 | void ContextualGlyphSubstitutionProcessor2::endStateTable() | |
142 | { | |
143 | } | |
144 | ||
145 | U_NAMESPACE_END |