sl@0: /* sl@0: * sl@0: * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved sl@0: * sl@0: */ sl@0: sl@0: #include "LETypes.h" sl@0: #include "LEGlyphFilter.h" sl@0: #include "OpenTypeTables.h" sl@0: #include "GlyphSubstitutionTables.h" sl@0: #include "MultipleSubstSubtables.h" sl@0: #include "GlyphIterator.h" sl@0: #include "LESwaps.h" sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: sl@0: le_uint32 MultipleSubstitutionSubtable::process(GlyphIterator *glyphIterator, LEErrorCode& success, sl@0: const LEGlyphFilter *filter) const sl@0: { sl@0: if (LE_FAILURE(success)) { sl@0: return 0; sl@0: } sl@0: sl@0: LEGlyphID glyph = glyphIterator->getCurrGlyphID(); sl@0: sl@0: // If there's a filter, we only want to do the sl@0: // substitution if the *input* glyphs doesn't sl@0: // exist. sl@0: // sl@0: // FIXME: is this always the right thing to do? sl@0: // FIXME: should this only be done for a non-zero sl@0: // glyphCount? sl@0: if (filter != NULL && filter->accept(glyph)) { sl@0: return 0; sl@0: } sl@0: sl@0: le_int32 coverageIndex = getGlyphCoverage(glyph); sl@0: le_uint16 seqCount = SWAPW(sequenceCount); sl@0: sl@0: if (coverageIndex >= 0 && coverageIndex < seqCount) { sl@0: Offset sequenceTableOffset = SWAPW(sequenceTableOffsetArray[coverageIndex]); sl@0: const SequenceTable *sequenceTable = (const SequenceTable *) ((char *) this + sequenceTableOffset); sl@0: le_uint16 glyphCount = SWAPW(sequenceTable->glyphCount); sl@0: sl@0: if (glyphCount == 0) { sl@0: glyphIterator->setCurrGlyphID(0xFFFF); sl@0: return 1; sl@0: } else if (glyphCount == 1) { sl@0: TTGlyphID substitute = SWAPW(sequenceTable->substituteArray[0]); sl@0: sl@0: if (filter != NULL && ! filter->accept(LE_SET_GLYPH(glyph, substitute))) { sl@0: return 0; sl@0: } sl@0: sl@0: glyphIterator->setCurrGlyphID(substitute); sl@0: return 1; sl@0: } else { sl@0: // If there's a filter, make sure all of the output glyphs sl@0: // exist. sl@0: if (filter != NULL) { sl@0: for (le_int32 i = 0; i < glyphCount; i += 1) { sl@0: TTGlyphID substitute = SWAPW(sequenceTable->substituteArray[i]); sl@0: sl@0: if (! filter->accept(substitute)) { sl@0: return 0; sl@0: } sl@0: } sl@0: } sl@0: sl@0: LEGlyphID *newGlyphs = glyphIterator->insertGlyphs(glyphCount, success); sl@0: if (LE_FAILURE(success)) { sl@0: return 0; sl@0: } sl@0: sl@0: le_int32 insert = 0, direction = 1; sl@0: sl@0: if (glyphIterator->isRightToLeft()) { sl@0: insert = glyphCount - 1; sl@0: direction = -1; sl@0: } sl@0: sl@0: for (le_int32 i = 0; i < glyphCount; i += 1) { sl@0: TTGlyphID substitute = SWAPW(sequenceTable->substituteArray[i]); sl@0: sl@0: newGlyphs[insert] = LE_SET_GLYPH(glyph, substitute); sl@0: insert += direction; sl@0: } sl@0: sl@0: return 1; sl@0: } sl@0: } sl@0: sl@0: return 0; sl@0: } sl@0: sl@0: U_NAMESPACE_END