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 "MorphTables.h" sl@0: #include "StateTables.h" sl@0: #include "MorphStateTables.h" sl@0: #include "SubtableProcessor.h" sl@0: #include "StateTableProcessor.h" sl@0: #include "LigatureSubstProc.h" sl@0: #include "LEGlyphStorage.h" sl@0: #include "LESwaps.h" sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: sl@0: #define ExtendedComplement(m) ((le_int32) (~((le_uint32) (m)))) sl@0: #define SignBit(m) ((ExtendedComplement(m) >> 1) & (le_int32)(m)) sl@0: #define SignExtend(v,m) (((v) & SignBit(m))? ((v) | ExtendedComplement(m)): (v)) sl@0: sl@0: UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LigatureSubstitutionProcessor) sl@0: sl@0: LigatureSubstitutionProcessor::LigatureSubstitutionProcessor(const MorphSubtableHeader *morphSubtableHeader) sl@0: : StateTableProcessor(morphSubtableHeader) sl@0: { sl@0: ligatureSubstitutionHeader = (const LigatureSubstitutionHeader *) morphSubtableHeader; sl@0: ligatureActionTableOffset = SWAPW(ligatureSubstitutionHeader->ligatureActionTableOffset); sl@0: componentTableOffset = SWAPW(ligatureSubstitutionHeader->componentTableOffset); sl@0: ligatureTableOffset = SWAPW(ligatureSubstitutionHeader->ligatureTableOffset); sl@0: sl@0: entryTable = (const LigatureSubstitutionStateEntry *) ((char *) &stateTableHeader->stHeader + entryTableOffset); sl@0: } sl@0: sl@0: LigatureSubstitutionProcessor::~LigatureSubstitutionProcessor() sl@0: { sl@0: } sl@0: sl@0: void LigatureSubstitutionProcessor::beginStateTable() sl@0: { sl@0: m = -1; sl@0: } sl@0: sl@0: ByteOffset LigatureSubstitutionProcessor::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex index) sl@0: { sl@0: const LigatureSubstitutionStateEntry *entry = &entryTable[index]; sl@0: ByteOffset newState = SWAPW(entry->newStateOffset); sl@0: le_int16 flags = SWAPW(entry->flags); sl@0: sl@0: if (flags & lsfSetComponent) { sl@0: if (++m >= nComponents) { sl@0: m = 0; sl@0: } sl@0: sl@0: componentStack[m] = currGlyph; sl@0: } sl@0: sl@0: ByteOffset actionOffset = flags & lsfActionOffsetMask; sl@0: sl@0: if (actionOffset != 0) { sl@0: const LigatureActionEntry *ap = (const LigatureActionEntry *) ((char *) &ligatureSubstitutionHeader->stHeader + actionOffset); sl@0: LigatureActionEntry action; sl@0: le_int32 offset, i = 0; sl@0: le_int32 stack[nComponents]; sl@0: le_int16 mm = -1; sl@0: sl@0: do { sl@0: le_uint32 componentGlyph = componentStack[m--]; sl@0: sl@0: action = SWAPL(*ap++); sl@0: sl@0: if (m < 0) { sl@0: m = nComponents - 1; sl@0: } sl@0: sl@0: offset = action & lafComponentOffsetMask; sl@0: if (offset != 0) { sl@0: const le_int16 *offsetTable = (const le_int16 *)((char *) &ligatureSubstitutionHeader->stHeader + 2 * SignExtend(offset, lafComponentOffsetMask)); sl@0: sl@0: i += SWAPW(offsetTable[LE_GET_GLYPH(glyphStorage[componentGlyph])]); sl@0: sl@0: if (action & (lafLast | lafStore)) { sl@0: const TTGlyphID *ligatureOffset = (const TTGlyphID *) ((char *) &ligatureSubstitutionHeader->stHeader + i); sl@0: TTGlyphID ligatureGlyph = SWAPW(*ligatureOffset); sl@0: sl@0: glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], ligatureGlyph); sl@0: stack[++mm] = componentGlyph; sl@0: i = 0; sl@0: } else { sl@0: glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], 0xFFFF); sl@0: } sl@0: } sl@0: } while (!(action & lafLast)); sl@0: sl@0: while (mm >= 0) { sl@0: if (++m >= nComponents) { sl@0: m = 0; sl@0: } sl@0: sl@0: componentStack[m] = stack[mm--]; sl@0: } sl@0: } sl@0: sl@0: if (!(flags & lsfDontAdvance)) { sl@0: // should handle reverse too! sl@0: currGlyph += 1; sl@0: } sl@0: sl@0: return newState; sl@0: } sl@0: sl@0: void LigatureSubstitutionProcessor::endStateTable() sl@0: { sl@0: } sl@0: sl@0: U_NAMESPACE_END