jdk/src/share/native/sun/font/layout/ContextualSubstSubtables.cpp
author prr
Thu, 07 Mar 2013 10:02:20 -0800
changeset 16891 91e99bed64ae
parent 7486 6a36b1ebc620
child 18256 79d3f8278a38
permissions -rw-r--r--
8001031: Better font processing Reviewed-by: srl, vadim
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3935
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3935
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3935
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3935
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3935
diff changeset
    22
 * questions.
2
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,
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    55
        le_int32 position,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    56
        LEErrorCode& success)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
{
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    58
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    59
        return;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    60
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    61
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    GlyphIterator tempIterator(*glyphIterator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    64
    for (le_int16 subst = 0; subst < substCount && LE_SUCCESS(success); subst += 1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        le_uint16 sequenceIndex = SWAPW(substLookupRecordArray[subst].sequenceIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        le_uint16 lookupListIndex = SWAPW(substLookupRecordArray[subst].lookupListIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        tempIterator.setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        tempIterator.next(sequenceIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    71
        lookupProcessor->applySingleLookup(lookupListIndex, &tempIterator, fontInstance, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
le_bool ContextualSubstitutionBase::matchGlyphIDs(const TTGlyphID *glyphArray, le_uint16 glyphCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                               GlyphIterator *glyphIterator, le_bool backtrack)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    le_int32 direction = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    le_int32 match = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    if (backtrack) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        match = glyphCount -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        direction = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    while (glyphCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (! glyphIterator->next()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        TTGlyphID glyph = (TTGlyphID) glyphIterator->getCurrGlyphID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (glyph != SWAPW(glyphArray[match])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        glyphCount -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        match += direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
le_bool ContextualSubstitutionBase::matchGlyphClasses(const le_uint16 *classArray, le_uint16 glyphCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                               GlyphIterator *glyphIterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                                               const ClassDefinitionTable *classDefinitionTable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                                               le_bool backtrack)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    le_int32 direction = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    le_int32 match = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    if (backtrack) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        match = glyphCount - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        direction = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    while (glyphCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (! glyphIterator->next()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        LEGlyphID glyph = glyphIterator->getCurrGlyphID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        le_int32 glyphClass = classDefinitionTable->getGlyphClass(glyph);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        le_int32 matchClass = SWAPW(classArray[match]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (glyphClass != matchClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            // Some fonts, e.g. Traditional Arabic, have classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            // in the class array which aren't in the class definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            // table. If we're looking for such a class, pretend that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            // we found it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            if (classDefinitionTable->hasGlyphClass(matchClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        glyphCount -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        match += direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
le_bool ContextualSubstitutionBase::matchGlyphCoverages(const Offset *coverageTableOffsetArray, le_uint16 glyphCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                                     GlyphIterator *glyphIterator, const char *offsetBase, le_bool backtrack)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    le_int32 direction = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    le_int32 glyph = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    if (backtrack) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        glyph = glyphCount - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        direction = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    while (glyphCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        Offset coverageTableOffset = SWAPW(coverageTableOffsetArray[glyph]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        const CoverageTable *coverageTable = (const CoverageTable *) (offsetBase + coverageTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (! glyphIterator->next()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (coverageTable->getGlyphCoverage((LEGlyphID) glyphIterator->getCurrGlyphID()) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        glyphCount -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        glyph += direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   173
le_uint32 ContextualSubstitutionSubtable::process(const LookupProcessor *lookupProcessor,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   174
                                                  GlyphIterator *glyphIterator,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   175
                                                  const LEFontInstance *fontInstance,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   176
                                                  LEErrorCode& success) const
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
{
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   178
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   179
        return 0;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   180
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   181
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    switch(SWAPW(subtableFormat))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        const ContextualSubstitutionFormat1Subtable *subtable = (const ContextualSubstitutionFormat1Subtable *) this;
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   190
        return subtable->process(lookupProcessor, glyphIterator, fontInstance, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        const ContextualSubstitutionFormat2Subtable *subtable = (const ContextualSubstitutionFormat2Subtable *) this;
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   196
        return subtable->process(lookupProcessor, glyphIterator, fontInstance, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        const ContextualSubstitutionFormat3Subtable *subtable = (const ContextualSubstitutionFormat3Subtable *) this;
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   202
        return subtable->process(lookupProcessor, glyphIterator, fontInstance, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   210
le_uint32 ContextualSubstitutionFormat1Subtable::process(const LookupProcessor *lookupProcessor,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   211
                                                         GlyphIterator *glyphIterator,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   212
                                                         const LEFontInstance *fontInstance,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   213
                                                         LEErrorCode& success) const
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
{
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   215
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   216
        return 0;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   217
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   218
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    LEGlyphID glyph = glyphIterator->getCurrGlyphID();
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 7486
diff changeset
   220
    le_int32 coverageIndex = getGlyphCoverage(lookupProcessor->getReference(), glyph, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    if (coverageIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        le_uint16 srSetCount = SWAPW(subRuleSetCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (coverageIndex < srSetCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            Offset subRuleSetTableOffset = SWAPW(subRuleSetTableOffsetArray[coverageIndex]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            const SubRuleSetTable *subRuleSetTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                (const SubRuleSetTable *) ((char *) this + subRuleSetTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            le_uint16 subRuleCount = SWAPW(subRuleSetTable->subRuleCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            le_int32 position = glyphIterator->getCurrStreamPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            for (le_uint16 subRule = 0; subRule < subRuleCount; subRule += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                Offset subRuleTableOffset =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    SWAPW(subRuleSetTable->subRuleTableOffsetArray[subRule]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                const SubRuleTable *subRuleTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    (const SubRuleTable *) ((char *) subRuleSetTable + subRuleTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                le_uint16 matchCount = SWAPW(subRuleTable->glyphCount) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                le_uint16 substCount = SWAPW(subRuleTable->substCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                if (matchGlyphIDs(subRuleTable->inputGlyphArray, matchCount, glyphIterator)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    const SubstitutionLookupRecord *substLookupRecordArray =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                        (const SubstitutionLookupRecord *) &subRuleTable->inputGlyphArray[matchCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   244
                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    return matchCount + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                glyphIterator->setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        // XXX If we get here, the table is mal-formed...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   259
le_uint32 ContextualSubstitutionFormat2Subtable::process(const LookupProcessor *lookupProcessor,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   260
                                                         GlyphIterator *glyphIterator,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   261
                                                         const LEFontInstance *fontInstance,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   262
                                                         LEErrorCode& success) const
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
{
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   264
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   265
        return 0;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   266
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   267
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    LEGlyphID glyph = glyphIterator->getCurrGlyphID();
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 7486
diff changeset
   269
    le_int32 coverageIndex = getGlyphCoverage(lookupProcessor->getReference(), glyph, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    if (coverageIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        const ClassDefinitionTable *classDefinitionTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            (const ClassDefinitionTable *) ((char *) this + SWAPW(classDefTableOffset));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        le_uint16 scSetCount = SWAPW(subClassSetCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        le_int32 setClass = classDefinitionTable->getGlyphClass(glyphIterator->getCurrGlyphID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (setClass < scSetCount && subClassSetTableOffsetArray[setClass] != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            Offset subClassSetTableOffset = SWAPW(subClassSetTableOffsetArray[setClass]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            const SubClassSetTable *subClassSetTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                (const SubClassSetTable *) ((char *) this + subClassSetTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            le_uint16 subClassRuleCount = SWAPW(subClassSetTable->subClassRuleCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            le_int32 position = glyphIterator->getCurrStreamPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            for (le_uint16 scRule = 0; scRule < subClassRuleCount; scRule += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                Offset subClassRuleTableOffset =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    SWAPW(subClassSetTable->subClassRuleTableOffsetArray[scRule]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                const SubClassRuleTable *subClassRuleTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    (const SubClassRuleTable *) ((char *) subClassSetTable + subClassRuleTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                le_uint16 matchCount = SWAPW(subClassRuleTable->glyphCount) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                le_uint16 substCount = SWAPW(subClassRuleTable->substCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                if (matchGlyphClasses(subClassRuleTable->classArray, matchCount, glyphIterator, classDefinitionTable)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    const SubstitutionLookupRecord *substLookupRecordArray =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                        (const SubstitutionLookupRecord *) &subClassRuleTable->classArray[matchCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   296
                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    return matchCount + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                glyphIterator->setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        // XXX If we get here, the table is mal-formed...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   311
le_uint32 ContextualSubstitutionFormat3Subtable::process(const LookupProcessor *lookupProcessor,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   312
                                                         GlyphIterator *glyphIterator,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   313
                                                         const LEFontInstance *fontInstance,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   314
                                                         LEErrorCode& success)const
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
{
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   316
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   317
        return 0;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   318
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   319
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    le_uint16 gCount = SWAPW(glyphCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    le_uint16 subCount = SWAPW(substCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    le_int32 position = glyphIterator->getCurrStreamPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    // Back up the glyph iterator so that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    // can call next() before the check, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    // will leave it pointing at the last glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    // that matched when we're done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    glyphIterator->prev();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    if (ContextualSubstitutionBase::matchGlyphCoverages(coverageTableOffsetArray, gCount, glyphIterator, (const char *) this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        const SubstitutionLookupRecord *substLookupRecordArray =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            (const SubstitutionLookupRecord *) &coverageTableOffsetArray[gCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   334
        ContextualSubstitutionBase::applySubstitutionLookups(lookupProcessor, substLookupRecordArray, subCount, glyphIterator, fontInstance, position, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return gCount + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    glyphIterator->setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   344
le_uint32 ChainingContextualSubstitutionSubtable::process(const LookupProcessor *lookupProcessor,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   345
                                                          GlyphIterator *glyphIterator,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   346
                                                          const LEFontInstance *fontInstance,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   347
                                                          LEErrorCode& success) const
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
{
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   349
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   350
        return 0;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   351
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   352
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    switch(SWAPW(subtableFormat))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        const ChainingContextualSubstitutionFormat1Subtable *subtable = (const ChainingContextualSubstitutionFormat1Subtable *) this;
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   361
        return subtable->process(lookupProcessor, glyphIterator, fontInstance, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        const ChainingContextualSubstitutionFormat2Subtable *subtable = (const ChainingContextualSubstitutionFormat2Subtable *) this;
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   367
        return subtable->process(lookupProcessor, glyphIterator, fontInstance, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        const ChainingContextualSubstitutionFormat3Subtable *subtable = (const ChainingContextualSubstitutionFormat3Subtable *) this;
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   373
        return subtable->process(lookupProcessor, glyphIterator, fontInstance, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
// NOTE: This could be a #define, but that seems to confuse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
// 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
   383
// GlyphIterator constructor. It somehow can't decide if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
// emptyFeatureList matches an le_uint32 or an le_uint16...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
static const FeatureMask emptyFeatureList = 0x00000000UL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   387
le_uint32 ChainingContextualSubstitutionFormat1Subtable::process(const LookupProcessor *lookupProcessor,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   388
                                                                 GlyphIterator *glyphIterator,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   389
                                                                 const LEFontInstance *fontInstance,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   390
                                                                 LEErrorCode& success) const
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
{
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   392
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   393
        return 0;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   394
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   395
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    LEGlyphID glyph = glyphIterator->getCurrGlyphID();
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 7486
diff changeset
   397
    le_int32 coverageIndex = getGlyphCoverage(lookupProcessor->getReference(), glyph, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    if (coverageIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        le_uint16 srSetCount = SWAPW(chainSubRuleSetCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        if (coverageIndex < srSetCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            Offset chainSubRuleSetTableOffset = SWAPW(chainSubRuleSetTableOffsetArray[coverageIndex]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            const ChainSubRuleSetTable *chainSubRuleSetTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                (const ChainSubRuleSetTable *) ((char *) this + chainSubRuleSetTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            le_uint16 chainSubRuleCount = SWAPW(chainSubRuleSetTable->chainSubRuleCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            le_int32 position = glyphIterator->getCurrStreamPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            GlyphIterator tempIterator(*glyphIterator, emptyFeatureList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            for (le_uint16 subRule = 0; subRule < chainSubRuleCount; subRule += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                Offset chainSubRuleTableOffset =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    SWAPW(chainSubRuleSetTable->chainSubRuleTableOffsetArray[subRule]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                const ChainSubRuleTable *chainSubRuleTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    (const ChainSubRuleTable *) ((char *) chainSubRuleSetTable + chainSubRuleTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                le_uint16 backtrackGlyphCount = SWAPW(chainSubRuleTable->backtrackGlyphCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                le_uint16 inputGlyphCount = (le_uint16) SWAPW(chainSubRuleTable->backtrackGlyphArray[backtrackGlyphCount]) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                const TTGlyphID *inputGlyphArray = &chainSubRuleTable->backtrackGlyphArray[backtrackGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                le_uint16 lookaheadGlyphCount = (le_uint16) SWAPW(inputGlyphArray[inputGlyphCount]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                const TTGlyphID *lookaheadGlyphArray = &inputGlyphArray[inputGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                le_uint16 substCount = (le_uint16) SWAPW(lookaheadGlyphArray[lookaheadGlyphCount]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                tempIterator.setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                if (! tempIterator.prev(backtrackGlyphCount)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                tempIterator.prev();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                if (! matchGlyphIDs(chainSubRuleTable->backtrackGlyphArray, backtrackGlyphCount, &tempIterator, TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                tempIterator.setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                tempIterator.next(inputGlyphCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                if (!matchGlyphIDs(lookaheadGlyphArray, lookaheadGlyphCount, &tempIterator)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                if (matchGlyphIDs(inputGlyphArray, inputGlyphCount, glyphIterator)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    const SubstitutionLookupRecord *substLookupRecordArray =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                        (const SubstitutionLookupRecord *) &lookaheadGlyphArray[lookaheadGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   443
                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    return inputGlyphCount + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                glyphIterator->setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        // XXX If we get here, the table is mal-formed...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   458
le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LookupProcessor *lookupProcessor,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   459
                                                                 GlyphIterator *glyphIterator,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   460
                                                                 const LEFontInstance *fontInstance,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   461
                                                                 LEErrorCode& success) const
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
{
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   463
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   464
        return 0;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   465
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   466
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    LEGlyphID glyph = glyphIterator->getCurrGlyphID();
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 7486
diff changeset
   468
    le_int32 coverageIndex = getGlyphCoverage(lookupProcessor->getReference(), glyph, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    if (coverageIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        const ClassDefinitionTable *backtrackClassDefinitionTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            (const ClassDefinitionTable *) ((char *) this + SWAPW(backtrackClassDefTableOffset));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        const ClassDefinitionTable *inputClassDefinitionTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            (const ClassDefinitionTable *) ((char *) this + SWAPW(inputClassDefTableOffset));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        const ClassDefinitionTable *lookaheadClassDefinitionTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            (const ClassDefinitionTable *) ((char *) this + SWAPW(lookaheadClassDefTableOffset));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        le_uint16 scSetCount = SWAPW(chainSubClassSetCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        le_int32 setClass = inputClassDefinitionTable->getGlyphClass(glyphIterator->getCurrGlyphID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if (setClass < scSetCount && chainSubClassSetTableOffsetArray[setClass] != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            Offset chainSubClassSetTableOffset = SWAPW(chainSubClassSetTableOffsetArray[setClass]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            const ChainSubClassSetTable *chainSubClassSetTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                (const ChainSubClassSetTable *) ((char *) this + chainSubClassSetTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            le_uint16 chainSubClassRuleCount = SWAPW(chainSubClassSetTable->chainSubClassRuleCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            le_int32 position = glyphIterator->getCurrStreamPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            GlyphIterator tempIterator(*glyphIterator, emptyFeatureList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            for (le_uint16 scRule = 0; scRule < chainSubClassRuleCount; scRule += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                Offset chainSubClassRuleTableOffset =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    SWAPW(chainSubClassSetTable->chainSubClassRuleTableOffsetArray[scRule]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                const ChainSubClassRuleTable *chainSubClassRuleTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    (const ChainSubClassRuleTable *) ((char *) chainSubClassSetTable + chainSubClassRuleTableOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                le_uint16 backtrackGlyphCount = SWAPW(chainSubClassRuleTable->backtrackGlyphCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                le_uint16 inputGlyphCount = SWAPW(chainSubClassRuleTable->backtrackClassArray[backtrackGlyphCount]) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                const le_uint16 *inputClassArray = &chainSubClassRuleTable->backtrackClassArray[backtrackGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                le_uint16 lookaheadGlyphCount = SWAPW(inputClassArray[inputGlyphCount]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                const le_uint16 *lookaheadClassArray = &inputClassArray[inputGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                le_uint16 substCount = SWAPW(lookaheadClassArray[lookaheadGlyphCount]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                tempIterator.setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                if (! tempIterator.prev(backtrackGlyphCount)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                tempIterator.prev();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                if (! matchGlyphClasses(chainSubClassRuleTable->backtrackClassArray, backtrackGlyphCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                    &tempIterator, backtrackClassDefinitionTable, TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                    continue;
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.setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                tempIterator.next(inputGlyphCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                if (! matchGlyphClasses(lookaheadClassArray, lookaheadGlyphCount, &tempIterator, lookaheadClassDefinitionTable)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                if (matchGlyphClasses(inputClassArray, inputGlyphCount, glyphIterator, inputClassDefinitionTable)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                    const SubstitutionLookupRecord *substLookupRecordArray =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                        (const SubstitutionLookupRecord *) &lookaheadClassArray[lookaheadGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   523
                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                    return inputGlyphCount + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                glyphIterator->setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        // XXX If we get here, the table is mal-formed...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   538
le_uint32 ChainingContextualSubstitutionFormat3Subtable::process(const LookupProcessor *lookupProcessor,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   539
                                                                 GlyphIterator *glyphIterator,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   540
                                                                 const LEFontInstance *fontInstance,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   541
                                                                 LEErrorCode & success) const
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
{
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   543
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   544
        return 0;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   545
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   546
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    le_uint16 backtrkGlyphCount = SWAPW(backtrackGlyphCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    le_uint16 inputGlyphCount = (le_uint16) SWAPW(backtrackCoverageTableOffsetArray[backtrkGlyphCount]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    const Offset *inputCoverageTableOffsetArray = &backtrackCoverageTableOffsetArray[backtrkGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    const le_uint16 lookaheadGlyphCount = (le_uint16) SWAPW(inputCoverageTableOffsetArray[inputGlyphCount]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    const Offset *lookaheadCoverageTableOffsetArray = &inputCoverageTableOffsetArray[inputGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    le_uint16 substCount = (le_uint16) SWAPW(lookaheadCoverageTableOffsetArray[lookaheadGlyphCount]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    le_int32 position = glyphIterator->getCurrStreamPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    GlyphIterator tempIterator(*glyphIterator, emptyFeatureList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    if (! tempIterator.prev(backtrkGlyphCount)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    tempIterator.prev();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    if (! ContextualSubstitutionBase::matchGlyphCoverages(backtrackCoverageTableOffsetArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        backtrkGlyphCount, &tempIterator, (const char *) this, TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    tempIterator.setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    tempIterator.next(inputGlyphCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    if (! ContextualSubstitutionBase::matchGlyphCoverages(lookaheadCoverageTableOffsetArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        lookaheadGlyphCount, &tempIterator, (const char *) this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    // Back up the glyph iterator so that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    // can call next() before the check, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    // will leave it pointing at the last glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    // that matched when we're done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    glyphIterator->prev();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    if (ContextualSubstitutionBase::matchGlyphCoverages(inputCoverageTableOffsetArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        inputGlyphCount, glyphIterator, (const char *) this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        const SubstitutionLookupRecord *substLookupRecordArray =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            (const SubstitutionLookupRecord *) &lookaheadCoverageTableOffsetArray[lookaheadGlyphCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   584
        ContextualSubstitutionBase::applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        return inputGlyphCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    glyphIterator->setCurrStreamPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
}
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   593
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   594
U_NAMESPACE_END