os/textandloc/fontservices/textshaperplugin/IcuSource/layout/ContextualGlyphSubstProc.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/layout/ContextualGlyphSubstProc.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,79 @@
1.4 +/*
1.5 + *
1.6 + * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
1.7 + *
1.8 + */
1.9 +
1.10 +#include "LETypes.h"
1.11 +#include "MorphTables.h"
1.12 +#include "StateTables.h"
1.13 +#include "MorphStateTables.h"
1.14 +#include "SubtableProcessor.h"
1.15 +#include "StateTableProcessor.h"
1.16 +#include "ContextualGlyphSubstProc.h"
1.17 +#include "LEGlyphStorage.h"
1.18 +#include "LESwaps.h"
1.19 +
1.20 +U_NAMESPACE_BEGIN
1.21 +
1.22 +UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ContextualGlyphSubstitutionProcessor)
1.23 +
1.24 +ContextualGlyphSubstitutionProcessor::ContextualGlyphSubstitutionProcessor(const MorphSubtableHeader *morphSubtableHeader)
1.25 + : StateTableProcessor(morphSubtableHeader)
1.26 +{
1.27 + contextualGlyphSubstitutionHeader = (const ContextualGlyphSubstitutionHeader *) morphSubtableHeader;
1.28 + substitutionTableOffset = SWAPW(contextualGlyphSubstitutionHeader->substitutionTableOffset);
1.29 +
1.30 + entryTable = (const ContextualGlyphSubstitutionStateEntry *) ((char *) &stateTableHeader->stHeader + entryTableOffset);
1.31 +}
1.32 +
1.33 +ContextualGlyphSubstitutionProcessor::~ContextualGlyphSubstitutionProcessor()
1.34 +{
1.35 +}
1.36 +
1.37 +void ContextualGlyphSubstitutionProcessor::beginStateTable()
1.38 +{
1.39 + markGlyph = 0;
1.40 +}
1.41 +
1.42 +ByteOffset ContextualGlyphSubstitutionProcessor::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex index)
1.43 +{
1.44 + const ContextualGlyphSubstitutionStateEntry *entry = &entryTable[index];
1.45 + ByteOffset newState = SWAPW(entry->newStateOffset);
1.46 + le_int16 flags = SWAPW(entry->flags);
1.47 + WordOffset markOffset = SWAPW(entry->markOffset);
1.48 + WordOffset currOffset = SWAPW(entry->currOffset);
1.49 +
1.50 + if (markOffset != 0) {
1.51 + const le_int16 *table = (const le_int16 *) ((char *) &stateTableHeader->stHeader + markOffset * 2);
1.52 + LEGlyphID mGlyph = glyphStorage[markGlyph];
1.53 + TTGlyphID newGlyph = SWAPW(table[LE_GET_GLYPH(mGlyph)]);
1.54 +
1.55 + glyphStorage[markGlyph] = LE_SET_GLYPH(mGlyph, newGlyph);
1.56 + }
1.57 +
1.58 + if (currOffset != 0) {
1.59 + const le_int16 *table = (const le_int16 *) ((char *) &stateTableHeader->stHeader + currOffset * 2);
1.60 + LEGlyphID thisGlyph = glyphStorage[currGlyph];
1.61 + TTGlyphID newGlyph = SWAPW(table[LE_GET_GLYPH(thisGlyph)]);
1.62 +
1.63 + glyphStorage[currGlyph] = LE_SET_GLYPH(thisGlyph, newGlyph);
1.64 + }
1.65 +
1.66 + if (flags & cgsSetMark) {
1.67 + markGlyph = currGlyph;
1.68 + }
1.69 +
1.70 + if (!(flags & cgsDontAdvance)) {
1.71 + // should handle reverse too!
1.72 + currGlyph += 1;
1.73 + }
1.74 +
1.75 + return newState;
1.76 +}
1.77 +
1.78 +void ContextualGlyphSubstitutionProcessor::endStateTable()
1.79 +{
1.80 +}
1.81 +
1.82 +U_NAMESPACE_END