2
|
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. Sun designates this
|
|
7 |
* particular file as subject to the "Classpath" exception as provided
|
|
8 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
21 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
22 |
* have any questions.
|
|
23 |
*
|
|
24 |
*/
|
|
25 |
|
|
26 |
/*
|
|
27 |
* (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
|
|
28 |
*
|
|
29 |
*/
|
|
30 |
|
|
31 |
#include "LETypes.h"
|
|
32 |
#include "LEFontInstance.h"
|
|
33 |
#include "OpenTypeTables.h"
|
|
34 |
#include "GlyphSubstitutionTables.h"
|
|
35 |
#include "ContextualSubstSubtables.h"
|
|
36 |
#include "GlyphIterator.h"
|
|
37 |
#include "LookupProcessor.h"
|
|
38 |
#include "CoverageTables.h"
|
|
39 |
#include "LESwaps.h"
|
|
40 |
|
3935
|
41 |
U_NAMESPACE_BEGIN
|
|
42 |
|
2
|
43 |
/*
|
|
44 |
NOTE: This could be optimized somewhat by keeping track
|
|
45 |
of the previous sequenceIndex in the loop and doing next()
|
|
46 |
or prev() of the delta between that and the current
|
|
47 |
sequenceIndex instead of always resetting to the front.
|
|
48 |
*/
|
|
49 |
void ContextualSubstitutionBase::applySubstitutionLookups(
|
|
50 |
const LookupProcessor *lookupProcessor,
|
|
51 |
const SubstitutionLookupRecord *substLookupRecordArray,
|
|
52 |
le_uint16 substCount,
|
|
53 |
GlyphIterator *glyphIterator,
|
|
54 |
const LEFontInstance *fontInstance,
|
|
55 |
le_int32 position)
|
|
56 |
{
|
|
57 |
GlyphIterator tempIterator(*glyphIterator);
|
|
58 |
|
|
59 |
for (le_int16 subst = 0; subst < substCount; subst += 1) {
|
|
60 |
le_uint16 sequenceIndex = SWAPW(substLookupRecordArray[subst].sequenceIndex);
|
|
61 |
le_uint16 lookupListIndex = SWAPW(substLookupRecordArray[subst].lookupListIndex);
|
|
62 |
|
|
63 |
tempIterator.setCurrStreamPosition(position);
|
|
64 |
tempIterator.next(sequenceIndex);
|
|
65 |
|
|
66 |
lookupProcessor->applySingleLookup(lookupListIndex, &tempIterator, fontInstance);
|
|
67 |
}
|
|
68 |
}
|
|
69 |
|
|
70 |
le_bool ContextualSubstitutionBase::matchGlyphIDs(const TTGlyphID *glyphArray, le_uint16 glyphCount,
|
|
71 |
GlyphIterator *glyphIterator, le_bool backtrack)
|
|
72 |
{
|
|
73 |
le_int32 direction = 1;
|
|
74 |
le_int32 match = 0;
|
|
75 |
|
|
76 |
if (backtrack) {
|
|
77 |
match = glyphCount -1;
|
|
78 |
direction = -1;
|
|
79 |
}
|
|
80 |
|
|
81 |
while (glyphCount > 0) {
|
|
82 |
if (! glyphIterator->next()) {
|
|
83 |
return FALSE;
|
|
84 |
}
|
|
85 |
|
|
86 |
TTGlyphID glyph = (TTGlyphID) glyphIterator->getCurrGlyphID();
|
|
87 |
|
|
88 |
if (glyph != SWAPW(glyphArray[match])) {
|
|
89 |
return FALSE;
|
|
90 |
}
|
|
91 |
|
|
92 |
glyphCount -= 1;
|
|
93 |
match += direction;
|
|
94 |
}
|
|
95 |
|
|
96 |
return TRUE;
|
|
97 |
}
|
|
98 |
|
|
99 |
le_bool ContextualSubstitutionBase::matchGlyphClasses(const le_uint16 *classArray, le_uint16 glyphCount,
|
|
100 |
GlyphIterator *glyphIterator,
|
|
101 |
const ClassDefinitionTable *classDefinitionTable,
|
|
102 |
le_bool backtrack)
|
|
103 |
{
|
|
104 |
le_int32 direction = 1;
|
|
105 |
le_int32 match = 0;
|
|
106 |
|
|
107 |
if (backtrack) {
|
|
108 |
match = glyphCount - 1;
|
|
109 |
direction = -1;
|
|
110 |
}
|
|
111 |
|
|
112 |
while (glyphCount > 0) {
|
|
113 |
if (! glyphIterator->next()) {
|
|
114 |
return FALSE;
|
|
115 |
}
|
|
116 |
|
|
117 |
LEGlyphID glyph = glyphIterator->getCurrGlyphID();
|
|
118 |
le_int32 glyphClass = classDefinitionTable->getGlyphClass(glyph);
|
|
119 |
le_int32 matchClass = SWAPW(classArray[match]);
|
|
120 |
|
|
121 |
if (glyphClass != matchClass) {
|
|
122 |
// Some fonts, e.g. Traditional Arabic, have classes
|
|
123 |
// in the class array which aren't in the class definition
|
|
124 |
// table. If we're looking for such a class, pretend that
|
|
125 |
// we found it.
|
|
126 |
if (classDefinitionTable->hasGlyphClass(matchClass)) {
|
|
127 |
return FALSE;
|
|
128 |
}
|
|
129 |
}
|
|
130 |
|
|
131 |
glyphCount -= 1;
|
|
132 |
match += direction;
|
|
133 |
}
|
|
134 |
|
|
135 |
return TRUE;
|
|
136 |
}
|
|
137 |
|
|
138 |
le_bool ContextualSubstitutionBase::matchGlyphCoverages(const Offset *coverageTableOffsetArray, le_uint16 glyphCount,
|
|
139 |
GlyphIterator *glyphIterator, const char *offsetBase, le_bool backtrack)
|
|
140 |
{
|
|
141 |
le_int32 direction = 1;
|
|
142 |
le_int32 glyph = 0;
|
|
143 |
|
|
144 |
if (backtrack) {
|
|
145 |
glyph = glyphCount - 1;
|
|
146 |
direction = -1;
|
|
147 |
}
|
|
148 |
|
|
149 |
while (glyphCount > 0) {
|
|
150 |
Offset coverageTableOffset = SWAPW(coverageTableOffsetArray[glyph]);
|
|
151 |
const CoverageTable *coverageTable = (const CoverageTable *) (offsetBase + coverageTableOffset);
|
|
152 |
|
|
153 |
if (! glyphIterator->next()) {
|
|
154 |
return FALSE;
|
|
155 |
}
|
|
156 |
|
|
157 |
if (coverageTable->getGlyphCoverage((LEGlyphID) glyphIterator->getCurrGlyphID()) < 0) {
|
|
158 |
return FALSE;
|
|
159 |
}
|
|
160 |
|
|
161 |
glyphCount -= 1;
|
|
162 |
glyph += direction;
|
|
163 |
}
|
|
164 |
|
|
165 |
return TRUE;
|
|
166 |
}
|
|
167 |
|
|
168 |
le_uint32 ContextualSubstitutionSubtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
169 |
const LEFontInstance *fontInstance) const
|
|
170 |
{
|
|
171 |
switch(SWAPW(subtableFormat))
|
|
172 |
{
|
|
173 |
case 0:
|
|
174 |
return 0;
|
|
175 |
|
|
176 |
case 1:
|
|
177 |
{
|
|
178 |
const ContextualSubstitutionFormat1Subtable *subtable = (const ContextualSubstitutionFormat1Subtable *) this;
|
|
179 |
|
|
180 |
return subtable->process(lookupProcessor, glyphIterator, fontInstance);
|
|
181 |
}
|
|
182 |
|
|
183 |
case 2:
|
|
184 |
{
|
|
185 |
const ContextualSubstitutionFormat2Subtable *subtable = (const ContextualSubstitutionFormat2Subtable *) this;
|
|
186 |
|
|
187 |
return subtable->process(lookupProcessor, glyphIterator, fontInstance);
|
|
188 |
}
|
|
189 |
|
|
190 |
case 3:
|
|
191 |
{
|
|
192 |
const ContextualSubstitutionFormat3Subtable *subtable = (const ContextualSubstitutionFormat3Subtable *) this;
|
|
193 |
|
|
194 |
return subtable->process(lookupProcessor, glyphIterator, fontInstance);
|
|
195 |
}
|
|
196 |
|
|
197 |
default:
|
|
198 |
return 0;
|
|
199 |
}
|
|
200 |
}
|
|
201 |
|
|
202 |
le_uint32 ContextualSubstitutionFormat1Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
203 |
const LEFontInstance *fontInstance) const
|
|
204 |
{
|
|
205 |
LEGlyphID glyph = glyphIterator->getCurrGlyphID();
|
|
206 |
le_int32 coverageIndex = getGlyphCoverage(glyph);
|
|
207 |
|
|
208 |
if (coverageIndex >= 0) {
|
|
209 |
le_uint16 srSetCount = SWAPW(subRuleSetCount);
|
|
210 |
|
|
211 |
if (coverageIndex < srSetCount) {
|
|
212 |
Offset subRuleSetTableOffset = SWAPW(subRuleSetTableOffsetArray[coverageIndex]);
|
|
213 |
const SubRuleSetTable *subRuleSetTable =
|
|
214 |
(const SubRuleSetTable *) ((char *) this + subRuleSetTableOffset);
|
|
215 |
le_uint16 subRuleCount = SWAPW(subRuleSetTable->subRuleCount);
|
|
216 |
le_int32 position = glyphIterator->getCurrStreamPosition();
|
|
217 |
|
|
218 |
for (le_uint16 subRule = 0; subRule < subRuleCount; subRule += 1) {
|
|
219 |
Offset subRuleTableOffset =
|
|
220 |
SWAPW(subRuleSetTable->subRuleTableOffsetArray[subRule]);
|
|
221 |
const SubRuleTable *subRuleTable =
|
|
222 |
(const SubRuleTable *) ((char *) subRuleSetTable + subRuleTableOffset);
|
|
223 |
le_uint16 matchCount = SWAPW(subRuleTable->glyphCount) - 1;
|
|
224 |
le_uint16 substCount = SWAPW(subRuleTable->substCount);
|
|
225 |
|
|
226 |
if (matchGlyphIDs(subRuleTable->inputGlyphArray, matchCount, glyphIterator)) {
|
|
227 |
const SubstitutionLookupRecord *substLookupRecordArray =
|
|
228 |
(const SubstitutionLookupRecord *) &subRuleTable->inputGlyphArray[matchCount];
|
|
229 |
|
|
230 |
applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
|
|
231 |
|
|
232 |
return matchCount + 1;
|
|
233 |
}
|
|
234 |
|
|
235 |
glyphIterator->setCurrStreamPosition(position);
|
|
236 |
}
|
|
237 |
}
|
|
238 |
|
|
239 |
// XXX If we get here, the table is mal-formed...
|
|
240 |
}
|
|
241 |
|
|
242 |
return 0;
|
|
243 |
}
|
|
244 |
|
|
245 |
le_uint32 ContextualSubstitutionFormat2Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
246 |
const LEFontInstance *fontInstance) const
|
|
247 |
{
|
|
248 |
LEGlyphID glyph = glyphIterator->getCurrGlyphID();
|
|
249 |
le_int32 coverageIndex = getGlyphCoverage(glyph);
|
|
250 |
|
|
251 |
if (coverageIndex >= 0) {
|
|
252 |
const ClassDefinitionTable *classDefinitionTable =
|
|
253 |
(const ClassDefinitionTable *) ((char *) this + SWAPW(classDefTableOffset));
|
|
254 |
le_uint16 scSetCount = SWAPW(subClassSetCount);
|
|
255 |
le_int32 setClass = classDefinitionTable->getGlyphClass(glyphIterator->getCurrGlyphID());
|
|
256 |
|
|
257 |
if (setClass < scSetCount && subClassSetTableOffsetArray[setClass] != 0) {
|
|
258 |
Offset subClassSetTableOffset = SWAPW(subClassSetTableOffsetArray[setClass]);
|
|
259 |
const SubClassSetTable *subClassSetTable =
|
|
260 |
(const SubClassSetTable *) ((char *) this + subClassSetTableOffset);
|
|
261 |
le_uint16 subClassRuleCount = SWAPW(subClassSetTable->subClassRuleCount);
|
|
262 |
le_int32 position = glyphIterator->getCurrStreamPosition();
|
|
263 |
|
|
264 |
for (le_uint16 scRule = 0; scRule < subClassRuleCount; scRule += 1) {
|
|
265 |
Offset subClassRuleTableOffset =
|
|
266 |
SWAPW(subClassSetTable->subClassRuleTableOffsetArray[scRule]);
|
|
267 |
const SubClassRuleTable *subClassRuleTable =
|
|
268 |
(const SubClassRuleTable *) ((char *) subClassSetTable + subClassRuleTableOffset);
|
|
269 |
le_uint16 matchCount = SWAPW(subClassRuleTable->glyphCount) - 1;
|
|
270 |
le_uint16 substCount = SWAPW(subClassRuleTable->substCount);
|
|
271 |
|
|
272 |
if (matchGlyphClasses(subClassRuleTable->classArray, matchCount, glyphIterator, classDefinitionTable)) {
|
|
273 |
const SubstitutionLookupRecord *substLookupRecordArray =
|
|
274 |
(const SubstitutionLookupRecord *) &subClassRuleTable->classArray[matchCount];
|
|
275 |
|
|
276 |
applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
|
|
277 |
|
|
278 |
return matchCount + 1;
|
|
279 |
}
|
|
280 |
|
|
281 |
glyphIterator->setCurrStreamPosition(position);
|
|
282 |
}
|
|
283 |
}
|
|
284 |
|
|
285 |
// XXX If we get here, the table is mal-formed...
|
|
286 |
}
|
|
287 |
|
|
288 |
return 0;
|
|
289 |
}
|
|
290 |
|
|
291 |
le_uint32 ContextualSubstitutionFormat3Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
292 |
const LEFontInstance *fontInstance)const
|
|
293 |
{
|
|
294 |
le_uint16 gCount = SWAPW(glyphCount);
|
|
295 |
le_uint16 subCount = SWAPW(substCount);
|
|
296 |
le_int32 position = glyphIterator->getCurrStreamPosition();
|
|
297 |
|
|
298 |
// Back up the glyph iterator so that we
|
|
299 |
// can call next() before the check, which
|
|
300 |
// will leave it pointing at the last glyph
|
|
301 |
// that matched when we're done.
|
|
302 |
glyphIterator->prev();
|
|
303 |
|
|
304 |
if (ContextualSubstitutionBase::matchGlyphCoverages(coverageTableOffsetArray, gCount, glyphIterator, (const char *) this)) {
|
|
305 |
const SubstitutionLookupRecord *substLookupRecordArray =
|
|
306 |
(const SubstitutionLookupRecord *) &coverageTableOffsetArray[gCount];
|
|
307 |
|
|
308 |
ContextualSubstitutionBase::applySubstitutionLookups(lookupProcessor, substLookupRecordArray, subCount, glyphIterator, fontInstance, position);
|
|
309 |
|
|
310 |
return gCount + 1;
|
|
311 |
}
|
|
312 |
|
|
313 |
glyphIterator->setCurrStreamPosition(position);
|
|
314 |
|
|
315 |
return 0;
|
|
316 |
}
|
|
317 |
|
|
318 |
le_uint32 ChainingContextualSubstitutionSubtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
319 |
const LEFontInstance *fontInstance) const
|
|
320 |
{
|
|
321 |
switch(SWAPW(subtableFormat))
|
|
322 |
{
|
|
323 |
case 0:
|
|
324 |
return 0;
|
|
325 |
|
|
326 |
case 1:
|
|
327 |
{
|
|
328 |
const ChainingContextualSubstitutionFormat1Subtable *subtable = (const ChainingContextualSubstitutionFormat1Subtable *) this;
|
|
329 |
|
|
330 |
return subtable->process(lookupProcessor, glyphIterator, fontInstance);
|
|
331 |
}
|
|
332 |
|
|
333 |
case 2:
|
|
334 |
{
|
|
335 |
const ChainingContextualSubstitutionFormat2Subtable *subtable = (const ChainingContextualSubstitutionFormat2Subtable *) this;
|
|
336 |
|
|
337 |
return subtable->process(lookupProcessor, glyphIterator, fontInstance);
|
|
338 |
}
|
|
339 |
|
|
340 |
case 3:
|
|
341 |
{
|
|
342 |
const ChainingContextualSubstitutionFormat3Subtable *subtable = (const ChainingContextualSubstitutionFormat3Subtable *) this;
|
|
343 |
|
|
344 |
return subtable->process(lookupProcessor, glyphIterator, fontInstance);
|
|
345 |
}
|
|
346 |
|
|
347 |
default:
|
|
348 |
return 0;
|
|
349 |
}
|
|
350 |
}
|
|
351 |
|
|
352 |
// NOTE: This could be a #define, but that seems to confuse
|
|
353 |
// the Visual Studio .NET 2003 compiler on the calls to the
|
3935
|
354 |
// GlyphIterator constructor. It somehow can't decide if
|
2
|
355 |
// emptyFeatureList matches an le_uint32 or an le_uint16...
|
|
356 |
static const FeatureMask emptyFeatureList = 0x00000000UL;
|
|
357 |
|
|
358 |
le_uint32 ChainingContextualSubstitutionFormat1Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
359 |
const LEFontInstance *fontInstance) const
|
|
360 |
{
|
|
361 |
LEGlyphID glyph = glyphIterator->getCurrGlyphID();
|
|
362 |
le_int32 coverageIndex = getGlyphCoverage(glyph);
|
|
363 |
|
|
364 |
if (coverageIndex >= 0) {
|
|
365 |
le_uint16 srSetCount = SWAPW(chainSubRuleSetCount);
|
|
366 |
|
|
367 |
if (coverageIndex < srSetCount) {
|
|
368 |
Offset chainSubRuleSetTableOffset = SWAPW(chainSubRuleSetTableOffsetArray[coverageIndex]);
|
|
369 |
const ChainSubRuleSetTable *chainSubRuleSetTable =
|
|
370 |
(const ChainSubRuleSetTable *) ((char *) this + chainSubRuleSetTableOffset);
|
|
371 |
le_uint16 chainSubRuleCount = SWAPW(chainSubRuleSetTable->chainSubRuleCount);
|
|
372 |
le_int32 position = glyphIterator->getCurrStreamPosition();
|
|
373 |
GlyphIterator tempIterator(*glyphIterator, emptyFeatureList);
|
|
374 |
|
|
375 |
for (le_uint16 subRule = 0; subRule < chainSubRuleCount; subRule += 1) {
|
|
376 |
Offset chainSubRuleTableOffset =
|
|
377 |
SWAPW(chainSubRuleSetTable->chainSubRuleTableOffsetArray[subRule]);
|
|
378 |
const ChainSubRuleTable *chainSubRuleTable =
|
|
379 |
(const ChainSubRuleTable *) ((char *) chainSubRuleSetTable + chainSubRuleTableOffset);
|
|
380 |
le_uint16 backtrackGlyphCount = SWAPW(chainSubRuleTable->backtrackGlyphCount);
|
|
381 |
le_uint16 inputGlyphCount = (le_uint16) SWAPW(chainSubRuleTable->backtrackGlyphArray[backtrackGlyphCount]) - 1;
|
|
382 |
const TTGlyphID *inputGlyphArray = &chainSubRuleTable->backtrackGlyphArray[backtrackGlyphCount + 1];
|
|
383 |
le_uint16 lookaheadGlyphCount = (le_uint16) SWAPW(inputGlyphArray[inputGlyphCount]);
|
|
384 |
const TTGlyphID *lookaheadGlyphArray = &inputGlyphArray[inputGlyphCount + 1];
|
|
385 |
le_uint16 substCount = (le_uint16) SWAPW(lookaheadGlyphArray[lookaheadGlyphCount]);
|
|
386 |
|
|
387 |
tempIterator.setCurrStreamPosition(position);
|
|
388 |
|
|
389 |
if (! tempIterator.prev(backtrackGlyphCount)) {
|
|
390 |
continue;
|
|
391 |
}
|
|
392 |
|
|
393 |
tempIterator.prev();
|
|
394 |
if (! matchGlyphIDs(chainSubRuleTable->backtrackGlyphArray, backtrackGlyphCount, &tempIterator, TRUE)) {
|
|
395 |
continue;
|
|
396 |
}
|
|
397 |
|
|
398 |
tempIterator.setCurrStreamPosition(position);
|
|
399 |
tempIterator.next(inputGlyphCount);
|
|
400 |
if (!matchGlyphIDs(lookaheadGlyphArray, lookaheadGlyphCount, &tempIterator)) {
|
|
401 |
continue;
|
|
402 |
}
|
|
403 |
|
|
404 |
if (matchGlyphIDs(inputGlyphArray, inputGlyphCount, glyphIterator)) {
|
|
405 |
const SubstitutionLookupRecord *substLookupRecordArray =
|
|
406 |
(const SubstitutionLookupRecord *) &lookaheadGlyphArray[lookaheadGlyphCount + 1];
|
|
407 |
|
|
408 |
applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
|
|
409 |
|
|
410 |
return inputGlyphCount + 1;
|
|
411 |
}
|
|
412 |
|
|
413 |
glyphIterator->setCurrStreamPosition(position);
|
|
414 |
}
|
|
415 |
}
|
|
416 |
|
|
417 |
// XXX If we get here, the table is mal-formed...
|
|
418 |
}
|
|
419 |
|
|
420 |
return 0;
|
|
421 |
}
|
|
422 |
|
|
423 |
le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
424 |
const LEFontInstance *fontInstance) const
|
|
425 |
{
|
|
426 |
LEGlyphID glyph = glyphIterator->getCurrGlyphID();
|
|
427 |
le_int32 coverageIndex = getGlyphCoverage(glyph);
|
|
428 |
|
|
429 |
if (coverageIndex >= 0) {
|
|
430 |
const ClassDefinitionTable *backtrackClassDefinitionTable =
|
|
431 |
(const ClassDefinitionTable *) ((char *) this + SWAPW(backtrackClassDefTableOffset));
|
|
432 |
const ClassDefinitionTable *inputClassDefinitionTable =
|
|
433 |
(const ClassDefinitionTable *) ((char *) this + SWAPW(inputClassDefTableOffset));
|
|
434 |
const ClassDefinitionTable *lookaheadClassDefinitionTable =
|
|
435 |
(const ClassDefinitionTable *) ((char *) this + SWAPW(lookaheadClassDefTableOffset));
|
|
436 |
le_uint16 scSetCount = SWAPW(chainSubClassSetCount);
|
|
437 |
le_int32 setClass = inputClassDefinitionTable->getGlyphClass(glyphIterator->getCurrGlyphID());
|
|
438 |
|
|
439 |
if (setClass < scSetCount && chainSubClassSetTableOffsetArray[setClass] != 0) {
|
|
440 |
Offset chainSubClassSetTableOffset = SWAPW(chainSubClassSetTableOffsetArray[setClass]);
|
|
441 |
const ChainSubClassSetTable *chainSubClassSetTable =
|
|
442 |
(const ChainSubClassSetTable *) ((char *) this + chainSubClassSetTableOffset);
|
|
443 |
le_uint16 chainSubClassRuleCount = SWAPW(chainSubClassSetTable->chainSubClassRuleCount);
|
|
444 |
le_int32 position = glyphIterator->getCurrStreamPosition();
|
|
445 |
GlyphIterator tempIterator(*glyphIterator, emptyFeatureList);
|
|
446 |
|
|
447 |
for (le_uint16 scRule = 0; scRule < chainSubClassRuleCount; scRule += 1) {
|
|
448 |
Offset chainSubClassRuleTableOffset =
|
|
449 |
SWAPW(chainSubClassSetTable->chainSubClassRuleTableOffsetArray[scRule]);
|
|
450 |
const ChainSubClassRuleTable *chainSubClassRuleTable =
|
|
451 |
(const ChainSubClassRuleTable *) ((char *) chainSubClassSetTable + chainSubClassRuleTableOffset);
|
|
452 |
le_uint16 backtrackGlyphCount = SWAPW(chainSubClassRuleTable->backtrackGlyphCount);
|
|
453 |
le_uint16 inputGlyphCount = SWAPW(chainSubClassRuleTable->backtrackClassArray[backtrackGlyphCount]) - 1;
|
|
454 |
const le_uint16 *inputClassArray = &chainSubClassRuleTable->backtrackClassArray[backtrackGlyphCount + 1];
|
|
455 |
le_uint16 lookaheadGlyphCount = SWAPW(inputClassArray[inputGlyphCount]);
|
|
456 |
const le_uint16 *lookaheadClassArray = &inputClassArray[inputGlyphCount + 1];
|
|
457 |
le_uint16 substCount = SWAPW(lookaheadClassArray[lookaheadGlyphCount]);
|
|
458 |
|
|
459 |
|
|
460 |
tempIterator.setCurrStreamPosition(position);
|
|
461 |
|
|
462 |
if (! tempIterator.prev(backtrackGlyphCount)) {
|
|
463 |
continue;
|
|
464 |
}
|
|
465 |
|
|
466 |
tempIterator.prev();
|
|
467 |
if (! matchGlyphClasses(chainSubClassRuleTable->backtrackClassArray, backtrackGlyphCount,
|
|
468 |
&tempIterator, backtrackClassDefinitionTable, TRUE)) {
|
|
469 |
continue;
|
|
470 |
}
|
|
471 |
|
|
472 |
tempIterator.setCurrStreamPosition(position);
|
|
473 |
tempIterator.next(inputGlyphCount);
|
|
474 |
if (! matchGlyphClasses(lookaheadClassArray, lookaheadGlyphCount, &tempIterator, lookaheadClassDefinitionTable)) {
|
|
475 |
continue;
|
|
476 |
}
|
|
477 |
|
|
478 |
if (matchGlyphClasses(inputClassArray, inputGlyphCount, glyphIterator, inputClassDefinitionTable)) {
|
|
479 |
const SubstitutionLookupRecord *substLookupRecordArray =
|
|
480 |
(const SubstitutionLookupRecord *) &lookaheadClassArray[lookaheadGlyphCount + 1];
|
|
481 |
|
|
482 |
applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
|
|
483 |
|
|
484 |
return inputGlyphCount + 1;
|
|
485 |
}
|
|
486 |
|
|
487 |
glyphIterator->setCurrStreamPosition(position);
|
|
488 |
}
|
|
489 |
}
|
|
490 |
|
|
491 |
// XXX If we get here, the table is mal-formed...
|
|
492 |
}
|
|
493 |
|
|
494 |
return 0;
|
|
495 |
}
|
|
496 |
|
|
497 |
le_uint32 ChainingContextualSubstitutionFormat3Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
498 |
const LEFontInstance *fontInstance) const
|
|
499 |
{
|
|
500 |
le_uint16 backtrkGlyphCount = SWAPW(backtrackGlyphCount);
|
|
501 |
le_uint16 inputGlyphCount = (le_uint16) SWAPW(backtrackCoverageTableOffsetArray[backtrkGlyphCount]);
|
|
502 |
const Offset *inputCoverageTableOffsetArray = &backtrackCoverageTableOffsetArray[backtrkGlyphCount + 1];
|
|
503 |
const le_uint16 lookaheadGlyphCount = (le_uint16) SWAPW(inputCoverageTableOffsetArray[inputGlyphCount]);
|
|
504 |
const Offset *lookaheadCoverageTableOffsetArray = &inputCoverageTableOffsetArray[inputGlyphCount + 1];
|
|
505 |
le_uint16 substCount = (le_uint16) SWAPW(lookaheadCoverageTableOffsetArray[lookaheadGlyphCount]);
|
|
506 |
le_int32 position = glyphIterator->getCurrStreamPosition();
|
|
507 |
GlyphIterator tempIterator(*glyphIterator, emptyFeatureList);
|
|
508 |
|
|
509 |
if (! tempIterator.prev(backtrkGlyphCount)) {
|
|
510 |
return 0;
|
|
511 |
}
|
|
512 |
|
|
513 |
tempIterator.prev();
|
|
514 |
if (! ContextualSubstitutionBase::matchGlyphCoverages(backtrackCoverageTableOffsetArray,
|
|
515 |
backtrkGlyphCount, &tempIterator, (const char *) this, TRUE)) {
|
|
516 |
return 0;
|
|
517 |
}
|
|
518 |
|
|
519 |
tempIterator.setCurrStreamPosition(position);
|
|
520 |
tempIterator.next(inputGlyphCount - 1);
|
|
521 |
if (! ContextualSubstitutionBase::matchGlyphCoverages(lookaheadCoverageTableOffsetArray,
|
|
522 |
lookaheadGlyphCount, &tempIterator, (const char *) this)) {
|
|
523 |
return 0;
|
|
524 |
}
|
|
525 |
|
|
526 |
// Back up the glyph iterator so that we
|
|
527 |
// can call next() before the check, which
|
|
528 |
// will leave it pointing at the last glyph
|
|
529 |
// that matched when we're done.
|
|
530 |
glyphIterator->prev();
|
|
531 |
|
|
532 |
if (ContextualSubstitutionBase::matchGlyphCoverages(inputCoverageTableOffsetArray,
|
|
533 |
inputGlyphCount, glyphIterator, (const char *) this)) {
|
|
534 |
const SubstitutionLookupRecord *substLookupRecordArray =
|
|
535 |
(const SubstitutionLookupRecord *) &lookaheadCoverageTableOffsetArray[lookaheadGlyphCount + 1];
|
|
536 |
|
|
537 |
ContextualSubstitutionBase::applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
|
|
538 |
|
|
539 |
return inputGlyphCount;
|
|
540 |
}
|
|
541 |
|
|
542 |
glyphIterator->setCurrStreamPosition(position);
|
|
543 |
|
|
544 |
return 0;
|
|
545 |
}
|
3935
|
546 |
|
|
547 |
U_NAMESPACE_END
|