1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * This code is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 only, as
6 * published by the Free Software Foundation. Oracle designates this
7 * particular file as subject to the "Classpath" exception as provided
8 * by Oracle in the LICENSE file that accompanied this code.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 /*
27 *
28 * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
29 *
30 */
31
32 #include "LETypes.h"
33 #include "MorphTables.h"
34 #include "StateTables.h"
35 #include "MorphStateTables.h"
36 #include "SubtableProcessor.h"
37 #include "StateTableProcessor.h"
38 #include "ContextualGlyphSubstProc.h"
39 #include "LEGlyphStorage.h"
40 #include "LESwaps.h"
41
42 U_NAMESPACE_BEGIN
43
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ContextualGlyphSubstitutionProcessor)44 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ContextualGlyphSubstitutionProcessor)
45
46 ContextualGlyphSubstitutionProcessor::ContextualGlyphSubstitutionProcessor(const LEReferenceTo<MorphSubtableHeader> &morphSubtableHeader, LEErrorCode &success)
47 : StateTableProcessor(morphSubtableHeader, success), entryTable(), contextualGlyphSubstitutionHeader(morphSubtableHeader, success)
48 {
49 if (LE_FAILURE(success)) return;
50 contextualGlyphSubstitutionHeader.orphan();
51 substitutionTableOffset = SWAPW(contextualGlyphSubstitutionHeader->substitutionTableOffset);
52
53
54 entryTable = LEReferenceToArrayOf<ContextualGlyphSubstitutionStateEntry>(stateTableHeader, success,
55 (const ContextualGlyphSubstitutionStateEntry*)(&stateTableHeader->stHeader),
56 entryTableOffset, LE_UNBOUNDED_ARRAY);
57 int16Table = LEReferenceToArrayOf<le_int16>(stateTableHeader, success, (const le_int16*)(&stateTableHeader->stHeader),
58 0, LE_UNBOUNDED_ARRAY); // rest of the table as le_int16s
59 }
60
~ContextualGlyphSubstitutionProcessor()61 ContextualGlyphSubstitutionProcessor::~ContextualGlyphSubstitutionProcessor()
62 {
63 }
64
beginStateTable()65 void ContextualGlyphSubstitutionProcessor::beginStateTable()
66 {
67 markGlyph = 0;
68 }
69
processStateEntry(LEGlyphStorage & glyphStorage,le_int32 & currGlyph,EntryTableIndex index,LEErrorCode & success)70 ByteOffset ContextualGlyphSubstitutionProcessor::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex index, LEErrorCode &success)
71 {
72 const ContextualGlyphSubstitutionStateEntry *entry = entryTable.getAlias(index, success);
73 if (LE_FAILURE(success)) return 0;
74 ByteOffset newState = SWAPW(entry->newStateOffset);
75 le_int16 flags = SWAPW(entry->flags);
76 WordOffset markOffset = SWAPW(entry->markOffset);
77 WordOffset currOffset = SWAPW(entry->currOffset);
78
79 if (markOffset != 0 && LE_SUCCESS(success)) {
80 if (markGlyph < 0 || markGlyph >= glyphStorage.getGlyphCount()) {
81 success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
82 return 0;
83 }
84 LEGlyphID mGlyph = glyphStorage[markGlyph];
85 TTGlyphID newGlyph = SWAPW(int16Table.getObject(markOffset + LE_GET_GLYPH(mGlyph), success)); // whew.
86
87 glyphStorage[markGlyph] = LE_SET_GLYPH(mGlyph, newGlyph);
88 }
89
90 if (currOffset != 0) {
91 if (currGlyph < 0 || currGlyph >= glyphStorage.getGlyphCount()) {
92 success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
93 return 0;
94 }
95 LEGlyphID thisGlyph = glyphStorage[currGlyph];
96 TTGlyphID newGlyph = SWAPW(int16Table.getObject(currOffset + LE_GET_GLYPH(thisGlyph), success)); // whew.
97
98 glyphStorage[currGlyph] = LE_SET_GLYPH(thisGlyph, newGlyph);
99 }
100
101 if (flags & cgsSetMark) {
102 markGlyph = currGlyph;
103 }
104
105 if (!(flags & cgsDontAdvance)) {
106 // should handle reverse too!
107 currGlyph += 1;
108 }
109
110 return newState;
111 }
112
endStateTable()113 void ContextualGlyphSubstitutionProcessor::endStateTable()
114 {
115 }
116
117 U_NAMESPACE_END
118