1/* 2 * (C) Copyright IBM Corp. 1998-2015 - All Rights Reserved 3 * 4 */ 5 6#include "LETypes.h" 7#include "LEGlyphFilter.h" 8#include "OpenTypeTables.h" 9#include "GlyphSubstitutionTables.h" 10#include "LigatureSubstSubtables.h" 11#include "GlyphIterator.h" 12#include "LESwaps.h" 13 14U_NAMESPACE_BEGIN 15 16le_uint32 LigatureSubstitutionSubtable::process(const LETableReference &base, GlyphIterator *glyphIterator, LEErrorCode &success, const LEGlyphFilter *filter) const 17{ 18 LEGlyphID glyph = glyphIterator->getCurrGlyphID(); 19 le_int32 coverageIndex = getGlyphCoverage(base, glyph, success); 20 21 if (coverageIndex >= 0) { 22 Offset ligSetTableOffset = SWAPW(ligSetTableOffsetArray[coverageIndex]); 23 const LigatureSetTable *ligSetTable = (const LigatureSetTable *) ((char *) this + ligSetTableOffset); 24 le_uint16 ligCount = SWAPW(ligSetTable->ligatureCount); 25 26 for (le_uint16 lig = 0; lig < ligCount; lig += 1) { 27 Offset ligTableOffset = SWAPW(ligSetTable->ligatureTableOffsetArray[lig]); 28 const LigatureTable *ligTable = (const LigatureTable *) ((char *)ligSetTable + ligTableOffset); 29 le_uint16 compCount = SWAPW(ligTable->compCount) - 1; 30 LEReferenceToArrayOf<TTGlyphID> 31 componentArrayRef(base, success, ligTable->componentArray, compCount); 32 if (LE_FAILURE(success)) { return 0; } 33 le_int32 startPosition = glyphIterator->getCurrStreamPosition(); 34 TTGlyphID ligGlyph = SWAPW(ligTable->ligGlyph); 35 le_uint16 comp; 36 37 for (comp = 0; comp < compCount; comp += 1) { 38 if (! glyphIterator->next()) { 39 break; 40 } 41 42 if (LE_GET_GLYPH(glyphIterator->getCurrGlyphID()) != SWAPW(ligTable->componentArray[comp])) { 43 break; 44 } 45 } 46 47 if (comp == compCount && (filter == NULL || filter->accept(LE_SET_GLYPH(glyph, ligGlyph)))) { 48 GlyphIterator tempIterator(*glyphIterator); 49 TTGlyphID deletedGlyph = tempIterator.ignoresMarks()? 0xFFFE : 0xFFFF; 50 51 while (comp > 0) { 52 tempIterator.setCurrGlyphID(deletedGlyph); 53 tempIterator.prev(); 54 55 comp -= 1; 56 } 57 58 tempIterator.setCurrGlyphID(ligGlyph); 59 60 return compCount + 1; 61 } 62 63 glyphIterator->setCurrStreamPosition(startPosition); 64 } 65 66 } 67 68 return 0; 69} 70 71U_NAMESPACE_END 72