jdk/src/share/native/sun/font/layout/ContextualSubstSubtables.cpp
author srl
Tue, 29 Sep 2009 14:06:13 -0700
changeset 3935 afcdb712a9c5
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6501644: sync LayoutEngine *code* structure to match ICU Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "LETypes.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "LEFontInstance.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "OpenTypeTables.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "GlyphSubstitutionTables.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "ContextualSubstSubtables.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "GlyphIterator.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "LookupProcessor.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "CoverageTables.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "LESwaps.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    41
U_NAMESPACE_BEGIN
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    42
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    NOTE: This could be optimized somewhat by keeping track
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    of the previous sequenceIndex in the loop and doing next()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    or prev() of the delta between that and the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    sequenceIndex instead of always resetting to the front.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
void ContextualSubstitutionBase::applySubstitutionLookups(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        const LookupProcessor *lookupProcessor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        const SubstitutionLookupRecord *substLookupRecordArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        le_uint16 substCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        GlyphIterator *glyphIterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        const LEFontInstance *fontInstance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        le_int32 position)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    GlyphIterator tempIterator(*glyphIterator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    for (le_int16 subst = 0; subst < substCount; subst += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        le_uint16 sequenceIndex = SWAPW(substLookupRecordArray[subst].sequenceIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        le_uint16 lookupListIndex = SWAPW(substLookupRecordArray[subst].lookupListIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        tempIterator.setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        tempIterator.next(sequenceIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        lookupProcessor->applySingleLookup(lookupListIndex, &tempIterator, fontInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
le_bool ContextualSubstitutionBase::matchGlyphIDs(const TTGlyphID *glyphArray, le_uint16 glyphCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                               GlyphIterator *glyphIterator, le_bool backtrack)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    le_int32 direction = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    le_int32 match = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    if (backtrack) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        match = glyphCount -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        direction = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    while (glyphCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        if (! glyphIterator->next()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        TTGlyphID glyph = (TTGlyphID) glyphIterator->getCurrGlyphID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        if (glyph != SWAPW(glyphArray[match])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        glyphCount -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        match += direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
le_bool ContextualSubstitutionBase::matchGlyphClasses(const le_uint16 *classArray, le_uint16 glyphCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                               GlyphIterator *glyphIterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                               const ClassDefinitionTable *classDefinitionTable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                                               le_bool backtrack)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    le_int32 direction = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    le_int32 match = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    if (backtrack) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        match = glyphCount - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        direction = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    while (glyphCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if (! glyphIterator->next()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        LEGlyphID glyph = glyphIterator->getCurrGlyphID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        le_int32 glyphClass = classDefinitionTable->getGlyphClass(glyph);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        le_int32 matchClass = SWAPW(classArray[match]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (glyphClass != matchClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            // Some fonts, e.g. Traditional Arabic, have classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            // in the class array which aren't in the class definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            // table. If we're looking for such a class, pretend that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            // we found it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            if (classDefinitionTable->hasGlyphClass(matchClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        glyphCount -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        match += direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
le_bool ContextualSubstitutionBase::matchGlyphCoverages(const Offset *coverageTableOffsetArray, le_uint16 glyphCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                                     GlyphIterator *glyphIterator, const char *offsetBase, le_bool backtrack)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    le_int32 direction = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    le_int32 glyph = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    if (backtrack) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        glyph = glyphCount - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        direction = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    while (glyphCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        Offset coverageTableOffset = SWAPW(coverageTableOffsetArray[glyph]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        const CoverageTable *coverageTable = (const CoverageTable *) (offsetBase + coverageTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (! glyphIterator->next()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (coverageTable->getGlyphCoverage((LEGlyphID) glyphIterator->getCurrGlyphID()) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        glyphCount -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        glyph += direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
le_uint32 ContextualSubstitutionSubtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                               const LEFontInstance *fontInstance) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    switch(SWAPW(subtableFormat))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        const ContextualSubstitutionFormat1Subtable *subtable = (const ContextualSubstitutionFormat1Subtable *) this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return subtable->process(lookupProcessor, glyphIterator, fontInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        const ContextualSubstitutionFormat2Subtable *subtable = (const ContextualSubstitutionFormat2Subtable *) this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return subtable->process(lookupProcessor, glyphIterator, fontInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        const ContextualSubstitutionFormat3Subtable *subtable = (const ContextualSubstitutionFormat3Subtable *) this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return subtable->process(lookupProcessor, glyphIterator, fontInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
le_uint32 ContextualSubstitutionFormat1Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                                                      const LEFontInstance *fontInstance) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    LEGlyphID glyph = glyphIterator->getCurrGlyphID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    le_int32 coverageIndex = getGlyphCoverage(glyph);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    if (coverageIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        le_uint16 srSetCount = SWAPW(subRuleSetCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (coverageIndex < srSetCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            Offset subRuleSetTableOffset = SWAPW(subRuleSetTableOffsetArray[coverageIndex]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            const SubRuleSetTable *subRuleSetTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                (const SubRuleSetTable *) ((char *) this + subRuleSetTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            le_uint16 subRuleCount = SWAPW(subRuleSetTable->subRuleCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            le_int32 position = glyphIterator->getCurrStreamPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            for (le_uint16 subRule = 0; subRule < subRuleCount; subRule += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                Offset subRuleTableOffset =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    SWAPW(subRuleSetTable->subRuleTableOffsetArray[subRule]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                const SubRuleTable *subRuleTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    (const SubRuleTable *) ((char *) subRuleSetTable + subRuleTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                le_uint16 matchCount = SWAPW(subRuleTable->glyphCount) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                le_uint16 substCount = SWAPW(subRuleTable->substCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                if (matchGlyphIDs(subRuleTable->inputGlyphArray, matchCount, glyphIterator)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    const SubstitutionLookupRecord *substLookupRecordArray =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                        (const SubstitutionLookupRecord *) &subRuleTable->inputGlyphArray[matchCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    return matchCount + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                glyphIterator->setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        // XXX If we get here, the table is mal-formed...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
le_uint32 ContextualSubstitutionFormat2Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                                      const LEFontInstance *fontInstance) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    LEGlyphID glyph = glyphIterator->getCurrGlyphID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    le_int32 coverageIndex = getGlyphCoverage(glyph);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    if (coverageIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        const ClassDefinitionTable *classDefinitionTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            (const ClassDefinitionTable *) ((char *) this + SWAPW(classDefTableOffset));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        le_uint16 scSetCount = SWAPW(subClassSetCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        le_int32 setClass = classDefinitionTable->getGlyphClass(glyphIterator->getCurrGlyphID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (setClass < scSetCount && subClassSetTableOffsetArray[setClass] != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            Offset subClassSetTableOffset = SWAPW(subClassSetTableOffsetArray[setClass]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            const SubClassSetTable *subClassSetTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                (const SubClassSetTable *) ((char *) this + subClassSetTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            le_uint16 subClassRuleCount = SWAPW(subClassSetTable->subClassRuleCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            le_int32 position = glyphIterator->getCurrStreamPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            for (le_uint16 scRule = 0; scRule < subClassRuleCount; scRule += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                Offset subClassRuleTableOffset =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    SWAPW(subClassSetTable->subClassRuleTableOffsetArray[scRule]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                const SubClassRuleTable *subClassRuleTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    (const SubClassRuleTable *) ((char *) subClassSetTable + subClassRuleTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                le_uint16 matchCount = SWAPW(subClassRuleTable->glyphCount) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                le_uint16 substCount = SWAPW(subClassRuleTable->substCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                if (matchGlyphClasses(subClassRuleTable->classArray, matchCount, glyphIterator, classDefinitionTable)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    const SubstitutionLookupRecord *substLookupRecordArray =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                        (const SubstitutionLookupRecord *) &subClassRuleTable->classArray[matchCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    return matchCount + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                glyphIterator->setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        // XXX If we get here, the table is mal-formed...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
le_uint32 ContextualSubstitutionFormat3Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                                                      const LEFontInstance *fontInstance)const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    le_uint16 gCount = SWAPW(glyphCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    le_uint16 subCount = SWAPW(substCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    le_int32 position = glyphIterator->getCurrStreamPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    // Back up the glyph iterator so that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    // can call next() before the check, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    // will leave it pointing at the last glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    // that matched when we're done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    glyphIterator->prev();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    if (ContextualSubstitutionBase::matchGlyphCoverages(coverageTableOffsetArray, gCount, glyphIterator, (const char *) this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        const SubstitutionLookupRecord *substLookupRecordArray =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            (const SubstitutionLookupRecord *) &coverageTableOffsetArray[gCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        ContextualSubstitutionBase::applySubstitutionLookups(lookupProcessor, substLookupRecordArray, subCount, glyphIterator, fontInstance, position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        return gCount + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    glyphIterator->setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
le_uint32 ChainingContextualSubstitutionSubtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                                                       const LEFontInstance *fontInstance) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    switch(SWAPW(subtableFormat))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        const ChainingContextualSubstitutionFormat1Subtable *subtable = (const ChainingContextualSubstitutionFormat1Subtable *) this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return subtable->process(lookupProcessor, glyphIterator, fontInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        const ChainingContextualSubstitutionFormat2Subtable *subtable = (const ChainingContextualSubstitutionFormat2Subtable *) this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return subtable->process(lookupProcessor, glyphIterator, fontInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        const ChainingContextualSubstitutionFormat3Subtable *subtable = (const ChainingContextualSubstitutionFormat3Subtable *) this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return subtable->process(lookupProcessor, glyphIterator, fontInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
// NOTE: This could be a #define, but that seems to confuse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
// the Visual Studio .NET 2003 compiler on the calls to the
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   354
// GlyphIterator constructor. It somehow can't decide if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
// emptyFeatureList matches an le_uint32 or an le_uint16...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
static const FeatureMask emptyFeatureList = 0x00000000UL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
le_uint32 ChainingContextualSubstitutionFormat1Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                                                              const LEFontInstance *fontInstance) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    LEGlyphID glyph = glyphIterator->getCurrGlyphID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    le_int32 coverageIndex = getGlyphCoverage(glyph);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    if (coverageIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        le_uint16 srSetCount = SWAPW(chainSubRuleSetCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if (coverageIndex < srSetCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            Offset chainSubRuleSetTableOffset = SWAPW(chainSubRuleSetTableOffsetArray[coverageIndex]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            const ChainSubRuleSetTable *chainSubRuleSetTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                (const ChainSubRuleSetTable *) ((char *) this + chainSubRuleSetTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            le_uint16 chainSubRuleCount = SWAPW(chainSubRuleSetTable->chainSubRuleCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            le_int32 position = glyphIterator->getCurrStreamPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            GlyphIterator tempIterator(*glyphIterator, emptyFeatureList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            for (le_uint16 subRule = 0; subRule < chainSubRuleCount; subRule += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                Offset chainSubRuleTableOffset =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    SWAPW(chainSubRuleSetTable->chainSubRuleTableOffsetArray[subRule]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                const ChainSubRuleTable *chainSubRuleTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    (const ChainSubRuleTable *) ((char *) chainSubRuleSetTable + chainSubRuleTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                le_uint16 backtrackGlyphCount = SWAPW(chainSubRuleTable->backtrackGlyphCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                le_uint16 inputGlyphCount = (le_uint16) SWAPW(chainSubRuleTable->backtrackGlyphArray[backtrackGlyphCount]) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                const TTGlyphID *inputGlyphArray = &chainSubRuleTable->backtrackGlyphArray[backtrackGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                le_uint16 lookaheadGlyphCount = (le_uint16) SWAPW(inputGlyphArray[inputGlyphCount]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                const TTGlyphID *lookaheadGlyphArray = &inputGlyphArray[inputGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                le_uint16 substCount = (le_uint16) SWAPW(lookaheadGlyphArray[lookaheadGlyphCount]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                tempIterator.setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                if (! tempIterator.prev(backtrackGlyphCount)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                tempIterator.prev();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                if (! matchGlyphIDs(chainSubRuleTable->backtrackGlyphArray, backtrackGlyphCount, &tempIterator, TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                tempIterator.setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                tempIterator.next(inputGlyphCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                if (!matchGlyphIDs(lookaheadGlyphArray, lookaheadGlyphCount, &tempIterator)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                if (matchGlyphIDs(inputGlyphArray, inputGlyphCount, glyphIterator)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    const SubstitutionLookupRecord *substLookupRecordArray =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                        (const SubstitutionLookupRecord *) &lookaheadGlyphArray[lookaheadGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    return inputGlyphCount + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                glyphIterator->setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        // XXX If we get here, the table is mal-formed...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                                              const LEFontInstance *fontInstance) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    LEGlyphID glyph = glyphIterator->getCurrGlyphID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    le_int32 coverageIndex = getGlyphCoverage(glyph);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    if (coverageIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        const ClassDefinitionTable *backtrackClassDefinitionTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            (const ClassDefinitionTable *) ((char *) this + SWAPW(backtrackClassDefTableOffset));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        const ClassDefinitionTable *inputClassDefinitionTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            (const ClassDefinitionTable *) ((char *) this + SWAPW(inputClassDefTableOffset));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        const ClassDefinitionTable *lookaheadClassDefinitionTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            (const ClassDefinitionTable *) ((char *) this + SWAPW(lookaheadClassDefTableOffset));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        le_uint16 scSetCount = SWAPW(chainSubClassSetCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        le_int32 setClass = inputClassDefinitionTable->getGlyphClass(glyphIterator->getCurrGlyphID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        if (setClass < scSetCount && chainSubClassSetTableOffsetArray[setClass] != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            Offset chainSubClassSetTableOffset = SWAPW(chainSubClassSetTableOffsetArray[setClass]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            const ChainSubClassSetTable *chainSubClassSetTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                (const ChainSubClassSetTable *) ((char *) this + chainSubClassSetTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            le_uint16 chainSubClassRuleCount = SWAPW(chainSubClassSetTable->chainSubClassRuleCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            le_int32 position = glyphIterator->getCurrStreamPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            GlyphIterator tempIterator(*glyphIterator, emptyFeatureList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            for (le_uint16 scRule = 0; scRule < chainSubClassRuleCount; scRule += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                Offset chainSubClassRuleTableOffset =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    SWAPW(chainSubClassSetTable->chainSubClassRuleTableOffsetArray[scRule]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                const ChainSubClassRuleTable *chainSubClassRuleTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                    (const ChainSubClassRuleTable *) ((char *) chainSubClassSetTable + chainSubClassRuleTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                le_uint16 backtrackGlyphCount = SWAPW(chainSubClassRuleTable->backtrackGlyphCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                le_uint16 inputGlyphCount = SWAPW(chainSubClassRuleTable->backtrackClassArray[backtrackGlyphCount]) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                const le_uint16 *inputClassArray = &chainSubClassRuleTable->backtrackClassArray[backtrackGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                le_uint16 lookaheadGlyphCount = SWAPW(inputClassArray[inputGlyphCount]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                const le_uint16 *lookaheadClassArray = &inputClassArray[inputGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                le_uint16 substCount = SWAPW(lookaheadClassArray[lookaheadGlyphCount]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                tempIterator.setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                if (! tempIterator.prev(backtrackGlyphCount)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                tempIterator.prev();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                if (! matchGlyphClasses(chainSubClassRuleTable->backtrackClassArray, backtrackGlyphCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    &tempIterator, backtrackClassDefinitionTable, TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                tempIterator.setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                tempIterator.next(inputGlyphCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                if (! matchGlyphClasses(lookaheadClassArray, lookaheadGlyphCount, &tempIterator, lookaheadClassDefinitionTable)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                if (matchGlyphClasses(inputClassArray, inputGlyphCount, glyphIterator, inputClassDefinitionTable)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    const SubstitutionLookupRecord *substLookupRecordArray =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                        (const SubstitutionLookupRecord *) &lookaheadClassArray[lookaheadGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    return inputGlyphCount + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                glyphIterator->setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        // XXX If we get here, the table is mal-formed...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
le_uint32 ChainingContextualSubstitutionFormat3Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                                                              const LEFontInstance *fontInstance) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    le_uint16 backtrkGlyphCount = SWAPW(backtrackGlyphCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    le_uint16 inputGlyphCount = (le_uint16) SWAPW(backtrackCoverageTableOffsetArray[backtrkGlyphCount]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    const Offset *inputCoverageTableOffsetArray = &backtrackCoverageTableOffsetArray[backtrkGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    const le_uint16 lookaheadGlyphCount = (le_uint16) SWAPW(inputCoverageTableOffsetArray[inputGlyphCount]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    const Offset *lookaheadCoverageTableOffsetArray = &inputCoverageTableOffsetArray[inputGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    le_uint16 substCount = (le_uint16) SWAPW(lookaheadCoverageTableOffsetArray[lookaheadGlyphCount]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    le_int32 position = glyphIterator->getCurrStreamPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    GlyphIterator tempIterator(*glyphIterator, emptyFeatureList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    if (! tempIterator.prev(backtrkGlyphCount)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    tempIterator.prev();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    if (! ContextualSubstitutionBase::matchGlyphCoverages(backtrackCoverageTableOffsetArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        backtrkGlyphCount, &tempIterator, (const char *) this, TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    tempIterator.setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    tempIterator.next(inputGlyphCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    if (! ContextualSubstitutionBase::matchGlyphCoverages(lookaheadCoverageTableOffsetArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        lookaheadGlyphCount, &tempIterator, (const char *) this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    // Back up the glyph iterator so that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    // can call next() before the check, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    // will leave it pointing at the last glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    // that matched when we're done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    glyphIterator->prev();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    if (ContextualSubstitutionBase::matchGlyphCoverages(inputCoverageTableOffsetArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        inputGlyphCount, glyphIterator, (const char *) this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        const SubstitutionLookupRecord *substLookupRecordArray =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            (const SubstitutionLookupRecord *) &lookaheadCoverageTableOffsetArray[lookaheadGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        ContextualSubstitutionBase::applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        return inputGlyphCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    glyphIterator->setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
}
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   546
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   547
U_NAMESPACE_END