1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
/*
* @(#)GlyphSubstLookupProc.cpp 1.6 00/03/15
*
* (C) Copyright IBM Corp. 1998, 1999, 2000, 2001 - All Rights Reserved
*
*/
#include "LETypes.h"
#include "MorphTables.h"
#include "StateTables.h"
#include "MorphStateTables.h"
#include "SubtableProcessor.h"
#include "StateTableProcessor.h"
#include "LigatureSubstProc.h"
#include "LESwaps.h"
U_NAMESPACE_BEGIN
#define ExtendedComplement(m) ((le_int32) (~((le_uint32) (m))))
#define SignBit(m) ((ExtendedComplement(m) >> 1) & (m))
#define SignExtend(v,m) (((v) & SignBit(m))? ((v) | ExtendedComplement(m)): (v))
LigatureSubstitutionProcessor::LigatureSubstitutionProcessor(const MorphSubtableHeader *morphSubtableHeader)
: StateTableProcessor(morphSubtableHeader)
{
ligatureSubstitutionHeader = (const LigatureSubstitutionHeader *) morphSubtableHeader;
ligatureActionTableOffset = SWAPW(ligatureSubstitutionHeader->ligatureActionTableOffset);
componentTableOffset = SWAPW(ligatureSubstitutionHeader->componentTableOffset);
ligatureTableOffset = SWAPW(ligatureSubstitutionHeader->ligatureTableOffset);
entryTable = (const LigatureSubstitutionStateEntry *) ((char *) &stateTableHeader->stHeader + entryTableOffset);
}
LigatureSubstitutionProcessor::~LigatureSubstitutionProcessor()
{
}
void LigatureSubstitutionProcessor::beginStateTable()
{
m = -1;
}
ByteOffset LigatureSubstitutionProcessor::processStateEntry(LEGlyphID *glyphs, le_int32 *charIndices, le_int32 &currGlyph, le_int32 glyphCount, EntryTableIndex index)
{
const LigatureSubstitutionStateEntry *entry = &entryTable[index];
ByteOffset newState = SWAPW(entry->newStateOffset);
le_int16 flags = SWAPW(entry->flags);
if (flags & lsfSetComponent) {
if (++m >= nComponents) {
m = 0;
}
componentStack[m] = currGlyph;
}
ByteOffset actionOffset = flags & lsfActionOffsetMask;
if (actionOffset != 0) {
const LigatureActionEntry *ap = (const LigatureActionEntry *) ((char *) &ligatureSubstitutionHeader->stHeader + actionOffset);
LigatureActionEntry action;
le_int32 offset, i = 0;
le_int32 stack[nComponents];
le_int16 mm = -1;
do {
le_uint32 componentGlyph = componentStack[m--];
action = SWAPL(*ap++);
if (m < 0) {
m = nComponents - 1;
}
offset = action & lafComponentOffsetMask;
if (offset != 0) {
const le_int16 *offsetTable = (const le_int16 *)((char *) &ligatureSubstitutionHeader->stHeader + 2 * SignExtend(offset, lafComponentOffsetMask));
i += SWAPW(offsetTable[glyphs[componentGlyph]]);
if (action & (lafLast | lafStore)) {
const le_int16 *ligatureOffset = (const le_int16 *) ((char *) &ligatureSubstitutionHeader->stHeader + i);
glyphs[componentGlyph] = SWAPW(*ligatureOffset);
stack[++mm] = componentGlyph;
i = 0;
} else {
glyphs[componentGlyph] = 0xFFFF;
}
}
} while (!(action & lafLast));
while (mm >= 0) {
if (++m >= nComponents) {
m = 0;
}
componentStack[m] = stack[mm--];
}
}
if (!(flags & lsfDontAdvance)) {
// should handle reverse too!
currGlyph += 1;
}
return newState;
}
void LigatureSubstitutionProcessor::endStateTable()
{
}
U_NAMESPACE_END
|