From 56ca435787c1686fcfe01bf4db822bb91d9ba769 Mon Sep 17 00:00:00 2001 From: Qunxin Liu Date: Thu, 28 Jan 2021 15:21:26 -0800 Subject: [PATCH] [subset] fix for collect_features and remove_redundant_lamngsys previously remove_redundant_sys () is missing in harfbuzz, after redundant langsys removal, some features are removed as well in prune_features() in fonttools. This change is trying to get the same result between harfbuzz and fonttools. --- src/hb-ot-layout-common.hh | 182 ++++++++++++++++-- src/hb-ot-layout-gpos-table.hh | 2 +- src/hb-ot-layout-gsub-table.hh | 2 +- src/hb-ot-layout-gsubgpos.hh | 75 +++++++- src/hb-subset-plan.cc | 43 ++++- src/hb-subset-plan.hh | 6 +- ...in-gids.627,644,623,62D,644,627,645,2E.ttf | Bin 48640 -> 48596 bytes ...eep-layout-retain-gids.627,644,62D,628.ttf | Bin 42884 -> 42836 bytes ...egular.keep-layout-retain-gids.627,644.ttf | Bin 36940 -> 36892 bytes ...retain-gids.633,645,627,621,20,644,627.ttf | Bin 46724 -> 46680 bytes ...ar.keep-layout-retain-gids.63A,64A,631.ttf | Bin 42896 -> 42896 bytes ...-layout.627,644,623,62D,644,627,645,2E.ttf | Bin 13332 -> 13288 bytes ...ri-Regular.keep-layout.627,644,62D,628.ttf | Bin 10232 -> 10188 bytes .../Amiri-Regular.keep-layout.627,644.ttf | Bin 4412 -> 4364 bytes ...keep-layout.633,645,627,621,20,644,627.ttf | Bin 10372 -> 10324 bytes .../Amiri-Regular.keep-layout.63A,64A,631.ttf | Bin 7824 -> 7824 bytes test/subset/data/fonts/Amiri-Regular.ttf | Bin 562684 -> 562980 bytes 17 files changed, 284 insertions(+), 26 deletions(-) diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index ec47e9ac5..5b758a875 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -94,6 +94,60 @@ static void ClassDef_remap_and_serialize (hb_serialize_context_t *c, bool use_class_zero, hb_map_t *klass_map /*INOUT*/); + +struct hb_prune_langsys_context_t +{ + hb_prune_langsys_context_t (const void *table_, + hb_hashmap_t *script_langsys_map_, + const hb_map_t *duplicate_feature_map_, + hb_set_t *new_collected_feature_indexes_) + :table (table_), + script_langsys_map (script_langsys_map_), + duplicate_feature_map (duplicate_feature_map_), + new_feature_indexes (new_collected_feature_indexes_), + script_count (0),langsys_count (0) {} + + bool visitedScript (const void *s) + { + if (script_count++ > HB_MAX_SCRIPTS) + return true; + + return visited (s, visited_script); + } + + bool visitedLangsys (const void *l) + { + if (langsys_count++ > HB_MAX_LANGSYS) + return true; + + return visited (l, visited_langsys); + } + + private: + template + bool visited (const T *p, hb_set_t &visited_set) + { + hb_codepoint_t delta = (hb_codepoint_t) ((uintptr_t) p - (uintptr_t) table); + if (visited_set.has (delta)) + return true; + + visited_set.add (delta); + return false; + } + + public: + const void *table; + hb_hashmap_t *script_langsys_map; + const hb_map_t *duplicate_feature_map; + hb_set_t *new_feature_indexes; + + private: + hb_set_t visited_script; + hb_set_t visited_langsys; + unsigned script_count; + unsigned langsys_count; +}; + struct hb_subset_layout_context_t : hb_dispatch_context_t { @@ -125,16 +179,21 @@ struct hb_subset_layout_context_t : hb_subset_context_t *subset_context; const hb_tag_t table_tag; const hb_map_t *lookup_index_map; + const hb_hashmap_t *script_langsys_map; const hb_map_t *feature_index_map; + unsigned cur_script_index; hb_subset_layout_context_t (hb_subset_context_t *c_, hb_tag_t tag_, hb_map_t *lookup_map_, - hb_map_t *feature_map_) : + hb_hashmap_t *script_langsys_map_, + hb_map_t *feature_index_map_) : subset_context (c_), table_tag (tag_), lookup_index_map (lookup_map_), - feature_index_map (feature_map_), + script_langsys_map (script_langsys_map_), + feature_index_map (feature_index_map_), + cur_script_index (0xFFFFu), script_count (0), langsys_count (0), feature_index_count (0), @@ -407,6 +466,30 @@ struct RecordListOfFeature : RecordListOf } }; +struct Script; +struct RecordListOfScript : RecordListOf