3 * (C) Copyright IBM Corp. and others 1998-2016 - All Rights Reserved
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"
19 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ContextualGlyphSubstitutionProcessor2)
21 ContextualGlyphSubstitutionProcessor2::ContextualGlyphSubstitutionProcessor2(
22 const LEReferenceTo<MorphSubtableHeader2> &morphSubtableHeader, LEErrorCode &success)
23 : StateTableProcessor2(morphSubtableHeader, success), contextualGlyphHeader(morphSubtableHeader, success)
25 if(LE_FAILURE(success)) return;
26 le_uint32 perGlyphTableOffset = SWAPL(contextualGlyphHeader->perGlyphTableOffset);
27 perGlyphTable = LEReferenceToArrayOf<le_uint32> (stHeader, success, perGlyphTableOffset, LE_UNBOUNDED_ARRAY);
28 entryTable = LEReferenceToArrayOf<ContextualGlyphStateEntry2>(stHeader, success, entryTableOffset, LE_UNBOUNDED_ARRAY);
31 ContextualGlyphSubstitutionProcessor2::~ContextualGlyphSubstitutionProcessor2()
35 void ContextualGlyphSubstitutionProcessor2::beginStateTable()
40 le_uint16 ContextualGlyphSubstitutionProcessor2::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph,
41 EntryTableIndex2 index, LEErrorCode &success)
43 if(LE_FAILURE(success)) return 0;
44 const ContextualGlyphStateEntry2 *entry = entryTable.getAlias(index, success);
45 if(LE_FAILURE(success)) return 0;
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);
51 if (markIndex != -1) {
52 le_uint32 offset = SWAPL(perGlyphTable(markIndex, success));
53 LEGlyphID mGlyph = glyphStorage[markGlyph];
54 TTGlyphID newGlyph = lookup(offset, mGlyph, success);
55 glyphStorage[markGlyph] = LE_SET_GLYPH(mGlyph, newGlyph);
58 if (currIndex != -1) {
59 le_uint32 offset = SWAPL(perGlyphTable(currIndex, success));
60 LEGlyphID thisGlyph = glyphStorage[currGlyph];
61 TTGlyphID newGlyph = lookup(offset, thisGlyph, success);
62 glyphStorage[currGlyph] = LE_SET_GLYPH(thisGlyph, newGlyph);
65 if (flags & cgsSetMark) {
66 markGlyph = currGlyph;
69 if (!(flags & cgsDontAdvance)) {
76 TTGlyphID ContextualGlyphSubstitutionProcessor2::lookup(le_uint32 offset, LEGlyphID gid, LEErrorCode &success)
78 TTGlyphID newGlyph = 0xFFFF;
79 if(LE_FAILURE(success)) return newGlyph;
80 LEReferenceTo<LookupTableBase> lookupTable(perGlyphTable, success, offset);
81 if(LE_FAILURE(success)) return newGlyph;
82 le_int16 format = SWAPW(lookupTable->format);
85 case ltfSimpleArray: {
87 // Disabled pending for design review
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;
91 TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
92 newGlyph = SWAPW(lookupTable0->valueArray(glyphCode, success));
96 case ltfSegmentSingle: {
98 // Disabled pending for design review
99 LEReferenceTo<SegmentSingleLookupTable> lookupTable2 = (SegmentSingleLookupTable *) lookupTable;
100 const LookupSegment *segment = lookupTable2->lookupSegment(lookupTable2->segments, gid);
101 if (segment != NULL) {
102 newGlyph = SWAPW(segment->value);
107 case ltfSegmentArray: {
108 //printf("Context Lookup Table Format4: specific interpretation needed!\n");
114 // Disabled pending for design review
115 LEReferenceTo<SingleTableLookupTable> lookupTable6 = (SingleTableLookupTable *) lookupTable;
116 const LEReferenceTo<LookupSingle> segment = lookupTable6->lookupSingle(lookupTable6->entries, gid);
117 if (segment != NULL) {
118 newGlyph = SWAPW(segment->value);
123 case ltfTrimmedArray: {
124 LEReferenceTo<TrimmedArrayLookupTable> lookupTable8(lookupTable, success);
125 if (LE_FAILURE(success)) return newGlyph;
126 TTGlyphID firstGlyph = SWAPW(lookupTable8->firstGlyph);
127 TTGlyphID glyphCount = SWAPW(lookupTable8->glyphCount);
128 TTGlyphID lastGlyph = firstGlyph + glyphCount;
129 TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
130 if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) {
131 LEReferenceToArrayOf<LookupValue> valueArray(lookupTable8, success, &lookupTable8->valueArray[0], glyphCount);
132 newGlyph = SWAPW(valueArray(glyphCode - firstGlyph, success));
141 void ContextualGlyphSubstitutionProcessor2::endStateTable()