1 /* 2 * 3 * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved 4 * 5 */ 6 7 #include "LETypes.h" 8 #include "LEGlyphFilter.h" 9 #include "OpenTypeTables.h" 10 #include "GlyphSubstitutionTables.h" 11 #include "MultipleSubstSubtables.h" 12 #include "GlyphIterator.h" 13 #include "LESwaps.h" 14 15 U_NAMESPACE_BEGIN 16 process(GlyphIterator * glyphIterator,const LEGlyphFilter * filter) const17le_uint32 MultipleSubstitutionSubtable::process(GlyphIterator *glyphIterator, const LEGlyphFilter *filter) const 18 { 19 LEGlyphID glyph = glyphIterator->getCurrGlyphID(); 20 21 // If there's a filter, we only want to do the 22 // substitution if the *input* glyphs doesn't 23 // exist. 24 // 25 // FIXME: is this always the right thing to do? 26 // FIXME: should this only be done for a non-zero 27 // glyphCount? 28 if (filter != NULL && filter->accept(glyph)) { 29 return 0; 30 } 31 32 le_int32 coverageIndex = getGlyphCoverage(glyph); 33 le_uint16 seqCount = SWAPW(sequenceCount); 34 35 if (coverageIndex >= 0 && coverageIndex < seqCount) { 36 Offset sequenceTableOffset = SWAPW(sequenceTableOffsetArray[coverageIndex]); 37 const SequenceTable *sequenceTable = (const SequenceTable *) ((char *) this + sequenceTableOffset); 38 le_uint16 glyphCount = SWAPW(sequenceTable->glyphCount); 39 40 if (glyphCount == 0) { 41 glyphIterator->setCurrGlyphID(0xFFFF); 42 return 1; 43 } else if (glyphCount == 1) { 44 TTGlyphID substitute = SWAPW(sequenceTable->substituteArray[0]); 45 46 if (filter != NULL && ! filter->accept(LE_SET_GLYPH(glyph, substitute))) { 47 return 0; 48 } 49 50 glyphIterator->setCurrGlyphID(substitute); 51 return 1; 52 } else { 53 // If there's a filter, make sure all of the output glyphs 54 // exist. 55 if (filter != NULL) { 56 for (le_int32 i = 0; i < glyphCount; i += 1) { 57 TTGlyphID substitute = SWAPW(sequenceTable->substituteArray[i]); 58 59 if (! filter->accept(substitute)) { 60 return 0; 61 } 62 } 63 } 64 65 LEGlyphID *newGlyphs = glyphIterator->insertGlyphs(glyphCount); 66 le_int32 insert = 0, direction = 1; 67 68 if (glyphIterator->isRightToLeft()) { 69 insert = glyphCount - 1; 70 direction = -1; 71 } 72 73 for (le_int32 i = 0; i < glyphCount; i += 1) { 74 TTGlyphID substitute = SWAPW(sequenceTable->substituteArray[i]); 75 76 newGlyphs[insert] = LE_SET_GLYPH(glyph, substitute); 77 insert += direction; 78 } 79 80 return 1; 81 } 82 } 83 84 return 0; 85 } 86 87 U_NAMESPACE_END 88