1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "LETypes.h"
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "MorphTables.h"
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "SubtableProcessor.h"
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "NonContextualGlyphSubst.h"
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "NonContextualGlyphSubstProc.h"
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "SegmentArrayProcessor.h"
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "LEGlyphStorage.h"
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "LESwaps.h"
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUOBJECT_DEFINE_RTTI_IMPLEMENTATION(SegmentArrayProcessor)
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruSegmentArrayProcessor::SegmentArrayProcessor()
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruSegmentArrayProcessor::SegmentArrayProcessor(const MorphSubtableHeader *morphSubtableHeader)
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  : NonContextualGlyphSubstitutionProcessor(morphSubtableHeader)
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const NonContextualGlyphSubstitutionHeader *header = (const NonContextualGlyphSubstitutionHeader *) morphSubtableHeader;
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    segmentArrayLookupTable = (const SegmentArrayLookupTable *) &header->table;
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruSegmentArrayProcessor::~SegmentArrayProcessor()
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid SegmentArrayProcessor::process(LEGlyphStorage &glyphStorage)
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const LookupSegment *segments = segmentArrayLookupTable->segments;
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 glyphCount = glyphStorage.getGlyphCount();
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 glyph;
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (glyph = 0; glyph < glyphCount; glyph += 1) {
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        LEGlyphID thisGlyph = glyphStorage[glyph];
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const LookupSegment *lookupSegment = segmentArrayLookupTable->lookupSegment(segments, thisGlyph);
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (lookupSegment != NULL)  {
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            TTGlyphID firstGlyph = SWAPW(lookupSegment->firstGlyph);
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            le_int16  offset = SWAPW(lookupSegment->value);
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (offset != 0) {
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                TTGlyphID  *glyphArray = (TTGlyphID *) ((char *) subtableHeader + offset);
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                TTGlyphID   newGlyph   = SWAPW(glyphArray[LE_GET_GLYPH(thisGlyph) - firstGlyph]);
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                glyphStorage[glyph] = LE_SET_GLYPH(thisGlyph, newGlyph);
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END
61