(OTF_drive_gsub_internal): Fix previous change.
[m17n/libotf.git] / src / otfdrive.c
index 0139011..3dd3c16 100644 (file)
@@ -119,7 +119,7 @@ gstring_subst (OTF *otf, OTF_GlyphString *gstring, int from, int to, int flag,
            gstring->glyphs[from + i].GlyphClass = 0;
        }
       gstring->glyphs[from + i].glyph_id = ids[i];
-      gstring->glyphs[from + i].positioning_type = 0;
+      gstring->glyphs[from + i].positioning_type = 1;
       gstring->glyphs[from + i].f.index.from = from_idx;
       gstring->glyphs[from + i].f.index.to = to_idx;
     }
@@ -241,7 +241,7 @@ setup_lookup_flags (OTF_LookupList *LookupList, OTF_FeatureList *FeatureList,
                {
                  feature = FeatureList->Feature + index;
                  for (j = 0; j < feature->LookupCount; j++)
-                   lookup_flags[feature->LookupListIndex[j]] = i + 1;
+                   lookup_flags[feature->LookupListIndex[j]] = index + 1;
                }
            }
          break;
@@ -259,14 +259,16 @@ setup_lookup_flags (OTF_LookupList *LookupList, OTF_FeatureList *FeatureList,
       tag = OTF_tag (tagname);
       for (i = 0; i < LangSys->FeatureCount; i++)
        {
-         feature = FeatureList->Feature + LangSys->FeatureIndex[i];
+         int index = LangSys->FeatureIndex[i];
+
+         feature = FeatureList->Feature + index;
          if (tag == feature->FeatureTag)
            {
              if (feature_table[i])
                break;
              if (use_it > 0)
                for (j = 0; j < feature->LookupCount; j++)
-                 lookup_flags[feature->LookupListIndex[j]] = j + 1;
+                 lookup_flags[feature->LookupListIndex[j]] = index + 1;
              feature_table[i] = use_it;
              break;
            }
@@ -454,6 +456,7 @@ lookup_gsub (OTF *otf, OTF_LookupList *lookup_list, unsigned lookup_list_index,
            g->glyph_id += subtable->u.single1.DeltaGlyphID;
          else
            g->glyph_id = subtable->u.single2.Substitute[coverage_idx];
+         g->positioning_type = 1;
          gidx++;
          break;
 
@@ -703,6 +706,7 @@ lookup_gsub (OTF *otf, OTF_LookupList *lookup_list, unsigned lookup_list_index,
            if (j < reverse->LookaheadGlyphCount)
              continue;
            g->glyph_id = reverse->Substitute[coverage_idx];
+           g->positioning_type = 1;
            gidx--;
          }
 
@@ -849,7 +853,6 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
       switch (lookup_type)
        {
        case 1:
-         positioning_type = lookup_type;
          if (subtable->Format == 1)
            {
              OTF_GPOS_Single1 *single1 = &subtable->u.single1;
@@ -864,13 +867,13 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
              format = single2->ValueFormat;
              value = single2->Value + coverage_idx;
            }
-         if (accumulate && g->positioning_type)
+         if (accumulate && (g->positioning_type & 0xF))
            {
              gidx = gstring_insert_for_gpos (gstring, gidx);
              g = gstring->glyphs + gidx;
            }
          g->positioning_type
-           = (g->positioning_type & 0xFFFFFFF0) | positioning_type;
+           = (g->positioning_type & 0xFFFFFFF0) | lookup_type;
          g->f.f1.format = format;
          g->f.f1.value = value;
          if (debug_flag)
@@ -983,7 +986,7 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
            OTF_GPOS_Cursive1 *cursive1 = &subtable->u.cursive1;
 
            g->positioning_type
-           = (g->positioning_type & 0xFFFFFFF0) | lookup_type;
+             = (g->positioning_type & 0xFFFFFFF0) | lookup_type;
            g->f.f3.entry_anchor
              = &cursive1->EntryExitRecord[coverage_idx].EntryAnchor;
            g->f.f3.exit_anchor
@@ -1760,7 +1763,6 @@ OTF_drive_gsub_internal (OTF *otf, OTF_GlyphString *gstring,
   for (i = 0; i < gsub->LookupList.LookupCount; i++)
     {
       int gidx;
-      int j;
 
       if (! lookup_flags[i]) continue;
 
@@ -1774,14 +1776,10 @@ OTF_drive_gsub_internal (OTF *otf, OTF_GlyphString *gstring,
              if (result < 0)
                return errret;
              if (gidx < result)
-               {
-                 if (with_log)
-                   for (j = gidx; j < result; j++)
-                     gstring->glyphs[j].positioning_type
-                       = ((gstring->glyphs[j].positioning_type & 0xF)
-                          | (lookup_flags[i] << 4));
-                 gidx = result;
-               }
+               for (; gidx < result; gidx++)
+                 gstring->glyphs[gidx].positioning_type
+                   = ((with_log && gstring->glyphs[gidx].positioning_type)
+                      ? (lookup_flags[i] << 4) : 0);
              else
                gidx++;
            }
@@ -1796,14 +1794,10 @@ OTF_drive_gsub_internal (OTF *otf, OTF_GlyphString *gstring,
              if (result < 0)
                return errret;
              if (gidx > result)
-               {
-                 if (with_log)
-                   for (j = gidx; j > result; j--)
-                     gstring->glyphs[j].positioning_type
-                       = ((gstring->glyphs[j].positioning_type & 0xF)
-                          | (lookup_flags[i] << 4));
-                 gidx = result;
-               }
+               for (; gidx > result; gidx--)
+                 gstring->glyphs[gidx].positioning_type
+                   = ((with_log && gstring->glyphs[gidx].positioning_type)
+                      ? (lookup_flags[i] << 4) : 0);
              else
                gidx--;
            }
@@ -1870,7 +1864,6 @@ OTF_drive_gpos_internal (OTF *otf, OTF_GlyphString *gstring,
   for (i = 0; i < gpos->LookupList.LookupCount; i++)
     {
       int gidx = 0;
-      int j;
 
       if (! lookup_flags[i]) continue;
 
@@ -1881,14 +1874,15 @@ OTF_drive_gpos_internal (OTF *otf, OTF_GlyphString *gstring,
          if (result < 0)
            return errret;
          if (gidx < result)
-           {
-             if (with_log)
-               for (j = gidx; j < result; j++)
-                 gstring->glyphs[j].positioning_type
-                   = ((gstring->glyphs[j].positioning_type & 0xF)
-                      | (lookup_flags[i] << 4));
-             gidx = result;
-           }
+           for (; gidx < result; gidx++)
+             {
+               int positioning_type
+                 = gstring->glyphs[gidx].positioning_type & 0xF;
+
+               if (with_log && positioning_type)
+                 gstring->glyphs[gidx].positioning_type
+                   = positioning_type | (lookup_flags[i] << 4);
+             }
          else
            gidx++;
        }