16889
|
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. and others 1998-2013 - All Rights Reserved
|
|
29 |
*
|
|
30 |
*/
|
|
31 |
|
|
32 |
#include "LETypes.h"
|
|
33 |
#include "MorphTables.h"
|
|
34 |
#include "StateTables.h"
|
|
35 |
#include "MorphStateTables.h"
|
|
36 |
#include "SubtableProcessor2.h"
|
|
37 |
#include "StateTableProcessor2.h"
|
|
38 |
#include "ContextualGlyphSubstProc2.h"
|
|
39 |
#include "LEGlyphStorage.h"
|
|
40 |
#include "LESwaps.h"
|
|
41 |
|
|
42 |
U_NAMESPACE_BEGIN
|
|
43 |
|
|
44 |
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ContextualGlyphSubstitutionProcessor2)
|
|
45 |
|
16891
|
46 |
ContextualGlyphSubstitutionProcessor2::ContextualGlyphSubstitutionProcessor2(
|
|
47 |
const LEReferenceTo<MorphSubtableHeader2> &morphSubtableHeader, LEErrorCode &success)
|
|
48 |
: StateTableProcessor2(morphSubtableHeader, success), contextualGlyphHeader(morphSubtableHeader, success)
|
16889
|
49 |
{
|
16891
|
50 |
if(LE_FAILURE(success)) return;
|
16889
|
51 |
le_uint32 perGlyphTableOffset = SWAPL(contextualGlyphHeader->perGlyphTableOffset);
|
16891
|
52 |
perGlyphTable = LEReferenceToArrayOf<le_uint32> (stHeader, success, perGlyphTableOffset, LE_UNBOUNDED_ARRAY);
|
|
53 |
entryTable = LEReferenceToArrayOf<ContextualGlyphStateEntry2>(stHeader, success, entryTableOffset, LE_UNBOUNDED_ARRAY);
|
16889
|
54 |
}
|
|
55 |
|
|
56 |
ContextualGlyphSubstitutionProcessor2::~ContextualGlyphSubstitutionProcessor2()
|
|
57 |
{
|
|
58 |
}
|
|
59 |
|
|
60 |
void ContextualGlyphSubstitutionProcessor2::beginStateTable()
|
|
61 |
{
|
|
62 |
markGlyph = 0;
|
|
63 |
}
|
|
64 |
|
16891
|
65 |
le_uint16 ContextualGlyphSubstitutionProcessor2::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph,
|
|
66 |
EntryTableIndex2 index, LEErrorCode &success)
|
16889
|
67 |
{
|
16891
|
68 |
if(LE_FAILURE(success)) return 0;
|
|
69 |
const ContextualGlyphStateEntry2 *entry = entryTable.getAlias(index, success);
|
|
70 |
if(LE_FAILURE(success)) return 0;
|
16889
|
71 |
le_uint16 newState = SWAPW(entry->newStateIndex);
|
|
72 |
le_uint16 flags = SWAPW(entry->flags);
|
|
73 |
le_int16 markIndex = SWAPW(entry->markIndex);
|
|
74 |
le_int16 currIndex = SWAPW(entry->currIndex);
|
|
75 |
|
|
76 |
if (markIndex != -1) {
|
16891
|
77 |
le_uint32 offset = SWAPL(perGlyphTable(markIndex, success));
|
16889
|
78 |
LEGlyphID mGlyph = glyphStorage[markGlyph];
|
16891
|
79 |
TTGlyphID newGlyph = lookup(offset, mGlyph, success);
|
16889
|
80 |
glyphStorage[markGlyph] = LE_SET_GLYPH(mGlyph, newGlyph);
|
|
81 |
}
|
|
82 |
|
|
83 |
if (currIndex != -1) {
|
16891
|
84 |
le_uint32 offset = SWAPL(perGlyphTable(currIndex, success));
|
16889
|
85 |
LEGlyphID thisGlyph = glyphStorage[currGlyph];
|
16891
|
86 |
TTGlyphID newGlyph = lookup(offset, thisGlyph, success);
|
16889
|
87 |
glyphStorage[currGlyph] = LE_SET_GLYPH(thisGlyph, newGlyph);
|
|
88 |
}
|
|
89 |
|
|
90 |
if (flags & cgsSetMark) {
|
|
91 |
markGlyph = currGlyph;
|
|
92 |
}
|
|
93 |
|
|
94 |
if (!(flags & cgsDontAdvance)) {
|
|
95 |
currGlyph += dir;
|
|
96 |
}
|
|
97 |
|
|
98 |
return newState;
|
|
99 |
}
|
|
100 |
|
16891
|
101 |
TTGlyphID ContextualGlyphSubstitutionProcessor2::lookup(le_uint32 offset, LEGlyphID gid, LEErrorCode &success)
|
16889
|
102 |
{
|
16891
|
103 |
TTGlyphID newGlyph = 0xFFFF;
|
|
104 |
if(LE_FAILURE(success)) return newGlyph;
|
|
105 |
LEReferenceTo<LookupTable> lookupTable(perGlyphTable, success, offset);
|
|
106 |
if(LE_FAILURE(success)) return newGlyph;
|
16889
|
107 |
le_int16 format = SWAPW(lookupTable->format);
|
|
108 |
|
|
109 |
switch (format) {
|
|
110 |
case ltfSimpleArray: {
|
|
111 |
#ifdef TEST_FORMAT
|
|
112 |
// Disabled pending for design review
|
16891
|
113 |
LEReferenceTo<SimpleArrayLookupTable> lookupTable0(lookupTable, success);
|
|
114 |
LEReferenceToArrayOf<LookupValue> valueArray(lookupTable0, success, &lookupTable0->valueArray[0], LE_UNBOUNDED_ARRAY);
|
|
115 |
if(LE_FAILURE(success)) return newGlyph;
|
16889
|
116 |
TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
|
16891
|
117 |
newGlyph = SWAPW(lookupTable0->valueArray(glyphCode, success));
|
16889
|
118 |
#endif
|
|
119 |
break;
|
|
120 |
}
|
|
121 |
case ltfSegmentSingle: {
|
|
122 |
#ifdef TEST_FORMAT
|
|
123 |
// Disabled pending for design review
|
16891
|
124 |
LEReferenceTo<SegmentSingleLookupTable> lookupTable2 = (SegmentSingleLookupTable *) lookupTable;
|
16889
|
125 |
const LookupSegment *segment = lookupTable2->lookupSegment(lookupTable2->segments, gid);
|
|
126 |
if (segment != NULL) {
|
|
127 |
newGlyph = SWAPW(segment->value);
|
|
128 |
}
|
|
129 |
#endif
|
|
130 |
break;
|
|
131 |
}
|
|
132 |
case ltfSegmentArray: {
|
16890
|
133 |
//printf("Context Lookup Table Format4: specific interpretation needed!\n");
|
16889
|
134 |
break;
|
|
135 |
}
|
|
136 |
case ltfSingleTable:
|
|
137 |
{
|
|
138 |
#ifdef TEST_FORMAT
|
|
139 |
// Disabled pending for design review
|
16891
|
140 |
LEReferenceTo<SingleTableLookupTable> lookupTable6 = (SingleTableLookupTable *) lookupTable;
|
|
141 |
const LEReferenceTo<LookupSingle> segment = lookupTable6->lookupSingle(lookupTable6->entries, gid);
|
16889
|
142 |
if (segment != NULL) {
|
|
143 |
newGlyph = SWAPW(segment->value);
|
|
144 |
}
|
|
145 |
#endif
|
|
146 |
break;
|
|
147 |
}
|
|
148 |
case ltfTrimmedArray: {
|
16891
|
149 |
LEReferenceTo<TrimmedArrayLookupTable> lookupTable8(lookupTable, success);
|
|
150 |
if (LE_FAILURE(success)) return newGlyph;
|
16889
|
151 |
TTGlyphID firstGlyph = SWAPW(lookupTable8->firstGlyph);
|
16891
|
152 |
TTGlyphID glyphCount = SWAPW(lookupTable8->glyphCount);
|
|
153 |
TTGlyphID lastGlyph = firstGlyph + glyphCount;
|
16889
|
154 |
TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
|
|
155 |
if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) {
|
16891
|
156 |
LEReferenceToArrayOf<LookupValue> valueArray(lookupTable8, success, &lookupTable8->valueArray[0], glyphCount);
|
|
157 |
newGlyph = SWAPW(valueArray(glyphCode - firstGlyph, success));
|
16889
|
158 |
}
|
|
159 |
}
|
|
160 |
default:
|
|
161 |
break;
|
|
162 |
}
|
|
163 |
return newGlyph;
|
|
164 |
}
|
|
165 |
|
|
166 |
void ContextualGlyphSubstitutionProcessor2::endStateTable()
|
|
167 |
{
|
|
168 |
}
|
|
169 |
|
|
170 |
U_NAMESPACE_END
|