2000-11-28 20:56:52 +00:00
|
|
|
/*
|
|
|
|
*
|
2013-04-18 21:24:51 +00:00
|
|
|
* (C) Copyright IBM Corp. 1998-2013 - 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"
|
2004-04-12 18:51:31 +00:00
|
|
|
#include "LEGlyphStorage.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))))
|
2003-11-25 23:41:24 +00:00
|
|
|
#define SignBit(m) ((ExtendedComplement(m) >> 1) & (le_int32)(m))
|
2000-11-28 20:56:52 +00:00
|
|
|
#define SignExtend(v,m) (((v) & SignBit(m))? ((v) | ExtendedComplement(m)): (v))
|
|
|
|
|
2004-10-19 06:25:41 +00:00
|
|
|
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LigatureSubstitutionProcessor)
|
2002-06-29 00:04:16 +00:00
|
|
|
|
2013-04-18 21:24:51 +00:00
|
|
|
LigatureSubstitutionProcessor::LigatureSubstitutionProcessor(const LEReferenceTo<MorphSubtableHeader> &morphSubtableHeader, LEErrorCode &success)
|
|
|
|
: StateTableProcessor(morphSubtableHeader, success), ligatureSubstitutionHeader(morphSubtableHeader, success)
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2013-04-18 21:24:51 +00:00
|
|
|
if(LE_FAILURE(success)) return;
|
2000-11-28 20:56:52 +00:00
|
|
|
ligatureActionTableOffset = SWAPW(ligatureSubstitutionHeader->ligatureActionTableOffset);
|
|
|
|
componentTableOffset = SWAPW(ligatureSubstitutionHeader->componentTableOffset);
|
|
|
|
ligatureTableOffset = SWAPW(ligatureSubstitutionHeader->ligatureTableOffset);
|
|
|
|
|
2013-04-18 21:24:51 +00:00
|
|
|
entryTable = LEReferenceToArrayOf<LigatureSubstitutionStateEntry>(stHeader, success, entryTableOffset, LE_UNBOUNDED_ARRAY);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LigatureSubstitutionProcessor::~LigatureSubstitutionProcessor()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void LigatureSubstitutionProcessor::beginStateTable()
|
|
|
|
{
|
|
|
|
m = -1;
|
|
|
|
}
|
|
|
|
|
2004-04-12 18:51:31 +00:00
|
|
|
ByteOffset LigatureSubstitutionProcessor::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex index)
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2013-04-18 21:24:51 +00:00
|
|
|
LEErrorCode success = LE_NO_ERROR;
|
|
|
|
const LigatureSubstitutionStateEntry *entry = entryTable.getAlias(index, success);
|
|
|
|
|
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;
|
2013-04-18 21:24:51 +00:00
|
|
|
} else if ( m == -1) {
|
|
|
|
// bad font- skip this glyph.
|
|
|
|
currGlyph++;
|
|
|
|
return newState;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ByteOffset actionOffset = flags & lsfActionOffsetMask;
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (actionOffset != 0) {
|
2013-04-18 21:24:51 +00:00
|
|
|
LEReferenceTo<LigatureActionEntry> ap(stHeader, success, 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--];
|
|
|
|
|
2013-04-18 21:24:51 +00:00
|
|
|
action = SWAPL(*ap.getAlias());
|
|
|
|
ap.addObject(success); // ap++
|
2000-11-28 20:56:52 +00:00
|
|
|
|
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) {
|
2013-04-18 21:24:51 +00:00
|
|
|
LEReferenceToArrayOf<le_int16> offsetTable(stHeader, success, 2 * SignExtend(offset, lafComponentOffsetMask), LE_UNBOUNDED_ARRAY);
|
|
|
|
|
|
|
|
if(LE_FAILURE(success)) {
|
|
|
|
currGlyph++;
|
|
|
|
LE_DEBUG_BAD_FONT("off end of ligature substitution header");
|
|
|
|
return newState; // get out! bad font
|
|
|
|
}
|
2013-09-18 20:08:25 +00:00
|
|
|
if(componentGlyph > (le_uint32)glyphStorage.getGlyphCount()) {
|
2013-04-18 21:24:51 +00:00
|
|
|
LE_DEBUG_BAD_FONT("preposterous componentGlyph");
|
|
|
|
currGlyph++;
|
|
|
|
return newState; // get out! bad font
|
|
|
|
}
|
|
|
|
i += SWAPW(offsetTable.getObject(LE_GET_GLYPH(glyphStorage[componentGlyph]), success));
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (action & (lafLast | lafStore)) {
|
2013-04-18 21:24:51 +00:00
|
|
|
LEReferenceTo<TTGlyphID> ligatureOffset(stHeader, success, i);
|
|
|
|
TTGlyphID ligatureGlyph = SWAPW(*ligatureOffset.getAlias());
|
|
|
|
|
|
|
|
glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], ligatureGlyph);
|
|
|
|
if(mm==nComponents) {
|
|
|
|
LE_DEBUG_BAD_FONT("exceeded nComponents");
|
|
|
|
mm--; // don't overrun the stack.
|
|
|
|
}
|
|
|
|
stack[++mm] = componentGlyph;
|
|
|
|
i = 0;
|
2001-01-19 00:30:17 +00:00
|
|
|
} else {
|
2013-04-18 21:24:51 +00:00
|
|
|
glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], 0xFFFF);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-18 21:24:51 +00:00
|
|
|
#if LE_ASSERT_BAD_FONT
|
|
|
|
if(m<0) {
|
|
|
|
LE_DEBUG_BAD_FONT("m<0")
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
2013-04-18 21:24:51 +00:00
|
|
|
#endif
|
|
|
|
} while (!(action & lafLast) && (m>=0) ); // stop if last bit is set, or if run out of items
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2013-04-18 21:24:51 +00:00
|
|
|
while (mm >= 0) {
|
|
|
|
if (++m >= nComponents) {
|
|
|
|
m = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentStack[m] = stack[mm--];
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|