*** empty log message ***
[m17n/libotf.git] / src / otfdrive.c
index 794438d..90be525 100644 (file)
@@ -102,16 +102,16 @@ gstring_subst (OTF *otf, OTF_GlyphString *gstring, int from, int to, int flag,
     GSTRING_DELETE (gstring, from, (len - num));
   for (i = 0; i < num; i++)
     {
-      if (otf->cmap)
-       gstring->glyphs[from + i].c = otf->cmap->decode_table[ids[i]];
-      else
-       gstring->glyphs[from + i].c = 0;
+      if (gstring->glyphs[from + i].glyph_id != ids[i])
+       {
+         gstring->glyphs[from + i].c = 0;
+         if (otf->gdef)
+           gstring->glyphs[from + i].GlyphClass
+             = get_class_def (&otf->gdef->glyph_class_def, ids[i]);
+         else
+           gstring->glyphs[from + i].GlyphClass = 0;
+       }
       gstring->glyphs[from + i].glyph_id = ids[i];
-      if (otf->gdef)
-       gstring->glyphs[from + i].GlyphClass
-         = get_class_def (&otf->gdef->glyph_class_def, ids[i]);
-      else
-       gstring->glyphs[from + i].GlyphClass = 0;
       gstring->glyphs[from + i].positioning_type = 0;
       gstring->glyphs[from + i].f.index.from = from_idx;
       gstring->glyphs[from + i].f.index.to = to_idx;
@@ -203,15 +203,19 @@ get_langsys (OTF_ScriptList *script_list,
 }
 
 static int
-setup_lookup_indices (OTF_LookupList *LookupList, OTF_FeatureList *FeatureList,
-                     const char *features, int *lookup_indices)
+setup_lookup_flags (OTF_LookupList *LookupList, OTF_FeatureList *FeatureList,
+                   OTF_LangSys *LangSys,
+                   const char *features, char *lookup_flags)
 {
   int i, j, n = 0;
   OTF_Feature *feature;
   int *feature_table = alloca (sizeof (int) * FeatureList->FeatureCount);
 
+  if (! feature_table)
+    return -1;
   for (i = 0; i < FeatureList->FeatureCount; i++)
     feature_table[i] = 0;
+  memset (lookup_flags, 0, LookupList->LookupCount);
 
   while (*features)
     {
@@ -222,13 +226,17 @@ setup_lookup_indices (OTF_LookupList *LookupList, OTF_FeatureList *FeatureList,
       if (*features == '*')
        {
          /* Consume all remaining features.  */
-         for (i = 0; i < FeatureList->FeatureCount; i++)
-           if (! feature_table[i])
-             {
-               feature = FeatureList->Feature + i;
-               for (j = 0; j < feature->LookupCount; j++)
-                 lookup_indices[n++] = feature->LookupListIndex[j];
-             }
+         for (i = 0; i < LangSys->FeatureCount; i++) 
+           {
+             int index = LangSys->FeatureIndex[i];
+
+             if (! feature_table[index])
+               {
+                 feature = FeatureList->Feature + index;
+                 for (j = 0; j < feature->LookupCount; j++)
+                   lookup_flags[feature->LookupListIndex[j]] = 1;
+               }
+           }
          break;
        }
 
@@ -242,23 +250,22 @@ setup_lookup_indices (OTF_LookupList *LookupList, OTF_FeatureList *FeatureList,
       for (; i < 4; i++)
        tagname[i] = '\0';
       tag = OTF_tag (tagname);
-      for (i = 0; i < FeatureList->FeatureCount; i++)
+      for (i = 0; i < LangSys->FeatureCount; i++)
        {
-         feature = FeatureList->Feature + i;
+         feature = FeatureList->Feature + LangSys->FeatureIndex[i];
          if (tag == feature->FeatureTag)
            {
              if (feature_table[i])
                break;
              if (use_it > 0)
                for (j = 0; j < feature->LookupCount; j++)
-                 lookup_indices[n++] = feature->LookupListIndex[j];
+                 lookup_flags[feature->LookupListIndex[j]] = 1;
              feature_table[i] = use_it;
              break;
            }
        }
     }
-
-  return n;
+  return 0;
 }
 
 static int
@@ -748,10 +755,25 @@ get_anchor (OTF_Anchor *anchor, OTF_ValueRecord *rec)
   return value_format;
 }
 
+static int
+gstring_insert_for_gpos (OTF_GlyphString *gstring, int gidx)
+{
+  int errret = -1;
+  int orig_gidx = gidx++;
+
+  while (gidx < gstring->used
+        && ! gstring->glyphs[gidx].glyph_id
+        && gstring->glyphs[gidx].positioning_type)
+    gidx++;
+  GSTRING_INSERT (gstring, gidx, 1);
+  gstring->glyphs[gidx] = gstring->glyphs[orig_gidx];
+  gstring->glyphs[gidx].glyph_id = 0;
+  return gidx;
+}
 
 static int
 lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
-            OTF_GlyphString *gstring, int gidx)
+            OTF_GlyphString *gstring, int gidx, int accumulate)
 {
   char *errfmt = "GPOS Looking up%s";
   int errret = -1;
@@ -762,8 +784,7 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
   OTF_Glyph *g = gstring->glyphs + gidx;
   int i;
 
-  if (IGNORED_GLYPH (g, flag)
-      || g->positioning_type)
+  if (IGNORED_GLYPH (g, flag))
     return (gidx + 1);
 
   /* Try all subtables until one of them handles the current glyph.  */
@@ -772,6 +793,10 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
       unsigned lookup_type = lookup->LookupType;
       OTF_LookupSubTableGPOS *subtable = lookup->SubTable.gpos + i;
       int coverage_idx;
+      int positioning_type;
+      enum OTF_ValueFormat format;
+      OTF_ValueRecord *value;
+      OTF_Anchor *anchor1, *anchor2;
 
       if (lookup_type == 9)
        {
@@ -792,21 +817,30 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
       switch (lookup_type)
        {
        case 1:
-         g->positioning_type = lookup_type;
+         positioning_type = lookup_type;
          if (subtable->Format == 1)
            {
              OTF_GPOS_Single1 *single1 = &subtable->u.single1;
 
-             g->f.f1.format = single1->ValueFormat;
-             g->f.f1.value = &single1->Value;
+             format = single1->ValueFormat;
+             value = &single1->Value;
            }
          else if (subtable->Format == 2)
            {
              OTF_GPOS_Single2 *single2 = &subtable->u.single2;
 
-             g->f.f1.format = single2->ValueFormat;
-             g->f.f1.value = single2->Value + coverage_idx;
+             format = single2->ValueFormat;
+             value = single2->Value + coverage_idx;
+           }
+         if (accumulate && g->positioning_type)
+           {
+             gidx = gstring_insert_for_gpos (gstring, gidx);         
+             g = gstring->glyphs + gidx;
            }
+         g->positioning_type = positioning_type;
+         g->f.f1.format = format;
+         g->f.f1.value = value;
+         gidx++;
          break;
 
        case 2:
@@ -832,16 +866,29 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
                    {
                      if (pair1->ValueFormat1)
                        {
+                         if (accumulate && g->positioning_type)
+                           {
+                             gidx = gstring_insert_for_gpos (gstring, gidx);
+                             g = gstring->glyphs + gidx;
+                             next_gidx += gidx - orig_gidx;
+                             nextg = gstring->glyphs + next_gidx;
+                           }
                          g->positioning_type = lookup_type;
                          g->f.f2.format = pair1->ValueFormat1;
                          g->f.f2.value = &set->PairValueRecord[j].Value1;
                        }
                      gidx = next_gidx;
+                     g = nextg;
                      if (pair1->ValueFormat2)
                        {
-                         nextg->positioning_type = lookup_type;
-                         nextg->f.f2.format = pair1->ValueFormat2;
-                         nextg->f.f2.value = &set->PairValueRecord[j].Value2;
+                         if (accumulate && g->positioning_type)
+                           {
+                             gidx = gstring_insert_for_gpos (gstring, gidx);
+                             g = gstring->glyphs + gidx;
+                           }
+                         g->positioning_type = lookup_type;
+                         g->f.f2.format = pair1->ValueFormat2;
+                         g->f.f2.value = &set->PairValueRecord[j].Value2;
                          gidx++;
                        }
                      break;
@@ -856,17 +903,30 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
                class2 = get_class_def (&pair2->ClassDef2, nextg->glyph_id);
                if (pair2->ValueFormat1)
                  {
+                   if (accumulate && g->positioning_type)
+                     {
+                       gidx = gstring_insert_for_gpos (gstring, gidx);
+                       g = gstring->glyphs + gidx;
+                       next_gidx += gidx - orig_gidx;
+                       nextg = gstring->glyphs + next_gidx;
+                     }
                    g->positioning_type = lookup_type;
                    g->f.f2.format = pair2->ValueFormat1;
                    g->f.f2.value
                      = &pair2->Class1Record[class1].Class2Record[class2].Value1;
                  }
                gidx = next_gidx;
+               g = nextg;
                if (pair2->ValueFormat2)
                  {
-                   nextg->positioning_type = lookup_type;
-                   nextg->f.f2.format = pair2->ValueFormat2;
-                   nextg->f.f2.value
+                   if (accumulate && g->positioning_type)
+                     {
+                       gidx = gstring_insert_for_gpos (gstring, gidx);
+                       g = gstring->glyphs + gidx;
+                     }
+                   g->positioning_type = lookup_type;
+                   g->f.f2.format = pair2->ValueFormat2;
+                   g->f.f2.value
                      = &pair2->Class1Record[class1].Class2Record[class2].Value2;
                    gidx++;
                  }
@@ -878,6 +938,11 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
          {
            OTF_GPOS_Cursive1 *cursive1 = &subtable->u.cursive1;
          
+           if (accumulate && g->positioning_type)
+             {
+               gidx = gstring_insert_for_gpos (gstring, gidx);
+               g = gstring->glyphs + gidx;
+             }
            g->positioning_type = lookup_type;
            g->f.f3.entry_anchor
              = &cursive1->EntryExitRecord[coverage_idx].EntryAnchor;
@@ -911,6 +976,11 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
              mark_record = mark_base1->MarkArray.MarkRecord + coverage_idx;
              base_record
                = mark_base1->BaseArray.AnchorRecord + coverage_idx_base;
+             if (accumulate && g->positioning_type)
+               {
+                 gidx = gstring_insert_for_gpos (gstring, gidx);
+                 g = gstring->glyphs + gidx;
+               }
              g->f.f4.mark_anchor = &mark_record->MarkAnchor;
              g->f.f4.base_anchor
                = &base_record->Anchor[mark_record->Class];
@@ -961,6 +1031,11 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
                  if (lig_anchor[mark_record->Class].AnchorFormat
                      && num_class[mark_record->Class]-- == 0)
                    {
+                     if (accumulate && g->positioning_type)
+                       {
+                         gidx = gstring_insert_for_gpos (gstring, gidx);
+                         g = gstring->glyphs + gidx;
+                       }
                      g->positioning_type = lookup_type;
                      g->f.f5.mark_anchor = &mark_record->MarkAnchor;
                      g->f.f5.ligature_anchor = lig_anchor + mark_record->Class;
@@ -994,6 +1069,11 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
              mark1_record = mark_mark1->Mark1Array.MarkRecord + coverage_idx;
              mark2_record
                = mark_mark1->Mark2Array.AnchorRecord + coverage_idx_base;
+             if (accumulate && g->positioning_type)
+               {
+                 gidx = gstring_insert_for_gpos (gstring, gidx);
+                 g = gstring->glyphs + gidx;
+               }
              g->f.f6.mark1_anchor = &mark1_record->MarkAnchor;
              g->f.f6.mark2_anchor
                = &mark2_record->Anchor[mark1_record->Class];
@@ -1022,7 +1102,8 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
                    lookup_gpos (lookup_list,
                                 rule->LookupRecord[k].LookupListIndex,
                                 gstring,
-                                gidx + rule->LookupRecord[k].SequenceIndex);
+                                gidx + rule->LookupRecord[k].SequenceIndex,
+                                accumulate);
                  gidx += rule->GlyphCount + (gstring->used - orig_used);
                  break;
                }
@@ -1052,7 +1133,8 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
                      lookup_gpos (lookup_list,
                                   rule->LookupRecord[k].LookupListIndex,
                                   gstring,
-                                  gidx + rule->LookupRecord[k].SequenceIndex);
+                                  gidx + rule->LookupRecord[k].SequenceIndex,
+                                  accumulate);
                    gidx += rule->GlyphCount + (gstring->used - orig_used);
                    break;
                  }
@@ -1072,7 +1154,8 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
                lookup_gpos (lookup_list,
                             context3->LookupRecord[j].LookupListIndex,
                             gstring,
-                            gidx + context3->LookupRecord[j].SequenceIndex);
+                            gidx + context3->LookupRecord[j].SequenceIndex,
+                            accumulate);
              gidx += context3->GlyphCount + (gstring->used - orig_used);
            }
          break;
@@ -1100,7 +1183,8 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
                    lookup_gpos (lookup_list,
                                 rule->LookupRecord[k].LookupListIndex,
                                 gstring,
-                                gidx + rule->LookupRecord[k].SequenceIndex);
+                                gidx + rule->LookupRecord[k].SequenceIndex,
+                                accumulate);
                  gidx += rule->InputGlyphCount + (gstring->used - orig_used);
                  break;
                }
