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 "LEGlyphFilter.h"
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "OpenTypeTables.h"
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "GlyphSubstitutionTables.h"
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "SingleSubstitutionSubtables.h"
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "GlyphIterator.h"
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "LESwaps.h"
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1759d709d503bab6e2b61931737e662dd293b40578ccorneliusle_uint32 SingleSubstitutionSubtable::process(const LEReferenceTo<SingleSubstitutionSubtable> &base, GlyphIterator *glyphIterator, LEErrorCode &success, const LEGlyphFilter *filter) const
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    switch(SWAPW(subtableFormat))
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case 0:
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return 0;
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case 1:
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
2659d709d503bab6e2b61931737e662dd293b40578ccornelius      const LEReferenceTo<SingleSubstitutionFormat1Subtable> subtable(base, success, (const SingleSubstitutionFormat1Subtable *) this);
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2859d709d503bab6e2b61931737e662dd293b40578ccornelius      return subtable->process(subtable, glyphIterator, success, filter);
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case 2:
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
3359d709d503bab6e2b61931737e662dd293b40578ccornelius      const LEReferenceTo<SingleSubstitutionFormat2Subtable> subtable(base, success, (const SingleSubstitutionFormat2Subtable *) this);
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
3559d709d503bab6e2b61931737e662dd293b40578ccornelius      return subtable->process(subtable, glyphIterator, success, filter);
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    default:
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return 0;
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
4359d709d503bab6e2b61931737e662dd293b40578ccorneliusle_uint32 SingleSubstitutionFormat1Subtable::process(const LEReferenceTo<SingleSubstitutionFormat1Subtable> &base, GlyphIterator *glyphIterator, LEErrorCode &success, const LEGlyphFilter *filter) const
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    LEGlyphID glyph = glyphIterator->getCurrGlyphID();
4659d709d503bab6e2b61931737e662dd293b40578ccornelius    le_int32 coverageIndex = getGlyphCoverage(base, glyph, success);
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (coverageIndex >= 0) {
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TTGlyphID substitute = ((TTGlyphID) LE_GET_GLYPH(glyph)) + SWAPW(deltaGlyphID);
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (filter == NULL || filter->accept(LE_SET_GLYPH(glyph, substitute))) {
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            glyphIterator->setCurrGlyphID(substitute);
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return 1;
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return 0;
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
6159d709d503bab6e2b61931737e662dd293b40578ccorneliusle_uint32 SingleSubstitutionFormat2Subtable::process(const LEReferenceTo<SingleSubstitutionFormat2Subtable> &base, GlyphIterator *glyphIterator, LEErrorCode &success, const LEGlyphFilter *filter) const
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    LEGlyphID glyph = glyphIterator->getCurrGlyphID();
6459d709d503bab6e2b61931737e662dd293b40578ccornelius    le_int32 coverageIndex = getGlyphCoverage(base, glyph, success);
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (coverageIndex >= 0) {
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TTGlyphID substitute = SWAPW(substituteArray[coverageIndex]);
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (filter == NULL || filter->accept(LE_SET_GLYPH(glyph, substitute))) {
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            glyphIterator->setCurrGlyphID(substitute);
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return 1;
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return 0;
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END
80