[GX] Add hb_ot_layout_feature_with_variations_get_lookups()
authorBehdad Esfahbod <behdad@behdad.org>
Sat, 10 Sep 2016 10:53:11 +0000 (03:53 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Sat, 17 Dec 2016 01:06:26 +0000 (19:06 -0600)
src/hb-ot-layout-common-private.hh
src/hb-ot-layout-gsubgpos-private.hh
src/hb-ot-layout.cc
src/hb-ot-layout.h

index e67a5145ddc7260e133f3613062bc7ce34bbab80..cdf43bf4031923a740029653456b1659419c492d 100644 (file)
@@ -1417,6 +1417,13 @@ struct ConditionSet
 
 struct FeatureTableSubstitutionRecord
 {
+  inline const Feature *find_substitute (unsigned int feature_index) const
+  {
+    if (featureIndex == feature_index)
+      return &(this+feature);
+    return NULL;
+  }
+
   inline bool sanitize (hb_sanitize_context_t *c) const
   {
     TRACE_SANITIZE (this);
@@ -1432,6 +1439,18 @@ struct FeatureTableSubstitutionRecord
 
 struct FeatureTableSubstitution
 {
+  inline const Feature *find_substitute (unsigned int feature_index) const
+  {
+    unsigned int count = substitutions.len;
+    for (unsigned int i = 0; i < count; i++)
+    {
+      const Feature *feature = (this+substitutions.array[i]).find_substitute (feature_index);
+      if (feature)
+        return feature;
+    }
+    return NULL;
+  }
+
   inline bool sanitize (hb_sanitize_context_t *c) const
   {
     TRACE_SANITIZE (this);
@@ -1470,6 +1489,8 @@ struct FeatureVariationRecord
 
 struct FeatureVariations
 {
+  static const unsigned int NOT_FOUND_INDEX = 0xFFFFFFFFu;
+
   inline bool find_index (const int *coords, unsigned int coord_len,
                          unsigned int *index) const
   {
@@ -1483,10 +1504,17 @@ struct FeatureVariations
        return true;
       }
     }
-    *index = 0xFFFFFFFF;
+    *index = NOT_FOUND_INDEX;
     return false;
   }
 
+  inline const Feature *find_substitute (unsigned int variations_index,
+                                        unsigned int feature_index) const
+  {
+    const FeatureVariationRecord &record = varRecords[variations_index];
+    return (this+record.substitutions).find_substitute (feature_index);
+  }
+
   inline bool sanitize (hb_sanitize_context_t *c) const
   {
     TRACE_SANITIZE (this);
index e20777acbf215082becc85459a5cd5a58792fa59..adea32f2344242ca6236b7ecbf00652df2c2882c 100644 (file)
@@ -2275,6 +2275,18 @@ struct GSUBGPOS
                                     unsigned int *index) const
   { return (version.to_int () >= 0x00010001u ? this+featureVars : Null(FeatureVariations))
           .find_index (coords, num_coords, index); }
+  inline const Feature& get_feature_variation (unsigned int feature_index,
+                                              unsigned int variations_index) const
+  {
+    if (FeatureVariations::NOT_FOUND_INDEX != variations_index &&
+       version.to_int () >= 0x00010001u)
+    {
+      const Feature *feature = (this+featureVars).find_substitute (variations_index, feature_index);
+      if (feature)
+        return *feature;
+    }
+    return get_feature (feature_index);
+  }
 
   inline bool sanitize (hb_sanitize_context_t *c) const
   {
index b352cdb5dda169c6dcc2c9579eeb43eac9811419..345d5e69501b838e1b1c71049488db3e383cdb04 100644 (file)
@@ -582,10 +582,13 @@ hb_ot_layout_feature_get_lookups (hb_face_t    *face,
                                  unsigned int *lookup_count /* IN/OUT */,
                                  unsigned int *lookup_indexes /* OUT */)
 {
-  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
-  const OT::Feature &f = g.get_feature (feature_index);
-
-  return f.get_lookup_indexes (start_offset, lookup_count, lookup_indexes);
+  return hb_ot_layout_feature_with_variations_get_lookups (face,
+                                                          table_tag,
+                                                          feature_index,
+                                                          HB_OT_LAYOUT_NO_VARIATIONS_INDEX,
+                                                          start_offset,
+                                                          lookup_count,
+                                                          lookup_indexes);
 }
 
 /**
@@ -850,6 +853,23 @@ hb_ot_layout_table_find_feature_variations (hb_face_t    *face,
   return g.find_variations_index (coords, num_coords, variations_index);
 }
 
+unsigned int
+hb_ot_layout_feature_with_variations_get_lookups (hb_face_t    *face,
+                                                 hb_tag_t      table_tag,
+                                                 unsigned int  feature_index,
+                                                 unsigned int  variations_index,
+                                                 unsigned int  start_offset,
+                                                 unsigned int *lookup_count /* IN/OUT */,
+                                                 unsigned int *lookup_indexes /* OUT */)
+{
+  ASSERT_STATIC (OT::FeatureVariations::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_VARIATIONS_INDEX);
+  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
+
+  const OT::Feature &f = g.get_feature_variation (feature_index, variations_index);
+
+  return f.get_lookup_indexes (start_offset, lookup_count, lookup_indexes);
+}
+
 
 /*
  * OT::GSUB
index 2e3db8c200a3c1a7a29aab852bf9727fd3c2874a..9861f0fc7bb7f015b88b1dfce28bd031817877f2 100644 (file)
@@ -246,6 +246,15 @@ hb_ot_layout_table_find_feature_variations (hb_face_t    *face,
                                            unsigned int  num_coords,
                                            unsigned int *variations_index /* out */);
 
+HB_EXTERN unsigned int
+hb_ot_layout_feature_with_variations_get_lookups (hb_face_t    *face,
+                                                 hb_tag_t      table_tag,
+                                                 unsigned int  feature_index,
+                                                 unsigned int  variations_index,
+                                                 unsigned int  start_offset,
+                                                 unsigned int *lookup_count /* IN/OUT */,
+                                                 unsigned int *lookup_indexes /* OUT */);
+
 
 /*
  * GSUB