2000-11-28 20:56:52 +00:00
|
|
|
/*
|
2000-12-21 02:44:45 +00:00
|
|
|
* @(#)GlyphSubstLookupProc.cpp 1.6 00/03/15
|
2000-11-28 20:56:52 +00:00
|
|
|
*
|
2001-01-19 00:30:17 +00:00
|
|
|
* (C) Copyright IBM Corp. 1998, 1999, 2000, 2001 - All Rights Reserved
|
2000-11-28 20:56:52 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LETypes.h"
|
|
|
|
#include "MorphTables.h"
|
|
|
|
#include "StateTables.h"
|
|
|
|
#include "MorphStateTables.h"
|
|
|
|
#include "SubtableProcessor.h"
|
|
|
|
#include "StateTableProcessor.h"
|
2000-12-21 21:57:18 +00:00
|
|
|
#include "LigatureSubstProc.h"
|
2000-11-28 20:56:52 +00:00
|
|
|
#include "LESwaps.h"
|
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2000-11-28 20:56:52 +00:00
|
|
|
#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))
|
|
|
|
|
2002-06-29 00:04:16 +00:00
|
|
|
const char LigatureSubstitutionProcessor::fgClassID=0;
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
LigatureSubstitutionProcessor::LigatureSubstitutionProcessor(const MorphSubtableHeader *morphSubtableHeader)
|
2000-11-28 20:56:52 +00:00
|
|
|
: StateTableProcessor(morphSubtableHeader)
|
|
|
|
{
|
2001-01-19 00:30:17 +00:00
|
|
|
ligatureSubstitutionHeader = (const LigatureSubstitutionHeader *) morphSubtableHeader;
|
2000-11-28 20:56:52 +00:00
|
|
|
ligatureActionTableOffset = SWAPW(ligatureSubstitutionHeader->ligatureActionTableOffset);
|
|
|
|
componentTableOffset = SWAPW(ligatureSubstitutionHeader->componentTableOffset);
|
|
|
|
ligatureTableOffset = SWAPW(ligatureSubstitutionHeader->ligatureTableOffset);
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
entryTable = (const LigatureSubstitutionStateEntry *) ((char *) &stateTableHeader->stHeader + entryTableOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LigatureSubstitutionProcessor::~LigatureSubstitutionProcessor()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void LigatureSubstitutionProcessor::beginStateTable()
|
|
|
|
{
|
|
|
|
m = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ByteOffset LigatureSubstitutionProcessor::processStateEntry(LEGlyphID *glyphs, le_int32 *charIndices, le_int32 &currGlyph, le_int32 glyphCount, EntryTableIndex index)
|
|
|
|
{
|
2001-01-19 00:30:17 +00:00
|
|
|
const LigatureSubstitutionStateEntry *entry = &entryTable[index];
|
2000-11-28 20:56:52 +00:00
|
|
|
ByteOffset newState = SWAPW(entry->newStateOffset);
|
|
|
|
le_int16 flags = SWAPW(entry->flags);
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (flags & lsfSetComponent) {
|
|
|
|
if (++m >= nComponents) {
|
2000-11-28 20:56:52 +00:00
|
|
|
m = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentStack[m] = currGlyph;
|
|
|
|
}
|
|
|
|
|
|
|
|
ByteOffset actionOffset = flags & lsfActionOffsetMask;
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (actionOffset != 0) {
|
|
|
|
const LigatureActionEntry *ap = (const LigatureActionEntry *) ((char *) &ligatureSubstitutionHeader->stHeader + actionOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
LigatureActionEntry action;
|
|
|
|
le_int32 offset, i = 0;
|
|
|
|
le_int32 stack[nComponents];
|
|
|
|
le_int16 mm = -1;
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
do {
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint32 componentGlyph = componentStack[m--];
|
|
|
|
|
|
|
|
action = SWAPL(*ap++);
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (m < 0) {
|
2000-11-28 20:56:52 +00:00
|
|
|
m = nComponents - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = action & lafComponentOffsetMask;
|
2001-01-19 00:30:17 +00:00
|
|
|
if (offset != 0) {
|
|
|
|
const le_int16 *offsetTable = (const le_int16 *)((char *) &ligatureSubstitutionHeader->stHeader + 2 * SignExtend(offset, lafComponentOffsetMask));
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2003-02-05 00:05:40 +00:00
|
|
|
i += SWAPW(offsetTable[LE_GET_GLYPH(glyphs[componentGlyph])]);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (action & (lafLast | lafStore)) {
|
2003-02-05 00:05:40 +00:00
|
|
|
const TTGlyphID *ligatureOffset = (const TTGlyphID *) ((char *) &ligatureSubstitutionHeader->stHeader + i);
|
|
|
|
TTGlyphID ligatureGlyph = SWAPW(*ligatureOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2003-02-05 00:05:40 +00:00
|
|
|
glyphs[componentGlyph] = LE_SET_GLYPH(glyphs[componentGlyph], ligatureGlyph);
|
2000-11-28 20:56:52 +00:00
|
|
|
stack[++mm] = componentGlyph;
|
|
|
|
i = 0;
|
2001-01-19 00:30:17 +00:00
|
|
|
} else {
|
2003-02-05 00:05:40 +00:00
|
|
|
glyphs[componentGlyph] = LE_SET_GLYPH(glyphs[componentGlyph], 0xFFFF);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
2001-01-19 00:30:17 +00:00
|
|
|
} while (!(action & lafLast));
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
while (mm >= 0) {
|
|
|
|
if (++m >= nComponents) {
|
2000-11-28 20:56:52 +00:00
|
|
|
m = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentStack[m] = stack[mm--];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (!(flags & lsfDontAdvance)) {
|
2000-11-28 20:56:52 +00:00
|
|
|
// should handle reverse too!
|
|
|
|
currGlyph += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LigatureSubstitutionProcessor::endStateTable()
|
|
|
|
{
|
|
|
|
}
|
2001-10-16 00:39:01 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_END
|