jdk/src/share/native/sun/font/layout/LookupProcessor.cpp
author prr
Thu, 07 Mar 2013 10:02:20 -0800
changeset 16891 91e99bed64ae
parent 16890 36b30720a997
child 18219 d4cd832b9802
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
 *
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents: 15967
diff changeset
    28
 * (C) Copyright IBM Corp. 1998-2013 - 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
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    47
le_uint32 LookupProcessor::applyLookupTable(const LEReferenceTo<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) {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    60
      LEReferenceTo<LookupSubtable> lookupSubtable = lookupTable->getLookupSubtable(lookupTable, subtable, success);
2
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,
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    75
                                  le_bool rightToLeft, const LEReferenceTo<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
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    92
    for (le_uint16 order = 0; order < lookupOrderCount && LE_SUCCESS(success); order += 1) {
2
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) {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    97
          const LEReferenceTo<LookupTable> lookupTable = lookupListTable->getLookupTable(lookupListTable, lookup, success);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    98
          if (!lookupTable.isValid() ||LE_FAILURE(success) ) {
13036
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
    99
                continue;
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents: 15967
diff changeset
   100
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            le_uint16 lookupFlags = SWAPW(lookupTable->lookupFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            glyphIterator.reset(lookupFlags, selectMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            while (glyphIterator.findFeatureTag()) {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   106
              applyLookupTable(lookupTable, &glyphIterator, fontInstance, success); // TODO
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   107
                if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   108
                    return 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            newGlyphCount = glyphIterator.applyInsertions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    return newGlyphCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
le_uint32 LookupProcessor::applySingleLookup(le_uint16 lookupTableIndex, GlyphIterator *glyphIterator,
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   120
                                          const LEFontInstance *fontInstance, LEErrorCode& success) const
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
{
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   122
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   123
        return 0;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   124
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   125
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   126
    const LEReferenceTo<LookupTable> lookupTable = lookupListTable->getLookupTable(lookupListTable, lookupTableIndex, success);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   127
    if (!lookupTable.isValid()) {
15967
688298c47675 8005191: [parfait] #384 sun/font/layout/LookupProcessor.cpp Null pointer dereference
jgodinez
parents: 13036
diff changeset
   128
        success = LE_INTERNAL_ERROR;
688298c47675 8005191: [parfait] #384 sun/font/layout/LookupProcessor.cpp Null pointer dereference
jgodinez
parents: 13036
diff changeset
   129
        return 0;
688298c47675 8005191: [parfait] #384 sun/font/layout/LookupProcessor.cpp Null pointer dereference
jgodinez
parents: 13036
diff changeset
   130
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    le_uint16 lookupFlags = SWAPW(lookupTable->lookupFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    GlyphIterator tempIterator(*glyphIterator, lookupFlags);
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   133
    le_uint32 delta = applyLookupTable(lookupTable, &tempIterator, fontInstance, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    return delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   138
le_int32 LookupProcessor::selectLookups(const LEReferenceTo<FeatureTable> &featureTable, FeatureMask featureMask, le_int32 order, LEErrorCode &success)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
{
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   140
  le_uint16 lookupCount = featureTable.isValid()? SWAPW(featureTable->lookupCount) : 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    le_int32  store = order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   143
    LEReferenceToArrayOf<le_uint16> lookupListIndexArray(featureTable, success, featureTable->lookupListIndexArray, lookupCount);
13036
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   144
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   145
    for (le_uint16 lookup = 0; LE_SUCCESS(success) && lookup < lookupCount; lookup += 1) {
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   146
      le_uint16 lookupListIndex = SWAPW(lookupListIndexArray.getObject(lookup,success));
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   147
      if (lookupListIndex >= lookupSelectCount) {
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   148
        continue;
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   149
      }
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   150
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   151
      lookupSelectArray[lookupListIndex] |= featureMask;
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   152
      lookupOrderArray[store++] = lookupListIndex;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    return store - order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   158
LookupProcessor::LookupProcessor(const LETableReference &baseAddress,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        Offset scriptListOffset, Offset featureListOffset, Offset lookupListOffset,
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   160
        LETag scriptTag, LETag languageTag, const FeatureMap *featureMap, le_int32 featureMapCount, le_bool orderFeatures,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   161
        LEErrorCode& success)
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   162
    : lookupListTable(), featureListTable(), lookupSelectArray(NULL), lookupSelectCount(0),
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   163
      lookupOrderArray(NULL), lookupOrderCount(0), fReference(baseAddress)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
{
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   165
  LEReferenceTo<ScriptListTable> scriptListTable;
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   166
  LEReferenceTo<LangSysTable> langSysTable;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    le_uint16 featureCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    le_uint16 lookupListCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    le_uint16 requiredFeatureIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   171
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   172
        return;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   173
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   174
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    if (scriptListOffset != 0) {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   176
      scriptListTable = LEReferenceTo<ScriptListTable>(baseAddress, success, scriptListOffset);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   177
      langSysTable = scriptListTable->findLanguage(scriptListTable, scriptTag, languageTag, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   179
      if (langSysTable.isValid() && LE_SUCCESS(success)) {
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   180
        featureCount = SWAPW(langSysTable->featureCount);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   181
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    if (featureListOffset != 0) {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   185
      featureListTable = LEReferenceTo<FeatureListTable>(baseAddress, success, featureListOffset);
2
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 (lookupListOffset != 0) {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   189
      lookupListTable = LEReferenceTo<LookupListTable>(baseAddress,success, lookupListOffset);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   190
      if(LE_SUCCESS(success) && lookupListTable.isValid()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        lookupListCount = SWAPW(lookupListTable->lookupCount);
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   192
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   195
    if (langSysTable.isEmpty() || featureListTable.isEmpty() || lookupListTable.isEmpty() ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        featureCount == 0 || lookupListCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   200
    if(langSysTable.isValid()) {
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   201
      requiredFeatureIndex = SWAPW(langSysTable->reqFeatureIndex);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   202
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    lookupSelectArray = LE_NEW_ARRAY(FeatureMask, lookupListCount);
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   205
    if (lookupSelectArray == NULL) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   206
        success = LE_MEMORY_ALLOCATION_ERROR;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   207
        return;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   208
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    for (int i = 0; i < lookupListCount; i += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        lookupSelectArray[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
13036
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   214
    lookupSelectCount = lookupListCount;
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   215
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    le_int32 count, order = 0;
16890
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   217
    le_uint32 featureReferences = 0;
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   218
    LEReferenceTo<FeatureTable> featureTable;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    LETag featureTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   221
    LEReferenceTo<FeatureTable> requiredFeatureTable;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    LETag requiredFeatureTag = 0x00000000U;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    // Count the total number of lookups referenced by all features. This will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    // be the maximum number of entries in the lookupOrderArray. We can't use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    // lookupListCount because some lookups might be referenced by more than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    // one feature.
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   228
    if(featureListTable.isValid() && LE_SUCCESS(success)) {
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   229
      LEReferenceToArrayOf<le_uint16> featureIndexArray(langSysTable, success, langSysTable->featureIndexArray, featureCount);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   231
      for (le_uint32 feature = 0; LE_SUCCESS(success)&&(feature < featureCount); feature += 1) {
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   232
        le_uint16 featureIndex = SWAPW(featureIndexArray.getObject(feature, success));
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   233
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   234
        featureTable = featureListTable->getFeatureTable(featureListTable, featureIndex,  &featureTag, success);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   235
        if (!featureTable.isValid() || LE_FAILURE(success)) {
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   236
          continue;
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents: 15967
diff changeset
   237
        }
3df90f344221 8008249: Sync ICU into JDK
prr
parents: 15967
diff changeset
   238
        featureReferences += SWAPW(featureTable->lookupCount);
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   239
      }
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents: 15967
diff changeset
   240
    }
13036
0fd2665c9314 7143617: Improve fontmanager layout lookup operations
bae
parents: 7486
diff changeset
   241
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   242
    if (!featureTable.isValid() || LE_FAILURE(success)) {
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents: 15967
diff changeset
   243
        success = LE_INTERNAL_ERROR;
3df90f344221 8008249: Sync ICU into JDK
prr
parents: 15967
diff changeset
   244
        return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    if (requiredFeatureIndex != 0xFFFF) {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   248
      requiredFeatureTable = featureListTable->getFeatureTable(featureListTable, requiredFeatureIndex, &requiredFeatureTag, success);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   249
      featureReferences += SWAPW(featureTable->lookupCount);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    lookupOrderArray = LE_NEW_ARRAY(le_uint16, featureReferences);
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   253
    if (lookupOrderArray == NULL) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   254
        success = LE_MEMORY_ALLOCATION_ERROR;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   255
        return;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   256
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    for (le_int32 f = 0; f < featureMapCount; f += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        FeatureMap fm = featureMap[f];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        // If this is the required feature, add its lookups
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (requiredFeatureTag == fm.tag) {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   264
          count += selectLookups(requiredFeatureTable, fm.mask, order, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (orderFeatures) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            // If we added lookups from the required feature, sort them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            if (count > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                OpenTypeUtilities::sort(lookupOrderArray, order);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            for (le_uint16 feature = 0; feature < featureCount; feature += 1) {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   274
              LEReferenceToArrayOf<le_uint16> featureIndexArray(langSysTable, success, langSysTable->featureIndexArray, featureCount);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   275
              le_uint16 featureIndex = SWAPW(featureIndexArray.getObject(feature,success));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                // don't add the required feature to the list more than once...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                // TODO: Do we need this check? (Spec. says required feature won't be in feature list...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                if (featureIndex == requiredFeatureIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   283
                featureTable = featureListTable->getFeatureTable(featureListTable, featureIndex, &featureTag, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                if (featureTag == fm.tag) {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   286
                  count += selectLookups(featureTable, fm.mask, order + count, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            if (count > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                OpenTypeUtilities::sort(&lookupOrderArray[order], count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            order += count;
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   295
        } else if(langSysTable.isValid()) {
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   296
          LEReferenceToArrayOf<le_uint16> featureIndexArray(langSysTable, success, langSysTable->featureIndexArray, featureCount);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   297
          for (le_uint16 feature = 0; LE_SUCCESS(success)&& (feature < featureCount); feature += 1) {
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   298
            le_uint16 featureIndex = SWAPW(featureIndexArray.getObject(feature,success));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                // don't add the required feature to the list more than once...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                // NOTE: This check is commented out because the spec. says that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                // the required feature won't be in the feature list, and because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                // any duplicate entries will be removed below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
#if 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                if (featureIndex == requiredFeatureIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   310
                featureTable = featureListTable->getFeatureTable(featureListTable, featureIndex, &featureTag, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                if (featureTag == fm.tag) {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   313
                  order += selectLookups(featureTable, fm.mask, order, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    if (!orderFeatures && (order > 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        OpenTypeUtilities::sort(lookupOrderArray, order);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        // If there's no specified feature order,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        // we will apply the lookups in the order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        // that they're in the font. If a particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        // lookup may be referenced by more than one feature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        // it will apprear in the lookupOrderArray more than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        // once, so remove any duplicate entries in the sorted array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        le_int32 out = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        for (le_int32 in = 1; in < order; in += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            if (lookupOrderArray[out - 1] != lookupOrderArray[in]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                if (out != in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    lookupOrderArray[out] = lookupOrderArray[in];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                out += 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        order = out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    lookupOrderCount = order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
LookupProcessor::LookupProcessor()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
{
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   348
        lookupOrderArray = NULL;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   349
        lookupSelectArray = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
LookupProcessor::~LookupProcessor()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    LE_DELETE_ARRAY(lookupOrderArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    LE_DELETE_ARRAY(lookupSelectArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
}
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   357
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   358
U_NAMESPACE_END