jdk/src/share/native/sun/font/layout/LigatureSubstProc2.cpp
author prr
Fri, 15 Feb 2013 13:07:17 -0800
changeset 16889 3df90f344221
child 16890 36b30720a997
permissions -rw-r--r--
8008249: Sync ICU into JDK Reviewed-by: bae, jgodinez
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     1
/*
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     3
 *
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     9
 *
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    14
 * accompanied this code).
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    15
 *
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    19
 *
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    22
 * questions.
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    23
 *
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    24
 */
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    25
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    26
/*
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    27
 *
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    28
 * (C) Copyright IBM Corp and Others. 1998-2013 - All Rights Reserved
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    29
 *
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    30
 */
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    31
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    32
#include "LETypes.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    33
#include "MorphTables.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    34
#include "StateTables.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    35
#include "MorphStateTables.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    36
#include "SubtableProcessor2.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    37
#include "StateTableProcessor2.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    38
#include "LigatureSubstProc2.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    39
#include "LEGlyphStorage.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    40
#include "LESwaps.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    41
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    42
U_NAMESPACE_BEGIN
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    43
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    44
#define ExtendedComplement(m) ((le_int32) (~((le_uint32) (m))))
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    45
#define SignBit(m) ((ExtendedComplement(m) >> 1) & (le_int32)(m))
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    46
#define SignExtend(v,m) (((v) & SignBit(m))? ((v) | ExtendedComplement(m)): (v))
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    47
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    48
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LigatureSubstitutionProcessor2)
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    49
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    50
LigatureSubstitutionProcessor2::LigatureSubstitutionProcessor2(const MorphSubtableHeader2 *morphSubtableHeader)
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    51
  : StateTableProcessor2(morphSubtableHeader)
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    52
{
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    53
    ligatureSubstitutionHeader = (const LigatureSubstitutionHeader2 *) morphSubtableHeader;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    54
    ligActionOffset = SWAPL(ligatureSubstitutionHeader->ligActionOffset);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    55
    componentOffset = SWAPL(ligatureSubstitutionHeader->componentOffset);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    56
    ligatureOffset = SWAPL(ligatureSubstitutionHeader->ligatureOffset);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    57
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    58
    entryTable = (const LigatureSubstitutionStateEntry2 *) ((char *) &stateTableHeader->stHeader + entryTableOffset);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    59
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    60
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    61
LigatureSubstitutionProcessor2::~LigatureSubstitutionProcessor2()
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    62
{
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    63
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    64
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    65
void LigatureSubstitutionProcessor2::beginStateTable()
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    66
{
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    67
    m = -1;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    68
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    69
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    70
le_uint16 LigatureSubstitutionProcessor2::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex2 index)
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    71
{
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    72
    const LigatureSubstitutionStateEntry2 *entry = &entryTable[index];
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    73
    le_uint16 nextStateIndex = SWAPW(entry->nextStateIndex);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    74
    le_uint16 flags = SWAPW(entry->entryFlags);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    75
    le_uint16 ligActionIndex = SWAPW(entry->ligActionIndex);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    76
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    77
    if (flags & lsfSetComponent) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    78
        if (++m >= nComponents) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    79
            m = 0;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    80
        }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    81
        componentStack[m] = currGlyph;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    82
    }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    83
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    84
    ByteOffset actionOffset = flags & lsfPerformAction;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    85
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    86
    if (actionOffset != 0) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    87
        const LigatureActionEntry *ap = (const LigatureActionEntry *) ((char *) &ligatureSubstitutionHeader->stHeader + ligActionOffset) + ligActionIndex;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    88
        const TTGlyphID *ligatureTable = (const TTGlyphID *) ((char *) &ligatureSubstitutionHeader->stHeader + ligatureOffset);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    89
        LigatureActionEntry action;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    90
        le_int32 offset, i = 0;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    91
        le_int32 stack[nComponents];
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    92
        le_int16 mm = -1;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    93
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    94
        const le_uint16 *componentTable = (const le_uint16 *)((char *) &ligatureSubstitutionHeader->stHeader + componentOffset);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    95
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    96
        do {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    97
            le_uint32 componentGlyph = componentStack[m--]; // pop off
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    98
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    99
            action = SWAPL(*ap++);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   100
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   101
            if (m < 0) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   102
                m = nComponents - 1;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   103
            }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   104
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   105
            offset = action & lafComponentOffsetMask;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   106
            if (offset != 0) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   107
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   108
                i += SWAPW(componentTable[LE_GET_GLYPH(glyphStorage[componentGlyph]) + (SignExtend(offset, lafComponentOffsetMask))]);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   109
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   110
                if (action & (lafLast | lafStore))  {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   111
                    TTGlyphID ligatureGlyph = SWAPW(ligatureTable[i]);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   112
                    glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], ligatureGlyph);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   113
                    stack[++mm] = componentGlyph;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   114
                    i = 0;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   115
                } else {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   116
                    glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], 0xFFFF);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   117
                }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   118
            }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   119
        } while (!(action & lafLast));
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   120
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   121
        while (mm >= 0) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   122
            if (++m >= nComponents) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   123
                m = 0;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   124
            }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   125
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   126
            componentStack[m] = stack[mm--];
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   127
        }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   128
    }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   129
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   130
    if (!(flags & lsfDontAdvance)) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   131
        currGlyph += dir;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   132
    }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   133
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   134
    return nextStateIndex;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   135
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   136
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   137
void LigatureSubstitutionProcessor2::endStateTable()
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   138
{
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   139
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   140
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   141
U_NAMESPACE_END