MorphTables.cpp 4.8 KB
Newer Older
D
duke 已提交
1 2 3 4 5
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
6
 * published by the Free Software Foundation.  Oracle designates this
D
duke 已提交
7
 * particular file as subject to the "Classpath" exception as provided
8
 * by Oracle in the LICENSE file that accompanied this code.
D
duke 已提交
9 10 11 12 13 14 15 16 17 18 19
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
20 21 22
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
 *
 */

/*
 *
 * (C) Copyright IBM Corp. 1998 - 2004 - All Rights Reserved
 *
 */


#include "LETypes.h"
#include "LayoutTables.h"
#include "MorphTables.h"
#include "SubtableProcessor.h"
#include "IndicRearrangementProcessor.h"
#include "ContextualGlyphSubstProc.h"
#include "LigatureSubstProc.h"
#include "NonContextualGlyphSubstProc.h"
//#include "ContextualGlyphInsertionProcessor.h"
#include "LEGlyphStorage.h"
#include "LESwaps.h"

45 46
U_NAMESPACE_BEGIN

P
prr 已提交
47
void MorphTableHeader::process(const LETableReference &base, LEGlyphStorage &glyphStorage, LEErrorCode &success) const
D
duke 已提交
48
{
P
prr 已提交
49 50 51
  le_uint32 chainCount = SWAPL(this->nChains);
  LEReferenceTo<ChainHeader> chainHeader(base, success, chains); // moving header
    LEReferenceToArrayOf<ChainHeader> chainHeaderArray(base, success, chains, chainCount);
D
duke 已提交
52 53
    le_uint32 chain;

P
prr 已提交
54
    for (chain = 0; LE_SUCCESS(success) && (chain < chainCount); chain += 1) {
V
vadim 已提交
55 56
        if (chain > 0) {
            le_uint32 chainLength = SWAPL(chainHeader->chainLength);
57 58 59 60
            if (chainLength & 0x03) { // incorrect alignment for 32 bit tables
                success = LE_MEMORY_ALLOCATION_ERROR; // as good a choice as any
                return;
            }
V
vadim 已提交
61 62
            chainHeader.addOffset(chainLength, success);
        }
D
duke 已提交
63 64 65
        FeatureFlags defaultFlags = SWAPL(chainHeader->defaultFlags);
        le_int16 nFeatureEntries = SWAPW(chainHeader->nFeatureEntries);
        le_int16 nSubtables = SWAPW(chainHeader->nSubtables);
P
prr 已提交
66 67
        LEReferenceTo<MorphSubtableHeader> subtableHeader =
          LEReferenceTo<MorphSubtableHeader>(chainHeader,success, &(chainHeader->featureTable[nFeatureEntries]));
D
duke 已提交
68 69
        le_int16 subtable;

P
prr 已提交
70
        for (subtable = 0; LE_SUCCESS(success) && (subtable < nSubtables); subtable += 1) {
V
vadim 已提交
71 72
            if (subtable > 0) {
                le_int16 length = SWAPW(subtableHeader->length);
73 74 75 76
                if (length & 0x03) { // incorrect alignment for 32 bit tables
                    success = LE_MEMORY_ALLOCATION_ERROR; // as good a choice as any
                    return;
                }
V
vadim 已提交
77
                subtableHeader.addOffset(length, success);
P
prr 已提交
78
                if (LE_FAILURE(success)) break;
V
vadim 已提交
79
            }
D
duke 已提交
80 81 82 83
            SubtableCoverage coverage = SWAPW(subtableHeader->coverage);
            FeatureFlags subtableFeatures = SWAPL(subtableHeader->subtableFeatures);

            // should check coverage more carefully...
P
prr 已提交
84 85
            if ((coverage & scfVertical) == 0 && (subtableFeatures & defaultFlags) != 0  && LE_SUCCESS(success)) {
              subtableHeader->process(subtableHeader, glyphStorage, success);
D
duke 已提交
86 87 88 89 90
            }
        }
    }
}

P
prr 已提交
91
void MorphSubtableHeader::process(const LEReferenceTo<MorphSubtableHeader> &base, LEGlyphStorage &glyphStorage, LEErrorCode &success) const
D
duke 已提交
92 93 94
{
    SubtableProcessor *processor = NULL;

P
prr 已提交
95 96
    if (LE_FAILURE(success)) return;

D
duke 已提交
97 98 99
    switch (SWAPW(coverage) & scfTypeMask)
    {
    case mstIndicRearrangement:
P
prr 已提交
100
      processor = new IndicRearrangementProcessor(base, success);
D
duke 已提交
101 102 103
        break;

    case mstContextualGlyphSubstitution:
P
prr 已提交
104
      processor = new ContextualGlyphSubstitutionProcessor(base, success);
D
duke 已提交
105 106 107
        break;

    case mstLigatureSubstitution:
P
prr 已提交
108
      processor = new LigatureSubstitutionProcessor(base, success);
D
duke 已提交
109 110 111 112 113 114
        break;

    case mstReservedUnused:
        break;

    case mstNonContextualGlyphSubstitution:
P
prr 已提交
115
      processor = NonContextualGlyphSubstitutionProcessor::createInstance(base, success);
D
duke 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128
        break;

    /*
    case mstContextualGlyphInsertion:
        processor = new ContextualGlyphInsertionProcessor(this);
        break;
    */

    default:
        break;
    }

    if (processor != NULL) {
P
prr 已提交
129 130 131 132
      if(LE_SUCCESS(success)) {
        processor->process(glyphStorage, success);
      }
      delete processor;
D
duke 已提交
133 134
    }
}
135 136

U_NAMESPACE_END