*** empty log message ***
[m17n/libotf.git] / src / otfdrive.c
index f917838..3dc6eda 100644 (file)
@@ -29,14 +29,14 @@ write to the Free Software Foundation, Inc., 59 Temple Place, Suite
 #include "otf.h"
 #include "otferror.h"
 
-/* Return nonzero if OTF_Glyph *G should be ignored according to
-   LookupFlag FLAG.  */
-#define IGNORED_GLYPH(g, flag)                 \
-  ((g)->glyph_id == 0                          \
-   || ((flag) & (1 << (g)->GlyphClass))                \
-   || (((flag) & OTF_MarkAttachmentType)       \
-       && (g)->GlyphClass == OTF_GlyphClassMark        \
-       && ((flag) >> 8) != (g)->MarkAttachClass))
+/* Return nonzero (-1 if ID is zero, 1 otherwise) if OTF_Glyph *G
+   should be ignored according to LookupFlag FLAG.  */
+#define IGNORED_GLYPH(g, flag)                         \
+  ((g)->glyph_id == 0 ? -1                             \
+   : (((flag) & (1 << (g)->GlyphClass))                        \
+      || (((flag) & OTF_MarkAttachmentType)            \
+         && (g)->GlyphClass == OTF_GlyphClassMark      \
+         && ((flag) >> 8) != (g)->MarkAttachClass)))
 
 #define GSTRING_DELETE(gstring, from, len)                             \
   do {                                                                 \
@@ -81,8 +81,11 @@ gstring_subst (OTF *otf, OTF_GlyphString *gstring, int from, int to, int flag,
   for (i = non_ignored_idx = to - 1; i >= from; i--)
     {
       OTF_Glyph *g = gstring->glyphs + i;
-      if (IGNORED_GLYPH (g, flag))
+
+      if (IGNORED_GLYPH (g, flag) == 1)
        {
+         /* Move this glyph to the next of the current target of
+            substitution.  */
          OTF_Glyph temp = *g;
 
          memmove (g, g + 1, sizeof (OTF_Glyph) * (non_ignored_idx - i));
@@ -99,13 +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++)
     {
-      gstring->glyphs[from + i].c = otf->cmap->decode_table[ids[i]];
+      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;
@@ -757,7 +763,7 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
   int i;
 
   if (IGNORED_GLYPH (g, flag)
-      || g->positioning_type)
+      || (0 & g->positioning_type))
     return (gidx + 1);
 
   /* Try all subtables until one of them handles the current glyph.  */
@@ -809,7 +815,7 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
            OTF_Glyph *nextg;
 
            for (next_gidx = gidx + 1, nextg = gstring->glyphs + next_gidx;
-                next_gidx < gstring->used && ! IGNORED_GLYPH (nextg, flag);
+                next_gidx < gstring->used && IGNORED_GLYPH (nextg, flag);
                 next_gidx++, nextg++);
 
            if (next_gidx >= gstring->used
@@ -890,9 +896,10 @@ lookup_gpos (OTF_LookupList *lookup_list, unsigned lookup_list_index,
              OTF_AnchorRecord *base_record;
              OTF_Glyph *baseg;
              int coverage_idx_base;
+             unsigned int this_flag = flag | OTF_IgnoreMarks;
 
              for (baseg = g - 1;
-                  baseg >= gstring->glyphs && IGNORED_GLYPH (baseg, flag);
+                  baseg >= gstring->glyphs && IGNORED_GLYPH (baseg, this_flag);
                   baseg--);
              if (baseg < gstring->glyphs)
                continue;
@@ -1423,6 +1430,8 @@ int
 OTF_drive_gsub (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_gsub_internal (otf, gstring, script, language, features, 0);
 }