jdk/src/share/native/sun/font/layout/ContextualGlyphSubstProc2.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 "ContextualGlyphSubstProc2.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
#include <stdio.h>
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    42
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    43
U_NAMESPACE_BEGIN
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    44
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    45
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ContextualGlyphSubstitutionProcessor2)
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    46
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    47
ContextualGlyphSubstitutionProcessor2::ContextualGlyphSubstitutionProcessor2(const MorphSubtableHeader2 *morphSubtableHeader)
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    48
  : StateTableProcessor2(morphSubtableHeader)
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    49
{
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    50
    contextualGlyphHeader = (const ContextualGlyphHeader2 *) morphSubtableHeader;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    51
    le_uint32 perGlyphTableOffset = SWAPL(contextualGlyphHeader->perGlyphTableOffset);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    52
    perGlyphTable = ((le_uint32 *) ((char *)&stateTableHeader->stHeader + perGlyphTableOffset));
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    53
    entryTable = (const ContextualGlyphStateEntry2 *) ((char *) &stateTableHeader->stHeader + entryTableOffset);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    54
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    55
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    56
ContextualGlyphSubstitutionProcessor2::~ContextualGlyphSubstitutionProcessor2()
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    57
{
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    58
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    59
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    60
void ContextualGlyphSubstitutionProcessor2::beginStateTable()
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    61
{
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    62
    markGlyph = 0;
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
le_uint16 ContextualGlyphSubstitutionProcessor2::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex2 index)
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    66
{
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    67
    const ContextualGlyphStateEntry2 *entry = &entryTable[index];
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    68
    le_uint16 newState = SWAPW(entry->newStateIndex);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    69
    le_uint16 flags = SWAPW(entry->flags);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    70
    le_int16 markIndex = SWAPW(entry->markIndex);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    71
    le_int16 currIndex = SWAPW(entry->currIndex);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    72
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    73
    if (markIndex != -1) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    74
        le_uint32 offset = SWAPL(perGlyphTable[markIndex]);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    75
        LEGlyphID mGlyph = glyphStorage[markGlyph];
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    76
        TTGlyphID newGlyph = lookup(offset, mGlyph);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    77
        glyphStorage[markGlyph] = LE_SET_GLYPH(mGlyph, newGlyph);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    78
    }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    79
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    80
    if (currIndex != -1) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    81
        le_uint32 offset = SWAPL(perGlyphTable[currIndex]);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    82
        LEGlyphID thisGlyph = glyphStorage[currGlyph];
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    83
        TTGlyphID newGlyph = lookup(offset, thisGlyph);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    84
        glyphStorage[currGlyph] = LE_SET_GLYPH(thisGlyph, newGlyph);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    85
    }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    86
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    87
    if (flags & cgsSetMark) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    88
        markGlyph = currGlyph;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    89
    }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    90
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    91
    if (!(flags & cgsDontAdvance)) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    92
        currGlyph += dir;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    93
    }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    94
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    95
    return newState;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    96
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    97
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    98
TTGlyphID ContextualGlyphSubstitutionProcessor2::lookup(le_uint32 offset, LEGlyphID gid)
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    99
{
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   100
    LookupTable *lookupTable = ((LookupTable *) ((char *)perGlyphTable + offset));
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   101
    le_int16 format = SWAPW(lookupTable->format);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   102
    TTGlyphID newGlyph = 0xFFFF;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   103
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   104
    switch (format) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   105
        case ltfSimpleArray: {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   106
#ifdef TEST_FORMAT
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   107
            // Disabled pending for design review
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   108
            SimpleArrayLookupTable *lookupTable0 = (SimpleArrayLookupTable *) lookupTable;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   109
            TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   110
            newGlyph = SWAPW(lookupTable0->valueArray[glyphCode]);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   111
#endif
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   112
            break;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   113
        }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   114
        case ltfSegmentSingle: {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   115
#ifdef TEST_FORMAT
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   116
            // Disabled pending for design review
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   117
            SegmentSingleLookupTable *lookupTable2 = (SegmentSingleLookupTable *) lookupTable;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   118
            const LookupSegment *segment = lookupTable2->lookupSegment(lookupTable2->segments, gid);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   119
            if (segment != NULL) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   120
                newGlyph = SWAPW(segment->value);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   121
            }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   122
#endif
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   123
            break;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   124
        }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   125
        case ltfSegmentArray: {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   126
            printf("Context Lookup Table Format4: specific interpretation needed!\n");
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   127
            break;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   128
        }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   129
        case ltfSingleTable:
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   130
        {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   131
#ifdef TEST_FORMAT
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   132
            // Disabled pending for design review
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   133
            SingleTableLookupTable *lookupTable6 = (SingleTableLookupTable *) lookupTable;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   134
            const LookupSingle *segment = lookupTable6->lookupSingle(lookupTable6->entries, gid);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   135
            if (segment != NULL) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   136
                newGlyph = SWAPW(segment->value);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   137
            }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   138
#endif
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   139
            break;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   140
        }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   141
        case ltfTrimmedArray: {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   142
            TrimmedArrayLookupTable *lookupTable8 = (TrimmedArrayLookupTable *) lookupTable;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   143
            TTGlyphID firstGlyph = SWAPW(lookupTable8->firstGlyph);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   144
            TTGlyphID lastGlyph  = firstGlyph + SWAPW(lookupTable8->glyphCount);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   145
            TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   146
            if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   147
                newGlyph = SWAPW(lookupTable8->valueArray[glyphCode - firstGlyph]);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   148
            }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   149
        }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   150
        default:
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   151
            break;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   152
    }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   153
    return newGlyph;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   154
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   155
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   156
void ContextualGlyphSubstitutionProcessor2::endStateTable()
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   157
{
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   158
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   159
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   160
U_NAMESPACE_END