jdk/src/share/native/sun/font/layout/LookupProcessor.cpp
author bae
Tue, 28 Feb 2012 10:44:56 +0400
changeset 13036 0fd2665c9314
parent 7486 6a36b1ebc620
child 15967 688298c47675
permissions -rw-r--r--
7143617: Improve fontmanager layout lookup operations Reviewed-by: igor, prr, mschoene
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
 *
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    28
 * (C) Copyright IBM Corp. 1998-2010 - All Rights Reserved
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "LETypes.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "OpenTypeUtilities.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "LEFontInstance.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "OpenTypeTables.h"
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    36
#include "ICUFeatures.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "Lookups.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "ScriptAndLanguage.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "GlyphDefinitionTables.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include "GlyphIterator.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include "LookupProcessor.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include "LEGlyphStorage.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "LESwaps.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    45
U_NAMESPACE_BEGIN
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    46
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
le_uint32 LookupProcessor::applyLookupTable(const LookupTable *lookupTable, GlyphIterator *glyphIterator,
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    48
                                         const LEFontInstance *fontInstance, LEErrorCode& success) const
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
{
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    50
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    51
        return 0;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    52
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    53
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    le_uint16 lookupType = SWAPW(lookupTable->lookupType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    le_uint16 subtableCount = SWAPW(lookupTable->subTableCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    le_int32 startPosition = glyphIterator->getCurrStreamPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    le_uint32 delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    for (le_uint16 subtable = 0; subtable < subtableCount; subtable += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        const LookupSubtable *lookupSubtable = lookupTable->getLookupSubtable(subtable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    62
        delta = applySubtable(lookupSubtable, lookupType, glyphIterator, fontInstance, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    64
        if (delta > 0 && LE_FAILURE(success)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        glyphIterator->setCurrStreamPosition(startPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    74
le_int32 LookupProcessor::process(LEGlyphStorage &glyphStorage, GlyphPositionAdjustments *glyphPositionAdjustments,
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    75
                              le_bool rightToLeft, const GlyphDefinitionTableHeader *glyphDefinitionTableHeader,
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    76
                              const LEFontInstance *fontInstance, LEErrorCode& success) const
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
{
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    78
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    79
        return 0;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    80
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    81
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    le_int32 glyphCount = glyphStorage.getGlyphCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    if (lookupSelectArray == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return glyphCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    GlyphIterator glyphIterator(glyphStorage, glyphPositionAdjustments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                rightToLeft, 0, 0, glyphDefinitionTableHeader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    le_int32 newGlyphCount = glyphCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    for (le_uint16 order = 0; order < lookupOrderCount; order += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        le_uint16 lookup = lookupOrderArray[order];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        FeatureMask selectMask = lookupSelectArray[lookup];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (selectMask != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            const LookupTable *lookupTable = lookupListTable->getLookupTable(lookup);
13036
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
    98
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
    99
            if (!lookupTable)
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   100
                continue;
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   101
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            le_uint16 lookupFlags = SWAPW(lookupTable->lookupFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            glyphIterator.reset(lookupFlags, selectMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            while (glyphIterator.findFeatureTag()) {
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   107
                applyLookupTable(lookupTable, &glyphIterator, fontInstance, success);
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   108
                if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   109
                    return 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            newGlyphCount = glyphIterator.applyInsertions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    return newGlyphCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
le_uint32 LookupProcessor::applySingleLookup(le_uint16 lookupTableIndex, GlyphIterator *glyphIterator,
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   121
                                          const LEFontInstance *fontInstance, LEErrorCode& success) const
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
{
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   123
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   124
        return 0;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   125
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   126
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    const LookupTable *lookupTable = lookupListTable->getLookupTable(lookupTableIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    le_uint16 lookupFlags = SWAPW(lookupTable->lookupFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    GlyphIterator tempIterator(*glyphIterator, lookupFlags);
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   130
    le_uint32 delta = applyLookupTable(lookupTable, &tempIterator, fontInstance, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    return delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
le_int32 LookupProcessor::selectLookups(const FeatureTable *featureTable, FeatureMask featureMask, le_int32 order)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    le_uint16 lookupCount = featureTable? SWAPW(featureTable->lookupCount) : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    le_int32  store = order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    for (le_uint16 lookup = 0; lookup < lookupCount; lookup += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        le_uint16 lookupListIndex = SWAPW(featureTable->lookupListIndexArray[lookup]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
13036
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   143
        if (lookupListIndex >= lookupSelectCount)
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   144
            continue;
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   145
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        lookupSelectArray[lookupListIndex] |= featureMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        lookupOrderArray[store++] = lookupListIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    return store - order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
LookupProcessor::LookupProcessor(const char *baseAddress,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        Offset scriptListOffset, Offset featureListOffset, Offset lookupListOffset,
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   155
        LETag scriptTag, LETag languageTag, const FeatureMap *featureMap, le_int32 featureMapCount, le_bool orderFeatures,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   156
        LEErrorCode& success)
13036
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   157
    : lookupListTable(NULL), featureListTable(NULL), lookupSelectArray(NULL), lookupSelectCount(0),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
      lookupOrderArray(NULL), lookupOrderCount(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    const ScriptListTable *scriptListTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    const LangSysTable *langSysTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    le_uint16 featureCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    le_uint16 lookupListCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    le_uint16 requiredFeatureIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   166
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   167
        return;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   168
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   169
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    if (scriptListOffset != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        scriptListTable = (const ScriptListTable *) (baseAddress + scriptListOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        langSysTable = scriptListTable->findLanguage(scriptTag, languageTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (langSysTable != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            featureCount = SWAPW(langSysTable->featureCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    if (featureListOffset != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        featureListTable = (const FeatureListTable *) (baseAddress + featureListOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    if (lookupListOffset != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        lookupListTable = (const LookupListTable *) (baseAddress + lookupListOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        lookupListCount = SWAPW(lookupListTable->lookupCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    if (langSysTable == NULL || featureListTable == NULL || lookupListTable == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        featureCount == 0 || lookupListCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    requiredFeatureIndex = SWAPW(langSysTable->reqFeatureIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    lookupSelectArray = LE_NEW_ARRAY(FeatureMask, lookupListCount);
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   196
    if (lookupSelectArray == NULL) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   197
        success = LE_MEMORY_ALLOCATION_ERROR;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   198
        return;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   199
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    for (int i = 0; i < lookupListCount; i += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        lookupSelectArray[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
13036
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   205
    lookupSelectCount = lookupListCount;
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   206
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    le_int32 count, order = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    le_int32 featureReferences = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    const FeatureTable *featureTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    LETag featureTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    const FeatureTable *requiredFeatureTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    LETag requiredFeatureTag = 0x00000000U;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    // Count the total number of lookups referenced by all features. This will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    // be the maximum number of entries in the lookupOrderArray. We can't use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    // lookupListCount because some lookups might be referenced by more than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    // one feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    for (le_int32 feature = 0; feature < featureCount; feature += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        le_uint16 featureIndex = SWAPW(langSysTable->featureIndexArray[feature]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        featureTable = featureListTable->getFeatureTable(featureIndex, &featureTag);
13036
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   223
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   224
        if (!featureTable)
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   225
            continue;
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   226
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        featureReferences += SWAPW(featureTable->lookupCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    if (requiredFeatureIndex != 0xFFFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        requiredFeatureTable = featureListTable->getFeatureTable(requiredFeatureIndex, &requiredFeatureTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        featureReferences += SWAPW(featureTable->lookupCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    lookupOrderArray = LE_NEW_ARRAY(le_uint16, featureReferences);
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   236
    if (lookupOrderArray == NULL) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   237
        success = LE_MEMORY_ALLOCATION_ERROR;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   238
        return;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   239
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    for (le_int32 f = 0; f < featureMapCount; f += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        FeatureMap fm = featureMap[f];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        // If this is the required feature, add its lookups
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (requiredFeatureTag == fm.tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            count += selectLookups(requiredFeatureTable, fm.mask, order);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (orderFeatures) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            // If we added lookups from the required feature, sort them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if (count > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                OpenTypeUtilities::sort(lookupOrderArray, order);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            for (le_uint16 feature = 0; feature < featureCount; feature += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                le_uint16 featureIndex = SWAPW(langSysTable->featureIndexArray[feature]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                // don't add the required feature to the list more than once...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                // TODO: Do we need this check? (Spec. says required feature won't be in feature list...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                if (featureIndex == requiredFeatureIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                featureTable = featureListTable->getFeatureTable(featureIndex, &featureTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                if (featureTag == fm.tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    count += selectLookups(featureTable, fm.mask, order + count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            if (count > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                OpenTypeUtilities::sort(&lookupOrderArray[order], count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            order += count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            for (le_uint16 feature = 0; feature < featureCount; feature += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                le_uint16 featureIndex = SWAPW(langSysTable->featureIndexArray[feature]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                // don't add the required feature to the list more than once...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                // NOTE: This check is commented out because the spec. says that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                // the required feature won't be in the feature list, and because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                // any duplicate entries will be removed below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
#if 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                if (featureIndex == requiredFeatureIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                featureTable = featureListTable->getFeatureTable(featureIndex, &featureTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                if (featureTag == fm.tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    order += selectLookups(featureTable, fm.mask, order);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    if (!orderFeatures && (order > 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        OpenTypeUtilities::sort(lookupOrderArray, order);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        // If there's no specified feature order,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        // we will apply the lookups in the order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        // that they're in the font. If a particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        // lookup may be referenced by more than one feature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        // it will apprear in the lookupOrderArray more than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        // once, so remove any duplicate entries in the sorted array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        le_int32 out = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        for (le_int32 in = 1; in < order; in += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            if (lookupOrderArray[out - 1] != lookupOrderArray[in]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                if (out != in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    lookupOrderArray[out] = lookupOrderArray[in];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                out += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        order = out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    lookupOrderCount = order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
LookupProcessor::LookupProcessor()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
{
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   329
        lookupOrderArray = NULL;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   330
        lookupSelectArray = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
LookupProcessor::~LookupProcessor()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    LE_DELETE_ARRAY(lookupOrderArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    LE_DELETE_ARRAY(lookupSelectArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
}
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   338
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   339
U_NAMESPACE_END