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