]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/layout/ContextualSubstSubtables.cpp
ICU-531.48.tar.gz
[apple/icu.git] / icuSources / layout / ContextualSubstSubtables.cpp
index 863b9ab2ad8acfb1e2cfc5808978b91101c84dc0..1737d8e9225ab46634fef0e5f4ae327e00ccab33 100644 (file)
@@ -1,7 +1,5 @@
 /*
- * @(#)ContextualSubstSubtables.cpp    1.11 00/03/15
- *
- * (C) Copyright IBM Corp. 1998-2003 - All Rights Reserved
+ * (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved
  *
  */
 
@@ -29,18 +27,23 @@ void ContextualSubstitutionBase::applySubstitutionLookups(
         le_uint16 substCount,
         GlyphIterator *glyphIterator,
         const LEFontInstance *fontInstance,
-        le_int32 position)
+        le_int32 position,
+        LEErrorCode& success)
 {
+    if (LE_FAILURE(success)) { 
+        return;
+    }
+
     GlyphIterator tempIterator(*glyphIterator);
 
-    for (le_int16 subst = 0; subst < substCount; subst += 1) {
+    for (le_int16 subst = 0; subst < substCount && LE_SUCCESS(success); subst += 1) {
         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);
+        lookupProcessor->applySingleLookup(lookupListIndex, &tempIterator, fontInstance, success);
     }
 }
 
