Imported Upstream version 2.6.7
[platform/upstream/harfbuzz.git] / src / hb-aat-map.cc
index bc87935..2c38c35 100644 (file)
 #include "hb-aat-map.hh"
 
 #include "hb-aat-layout.hh"
+#include "hb-aat-layout-feat-table.hh"
 
 
-void hb_aat_map_builder_t::add_feature (hb_tag_t tag,
-                                       unsigned int value)
+void hb_aat_map_builder_t::add_feature (hb_tag_t tag, unsigned value)
 {
+  if (!face->table.feat->has_data ()) return;
+
   if (tag == HB_TAG ('a','a','l','t'))
   {
+    if (!face->table.feat->exposes_feature (HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_ALTERNATIVES))
+      return;
     feature_info_t *info = features.push();
     info->type = HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_ALTERNATIVES;
     info->setting = (hb_aat_layout_feature_selector_t) value;
+    info->seq = features.length;
+    info->is_exclusive = true;
     return;
   }
 
   const hb_aat_feature_mapping_t *mapping = hb_aat_layout_find_feature_mapping (tag);
   if (!mapping) return;
 
+  const AAT::FeatureName* feature = &face->table.feat->get_feature (mapping->aatFeatureType);
+  if (!feature->has_data ())
+  {
+    /* Special case: Chain::compile_flags will fall back to the deprecated version of
+     * small-caps if necessary, so we need to check for that possibility.
+     * https://github.com/harfbuzz/harfbuzz/issues/2307 */
+    if (mapping->aatFeatureType == HB_AAT_LAYOUT_FEATURE_TYPE_LOWER_CASE &&
+       mapping->selectorToEnable == HB_AAT_LAYOUT_FEATURE_SELECTOR_LOWER_CASE_SMALL_CAPS)
+    {
+      feature = &face->table.feat->get_feature (HB_AAT_LAYOUT_FEATURE_TYPE_LETTER_CASE);
+      if (!feature->has_data ()) return;
+    }
+    else return;
+  }
+
   feature_info_t *info = features.push();
   info->type = mapping->aatFeatureType;
   info->setting = value ? mapping->selectorToEnable : mapping->selectorToDisable;
+  info->seq = features.length;
+  info->is_exclusive = feature->is_exclusive ();
 }
 
 void
@@ -63,7 +86,11 @@ hb_aat_map_builder_t::compile (hb_aat_map_t  &m)
     features.qsort ();
     unsigned int j = 0;
     for (unsigned int i = 1; i < features.length; i++)
-      if (features[i].type != features[j].type)
+      if (features[i].type != features[j].type ||
+         /* Nonexclusive feature selectors come in even/odd pairs to turn a setting on/off
+          * respectively, so we mask out the low-order bit when checking for "duplicates"
+          * (selectors referring to the same feature setting) here. */
+         (!features[i].is_exclusive && ((features[i].setting & ~1) != (features[j].setting & ~1))))
        features[++j] = features[i];
     features.shrink (j + 1);
   }