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