(get_uvs_glyph): Complete the code.
authorhanda <handa>
Wed, 24 Dec 2008 13:20:11 +0000 (13:20 +0000)
committerhanda <handa>
Wed, 24 Dec 2008 13:20:11 +0000 (13:20 +0000)
src/otfdrive.c

index 115cf9f..90be525 100644 (file)
@@ -1339,6 +1339,66 @@ lookup_encoding_12 (OTF_EncodingSubtable12 *sub12, OTF_GlyphString *gstring)
 static OTF_GlyphID
 get_uvs_glyph (OTF_cmap *cmap, OTF_EncodingSubtable14 *sub14, int c1, int c2)
 {
+  unsigned nRecords = sub14->nRecords;
+  OTF_VariationSelectorRecord *record;
+  unsigned i;
+
+  for (i = 0; i < nRecords; i++)
+    {
+      record = &sub14->Records[i];
+      if (record->varSelector == c2)
+       {
+         if (record->defaultUVSOffset)
+           {
+             OTF_UnicodeValueRange *uVRs = record->unicodeValueRanges;
+             unsigned numUVRs = record->numUnicodeValueRanges;
+             unsigned top = numUVRs, bottom = 0, middle;
+
+             if (uVRs[0].startUnicodeValue <= c1)
+               {
+                 unsigned additionalCount, startUnicodeValue;
+
+                 for (;;)
+                   {
+                     middle = (top + bottom) / 2;
+                     if (c1 < uVRs[middle].startUnicodeValue)
+                       top = middle;
+                     else if (bottom == middle)
+                       break;
+                     else
+                       bottom = middle;
+                   }
+                 startUnicodeValue = uVRs[bottom].startUnicodeValue;
+                 additionalCount = uVRs[bottom].additionalCount;
+                 if (c1 <= startUnicodeValue + additionalCount)
+                   return cmap->unicode_table[c1];
+               }
+           }
+         if (record->nonDefaultUVSOffset)
+           {
+             OTF_UVSMapping *uvsMappings = record->uvsMappings;
+             unsigned numUVSMs = record->numUVSMappings;
+             unsigned top = numUVSMs, bottom = 0, middle;
+
+             if (uvsMappings[0].unicodeValue <= c1)
+               {
+                 for (;;)
+                   {
+                     middle = (top + bottom) / 2;
+                     if (c1 < uvsMappings[middle].unicodeValue)
+                       top = middle;
+                     else if (bottom == middle)
+                       break;
+                     else
+                       bottom = middle;
+                   }
+                 if (uvsMappings[bottom].unicodeValue == c1)
+                   return uvsMappings[bottom].glyphID;
+               }
+           }
+         return 0;
+       }
+    }
   return 0;
 }