From 718bf5aab397290ab5214c6a6bff3e248c4ab094 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Tue, 29 Sep 2020 13:16:01 -0700 Subject: [PATCH] [subset] only keep features reachable from script in the final subset. Matches fontTools behaviour. --- src/hb-ot-layout-gsubgpos.hh | 31 +++++++++++++++++++++---------- src/hb-subset-plan.cc | 21 +++++++++++++++++---- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index afa00d20c..b3028e655 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -3380,20 +3380,31 @@ struct GSUBGPOS return_trace (true); } - void closure_features (const hb_map_t *lookup_indexes, /* IN */ - hb_set_t *feature_indexes /* OUT */) const + void prune_features (const hb_map_t *lookup_indices, /* IN */ + hb_set_t *feature_indices /* IN/OUT */) const { - unsigned int feature_count = hb_min (get_feature_count (), (unsigned) HB_MAX_FEATURES); - for (unsigned i = 0; i < feature_count; i++) +#ifndef HB_NO_VAR + // This is the set of feature indices which have alternate versions defined + // if the FeatureVariation's table and the alternate version(s) intersect the + // set of lookup indices. + hb_set_t alternate_feature_indices; + if (version.to_int () >= 0x00010001u) + (this+featureVars).closure_features (lookup_indices, &alternate_feature_indices); + if (alternate_feature_indices.in_error()) { + feature_indices->successful = false; + return; + } +#endif + + for (unsigned i : feature_indices->iter()) { const Feature& f = get_feature (i); - if ((!f.featureParams.is_null ()) || f.intersects_lookup_indexes (lookup_indexes)) - feature_indexes->add (i); + + if (f.featureParams.is_null () + && !f.intersects_lookup_indexes (lookup_indices) + && !alternate_feature_indices.has (i)) + feature_indices->del (i); } -#ifndef HB_NO_VAR - if (version.to_int () >= 0x00010001u) - (this+featureVars).closure_features (lookup_indexes, feature_indexes); -#endif } unsigned int get_size () const diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 24beada3e..b58c27eeb 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -88,10 +88,17 @@ _gsub_closure_glyphs_lookups_features (hb_face_t *face, &lookup_indices); _remap_indexes (&lookup_indices, gsub_lookups); - //closure features + // Collect and prune features hb_set_t feature_indices; - gsub->closure_features (gsub_lookups, &feature_indices); + hb_ot_layout_collect_features (face, + HB_OT_TAG_GSUB, + nullptr, + nullptr, + nullptr, + &feature_indices); + gsub->prune_features (gsub_lookups, &feature_indices); _remap_indexes (&feature_indices, gsub_features); + gsub.destroy (); } @@ -114,9 +121,15 @@ _gpos_closure_lookups_features (hb_face_t *face, &lookup_indices); _remap_indexes (&lookup_indices, gpos_lookups); - //closure features + // Collect and prune features hb_set_t feature_indices; - gpos->closure_features (gpos_lookups, &feature_indices); + hb_ot_layout_collect_features (face, + HB_OT_TAG_GPOS, + nullptr, + nullptr, + nullptr, + &feature_indices); + gpos->prune_features (gpos_lookups, &feature_indices); _remap_indexes (&feature_indices, gpos_features); gpos.destroy (); }