os/textandloc/fontservices/textshaperplugin/IcuSource/layout/MultipleSubstSubtables.cpp
First public contribution.
3 * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
8 #include "LEGlyphFilter.h"
9 #include "OpenTypeTables.h"
10 #include "GlyphSubstitutionTables.h"
11 #include "MultipleSubstSubtables.h"
12 #include "GlyphIterator.h"
17 le_uint32 MultipleSubstitutionSubtable::process(GlyphIterator *glyphIterator, LEErrorCode& success,
18 const LEGlyphFilter *filter) const
20 if (LE_FAILURE(success)) {
24 LEGlyphID glyph = glyphIterator->getCurrGlyphID();
26 // If there's a filter, we only want to do the
27 // substitution if the *input* glyphs doesn't
30 // FIXME: is this always the right thing to do?
31 // FIXME: should this only be done for a non-zero
33 if (filter != NULL && filter->accept(glyph)) {
37 le_int32 coverageIndex = getGlyphCoverage(glyph);
38 le_uint16 seqCount = SWAPW(sequenceCount);
40 if (coverageIndex >= 0 && coverageIndex < seqCount) {
41 Offset sequenceTableOffset = SWAPW(sequenceTableOffsetArray[coverageIndex]);
42 const SequenceTable *sequenceTable = (const SequenceTable *) ((char *) this + sequenceTableOffset);
43 le_uint16 glyphCount = SWAPW(sequenceTable->glyphCount);
45 if (glyphCount == 0) {
46 glyphIterator->setCurrGlyphID(0xFFFF);
48 } else if (glyphCount == 1) {
49 TTGlyphID substitute = SWAPW(sequenceTable->substituteArray[0]);
51 if (filter != NULL && ! filter->accept(LE_SET_GLYPH(glyph, substitute))) {
55 glyphIterator->setCurrGlyphID(substitute);
58 // If there's a filter, make sure all of the output glyphs
61 for (le_int32 i = 0; i < glyphCount; i += 1) {
62 TTGlyphID substitute = SWAPW(sequenceTable->substituteArray[i]);
64 if (! filter->accept(substitute)) {
70 LEGlyphID *newGlyphs = glyphIterator->insertGlyphs(glyphCount, success);
71 if (LE_FAILURE(success)) {
75 le_int32 insert = 0, direction = 1;
77 if (glyphIterator->isRightToLeft()) {
78 insert = glyphCount - 1;
82 for (le_int32 i = 0; i < glyphCount; i += 1) {
83 TTGlyphID substitute = SWAPW(sequenceTable->substituteArray[i]);
85 newGlyphs[insert] = LE_SET_GLYPH(glyph, substitute);