@@ -57,20 +60,20 @@ le_bool ContextualSubstitutionBase::matchGlyphIDs(const TTGlyphID *glyphArray, l
 
     while (glyphCount > 0) {
         if (! glyphIterator->next()) {
-            return false;
+            return FALSE;
         }
 
         TTGlyphID glyph = (TTGlyphID) glyphIterator->getCurrGlyphID();
 
         if (glyph != SWAPW(glyphArray[match])) {
-            return false;
+            return FALSE;
         }
 
         glyphCount -= 1;
         match += direction;
     }
 
-    return true;
+    return TRUE;
 }
 
 le_bool ContextualSubstitutionBase::matchGlyphClasses(const le_uint16 *classArray, le_uint16 glyphCount,
@@ -88,7 +91,7 @@ le_bool ContextualSubstitutionBase::matchGlyphClasses(const le_uint16 *classArra
 
     while (glyphCount > 0) {
         if (! glyphIterator->next()) {
-            return false;
+            return FALSE;
         }
 
         LEGlyphID glyph = glyphIterator->getCurrGlyphID();
@@ -101,7 +104,7 @@ le_bool ContextualSubstitutionBase::matchGlyphClasses(const le_uint16 *classArra
             // table. If we're looking for such a class, pretend that
             // we found it.
             if (classDefinitionTable->hasGlyphClass(matchClass)) {
-                return false;
+                return FALSE;
             }
         }
 
@@ -109,7 +112,7 @@ le_bool ContextualSubstitutionBase::matchGlyphClasses(const le_uint16 *classArra
         match += direction;
     }
 
-    return true;
+    return TRUE;
 }
 
 le_bool ContextualSubstitutionBase::matchGlyphCoverages(const Offset *coverageTableOffsetArray, le_uint16 glyphCount,
@@ -128,23 +131,29 @@ le_bool ContextualSubstitutionBase::matchGlyphCoverages(const Offset *coverageTa
         const CoverageTable *coverageTable = (const CoverageTable *) (offsetBase + coverageTableOffset);
 
         if (! glyphIterator->next()) {
-            return false;
+            return FALSE;
         }
 
         if (coverageTable->getGlyphCoverage((LEGlyphID) glyphIterator->getCurrGlyphID()) < 0) {
-            return false;
+            return FALSE;
         }
 
         glyphCount -= 1;
         glyph += direction;
     }
 
-    return true;
+    return TRUE;
 }
 
-le_uint32 ContextualSubstitutionSubtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
-                                               const LEFontInstance *fontInstance) const
+le_uint32 ContextualSubstitutionSubtable::process(const LookupProcessor *lookupProcessor, 
+                                                  GlyphIterator *glyphIterator,
+                                                  const LEFontInstance *fontInstance,
+                                                  LEErrorCode& success) const
 {
+    if (LE_FAILURE(success)) { 
+        return 0;
+    }
+
     switch(SWAPW(subtableFormat))
     {
     case 0:
@@ -153,22 +162,19 @@ le_uint32 ContextualSubstitutionSubtable::process(const LookupProcessor *lookupP
     case 1:
     {
         const ContextualSubstitutionFormat1Subtable *subtable = (const ContextualSubstitutionFormat1Subtable *) this;
-
-        return subtable->process(lookupProcessor, glyphIterator, fontInstance);
+        return subtable->process(lookupProcessor, glyphIterator, fontInstance, success);
     }
 
     case 2:
     {
         const ContextualSubstitutionFormat2Subtable *subtable = (const ContextualSubstitutionFormat2Subtable *) this;
-
-        return subtable->process(lookupProcessor, glyphIterator, fontInstance);
+        return subtable->process(lookupProcessor, glyphIterator, fontInstance, success);
     }
 
     case 3:
     {
         const ContextualSubstitutionFormat3Subtable *subtable = (const ContextualSubstitutionFormat3Subtable *) this;
-
-        return subtable->process(lookupProcessor, glyphIterator, fontInstance);
+        return subtable->process(lookupProcessor, glyphIterator, fontInstance, success);
     }
 
     default:
@@ -176,11 +182,17 @@ le_uint32 ContextualSubstitutionSubtable::process(const LookupProcessor *lookupP
     }
 }
 
-le_uint32 ContextualSubstitutionFormat1Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
-                                                      const LEFontInstance *fontInstance) const
+le_uint32 ContextualSubstitutionFormat1Subtable::process(const LookupProcessor *lookupProcessor, 
+                                                         GlyphIterator *glyphIterator,
+                                                         const LEFontInstance *fontInstance,
+                                                         LEErrorCode& success) const
 {
+    if (LE_FAILURE(success)) { 
+        return 0;
+    }
+
     LEGlyphID glyph = glyphIterator->getCurrGlyphID();
-    le_int32 coverageIndex = getGlyphCoverage(glyph);
+    le_int32 coverageIndex = getGlyphCoverage(lookupProcessor->getReference(), glyph, success);
 
     if (coverageIndex >= 0) {
         le_uint16 srSetCount = SWAPW(subRuleSetCount);
@@ -204,7 +216,7 @@ le_uint32 ContextualSubstitutionFormat1Subtable::process(const LookupProcessor *
                     const SubstitutionLookupRecord *substLookupRecordArray = 
                         (const SubstitutionLookupRecord *) &subRuleTable->inputGlyphArray[matchCount];
 
-                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
+                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position, success);
 
                     return matchCount + 1;
                 }
@@ -219,11 +231,17 @@ le_uint32 ContextualSubstitutionFormat1Subtable::process(const LookupProcessor *
     return 0;
 }
 
-le_uint32 ContextualSubstitutionFormat2Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
-                                                      const LEFontInstance *fontInstance) const
+le_uint32 ContextualSubstitutionFormat2Subtable::process(const LookupProcessor *lookupProcessor, 
+                                                         GlyphIterator *glyphIterator,
+                                                         const LEFontInstance *fontInstance,
+                                                         LEErrorCode& success) const
 {
+    if (LE_FAILURE(success)) { 
+        return 0;
+    }
+
     LEGlyphID glyph = glyphIterator->getCurrGlyphID();
-    le_int32 coverageIndex = getGlyphCoverage(glyph);
+    le_int32 coverageIndex = getGlyphCoverage(lookupProcessor->getReference(), glyph, success);
 
     if (coverageIndex >= 0) {
         const ClassDefinitionTable *classDefinitionTable =
@@ -250,7 +268,7 @@ le_uint32 ContextualSubstitutionFormat2Subtable::process(const LookupProcessor *
                     const SubstitutionLookupRecord *substLookupRecordArray = 
                         (const SubstitutionLookupRecord *) &subClassRuleTable->classArray[matchCount];
 
-                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
+                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position, success);
 
                     return matchCount + 1;
                 }
@@ -265,9 +283,15 @@ le_uint32 ContextualSubstitutionFormat2Subtable::process(const LookupProcessor *
     return 0;
 }
 
-le_uint32 ContextualSubstitutionFormat3Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
-                                                      const LEFontInstance *fontInstance)const 
+le_uint32 ContextualSubstitutionFormat3Subtable::process(const LookupProcessor *lookupProcessor, 
+                                                         GlyphIterator *glyphIterator,
+                                                         const LEFontInstance *fontInstance,
+                                                         LEErrorCode& success)const 
 {
+    if (LE_FAILURE(success)) { 
+        return 0;
+    }
+
     le_uint16 gCount = SWAPW(glyphCount);
     le_uint16 subCount = SWAPW(substCount);
     le_int32 position = glyphIterator->getCurrStreamPosition();
@@ -282,7 +306,7 @@ le_uint32 ContextualSubstitutionFormat3Subtable::process(const LookupProcessor *
         const SubstitutionLookupRecord *substLookupRecordArray = 
             (const SubstitutionLookupRecord *) &coverageTableOffsetArray[gCount];
 
-        ContextualSubstitutionBase::applySubstitutionLookups(lookupProcessor, substLookupRecordArray, subCount, glyphIterator, fontInstance, position);
+        ContextualSubstitutionBase::applySubstitutionLookups(lookupProcessor, substLookupRecordArray, subCount, glyphIterator, fontInstance, position, success);
 
         return gCount + 1;
     }
@@ -292,9 +316,15 @@ le_uint32 ContextualSubstitutionFormat3Subtable::process(const LookupProcessor *
     return 0;
 }
 
-le_uint32 ChainingContextualSubstitutionSubtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
-                                                       const LEFontInstance *fontInstance) const
+le_uint32 ChainingContextualSubstitutionSubtable::process(const LookupProcessor *lookupProcessor, 
+                                                          GlyphIterator *glyphIterator,
+                                                          const LEFontInstance *fontInstance,
+                                                          LEErrorCode& success) const
 {
+    if (LE_FAILURE(success)) { 
+        return 0;
+    }
+
     switch(SWAPW(subtableFormat))
     {
     case 0:
@@ -303,22 +333,19 @@ le_uint32 ChainingContextualSubstitutionSubtable::process(const LookupProcessor
     case 1:
     {
         const ChainingContextualSubstitutionFormat1Subtable *subtable = (const ChainingContextualSubstitutionFormat1Subtable *) this;
-
-        return subtable->process(lookupProcessor, glyphIterator, fontInstance);
+        return subtable->process(lookupProcessor, glyphIterator, fontInstance, success);
     }
 
     case 2:
     {
         const ChainingContextualSubstitutionFormat2Subtable *subtable = (const ChainingContextualSubstitutionFormat2Subtable *) this;
-
-        return subtable->process(lookupProcessor, glyphIterator, fontInstance);
+        return subtable->process(lookupProcessor, glyphIterator, fontInstance, success);
     }
 
     case 3:
     {
         const ChainingContextualSubstitutionFormat3Subtable *subtable = (const ChainingContextualSubstitutionFormat3Subtable *) this;
-
-        return subtable->process(lookupProcessor, glyphIterator, fontInstance);
+        return subtable->process(lookupProcessor, glyphIterator, fontInstance, success);
     }
 
     default:
@@ -326,13 +353,23 @@ le_uint32 ChainingContextualSubstitutionSubtable::process(const LookupProcessor
     }
 }
 
-const LETag emptyTag = 0;
+// NOTE: This could be a #define, but that seems to confuse
+// the Visual Studio .NET 2003 compiler on the calls to the
+// GlyphIterator constructor. It somehow can't decide if
+// emptyFeatureList matches an le_uint32 or an le_uint16...
+static const FeatureMask emptyFeatureList = 0x00000000UL;
 
-le_uint32 ChainingContextualSubstitutionFormat1Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
-                                                              const LEFontInstance *fontInstance) const
+le_uint32 ChainingContextualSubstitutionFormat1Subtable::process(const LookupProcessor *lookupProcessor, 
+                                                                 GlyphIterator *glyphIterator,
+                                                                 const LEFontInstance *fontInstance,
+                                                                 LEErrorCode& success) const
 {
+    if (LE_FAILURE(success)) { 
+        return 0;
+    }
+
     LEGlyphID glyph = glyphIterator->getCurrGlyphID();
-    le_int32 coverageIndex = getGlyphCoverage(glyph);
+    le_int32 coverageIndex = getGlyphCoverage(lookupProcessor->getReference(), glyph, success);
 
     if (coverageIndex >= 0) {
         le_uint16 srSetCount = SWAPW(chainSubRuleSetCount);
@@ -343,7 +380,7 @@ le_uint32 ChainingContextualSubstitutionFormat1Subtable::process(const LookupPro
                 (const ChainSubRuleSetTable *) ((char *) this + chainSubRuleSetTableOffset);
             le_uint16 chainSubRuleCount = SWAPW(chainSubRuleSetTable->chainSubRuleCount);
             le_int32 position = glyphIterator->getCurrStreamPosition();
-            GlyphIterator tempIterator(*glyphIterator, emptyTag);
+            GlyphIterator tempIterator(*glyphIterator, emptyFeatureList);
 
             for (le_uint16 subRule = 0; subRule < chainSubRuleCount; subRule += 1) {
                 Offset chainSubRuleTableOffset =
@@ -364,7 +401,7 @@ le_uint32 ChainingContextualSubstitutionFormat1Subtable::process(const LookupPro
                 }
 
                 tempIterator.prev();
-                if (! matchGlyphIDs(chainSubRuleTable->backtrackGlyphArray, backtrackGlyphCount, &tempIterator, true)) {
+                if (! matchGlyphIDs(chainSubRuleTable->backtrackGlyphArray, backtrackGlyphCount, &tempIterator, TRUE)) {
                     continue;
                 }
 
@@ -378,7 +415,7 @@ le_uint32 ChainingContextualSubstitutionFormat1Subtable::process(const LookupPro
                     const SubstitutionLookupRecord *substLookupRecordArray = 
                         (const SubstitutionLookupRecord *) &lookaheadGlyphArray[lookaheadGlyphCount + 1];
 
-                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
+                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position, success);
 
                     return inputGlyphCount + 1;
                 }
@@ -393,11 +430,17 @@ le_uint32 ChainingContextualSubstitutionFormat1Subtable::process(const LookupPro
     return 0;
 }
 
-le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
-                                                              const LEFontInstance *fontInstance) const
+le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LookupProcessor *lookupProcessor, 
+                                                                 GlyphIterator *glyphIterator,
+                                                                 const LEFontInstance *fontInstance,
+                                                                 LEErrorCode& success) const
 {
+    if (LE_FAILURE(success)) { 
+        return 0;
+    }
+
     LEGlyphID glyph = glyphIterator->getCurrGlyphID();
-    le_int32 coverageIndex = getGlyphCoverage(glyph);
+    le_int32 coverageIndex = getGlyphCoverage(lookupProcessor->getReference(), glyph, success);
 
     if (coverageIndex >= 0) {
         const ClassDefinitionTable *backtrackClassDefinitionTable =
@@ -415,7 +458,7 @@ le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LookupPro
                 (const ChainSubClassSetTable *) ((char *) this + chainSubClassSetTableOffset);
             le_uint16 chainSubClassRuleCount = SWAPW(chainSubClassSetTable->chainSubClassRuleCount);
             le_int32 position = glyphIterator->getCurrStreamPosition();
-            GlyphIterator tempIterator(*glyphIterator, emptyTag);
+            GlyphIterator tempIterator(*glyphIterator, emptyFeatureList);
 
             for (le_uint16 scRule = 0; scRule < chainSubClassRuleCount; scRule += 1) {
                 Offset chainSubClassRuleTableOffset =
@@ -438,7 +481,7 @@ le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LookupPro
 
                 tempIterator.prev();
                 if (! matchGlyphClasses(chainSubClassRuleTable->backtrackClassArray, backtrackGlyphCount,
-                    &tempIterator, backtrackClassDefinitionTable, true)) {
+                    &tempIterator, backtrackClassDefinitionTable, TRUE)) {
                     continue;
                 }
 
@@ -452,7 +495,7 @@ le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LookupPro
                     const SubstitutionLookupRecord *substLookupRecordArray = 
                         (const SubstitutionLookupRecord *) &lookaheadClassArray[lookaheadGlyphCount + 1];
 
-                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
+                    applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position, success);
 
                     return inputGlyphCount + 1;
                 }
@@ -467,9 +510,15 @@ le_uint32 ChainingContextualSubstitutionFormat2Subtable::process(const LookupPro
     return 0;
 }
 
-le_uint32 ChainingContextualSubstitutionFormat3Subtable::process(const LookupProcessor *lookupProcessor, GlyphIterator *glyphIterator,
-                                                              const LEFontInstance *fontInstance) const
+le_uint32 ChainingContextualSubstitutionFormat3Subtable::process(const LookupProcessor *lookupProcessor, 
+                                                                 GlyphIterator *glyphIterator,
+                                                                 const LEFontInstance *fontInstance,
+                                                                 LEErrorCode & success) const
 {
+    if (LE_FAILURE(success)) { 
+        return 0;
+    }
+
     le_uint16 backtrkGlyphCount = SWAPW(backtrackGlyphCount);
     le_uint16 inputGlyphCount = (le_uint16) SWAPW(backtrackCoverageTableOffsetArray[backtrkGlyphCount]);
     const Offset *inputCoverageTableOffsetArray = &backtrackCoverageTableOffsetArray[backtrkGlyphCount + 1];
@@ -477,7 +526,7 @@ le_uint32 ChainingContextualSubstitutionFormat3Subtable::process(const LookupPro
     const Offset *lookaheadCoverageTableOffsetArray = &inputCoverageTableOffsetArray[inputGlyphCount + 1];
     le_uint16 substCount = (le_uint16) SWAPW(lookaheadCoverageTableOffsetArray[lookaheadGlyphCount]);
     le_int32 position = glyphIterator->getCurrStreamPosition();
-    GlyphIterator tempIterator(*glyphIterator, emptyTag);
+    GlyphIterator tempIterator(*glyphIterator, emptyFeatureList);
 
     if (! tempIterator.prev(backtrkGlyphCount)) {
         return 0;
@@ -485,7 +534,7 @@ le_uint32 ChainingContextualSubstitutionFormat3Subtable::process(const LookupPro
 
     tempIterator.prev();
     if (! ContextualSubstitutionBase::matchGlyphCoverages(backtrackCoverageTableOffsetArray,
-        backtrkGlyphCount, &tempIterator, (const char *) this, true)) {
+        backtrkGlyphCount, &tempIterator, (const char *) this, TRUE)) {
         return 0;
     }
 
@@ -507,7 +556,7 @@ le_uint32 ChainingContextualSubstitutionFormat3Subtable::process(const LookupPro
         const SubstitutionLookupRecord *substLookupRecordArray = 
             (const SubstitutionLookupRecord *) &lookaheadCoverageTableOffsetArray[lookaheadGlyphCount + 1];
 
-        ContextualSubstitutionBase::applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position);
+        ContextualSubstitutionBase::applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position, success);
 
         return inputGlyphCount;
     }