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 "SubtableProcessor.h"
10 #include "NonContextualGlyphSubst.h"
11 #include "NonContextualGlyphSubstProc.h"
12 #include "SegmentArrayProcessor.h"
13 #include "LEGlyphStorage.h"
14 #include "LESwaps.h"
15 
16 U_NAMESPACE_BEGIN
17 
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SegmentArrayProcessor)18 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SegmentArrayProcessor)
19 
20 SegmentArrayProcessor::SegmentArrayProcessor()
21 {
22 }
23 
SegmentArrayProcessor(const LEReferenceTo<MorphSubtableHeader> & morphSubtableHeader,LEErrorCode & success)24 SegmentArrayProcessor::SegmentArrayProcessor(const LEReferenceTo<MorphSubtableHeader> &morphSubtableHeader, LEErrorCode &success)
25   : NonContextualGlyphSubstitutionProcessor(morphSubtableHeader, success)
26 {
27   LEReferenceTo<NonContextualGlyphSubstitutionHeader> header(morphSubtableHeader, success);
28   segmentArrayLookupTable = LEReferenceTo<SegmentArrayLookupTable>(morphSubtableHeader, success, (const SegmentArrayLookupTable*)&header->table);
29 }
30 
~SegmentArrayProcessor()31 SegmentArrayProcessor::~SegmentArrayProcessor()
32 {
33 }
34 
process(LEGlyphStorage & glyphStorage,LEErrorCode & success)35 void SegmentArrayProcessor::process(LEGlyphStorage &glyphStorage, LEErrorCode &success)
36 {
37     const LookupSegment *segments = segmentArrayLookupTable->segments;
38     le_int32 glyphCount = glyphStorage.getGlyphCount();
39     le_int32 glyph;
40 
41     for (glyph = 0; glyph < glyphCount; glyph += 1) {
42         LEGlyphID thisGlyph = glyphStorage[glyph];
43         const LookupSegment *lookupSegment = segmentArrayLookupTable->lookupSegment(segmentArrayLookupTable, segments, thisGlyph, success);
44 
45         if (lookupSegment != NULL)  {
46             TTGlyphID firstGlyph = SWAPW(lookupSegment->firstGlyph);
47             le_int16  offset = SWAPW(lookupSegment->value);
48 
49             if (offset != 0) {
50               LEReferenceToArrayOf<TTGlyphID> glyphArray(subtableHeader, success, offset, LE_UNBOUNDED_ARRAY);
51               TTGlyphID   newGlyph   = SWAPW(glyphArray(LE_GET_GLYPH(thisGlyph) - firstGlyph, success));
52               glyphStorage[glyph] = LE_SET_GLYPH(thisGlyph, newGlyph);
53             }
54         }
55     }
56 }
57 
58 U_NAMESPACE_END
59