jdk/src/share/native/sun/font/layout/LigatureSubstProc2.cpp
author prr
Thu, 07 Mar 2013 10:02:20 -0800
changeset 16891 91e99bed64ae
parent 16890 36b30720a997
child 22330 cafb826672bd
permissions -rw-r--r--
8001031: Better font processing Reviewed-by: srl, vadim
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     1
/*
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     3
 *
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
     9
 *
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    14
 * accompanied this code).
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    15
 *
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    19
 *
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    22
 * questions.
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    23
 *
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    24
 */
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    25
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    26
/*
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    27
 *
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    28
 * (C) Copyright IBM Corp and Others. 1998-2013 - All Rights Reserved
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    29
 *
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    30
 */
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    31
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    32
#include "LETypes.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    33
#include "MorphTables.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    34
#include "StateTables.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    35
#include "MorphStateTables.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    36
#include "SubtableProcessor2.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    37
#include "StateTableProcessor2.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    38
#include "LigatureSubstProc2.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    39
#include "LEGlyphStorage.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    40
#include "LESwaps.h"
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    41
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    42
U_NAMESPACE_BEGIN
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    43
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    44
#define ExtendedComplement(m) ((le_int32) (~((le_uint32) (m))))
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    45
#define SignBit(m) ((ExtendedComplement(m) >> 1) & (le_int32)(m))
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    46
#define SignExtend(v,m) (((v) & SignBit(m))? ((v) | ExtendedComplement(m)): (v))
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    47
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    48
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LigatureSubstitutionProcessor2)
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    49
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    50
LigatureSubstitutionProcessor2::LigatureSubstitutionProcessor2(const LEReferenceTo<MorphSubtableHeader2> &morphSubtableHeader, LEErrorCode &success)
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    51
  : StateTableProcessor2(morphSubtableHeader, success),
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    52
  ligActionOffset(0),
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    53
  ligatureSubstitutionHeader(morphSubtableHeader, success), componentOffset(0), ligatureOffset(0), entryTable()
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    54
{
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    55
    if (LE_FAILURE(success)) return;
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    56
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    57
    ligActionOffset = SWAPL(ligatureSubstitutionHeader->ligActionOffset);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    58
    componentOffset = SWAPL(ligatureSubstitutionHeader->componentOffset);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    59
    ligatureOffset = SWAPL(ligatureSubstitutionHeader->ligatureOffset);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    60
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    61
    entryTable = LEReferenceToArrayOf<LigatureSubstitutionStateEntry2>(stHeader, success, entryTableOffset, LE_UNBOUNDED_ARRAY);
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    62
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    63
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    64
LigatureSubstitutionProcessor2::~LigatureSubstitutionProcessor2()
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    65
{
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    66
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    67
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    68
void LigatureSubstitutionProcessor2::beginStateTable()
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    69
{
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    70
    m = -1;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    71
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    72
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    73
le_uint16 LigatureSubstitutionProcessor2::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex2 index, LEErrorCode &success)
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    74
{
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    75
    const LigatureSubstitutionStateEntry2 *entry = entryTable.getAlias(index, success);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    76
    if(LE_FAILURE(success)) return 0;
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    77
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    78
    le_uint16 nextStateIndex = SWAPW(entry->nextStateIndex);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    79
    le_uint16 flags = SWAPW(entry->entryFlags);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    80
    le_uint16 ligActionIndex = SWAPW(entry->ligActionIndex);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    81
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    82
    if (flags & lsfSetComponent) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    83
        if (++m >= nComponents) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    84
            m = 0;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    85
        }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    86
        componentStack[m] = currGlyph;
16890
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
    87
    } else if ( m == -1) {
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
    88
        // bad font- skip this glyph.
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    89
        //LE_DEBUG_BAD_FONT("m==-1 (componentCount went negative)")
16890
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
    90
        currGlyph+= dir;
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
    91
        return nextStateIndex;
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    92
    }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    93
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    94
    ByteOffset actionOffset = flags & lsfPerformAction;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    95
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
    96
    if (actionOffset != 0) {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    97
        LEReferenceTo<LigatureActionEntry> ap(stHeader, success, ligActionOffset); // byte offset
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    98
        ap.addObject(ligActionIndex - 1, success);  // index offset ( one before the actual start, because we will pre-increment)
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
    99
        LEReferenceToArrayOf<TTGlyphID> ligatureTable(stHeader, success, ligatureOffset, LE_UNBOUNDED_ARRAY);
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   100
        LigatureActionEntry action;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   101
        le_int32 offset, i = 0;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   102
        le_int32 stack[nComponents];
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   103
        le_int16 mm = -1;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   104
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   105
        LEReferenceToArrayOf<le_uint16> componentTable(stHeader, success, componentOffset, LE_UNBOUNDED_ARRAY);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   106
        if(LE_FAILURE(success)) {
16890
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   107
          currGlyph+= dir;
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   108
            return nextStateIndex; // get out! bad font
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   109
        }
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   110
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   111
        do {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   112
            le_uint32 componentGlyph = componentStack[m--]; // pop off
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   113
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   114
            ap.addObject(success);
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   115
            action = SWAPL(*ap.getAlias());
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   116
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   117
            if (m < 0) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   118
                m = nComponents - 1;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   119
            }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   120
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   121
            offset = action & lafComponentOffsetMask;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   122
            if (offset != 0) {
16890
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   123
                if(componentGlyph > glyphStorage.getGlyphCount()) {
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   124
                  LE_DEBUG_BAD_FONT("preposterous componentGlyph");
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   125
                  currGlyph+= dir;
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   126
                  return nextStateIndex; // get out! bad font
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   127
                }
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   128
                i += SWAPW(componentTable(LE_GET_GLYPH(glyphStorage[componentGlyph]) + (SignExtend(offset, lafComponentOffsetMask)),success));
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   129
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   130
                if (action & (lafLast | lafStore))  {
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 16890
diff changeset
   131
                  TTGlyphID ligatureGlyph = SWAPW(ligatureTable(i,success));
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   132
                    glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], ligatureGlyph);
16890
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   133
                    if(mm==nComponents) {
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   134
                      LE_DEBUG_BAD_FONT("exceeded nComponents");
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   135
                      mm--; // don't overrun the stack.
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   136
                    }
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   137
                    stack[++mm] = componentGlyph;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   138
                    i = 0;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   139
                } else {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   140
                    glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], 0xFFFF);
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   141
                }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   142
            }
16890
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   143
#if LE_ASSERT_BAD_FONT
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   144
            if(m<0) {
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   145
              LE_DEBUG_BAD_FONT("m<0")
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   146
            }
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   147
#endif
36b30720a997 8004986: Better handling of glyph table
prr
parents: 16889
diff changeset
   148
        } while (!(action & lafLast) && (m>=0) ); // stop if last bit is set, or if run out of items
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   149
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   150
        while (mm >= 0) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   151
            if (++m >= nComponents) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   152
                m = 0;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   153
            }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   154
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   155
            componentStack[m] = stack[mm--];
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   156
        }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   157
    }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   158
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   159
    if (!(flags & lsfDontAdvance)) {
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   160
        currGlyph += dir;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   161
    }
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   162
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   163
    return nextStateIndex;
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   164
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   165
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   166
void LigatureSubstitutionProcessor2::endStateTable()
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   167
{
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   168
}
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   169
3df90f344221 8008249: Sync ICU into JDK
prr
parents:
diff changeset
   170
U_NAMESPACE_END