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 "LEGlyphStorage.h"
|
|
39 |
#include "LESwaps.h"
|
|
40 |
#include "LookupTables.h"
|
|
41 |
|
|
42 |
U_NAMESPACE_BEGIN
|
|
43 |
|
|
44 |
StateTableProcessor2::StateTableProcessor2()
|
|
45 |
{
|
|
46 |
}
|
|
47 |
|
16891
|
48 |
StateTableProcessor2::StateTableProcessor2(const LEReferenceTo<MorphSubtableHeader2> &morphSubtableHeader, LEErrorCode &success)
|
|
49 |
: SubtableProcessor2(morphSubtableHeader, success), stateTableHeader(morphSubtableHeader, success),
|
|
50 |
stHeader(stateTableHeader, success, (const StateTableHeader2*)&stateTableHeader->stHeader),
|
|
51 |
nClasses(0), classTableOffset(0), stateArrayOffset(0), entryTableOffset(0), classTable(), format(0),
|
|
52 |
stateArray()
|
16889
|
53 |
{
|
16891
|
54 |
if (LE_FAILURE(success)) {
|
|
55 |
return;
|
|
56 |
}
|
|
57 |
nClasses = SWAPL(stHeader->nClasses);
|
|
58 |
classTableOffset = SWAPL(stHeader->classTableOffset);
|
|
59 |
stateArrayOffset = SWAPL(stHeader->stateArrayOffset);
|
|
60 |
entryTableOffset = SWAPL(stHeader->entryTableOffset);
|
16889
|
61 |
|
16891
|
62 |
classTable = LEReferenceTo<LookupTable>(stHeader, success, classTableOffset);
|
|
63 |
format = SWAPW(classTable->format);
|
16889
|
64 |
|
16891
|
65 |
stateArray = LEReferenceToArrayOf<EntryTableIndex2>(stHeader, success, stateArrayOffset, LE_UNBOUNDED_ARRAY);
|
16889
|
66 |
}
|
|
67 |
|
|
68 |
StateTableProcessor2::~StateTableProcessor2()
|
|
69 |
{
|
|
70 |
}
|
|
71 |
|
16891
|
72 |
void StateTableProcessor2::process(LEGlyphStorage &glyphStorage, LEErrorCode &success)
|
16889
|
73 |
{
|
16891
|
74 |
if (LE_FAILURE(success)) return;
|
16889
|
75 |
// Start at state 0
|
|
76 |
// XXX: How do we know when to start at state 1?
|
|
77 |
le_uint16 currentState = 0;
|
|
78 |
le_int32 glyphCount = glyphStorage.getGlyphCount();
|
|
79 |
|
16890
|
80 |
LE_STATE_PATIENCE_INIT();
|
|
81 |
|
16889
|
82 |
le_int32 currGlyph = 0;
|
|
83 |
if ((coverage & scfReverse2) != 0) { // process glyphs in descending order
|
|
84 |
currGlyph = glyphCount - 1;
|
|
85 |
dir = -1;
|
|
86 |
} else {
|
|
87 |
dir = 1;
|
|
88 |
}
|
|
89 |
|
|
90 |
beginStateTable();
|
|
91 |
switch (format) {
|
|
92 |
case ltfSimpleArray: {
|
|
93 |
#ifdef TEST_FORMAT
|
16891
|
94 |
LEReferenceTo<SimpleArrayLookupTable> lookupTable0(classTable, success);
|
|
95 |
if(LE_FAILURE(success)) break;
|
16889
|
96 |
while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
|
16891
|
97 |
if (LE_FAILURE(success)) break;
|
|
98 |
if (LE_STATE_PATIENCE_DECR()) {
|
16890
|
99 |
LE_DEBUG_BAD_FONT("patience exceeded - state table not moving")
|
|
100 |
break; // patience exceeded.
|
|
101 |
}
|
16889
|
102 |
LookupValue classCode = classCodeOOB;
|
|
103 |
if (currGlyph == glyphCount || currGlyph == -1) {
|
|
104 |
// XXX: How do we handle EOT vs. EOL?
|
|
105 |
classCode = classCodeEOT;
|
|
106 |
} else {
|
|
107 |
LEGlyphID gid = glyphStorage[currGlyph];
|
|
108 |
TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
|
|
109 |
|
|
110 |
if (glyphCode == 0xFFFF) {
|
|
111 |
classCode = classCodeDEL;
|
|
112 |
} else {
|
|
113 |
classCode = SWAPW(lookupTable0->valueArray[gid]);
|
|
114 |
}
|
|
115 |
}
|
16891
|
116 |
EntryTableIndex2 entryTableIndex = SWAPW(stateArray(classCode + currentState * nClasses, success));
|
16890
|
117 |
LE_STATE_PATIENCE_CURR(le_int32, currGlyph);
|
16889
|
118 |
currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex); // return a zero-based index instead of a byte offset
|
16890
|
119 |
LE_STATE_PATIENCE_INCR(currGlyph);
|
16889
|
120 |
}
|
|
121 |
#endif
|
|
122 |
break;
|
|
123 |
}
|
|
124 |
case ltfSegmentSingle: {
|
16891
|
125 |
LEReferenceTo<SegmentSingleLookupTable> lookupTable2(classTable, success);
|
|
126 |
if(LE_FAILURE(success)) break;
|
16889
|
127 |
while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
|
16891
|
128 |
if (LE_FAILURE(success)) break;
|
|
129 |
if (LE_STATE_PATIENCE_DECR()) {
|
|
130 |
LE_DEBUG_BAD_FONT("patience exceeded - state table not moving")
|
16890
|
131 |
break; // patience exceeded.
|
|
132 |
}
|
16889
|
133 |
LookupValue classCode = classCodeOOB;
|
|
134 |
if (currGlyph == glyphCount || currGlyph == -1) {
|
|
135 |
// XXX: How do we handle EOT vs. EOL?
|
|
136 |
classCode = classCodeEOT;
|
|
137 |
} else {
|
|
138 |
LEGlyphID gid = glyphStorage[currGlyph];
|
|
139 |
TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
|
|
140 |
|
|
141 |
if (glyphCode == 0xFFFF) {
|
|
142 |
classCode = classCodeDEL;
|
|
143 |
} else {
|
16891
|
144 |
const LookupSegment *segment =
|
|
145 |
lookupTable2->lookupSegment(lookupTable2, lookupTable2->segments, gid, success);
|
|
146 |
if (segment != NULL && LE_SUCCESS(success)) {
|
16889
|
147 |
classCode = SWAPW(segment->value);
|
|
148 |
}
|
|
149 |
}
|
|
150 |
}
|
16891
|
151 |
EntryTableIndex2 entryTableIndex = SWAPW(stateArray(classCode + currentState * nClasses,success));
|
16890
|
152 |
LE_STATE_PATIENCE_CURR(le_int32, currGlyph);
|
16891
|
153 |
currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex, success);
|
16890
|
154 |
LE_STATE_PATIENCE_INCR(currGlyph);
|
16889
|
155 |
}
|
|
156 |
break;
|
|
157 |
}
|
|
158 |
case ltfSegmentArray: {
|
16890
|
159 |
//printf("Lookup Table Format4: specific interpretation needed!\n");
|
16889
|
160 |
break;
|
|
161 |
}
|
|
162 |
case ltfSingleTable: {
|
16891
|
163 |
LEReferenceTo<SingleTableLookupTable> lookupTable6(classTable, success);
|
16889
|
164 |
while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
|
16891
|
165 |
if (LE_FAILURE(success)) break;
|
|
166 |
if (LE_STATE_PATIENCE_DECR()) {
|
16890
|
167 |
LE_DEBUG_BAD_FONT("patience exceeded - state table not moving")
|
|
168 |
break; // patience exceeded.
|
|
169 |
}
|
16889
|
170 |
LookupValue classCode = classCodeOOB;
|
|
171 |
if (currGlyph == glyphCount || currGlyph == -1) {
|
|
172 |
// XXX: How do we handle EOT vs. EOL?
|
|
173 |
classCode = classCodeEOT;
|
16890
|
174 |
} else if(currGlyph > glyphCount) {
|
|
175 |
// note if > glyphCount, we've run off the end (bad font)
|
|
176 |
currGlyph = glyphCount;
|
|
177 |
classCode = classCodeEOT;
|
16889
|
178 |
} else {
|
|
179 |
LEGlyphID gid = glyphStorage[currGlyph];
|
|
180 |
TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
|
|
181 |
|
|
182 |
if (glyphCode == 0xFFFF) {
|
|
183 |
classCode = classCodeDEL;
|
|
184 |
} else {
|
16891
|
185 |
const LookupSingle *segment = lookupTable6->lookupSingle(lookupTable6, lookupTable6->entries, gid, success);
|
16889
|
186 |
if (segment != NULL) {
|
|
187 |
classCode = SWAPW(segment->value);
|
|
188 |
}
|
|
189 |
}
|
|
190 |
}
|
16891
|
191 |
EntryTableIndex2 entryTableIndex = SWAPW(stateArray(classCode + currentState * nClasses, success));
|
16890
|
192 |
LE_STATE_PATIENCE_CURR(le_int32, currGlyph);
|
16891
|
193 |
currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex, success);
|
16890
|
194 |
LE_STATE_PATIENCE_INCR(currGlyph);
|
16889
|
195 |
}
|
|
196 |
break;
|
|
197 |
}
|
|
198 |
case ltfTrimmedArray: {
|
16891
|
199 |
LEReferenceTo<TrimmedArrayLookupTable> lookupTable8(classTable, success);
|
|
200 |
if (LE_FAILURE(success)) break;
|
16889
|
201 |
TTGlyphID firstGlyph = SWAPW(lookupTable8->firstGlyph);
|
|
202 |
TTGlyphID lastGlyph = firstGlyph + SWAPW(lookupTable8->glyphCount);
|
|
203 |
|
|
204 |
while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
|
16890
|
205 |
if(LE_STATE_PATIENCE_DECR()) {
|
|
206 |
LE_DEBUG_BAD_FONT("patience exceeded - state table not moving")
|
|
207 |
break; // patience exceeded.
|
|
208 |
}
|
|
209 |
|
16889
|
210 |
LookupValue classCode = classCodeOOB;
|
|
211 |
if (currGlyph == glyphCount || currGlyph == -1) {
|
|
212 |
// XXX: How do we handle EOT vs. EOL?
|
|
213 |
classCode = classCodeEOT;
|
|
214 |
} else {
|
|
215 |
TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(glyphStorage[currGlyph]);
|
|
216 |
if (glyphCode == 0xFFFF) {
|
|
217 |
classCode = classCodeDEL;
|
|
218 |
} else if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) {
|
|
219 |
classCode = SWAPW(lookupTable8->valueArray[glyphCode - firstGlyph]);
|
|
220 |
}
|
|
221 |
}
|
16891
|
222 |
EntryTableIndex2 entryTableIndex = SWAPW(stateArray(classCode + currentState * nClasses, success));
|
16890
|
223 |
LE_STATE_PATIENCE_CURR(le_int32, currGlyph);
|
16891
|
224 |
currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex, success);
|
16890
|
225 |
LE_STATE_PATIENCE_INCR(currGlyph);
|
16889
|
226 |
}
|
|
227 |
break;
|
|
228 |
}
|
|
229 |
default:
|
|
230 |
break;
|
|
231 |
}
|
|
232 |
|
|
233 |
endStateTable();
|
|
234 |
}
|
|
235 |
|
|
236 |
U_NAMESPACE_END
|