1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
359d709d503bab6e2b61931737e662dd293b40578ccornelius * (C) Copyright IBM Corp. 1998-2013 - 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 "SegmentSingleProcessor.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(SegmentSingleProcessor)
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruSegmentSingleProcessor::SegmentSingleProcessor()
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2459d709d503bab6e2b61931737e662dd293b40578ccorneliusSegmentSingleProcessor::SegmentSingleProcessor(const LEReferenceTo<MorphSubtableHeader> &morphSubtableHeader, LEErrorCode &success)
2559d709d503bab6e2b61931737e662dd293b40578ccornelius  : NonContextualGlyphSubstitutionProcessor(morphSubtableHeader, success)
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
2759d709d503bab6e2b61931737e662dd293b40578ccornelius  LEReferenceTo<NonContextualGlyphSubstitutionHeader> header(morphSubtableHeader, success);
2859d709d503bab6e2b61931737e662dd293b40578ccornelius  segmentSingleLookupTable = LEReferenceTo<SegmentSingleLookupTable>(morphSubtableHeader, success, (const SegmentSingleLookupTable*)&header->table);
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruSegmentSingleProcessor::~SegmentSingleProcessor()
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
3559d709d503bab6e2b61931737e662dd293b40578ccorneliusvoid SegmentSingleProcessor::process(LEGlyphStorage &glyphStorage, LEErrorCode &success)
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const LookupSegment *segments = segmentSingleLookupTable->segments;
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 glyphCount = glyphStorage.getGlyphCount();
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 glyph;
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
4159d709d503bab6e2b61931737e662dd293b40578ccornelius    for (glyph = 0; glyph < glyphCount && LE_SUCCESS(success); glyph += 1) {
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        LEGlyphID thisGlyph = glyphStorage[glyph];
4359d709d503bab6e2b61931737e662dd293b40578ccornelius        const LookupSegment *lookupSegment = segmentSingleLookupTable->lookupSegment(segmentSingleLookupTable, segments, thisGlyph, success);
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
4559d709d503bab6e2b61931737e662dd293b40578ccornelius        if (lookupSegment != NULL && LE_SUCCESS(success)) {
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            TTGlyphID   newGlyph  = (TTGlyphID) LE_GET_GLYPH(thisGlyph) + SWAPW(lookupSegment->value);
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            glyphStorage[glyph] = LE_SET_GLYPH(thisGlyph, newGlyph);
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END
54