@@ -1135,7 +1219,8 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
                    lookup_gpos (lookup_list,
                                 rule->LookupRecord[k].LookupListIndex,
                                 gstring,
-                                gidx + rule->LookupRecord[k].SequenceIndex);
+                                gidx + rule->LookupRecord[k].SequenceIndex,
+                                accumulate);
                  gidx += rule->InputGlyphCount + (gstring->used - orig_used);
                  break;
                }
@@ -1157,7 +1242,8 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
                lookup_gpos (lookup_list,
                             context3->LookupRecord[j].LookupListIndex,
                             gstring,
-                            gidx + context3->LookupRecord[j].SequenceIndex);
+                            gidx + context3->LookupRecord[j].SequenceIndex,
+                            accumulate);
              gidx += context3->InputGlyphCount + (gstring->used - orig_used);
            }
          else
@@ -1208,7 +1294,7 @@ lookup_encoding_4 (OTF_EncodingSubtable4 *sub4, OTF_GlyphString *gstring)
        gstring->glyphs[i].glyph_id = 0;
       for (j = 0; j < segCount; j++)
        {
-         OTF_cmapSegument *seg = sub4->segments + i;
+         OTF_cmapSegment *seg = sub4->segments + i;
 
          if (c >= seg->startCount && c <= seg->endCount)
            {
@@ -1250,10 +1336,103 @@ lookup_encoding_12 (OTF_EncodingSubtable12 *sub12, OTF_GlyphString *gstring)
   return 0;
 }
 
+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;
+}
+
+static void
+check_cmap_uvs (OTF_cmap *cmap, OTF_GlyphString *gstring, int idx)
+{  
+  OTF_EncodingSubtable14 *sub14;
+  int c1 = gstring->glyphs[idx - 1].c;
+  int c2 = gstring->glyphs[idx].c;
+  OTF_GlyphID code;
+  int i;
+
+  gstring->glyphs[idx].glyph_id = 0;
+  for (i = 0; i < cmap->numTables; i++)
+    if (cmap->EncodingRecord[i].subtable.format == 14)
+      break;
+  if (i == cmap->numTables)
+    return;
+  code = get_uvs_glyph (cmap, cmap->EncodingRecord[i].subtable.f.f14, c1, c2);
+  if (code == 0)
+    return;
+  gstring->glyphs[idx - 1].glyph_id = code;
+  gstring->used--;
+  memmove (gstring->glyphs + idx, gstring->glyphs + idx + 1,
+          sizeof (OTF_Glyph) * (gstring->used - idx));
+}
+
 \f
 
 /* API */
 
