jdk/src/share/native/sun/font/layout/ContextualGlyphSubstProc2.cpp
author kvn
Tue, 28 Jan 2014 14:57:41 -0800
changeset 22607 ba232b417248
parent 16891 91e99bed64ae
child 23908 fdbaab67db73
permissions -rw-r--r--
Merge
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
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
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ContextualGlyphSubstitutionProcessor2)
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    45
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    46
ContextualGlyphSubstitutionProcessor2::ContextualGlyphSubstitutionProcessor2(
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    47
                                  const LEReferenceTo<MorphSubtableHeader2> &morphSubtableHeader, LEErrorCode &success)
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    48
  : StateTableProcessor2(morphSubtableHeader, success), contextualGlyphHeader(morphSubtableHeader, success)
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    49
{
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    50
    if(LE_FAILURE(success)) return;
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    51
    le_uint32 perGlyphTableOffset = SWAPL(contextualGlyphHeader->perGlyphTableOffset);
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    52
    perGlyphTable = LEReferenceToArrayOf<le_uint32> (stHeader, success, perGlyphTableOffset, LE_UNBOUNDED_ARRAY);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    53
    entryTable = LEReferenceToArrayOf<ContextualGlyphStateEntry2>(stHeader, success, entryTableOffset, LE_UNBOUNDED_ARRAY);
16889
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
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    65
le_uint16 ContextualGlyphSubstitutionProcessor2::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph,
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    66
    EntryTableIndex2 index, LEErrorCode &success)
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    67
{
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    68
    if(LE_FAILURE(success)) return 0;
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    69
    const ContextualGlyphStateEntry2 *entry = entryTable.getAlias(index, success);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    70
    if(LE_FAILURE(success)) return 0;
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    71
    le_uint16 newState = SWAPW(entry->newStateIndex);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    72
    le_uint16 flags = SWAPW(entry->flags);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    73
    le_int16 markIndex = SWAPW(entry->markIndex);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    74
    le_int16 currIndex = SWAPW(entry->currIndex);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    75
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    76
    if (markIndex != -1) {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    77
        le_uint32 offset = SWAPL(perGlyphTable(markIndex, success));
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    78
        LEGlyphID mGlyph = glyphStorage[markGlyph];
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    79
        TTGlyphID newGlyph = lookup(offset, mGlyph, success);
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    80
        glyphStorage[markGlyph] = LE_SET_GLYPH(mGlyph, newGlyph);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    81
    }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    82
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    83
    if (currIndex != -1) {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    84
        le_uint32 offset = SWAPL(perGlyphTable(currIndex, success));
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    85
        LEGlyphID thisGlyph = glyphStorage[currGlyph];
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    86
        TTGlyphID newGlyph = lookup(offset, thisGlyph, success);
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    87
        glyphStorage[currGlyph] = LE_SET_GLYPH(thisGlyph, newGlyph);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    88
    }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    89
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    90
    if (flags & cgsSetMark) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    91
        markGlyph = currGlyph;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    92
    }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    93
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    94
    if (!(flags & cgsDontAdvance)) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    95
        currGlyph += dir;
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
    return newState;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    99
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   100
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   101
TTGlyphID ContextualGlyphSubstitutionProcessor2::lookup(le_uint32 offset, LEGlyphID gid, LEErrorCode &success)
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   102
{
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   103
    TTGlyphID newGlyph = 0xFFFF;
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   104
    if(LE_FAILURE(success))  return newGlyph;
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   105
    LEReferenceTo<LookupTable> lookupTable(perGlyphTable, success, offset);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   106
    if(LE_FAILURE(success))  return newGlyph;
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   107
    le_int16 format = SWAPW(lookupTable->format);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   108
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   109
    switch (format) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   110
        case ltfSimpleArray: {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   111
#ifdef TEST_FORMAT
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   112
            // Disabled pending for design review
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   113
            LEReferenceTo<SimpleArrayLookupTable> lookupTable0(lookupTable, success);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   114
            LEReferenceToArrayOf<LookupValue> valueArray(lookupTable0, success, &lookupTable0->valueArray[0], LE_UNBOUNDED_ARRAY);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   115
            if(LE_FAILURE(success))  return newGlyph;
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   116
            TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   117
            newGlyph = SWAPW(lookupTable0->valueArray(glyphCode, success));
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   118
#endif
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   119
            break;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   120
        }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   121
        case ltfSegmentSingle: {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   122
#ifdef TEST_FORMAT
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   123
            // Disabled pending for design review
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   124
            LEReferenceTo<SegmentSingleLookupTable> lookupTable2 = (SegmentSingleLookupTable *) lookupTable;
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   125
            const LookupSegment *segment = lookupTable2->lookupSegment(lookupTable2->segments, gid);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   126
            if (segment != NULL) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   127
                newGlyph = SWAPW(segment->value);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   128
            }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   129
#endif
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   130
            break;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   131
        }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   132
        case ltfSegmentArray: {
16890
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   133
            //printf("Context Lookup Table Format4: specific interpretation needed!\n");
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   134
            break;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   135
        }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   136
        case ltfSingleTable:
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   137
        {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   138
#ifdef TEST_FORMAT
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   139
            // Disabled pending for design review
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   140
            LEReferenceTo<SingleTableLookupTable> lookupTable6 = (SingleTableLookupTable *) lookupTable;
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   141
            const LEReferenceTo<LookupSingle> segment = lookupTable6->lookupSingle(lookupTable6->entries, gid);
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   142
            if (segment != NULL) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   143
                newGlyph = SWAPW(segment->value);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   144
            }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   145
#endif
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   146
            break;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   147
        }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   148
        case ltfTrimmedArray: {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   149
            LEReferenceTo<TrimmedArrayLookupTable> lookupTable8(lookupTable, success);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   150
            if (LE_FAILURE(success)) return newGlyph;
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   151
            TTGlyphID firstGlyph = SWAPW(lookupTable8->firstGlyph);
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   152
            TTGlyphID glyphCount = SWAPW(lookupTable8->glyphCount);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   153
            TTGlyphID lastGlyph  = firstGlyph + glyphCount;
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   154
            TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   155
            if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   156
              LEReferenceToArrayOf<LookupValue> valueArray(lookupTable8, success, &lookupTable8->valueArray[0], glyphCount);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   157
              newGlyph = SWAPW(valueArray(glyphCode - firstGlyph, success));
16889
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
        default:
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   161
            break;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   162
    }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   163
    return newGlyph;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   164
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   165
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   166
void ContextualGlyphSubstitutionProcessor2::endStateTable()
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   167
{
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   168
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   169
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   170
U_NAMESPACE_END