2000-11-28 20:56:52 +00:00
|
|
|
/*
|
2000-12-21 02:44:45 +00:00
|
|
|
* @(#)ContextualSubstSubtables.cpp 1.11 00/03/15
|
2000-11-28 20:56:52 +00:00
|
|
|
*
|
2001-01-19 00:30:17 +00:00
|
|
|
* (C) Copyright IBM Corp. 1998, 1999, 2000, 2001 - All Rights Reserved
|
2000-11-28 20:56:52 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LETypes.h"
|
|
|
|
#include "LEFontInstance.h"
|
|
|
|
#include "OpenTypeTables.h"
|
|
|
|
#include "GlyphSubstitutionTables.h"
|
2000-12-21 02:44:45 +00:00
|
|
|
#include "ContextualSubstSubtables.h"
|
2000-11-28 20:56:52 +00:00
|
|
|
#include "GlyphIterator.h"
|
|
|
|
#include "LookupProcessor.h"
|
|
|
|
#include "CoverageTables.h"
|
|
|
|
#include "LESwaps.h"
|
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2000-11-28 20:56:52 +00:00
|
|
|
/*
|
|
|
|
NOTE: This could be optimized somewhat by keeping track
|
|
|
|
of the previous sequenceIndex in the loop and doing next()
|
|
|
|
or prev() of the delta between that and the current
|
|
|
|
sequenceIndex instead of always resetting to the front.
|
|
|
|
*/
|
|
|
|
void ContextualSubstitutionBase::applySubstitutionLookups(
|
2001-01-19 00:30:17 +00:00
|
|
|
const LookupProcessor *lookupProcessor,
|
|
|
|
const SubstitutionLookupRecord *substLookupRecordArray,
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 substCount,
|
|
|
|
GlyphIterator *glyphIterator,
|
2000-12-21 01:18:44 +00:00
|
|
|
const LEFontInstance *fontInstance,
|
2000-11-28 20:56:52 +00:00
|
|
|
le_int32 position)
|
|
|
|
{
|
|
|
|
GlyphIterator tempIterator(*glyphIterator);
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
for (le_int16 subst = 0; subst < substCount; subst += 1) {
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 sequenceIndex = SWAPW(substLookupRecordArray[subst].sequenceIndex);
|
|
|
|
le_uint16 lookupListIndex = SWAPW(substLookupRecordArray[subst].lookupListIndex);
|
|
|
|
|
|
|
|
tempIterator.setCurrStreamPosition(position);
|
|
|
|
tempIterator.next(sequenceIndex);
|
|
|
|
|
|
|
|
lookupProcessor->applySingleLookup(lookupListIndex, &tempIterator, fontInstance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-05 00:05:40 +00:00
|
|
|
le_bool ContextualSubstitutionBase::matchGlyphIDs(const TTGlyphID *glyphArray, le_uint16 glyphCount,
|
2002-07-30 22:58:29 +00:00
|
|
|
GlyphIterator *glyphIterator, le_bool backtrack)
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2002-07-30 22:58:29 +00:00
|
|
|
le_int32 direction = 1;
|
|
|
|
le_int32 match = 0;
|
|
|
|
|
|
|
|
if (backtrack) {
|
|
|
|
match = glyphCount -1;
|
|
|
|
direction = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (glyphCount > 0) {
|
2001-01-19 00:30:17 +00:00
|
|
|
if (! glyphIterator->next()) {
|
2000-11-28 20:56:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-02-05 00:05:40 +00:00
|
|
|
TTGlyphID glyph = (TTGlyphID) glyphIterator->getCurrGlyphID();
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (glyph != SWAPW(glyphArray[match])) {
|
2000-11-28 20:56:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-07-30 22:58:29 +00:00
|
|
|
|
|
|
|
glyphCount -= 1;
|
|
|
|
match += direction;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_bool ContextualSubstitutionBase::matchGlyphClasses(const le_uint16 *classArray, le_uint16 glyphCount,
|
2000-11-28 20:56:52 +00:00
|
|
|
GlyphIterator *glyphIterator,
|
2002-07-30 22:58:29 +00:00
|
|
|
const ClassDefinitionTable *classDefinitionTable,
|
|
|
|
le_bool backtrack)
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2002-07-30 22:58:29 +00:00
|
|
|
le_int32 direction = 1;
|
|
|
|
le_int32 match = 0;
|
|
|
|
|
|
|
|
if (backtrack) {
|
|
|
|
match = glyphCount - 1;
|
|
|
|
direction = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (glyphCount > 0) {
|
2001-01-19 00:30:17 +00:00
|
|
|
if (! glyphIterator->next()) {
|
2000-11-28 20:56:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-02-05 00:05:40 +00:00
|
|
|
LEGlyphID glyph = glyphIterator->getCurrGlyphID();
|
2000-11-28 20:56:52 +00:00
|
|
|
le_int32 glyphClass = classDefinitionTable->getGlyphClass(glyph);
|
|
|
|
le_int32 matchClass = SWAPW(classArray[match]);
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (glyphClass != matchClass) {
|
2000-11-28 20:56:52 +00:00
|
|
|
// Some fonts, e.g. Traditional Arabic, have classes
|
|
|
|
// in the class array which aren't in the class definition
|
|
|
|
// table. If we're looking for such a class, pretend that
|
|
|
|
// we found it.
|
2001-01-19 00:30:17 +00:00
|
|
|
if (classDefinitionTable->hasGlyphClass(matchClass)) {
|
2000-11-28 20:56:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2002-07-30 22:58:29 +00:00
|
|
|
|
|
|
|
glyphCount -= 1;
|
|
|
|
match += direction;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_bool ContextualSubstitutionBase::matchGlyphCoverages(const Offset *coverageTableOffsetArray, le_uint16 glyphCount,
|
2002-07-30 22:58:29 +00:00
|
|
|
GlyphIterator *glyphIterator, const char *offsetBase, le_bool backtrack)
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2002-07-30 22:58:29 +00:00
|
|
|
le_int32 direction = 1;
|
|
|
|
le_int32 glyph = 0;
|
|
|
|
|
|
|
|
if (backtrack) {
|
|
|
|
glyph = glyphCount - 1;
|
|
|
|
direction = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (glyphCount > 0) {
|
2000-11-28 20:56:52 +00:00
|
|
|
Offset coverageTableOffset = SWAPW(coverageTableOffsetArray[glyph]);
|
2001-01-19 00:30:17 +00:00
|
|
|
const CoverageTable *coverageTable = (const CoverageTable *) (offsetBase + coverageTableOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (! glyphIterator->next()) {
|
2000-11-28 20:56:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (coverageTable->getGlyphCoverage((LEGlyphID) glyphIterator->getCurrGlyphID()) < 0) {
|
2000-11-28 20:56:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-07-30 22:58:29 +00:00
|
|
|
|
|
|
|
glyphCount -= 1;
|
|
|
|
glyph += direction;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_uint32 ContextualSubstitutionSubtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
|
|
const LEFontInstance *fontInstance) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
|
|
|
switch(SWAPW(subtableFormat))
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
2001-01-19 00:30:17 +00:00
|
|
|
const ContextualSubstitutionFormat1Subtable *subtable = (const ContextualSubstitutionFormat1Subtable *) this;
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
return subtable->process(lookupProcessor, glyphIterator, fontInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
2001-01-19 00:30:17 +00:00
|
|
|
const ContextualSubstitutionFormat2Subtable *subtable = (const ContextualSubstitutionFormat2Subtable *) this;
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
return subtable->process(lookupProcessor, glyphIterator, fontInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
{
|
2001-01-19 00:30:17 +00:00
|
|
|
const ContextualSubstitutionFormat3Subtable *subtable = (const ContextualSubstitutionFormat3Subtable *) this;
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
return subtable->process(lookupProcessor, glyphIterator, fontInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_uint32 ContextualSubstitutionFormat1Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
|
|
const LEFontInstance *fontInstance) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2003-02-05 00:05:40 +00:00
|
|
|
LEGlyphID glyph = glyphIterator->getCurrGlyphID();
|
2000-11-28 20:56:52 +00:00
|
|
|
le_int32 coverageIndex = getGlyphCoverage(glyph);
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (coverageIndex >= 0) {
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 srSetCount = SWAPW(subRuleSetCount);
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (coverageIndex < srSetCount) {
|
2000-11-28 20:56:52 +00:00
|
|
|
Offset subRuleSetTableOffset = SWAPW(subRuleSetTableOffsetArray[coverageIndex]);
|
2001-01-19 00:30:17 +00:00
|
|
|
const SubRuleSetTable *subRuleSetTable =
|
|
|
|
(const SubRuleSetTable *) ((char *) this + subRuleSetTableOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 subRuleCount = SWAPW(subRuleSetTable->subRuleCount);
|
|
|
|
le_int32 position = glyphIterator->getCurrStreamPosition();
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
for (le_uint16 subRule = 0; subRule < subRuleCount; subRule += 1) {
|
2000-11-28 20:56:52 +00:00
|
|
|
Offset subRuleTableOffset =
|
|
|
|
SWAPW(subRuleSetTable->subRuleTableOffsetArray[subRule]);
|
2001-01-19 00:30:17 +00:00
|
|
|
const SubRuleTable *subRuleTable =
|
|
|
|
(const SubRuleTable *) ((char *) subRuleSetTable + subRuleTableOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 matchCount = SWAPW(subRuleTable->glyphCount) - 1;
|
|
|
|
le_uint16 substCount = SWAPW(subRuleTable->substCount);
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (matchGlyphIDs(subRuleTable->inputGlyphArray, matchCount, glyphIterator)) {
|
|
|
|
const SubstitutionLookupRecord *substLookupRecordArray =
|
|
|
|
(const SubstitutionLookupRecord *) &subRuleTable->inputGlyphArray[matchCount];
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
|
|
|
|
|
|
|
|
return matchCount + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
glyphIterator->setCurrStreamPosition(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX If we get here, the table is mal-formed...
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_uint32 ContextualSubstitutionFormat2Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
|
|
const LEFontInstance *fontInstance) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2003-02-05 00:05:40 +00:00
|
|
|
LEGlyphID glyph = glyphIterator->getCurrGlyphID();
|
2000-11-28 20:56:52 +00:00
|
|
|
le_int32 coverageIndex = getGlyphCoverage(glyph);
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (coverageIndex >= 0) {
|
|
|
|
const ClassDefinitionTable *classDefinitionTable =
|
|
|
|
(const ClassDefinitionTable *) ((char *) this + SWAPW(classDefTableOffset));
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 scSetCount = SWAPW(subClassSetCount);
|
2003-02-05 00:05:40 +00:00
|
|
|
le_int32 setClass = classDefinitionTable->getGlyphClass(glyphIterator->getCurrGlyphID());
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (setClass < scSetCount && subClassSetTableOffsetArray[setClass] != 0) {
|
2000-11-28 20:56:52 +00:00
|
|
|
Offset subClassSetTableOffset = SWAPW(subClassSetTableOffsetArray[setClass]);
|
2001-01-19 00:30:17 +00:00
|
|
|
const SubClassSetTable *subClassSetTable =
|
|
|
|
(const SubClassSetTable *) ((char *) this + subClassSetTableOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 subClassRuleCount = SWAPW(subClassSetTable->subClassRuleCount);
|
|
|
|
le_int32 position = glyphIterator->getCurrStreamPosition();
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
for (le_uint16 scRule = 0; scRule < subClassRuleCount; scRule += 1) {
|
2000-11-28 20:56:52 +00:00
|
|
|
Offset subClassRuleTableOffset =
|
|
|
|
SWAPW(subClassSetTable->subClassRuleTableOffsetArray[scRule]);
|
2001-01-19 00:30:17 +00:00
|
|
|
const SubClassRuleTable *subClassRuleTable =
|
|
|
|
(const SubClassRuleTable *) ((char *) subClassSetTable + subClassRuleTableOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 matchCount = SWAPW(subClassRuleTable->glyphCount) - 1;
|
|
|
|
le_uint16 substCount = SWAPW(subClassRuleTable->substCount);
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (matchGlyphClasses(subClassRuleTable->classArray, matchCount, glyphIterator, classDefinitionTable)) {
|
|
|
|
const SubstitutionLookupRecord *substLookupRecordArray =
|
|
|
|
(const SubstitutionLookupRecord *) &subClassRuleTable->classArray[matchCount];
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
|
|
|
|
|
|
|
|
return matchCount + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
glyphIterator->setCurrStreamPosition(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX If we get here, the table is mal-formed...
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_uint32 ContextualSubstitutionFormat3Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
|
|
const LEFontInstance *fontInstance)const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
|
|
|
le_uint16 gCount = SWAPW(glyphCount);
|
|
|
|
le_uint16 subCount = SWAPW(substCount);
|
|
|
|
le_int32 position = glyphIterator->getCurrStreamPosition();
|
|
|
|
|
|
|
|
// Back up the glyph iterator so that we
|
|
|
|
// can call next() before the check, which
|
|
|
|
// will leave it pointing at the last glyph
|
|
|
|
// that matched when we're done.
|
|
|
|
glyphIterator->prev();
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (ContextualSubstitutionBase::matchGlyphCoverages(coverageTableOffsetArray, gCount, glyphIterator, (const char *) this)) {
|
|
|
|
const SubstitutionLookupRecord *substLookupRecordArray =
|
|
|
|
(const SubstitutionLookupRecord *) &coverageTableOffsetArray[gCount];
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
ContextualSubstitutionBase::applySubstitutionLookups(lookupProcessor, substLookupRecordArray, subCount, glyphIterator, fontInstance, position);
|
|
|
|
|
|
|
|
return gCount + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
glyphIterator->setCurrStreamPosition(position);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_uint32 ChainingContextualSubstitutionSubtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
|
|
const LEFontInstance *fontInstance) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
|
|
|
switch(SWAPW(subtableFormat))
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
2001-01-19 00:30:17 +00:00
|
|
|
const ChainingContextualSubstitutionFormat1Subtable *subtable = (const ChainingContextualSubstitutionFormat1Subtable *) this;
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
return subtable->process(lookupProcessor, glyphIterator, fontInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
2001-01-19 00:30:17 +00:00
|
|
|
const ChainingContextualSubstitutionFormat2Subtable *subtable = (const ChainingContextualSubstitutionFormat2Subtable *) this;
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
return subtable->process(lookupProcessor, glyphIterator, fontInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
{
|
2001-01-19 00:30:17 +00:00
|
|
|
const ChainingContextualSubstitutionFormat3Subtable *subtable = (const ChainingContextualSubstitutionFormat3Subtable *) this;
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
return subtable->process(lookupProcessor, glyphIterator, fontInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-07 23:33:41 +00:00
|
|
|
const LETag emptyTag = 0;
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_uint32 ChainingContextualSubstitutionFormat1Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
|
|
const LEFontInstance *fontInstance) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2003-02-05 00:05:40 +00:00
|
|
|
LEGlyphID glyph = glyphIterator->getCurrGlyphID();
|
2000-11-28 20:56:52 +00:00
|
|
|
le_int32 coverageIndex = getGlyphCoverage(glyph);
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (coverageIndex >= 0) {
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 srSetCount = SWAPW(chainSubRuleSetCount);
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (coverageIndex < srSetCount) {
|
2000-11-28 20:56:52 +00:00
|
|
|
Offset chainSubRuleSetTableOffset = SWAPW(chainSubRuleSetTableOffsetArray[coverageIndex]);
|
2001-01-19 00:30:17 +00:00
|
|
|
const ChainSubRuleSetTable *chainSubRuleSetTable =
|
|
|
|
(const ChainSubRuleSetTable *) ((char *) this + chainSubRuleSetTableOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 chainSubRuleCount = SWAPW(chainSubRuleSetTable->chainSubRuleCount);
|
|
|
|
le_int32 position = glyphIterator->getCurrStreamPosition();
|
2003-03-07 23:33:41 +00:00
|
|
|
GlyphIterator tempIterator(*glyphIterator, emptyTag);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
for (le_uint16 subRule = 0; subRule < chainSubRuleCount; subRule += 1) {
|
2000-11-28 20:56:52 +00:00
|
|
|
Offset chainSubRuleTableOffset =
|
|
|
|
SWAPW(chainSubRuleSetTable->chainSubRuleTableOffsetArray[subRule]);
|
2001-01-19 00:30:17 +00:00
|
|
|
const ChainSubRuleTable *chainSubRuleTable =
|
|
|
|
(const ChainSubRuleTable *) ((char *) chainSubRuleSetTable + chainSubRuleTableOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 backtrackGlyphCount = SWAPW(chainSubRuleTable->backtrackGlyphCount);
|
|
|
|
le_uint16 inputGlyphCount = (le_uint16) SWAPW(chainSubRuleTable->backtrackGlyphArray[backtrackGlyphCount]) - 1;
|
2003-02-05 00:05:40 +00:00
|
|
|
const TTGlyphID *inputGlyphArray = &chainSubRuleTable->backtrackGlyphArray[backtrackGlyphCount + 1];
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 lookaheadGlyphCount = (le_uint16) SWAPW(inputGlyphArray[inputGlyphCount]);
|
2003-02-05 00:05:40 +00:00
|
|
|
const TTGlyphID *lookaheadGlyphArray = &inputGlyphArray[inputGlyphCount + 1];
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 substCount = (le_uint16) SWAPW(lookaheadGlyphArray[lookaheadGlyphCount]);
|
|
|
|
|
|
|
|
tempIterator.setCurrStreamPosition(position);
|
2002-07-30 22:58:29 +00:00
|
|
|
|
|
|
|
if (! tempIterator.prev(backtrackGlyphCount)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
tempIterator.prev();
|
|
|
|
if (! matchGlyphIDs(chainSubRuleTable->backtrackGlyphArray, backtrackGlyphCount, &tempIterator, true)) {
|
2000-11-28 20:56:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
tempIterator.setCurrStreamPosition(position);
|
|
|
|
tempIterator.next(inputGlyphCount);
|
2001-01-19 00:30:17 +00:00
|
|
|
if (!matchGlyphIDs(lookaheadGlyphArray, lookaheadGlyphCount, &tempIterator)) {
|
2000-11-28 20:56:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (matchGlyphIDs(inputGlyphArray, inputGlyphCount, glyphIterator)) {
|
|
|
|
const SubstitutionLookupRecord *substLookupRecordArray =
|
|
|
|
(const SubstitutionLookupRecord *) &lookaheadGlyphArray[lookaheadGlyphCount + 1];
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
|
|
|
|
|
|
|
|
return inputGlyphCount + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
glyphIterator->setCurrStreamPosition(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX If we get here, the table is mal-formed...
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
|
|
const LEFontInstance *fontInstance) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2003-02-05 00:05:40 +00:00
|
|
|
LEGlyphID glyph = glyphIterator->getCurrGlyphID();
|
2000-11-28 20:56:52 +00:00
|
|
|
le_int32 coverageIndex = getGlyphCoverage(glyph);
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (coverageIndex >= 0) {
|
|
|
|
const ClassDefinitionTable *backtrackClassDefinitionTable =
|
|
|
|
(const ClassDefinitionTable *) ((char *) this + SWAPW(backtrackClassDefTableOffset));
|
|
|
|
const ClassDefinitionTable *inputClassDefinitionTable =
|
|
|
|
(const ClassDefinitionTable *) ((char *) this + SWAPW(inputClassDefTableOffset));
|
|
|
|
const ClassDefinitionTable *lookaheadClassDefinitionTable =
|
|
|
|
(const ClassDefinitionTable *) ((char *) this + SWAPW(lookaheadClassDefTableOffset));
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 scSetCount = SWAPW(chainSubClassSetCount);
|
2003-02-05 00:05:40 +00:00
|
|
|
le_int32 setClass = inputClassDefinitionTable->getGlyphClass(glyphIterator->getCurrGlyphID());
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (setClass < scSetCount && chainSubClassSetTableOffsetArray[setClass] != 0) {
|
2000-11-28 20:56:52 +00:00
|
|
|
Offset chainSubClassSetTableOffset = SWAPW(chainSubClassSetTableOffsetArray[setClass]);
|
2001-01-19 00:30:17 +00:00
|
|
|
const ChainSubClassSetTable *chainSubClassSetTable =
|
|
|
|
(const ChainSubClassSetTable *) ((char *) this + chainSubClassSetTableOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 chainSubClassRuleCount = SWAPW(chainSubClassSetTable->chainSubClassRuleCount);
|
|
|
|
le_int32 position = glyphIterator->getCurrStreamPosition();
|
2003-03-07 23:33:41 +00:00
|
|
|
GlyphIterator tempIterator(*glyphIterator, emptyTag);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
for (le_uint16 scRule = 0; scRule < chainSubClassRuleCount; scRule += 1) {
|
2000-11-28 20:56:52 +00:00
|
|
|
Offset chainSubClassRuleTableOffset =
|
|
|
|
SWAPW(chainSubClassSetTable->chainSubClassRuleTableOffsetArray[scRule]);
|
2001-01-19 00:30:17 +00:00
|
|
|
const ChainSubClassRuleTable *chainSubClassRuleTable =
|
|
|
|
(const ChainSubClassRuleTable *) ((char *) chainSubClassSetTable + chainSubClassRuleTableOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 backtrackGlyphCount = SWAPW(chainSubClassRuleTable->backtrackGlyphCount);
|
|
|
|
le_uint16 inputGlyphCount = SWAPW(chainSubClassRuleTable->backtrackClassArray[backtrackGlyphCount]) - 1;
|
2001-01-19 00:30:17 +00:00
|
|
|
const le_uint16 *inputClassArray = &chainSubClassRuleTable->backtrackClassArray[backtrackGlyphCount + 1];
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 lookaheadGlyphCount = SWAPW(inputClassArray[inputGlyphCount]);
|
2001-01-19 00:30:17 +00:00
|
|
|
const le_uint16 *lookaheadClassArray = &inputClassArray[inputGlyphCount + 1];
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 substCount = SWAPW(lookaheadClassArray[lookaheadGlyphCount]);
|
|
|
|
|
|
|
|
|
|
|
|
tempIterator.setCurrStreamPosition(position);
|
2002-07-30 22:58:29 +00:00
|
|
|
|
|
|
|
if (! tempIterator.prev(backtrackGlyphCount)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
tempIterator.prev();
|
2000-11-28 20:56:52 +00:00
|
|
|
if (! matchGlyphClasses(chainSubClassRuleTable->backtrackClassArray, backtrackGlyphCount,
|
2002-07-30 22:58:29 +00:00
|
|
|
&tempIterator, backtrackClassDefinitionTable, true)) {
|
2000-11-28 20:56:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
tempIterator.setCurrStreamPosition(position);
|
|
|
|
tempIterator.next(inputGlyphCount);
|
2001-01-19 00:30:17 +00:00
|
|
|
if (! matchGlyphClasses(lookaheadClassArray, lookaheadGlyphCount, &tempIterator, lookaheadClassDefinitionTable)) {
|
2000-11-28 20:56:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (matchGlyphClasses(inputClassArray, inputGlyphCount, glyphIterator, inputClassDefinitionTable)) {
|
|
|
|
const SubstitutionLookupRecord *substLookupRecordArray =
|
|
|
|
(const SubstitutionLookupRecord *) &lookaheadClassArray[lookaheadGlyphCount + 1];
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
|
|
|
|
|
|
|
|
return inputGlyphCount + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
glyphIterator->setCurrStreamPosition(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX If we get here, the table is mal-formed...
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_uint32 ChainingContextualSubstitutionFormat3Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
|
|
|
|
const LEFontInstance *fontInstance) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
|
|
|
le_uint16 backtrkGlyphCount = SWAPW(backtrackGlyphCount);
|
|
|
|
le_uint16 inputGlyphCount = (le_uint16) SWAPW(backtrackCoverageTableOffsetArray[backtrkGlyphCount]);
|
2001-01-19 00:30:17 +00:00
|
|
|
const Offset *inputCoverageTableOffsetArray = &backtrackCoverageTableOffsetArray[backtrkGlyphCount + 1];
|
|
|
|
const le_uint16 lookaheadGlyphCount = (le_uint16) SWAPW(inputCoverageTableOffsetArray[inputGlyphCount]);
|
|
|
|
const Offset *lookaheadCoverageTableOffsetArray = &inputCoverageTableOffsetArray[inputGlyphCount + 1];
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 substCount = (le_uint16) SWAPW(lookaheadCoverageTableOffsetArray[lookaheadGlyphCount]);
|
|
|
|
le_int32 position = glyphIterator->getCurrStreamPosition();
|
2003-03-07 23:33:41 +00:00
|
|
|
GlyphIterator tempIterator(*glyphIterator, emptyTag);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2002-07-30 22:58:29 +00:00
|
|
|
if (! tempIterator.prev(backtrkGlyphCount)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
tempIterator.prev();
|
2000-11-28 20:56:52 +00:00
|
|
|
if (! ContextualSubstitutionBase::matchGlyphCoverages(backtrackCoverageTableOffsetArray,
|
2002-07-30 22:58:29 +00:00
|
|
|
backtrkGlyphCount, &tempIterator, (const char *) this, true)) {
|
2000-11-28 20:56:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
tempIterator.setCurrStreamPosition(position);
|
|
|
|
tempIterator.next(inputGlyphCount - 1);
|
|
|
|
if (! ContextualSubstitutionBase::matchGlyphCoverages(lookaheadCoverageTableOffsetArray,
|
2001-01-19 00:30:17 +00:00
|
|
|
lookaheadGlyphCount, &tempIterator, (const char *) this)) {
|
2000-11-28 20:56:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Back up the glyph iterator so that we
|
|
|
|
// can call next() before the check, which
|
|
|
|
// will leave it pointing at the last glyph
|
|
|
|
// that matched when we're done.
|
|
|
|
glyphIterator->prev();
|
|
|
|
|
|
|
|
if (ContextualSubstitutionBase::matchGlyphCoverages(inputCoverageTableOffsetArray,
|
2001-01-19 00:30:17 +00:00
|
|
|
inputGlyphCount, glyphIterator, (const char *) this)) {
|
|
|
|
const SubstitutionLookupRecord *substLookupRecordArray =
|
|
|
|
(const SubstitutionLookupRecord *) &lookaheadCoverageTableOffsetArray[lookaheadGlyphCount + 1];
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
ContextualSubstitutionBase::applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
|
|
|
|
|
2003-03-07 23:33:41 +00:00
|
|
|
return inputGlyphCount;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glyphIterator->setCurrStreamPosition(position);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2001-10-16 00:39:01 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_END
|