+#define UVS_P(C)       \
+  (((C) >= 0xFE00 && (C) <= 0xFE0F) || ((C) >= 0xE0100 && (C) <= 0xE01EF))
+
 int
 OTF_drive_cmap (OTF *otf, OTF_GlyphString *gstring)
 {
@@ -1271,6 +1450,8 @@ OTF_drive_cmap (OTF *otf, OTF_GlyphString *gstring)
        int c = gstring->glyphs[i].c;
        if (c < 32 || ! cmap->unicode_table)
          gstring->glyphs[i].glyph_id = 0;
+       else if (UVS_P (c) && i > 0)
+         check_cmap_uvs (cmap, gstring, i);
        else
          gstring->glyphs[i].glyph_id = cmap->unicode_table[c];
       }
@@ -1363,8 +1544,8 @@ OTF_drive_gsub_internal (OTF *otf, OTF_GlyphString *gstring,
   int errret = -1;
   OTF_GSUB *gsub;
   OTF_LangSys *LangSys;
-  int *lookup_indices;
-  int i, n;
+  char *lookup_flags;
+  int i;
 
   for (i = 0; i < gstring->used; i++)
     {
@@ -1383,28 +1564,24 @@ OTF_drive_gsub_internal (OTF *otf, OTF_GlyphString *gstring,
   if (! LangSys)
     return errret;
 
-  /* One lookup may be used by multiple features.  */
-  lookup_indices = alloca (sizeof (int)
-                          * gsub->LookupList.LookupCount
-                          * (gsub->FeatureList.FeatureCount + 1));
-  if (! lookup_indices)
+  lookup_flags = alloca (gsub->LookupList.LookupCount);
+  if (! lookup_flags
+      || setup_lookup_flags (&gsub->LookupList, &gsub->FeatureList, LangSys,
+                            features, lookup_flags) < 0)
     OTF_ERROR (OTF_ERROR_MEMORY, " feature list");
-  n = setup_lookup_indices (&gsub->LookupList, &gsub->FeatureList,
-                           features, lookup_indices);
-  if (n < 0)
-    return errret;
 
-  for (i = 0; i < n; i++)
+  for (i = 0; i < gsub->LookupList.LookupCount; i++)
     {
-      int index = lookup_indices[i];
       int gidx;
 
-      if (gsub->LookupList.Lookup[index].LookupType != 8)
+      if (! lookup_flags[i]) continue;
+
+      if (gsub->LookupList.Lookup[i].LookupType != 8)
        {
          gidx = 0;
          while (gidx < gstring->used)
            {
-             gidx = lookup_gsub (otf, &gsub->LookupList, index, gstring, gidx,
+             gidx = lookup_gsub (otf, &gsub->LookupList, i, gstring, gidx,
                                  alternate_subst);
              if (gidx < 0)
                return errret;
@@ -1415,7 +1592,7 @@ OTF_drive_gsub_internal (OTF *otf, OTF_GlyphString *gstring,
          gidx = gstring->used - 1;
          while (gidx >= 0)
            {
-             gidx = lookup_gsub (otf, &gsub->LookupList, index, gstring, gidx,
+             gidx = lookup_gsub (otf, &gsub->LookupList, i, gstring, gidx,
                                  alternate_subst);
              if (gidx < 0)
                return errret;
@@ -1436,14 +1613,16 @@ OTF_drive_gsub (OTF *otf, OTF_GlyphString *gstring,
 }
 
 int
-OTF_drive_gpos (OTF *otf, OTF_GlyphString *gstring,
-               const char *script, const char *language, const char *features)
+OTF_drive_gpos_internal (OTF *otf, OTF_GlyphString *gstring,
+                        const char *script, const char *language,
+                        const char *features,
+                        int accumulate)
 {
   char *errfmt = "GPOS driving%s";
   int errret = -1;
   OTF_GPOS *gpos;
   OTF_LangSys *LangSys;
-  int *lookup_indices;
+  char *lookup_flags;
   int i, n;
 
   for (i = 0; i < gstring->used; i++)
@@ -1460,25 +1639,21 @@ OTF_drive_gpos (OTF *otf, OTF_GlyphString *gstring,
   if (! LangSys)
     return errret;
 
-  /* One lookup may be used by multiple features.  */
-  lookup_indices = alloca (sizeof (int)
-                          * gpos->LookupList.LookupCount
-                          * (gpos->FeatureList.FeatureCount + 1));
-  if (! lookup_indices)
+  lookup_flags = alloca (gpos->LookupList.LookupCount);
+  if (! lookup_flags
+      || setup_lookup_flags (&gpos->LookupList, &gpos->FeatureList, LangSys,
+                            features, lookup_flags) < 0)
     OTF_ERROR (OTF_ERROR_MEMORY, " feature list");
-  n = setup_lookup_indices (&gpos->LookupList, &gpos->FeatureList,
-                           features, lookup_indices);
-  if (n < 0)
-    return errret;
 
-  for (i = 0; i < n; i++)
+  for (i = 0; i < gpos->LookupList.LookupCount; i++)
     {
-      int index = lookup_indices[i];
       int gidx = 0;
 
+      if (! lookup_flags[i]) continue;
+
       while (gidx < gstring->used)
        {
-         gidx = lookup_gpos (&gpos->LookupList, index, gstring, gidx);
+         gidx = lookup_gpos (&gpos->LookupList, i, gstring, gidx, accumulate);
          if (gidx < 0)
            return errret;
        }
@@ -1488,6 +1663,24 @@ OTF_drive_gpos (OTF *otf, OTF_GlyphString *gstring,
 }
 
 int
+OTF_drive_gpos (OTF *otf, OTF_GlyphString *gstring,
+               const char *script, const char *language, const char *features)
+{
+  if (! otf->cmap)
+    OTF_get_table (otf, "cmap");
+  return OTF_drive_gpos_internal (otf, gstring, script, language, features, 0);
+}
+
+int
+OTF_drive_gpos2 (OTF *otf, OTF_GlyphString *gstring,
+               const char *script, const char *language, const char *features)
+{
+  if (! otf->cmap)
+    OTF_get_table (otf, "cmap");
+  return OTF_drive_gpos_internal (otf, gstring, script, language, features, 1);
+}
+
+int
 OTF_drive_tables (OTF *otf, OTF_GlyphString *gstring,
                  const char *script, const char *language,
                  const char *gsub_features, const char *gpos_features)