Oops, actually set global mask
[framework/uifw/harfbuzz.git] / src / hb-ot-layout-gsub-private.hh
index 96c1c9c..f09b4d2 100644 (file)
@@ -29,6 +29,8 @@
 
 #include "hb-ot-layout-gsubgpos-private.hh"
 
+HB_BEGIN_DECLS
+
 
 struct SingleSubstFormat1
 {
@@ -274,6 +276,8 @@ struct AlternateSubstFormat1
   {
     TRACE_APPLY ();
     hb_codepoint_t glyph_id = c->buffer->info[c->buffer->i].codepoint;
+    hb_mask_t glyph_mask = c->buffer->info[c->buffer->i].mask;
+    hb_mask_t lookup_mask = c->lookup_mask;
 
     unsigned int index = (this+coverage) (glyph_id);
     if (likely (index == NOT_COVERED))
@@ -284,19 +288,14 @@ struct AlternateSubstFormat1
     if (unlikely (!alt_set.len))
       return false;
 
-    unsigned int alt_index = 0;
-
-    /* XXX callback to user to choose alternate
-    if (c->layout->face->altfunc)
-      alt_index = (c->layout->face->altfunc)(c->layout->layout, c->buffer,
-                                   c->buffer->out_len, glyph_id,
-                                   alt_set.len, alt_set.array);
-                                  */
+    /* Note: This breaks badly if two features enabled this lookup together. */
+    unsigned int shift = _hb_ctz (lookup_mask);
+    unsigned int alt_index = ((lookup_mask & glyph_mask) >> shift);
 
-    if (unlikely (alt_index >= alt_set.len))
+    if (unlikely (alt_index > alt_set.len || alt_index == 0))
       return false;
 
-    glyph_id = alt_set[alt_index];
+    glyph_id = alt_set[alt_index - 1];
 
     c->buffer->replace_glyph (glyph_id);
 
@@ -544,8 +543,9 @@ struct LigatureSubst
 };
 
 
-
+HB_BEGIN_DECLS
 static inline bool substitute_lookup (hb_apply_context_t *c, unsigned int lookup_index);
+HB_END_DECLS
 
 struct ContextSubst : Context
 {
@@ -777,6 +777,7 @@ struct SubstLookup : Lookup
 
   inline bool apply_once (hb_ot_layout_context_t *layout,
                          hb_buffer_t *buffer,
+                         hb_mask_t lookup_mask,
                          unsigned int context_length,
                          unsigned int nesting_level_left) const
   {
@@ -785,6 +786,7 @@ struct SubstLookup : Lookup
 
     c->layout = layout;
     c->buffer = buffer;
+    c->lookup_mask = lookup_mask;
     c->context_length = context_length;
     c->nesting_level_left = nesting_level_left;
     c->lookup_flag = get_flag ();
@@ -831,7 +833,7 @@ struct SubstLookup : Lookup
        while (buffer->i < buffer->len)
        {
          if ((buffer->info[buffer->i].mask & mask) &&
-             apply_once (layout, buffer, NO_CONTEXT, MAX_NESTING_LEVEL))
+             apply_once (layout, buffer, mask, NO_CONTEXT, MAX_NESTING_LEVEL))
            ret = true;
          else
            buffer->next_glyph ();
@@ -847,7 +849,7 @@ struct SubstLookup : Lookup
        do
        {
          if ((buffer->info[buffer->i].mask & mask) &&
-             apply_once (layout, buffer, NO_CONTEXT, MAX_NESTING_LEVEL))
+             apply_once (layout, buffer, mask, NO_CONTEXT, MAX_NESTING_LEVEL))
            ret = true;
          else
            buffer->i--;
@@ -933,8 +935,10 @@ static inline bool substitute_lookup (hb_apply_context_t *c, unsigned int lookup
   if (unlikely (c->context_length < 1))
     return false;
 
-  return l.apply_once (c->layout, c->buffer, c->context_length, c->nesting_level_left - 1);
+  return l.apply_once (c->layout, c->buffer, c->lookup_mask, c->context_length, c->nesting_level_left - 1);
 }
 
 
+HB_END_DECLS
+
 #endif /* HB_OT_LAYOUT_GSUB_PRIVATE_HH */