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