]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/layout/PairPositioningSubtables.cpp
ICU-57132.0.1.tar.gz
[apple/icu.git] / icuSources / layout / PairPositioningSubtables.cpp
index 709aa48ed8037088dceb5a0e239ec9e0397a832d..2ff3383af46ffb599c2858fb60d9b19091bcb54a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *
- * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
+ * (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved
  *
  */
 
@@ -16,7 +16,7 @@
 
 U_NAMESPACE_BEGIN
 
-le_uint32 PairPositioningSubtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
+le_uint32 PairPositioningSubtable::process(const LEReferenceTo<PairPositioningSubtable> &base, GlyphIterator *glyphIterator, const LEFontInstance *fontInstance, LEErrorCode &success) const
 {
     switch(SWAPW(subtableFormat))
     {
@@ -25,27 +25,32 @@ le_uint32 PairPositioningSubtable::process(GlyphIterator *glyphIterator, const L
 
     case 1:
     {
-        const PairPositioningFormat1Subtable *subtable = (const PairPositioningFormat1Subtable *) this;
+      const LEReferenceTo<PairPositioningFormat1Subtable> subtable(base, success, (const PairPositioningFormat1Subtable *) this);
 
-        return subtable->process(glyphIterator, fontInstance);
+      if(LE_SUCCESS(success))
+      return subtable->process(subtable, glyphIterator, fontInstance, success);
+      else
+        return 0;
     }
 
     case 2:
     {
-        const PairPositioningFormat2Subtable *subtable = (const PairPositioningFormat2Subtable *) this;
+      const LEReferenceTo<PairPositioningFormat2Subtable> subtable(base, success, (const PairPositioningFormat2Subtable *) this);
 
-        return subtable->process(glyphIterator, fontInstance);
+      if(LE_SUCCESS(success))
+      return subtable->process(subtable, glyphIterator, fontInstance, success);
+      else
+        return 0;
     }
-
     default:
-        return 0;
+      return 0;
     }
 }
 
-le_uint32 PairPositioningFormat1Subtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
+le_uint32 PairPositioningFormat1Subtable::process(const LEReferenceTo<PairPositioningFormat1Subtable> &base, GlyphIterator *glyphIterator, const LEFontInstance *fontInstance, LEErrorCode &success) const
 {
     LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
-    le_int32 coverageIndex = getGlyphCoverage(firstGlyph);
+    le_int32 coverageIndex = getGlyphCoverage(base, firstGlyph, success);
     GlyphIterator tempIterator(*glyphIterator);
 
     if (coverageIndex >= 0 && glyphIterator->next()) {
@@ -76,16 +81,19 @@ le_uint32 PairPositioningFormat1Subtable::process(GlyphIterator *glyphIterator,
             valueRecord2->adjustPosition(SWAPW(valueFormat2), (char *) this, *glyphIterator, fontInstance);
         }
 
-        return 2;
+        // back up glyphIterator so second glyph can be
+        // first glyph in the next pair
+        glyphIterator->prev();
+        return 1;
     }
 
     return 0;
 }
 
-le_uint32 PairPositioningFormat2Subtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
+le_uint32 PairPositioningFormat2Subtable::process(const LEReferenceTo<PairPositioningFormat2Subtable> &base, GlyphIterator *glyphIterator, const LEFontInstance *fontInstance, LEErrorCode &success) const
 {
     LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
-    le_int32 coverageIndex = getGlyphCoverage(firstGlyph);
+    le_int32 coverageIndex = getGlyphCoverage(base, firstGlyph, success);
     GlyphIterator tempIterator(*glyphIterator);
 
     if (coverageIndex >= 0 && glyphIterator->next()) {
@@ -112,7 +120,10 @@ le_uint32 PairPositioningFormat2Subtable::process(GlyphIterator *glyphIterator,
             valueRecord2->adjustPosition(SWAPW(valueFormat2), (const char *) this, *glyphIterator, fontInstance);
         }
 
-        return 2;
+        // back up glyphIterator so second glyph can be
+        // first glyph in the next pair
+        glyphIterator->prev();
+        return 1;
     }
 
     return 0;
@@ -120,6 +131,20 @@ le_uint32 PairPositioningFormat2Subtable::process(GlyphIterator *glyphIterator,
 
 const PairValueRecord *PairPositioningFormat1Subtable::findPairValueRecord(TTGlyphID glyphID, const PairValueRecord *records, le_uint16 recordCount, le_uint16 recordSize) const
 {
+#if 1
+       // The OpenType spec. says that the ValueRecord table is
+       // sorted by secondGlyph. Unfortunately, there are fonts
+       // around that have an unsorted ValueRecord table.
+       const PairValueRecord *record = records;
+
+       for(le_int32 r = 0; r < recordCount; r += 1) {
+               if (SWAPW(record->secondGlyph) == glyphID) {
+                       return record;
+               }
+
+               record = (const PairValueRecord *) ((char *) record + recordSize);
+       }
+#else
     le_uint8 bit = OpenTypeUtilities::highBit(recordCount);
     le_uint16 power = 1 << bit;
     le_uint16 extra = (recordCount - power) * recordSize;
@@ -143,6 +168,7 @@ const PairValueRecord *PairPositioningFormat1Subtable::findPairValueRecord(TTGly
     if (SWAPW(record->secondGlyph) == glyphID) {
         return record;
     }
+#endif
 
     return NULL;
 }