From e3e1ae876646937302593d37ea68e1e650621fcb Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Fri, 13 Aug 2021 10:53:20 -0700 Subject: [PATCH 01/12] [subset] proposed update to subset set apis. --- src/hb-subset.h | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/hb-subset.h b/src/hb-subset.h index 4f17bc5b8..bc6540d9b 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -79,6 +79,29 @@ typedef enum { /*< flags >*/ HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES = 0x00000100u, } hb_subset_flags_t; +/** + * hb_subset_sets_t: + * @HB_SUBSET_SETS_LAYOUT_FEATURE_TAG: the set of layout feature tags that will be retained + * in the subset. + * @HB_SUBSET_SETS_NAME_INDEX: the set of name ids that will be retained. + * @HB_SUBSET_SETS_NAME_LANG_INDEX: the set of name lang ids that will be retained. + * @HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG: the set of table tags which specifies tables that should not be + * subsetted. + * @HB_SUBSET_SETS_DROP_TABLE_TAG: the set of table tags which specifies tables which will be dropped + * in the subset. + * + * List of sets that can be configured on the subset input. + * + * Since: REPLACE + **/ +typedef enum { /*< flags >*/ + HB_SUBSET_SETS_LAYOUT_FEATURE_TAG = 0, + HB_SUBSET_SETS_NAME_INDEX, + HB_SUBSET_SETS_NAME_LANG_INDEX, + HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG, + HB_SUBSET_SETS_DROP_TABLE_TAG, +} hb_subset_sets_t; + HB_EXTERN hb_subset_input_t * hb_subset_input_create_or_fail (void); @@ -106,19 +129,7 @@ HB_EXTERN hb_set_t * hb_subset_input_glyph_set (hb_subset_input_t *input); HB_EXTERN hb_set_t * -hb_subset_input_nameid_set (hb_subset_input_t *input); - -HB_EXTERN hb_set_t * -hb_subset_input_namelangid_set (hb_subset_input_t *input); - -HB_EXTERN hb_set_t * -hb_subset_input_layout_features_set (hb_subset_input_t *input); - -HB_EXTERN hb_set_t * -hb_subset_input_no_subset_tables_set (hb_subset_input_t *input); - -HB_EXTERN hb_set_t * -hb_subset_input_drop_tables_set (hb_subset_input_t *input); +hb_subset_input_set (hb_subset_input_t *input, hb_subset_sets_t set_type); HB_EXTERN hb_subset_flags_t hb_subset_input_get_flags (hb_subset_input_t *input); From 4c389fd9e5c09574651c5dca3917857cc2cf910c Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Fri, 13 Aug 2021 11:14:52 -0700 Subject: [PATCH 02/12] [subset] add unicode and glyph set enums. --- src/hb-subset.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/hb-subset.h b/src/hb-subset.h index bc6540d9b..32664156f 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -95,11 +95,14 @@ typedef enum { /*< flags >*/ * Since: REPLACE **/ typedef enum { /*< flags >*/ - HB_SUBSET_SETS_LAYOUT_FEATURE_TAG = 0, + HB_SUBSET_SETS_UNICODE_CODEPOINT = 0, + HB_SUBSET_SETS_GLYPH_INDEX, + HB_SUBSET_SETS_LAYOUT_FEATURE_TAG, HB_SUBSET_SETS_NAME_INDEX, HB_SUBSET_SETS_NAME_LANG_INDEX, HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG, HB_SUBSET_SETS_DROP_TABLE_TAG, + HB_SUBSET_SETS_COUNT } hb_subset_sets_t; HB_EXTERN hb_subset_input_t * From 1b5e1593010eb7c79c58bb68ea1200ef6c8cb740 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 25 Aug 2021 14:56:55 -0700 Subject: [PATCH 03/12] [subset] Remove HB_SUBSET_SETS_COUNT and flags comment. --- src/hb-subset.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/hb-subset.h b/src/hb-subset.h index 32664156f..5acf4823e 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -94,7 +94,7 @@ typedef enum { /*< flags >*/ * * Since: REPLACE **/ -typedef enum { /*< flags >*/ +typedef enum { HB_SUBSET_SETS_UNICODE_CODEPOINT = 0, HB_SUBSET_SETS_GLYPH_INDEX, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG, @@ -102,7 +102,6 @@ typedef enum { /*< flags >*/ HB_SUBSET_SETS_NAME_LANG_INDEX, HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG, HB_SUBSET_SETS_DROP_TABLE_TAG, - HB_SUBSET_SETS_COUNT } hb_subset_sets_t; HB_EXTERN hb_subset_input_t * From 1457c1f0806ce63051cf48c47b9a03741533fc8f Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 25 Aug 2021 15:01:28 -0700 Subject: [PATCH 04/12] [subset] set enum name changes. --- src/hb-subset.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/hb-subset.h b/src/hb-subset.h index 5acf4823e..77536650e 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -81,10 +81,12 @@ typedef enum { /*< flags >*/ /** * hb_subset_sets_t: + * HB_SUBSET_SETS_GLYPH_INDEX: the set of glyph indexes to retain in the subset. + * HB_SUBSET_SETS_UNICODE: the set of unicode codepoints to retain in the subset. * @HB_SUBSET_SETS_LAYOUT_FEATURE_TAG: the set of layout feature tags that will be retained * in the subset. - * @HB_SUBSET_SETS_NAME_INDEX: the set of name ids that will be retained. - * @HB_SUBSET_SETS_NAME_LANG_INDEX: the set of name lang ids that will be retained. + * @HB_SUBSET_SETS_NAME_ID: the set of name ids that will be retained. + * @HB_SUBSET_SETS_NAME_LANG_ID: the set of name lang ids that will be retained. * @HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG: the set of table tags which specifies tables that should not be * subsetted. * @HB_SUBSET_SETS_DROP_TABLE_TAG: the set of table tags which specifies tables which will be dropped @@ -95,11 +97,11 @@ typedef enum { /*< flags >*/ * Since: REPLACE **/ typedef enum { - HB_SUBSET_SETS_UNICODE_CODEPOINT = 0, - HB_SUBSET_SETS_GLYPH_INDEX, + HB_SUBSET_SETS_GLYPH_INDEX = 0, + HB_SUBSET_SETS_UNICODE, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG, - HB_SUBSET_SETS_NAME_INDEX, - HB_SUBSET_SETS_NAME_LANG_INDEX, + HB_SUBSET_SETS_NAME_ID, + HB_SUBSET_SETS_NAME_LANG_ID, HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG, HB_SUBSET_SETS_DROP_TABLE_TAG, } hb_subset_sets_t; From 3282f540a967670d8ee6ac2d78193f6bfaa8c68c Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 25 Aug 2021 15:06:42 -0700 Subject: [PATCH 05/12] [subset] restore legacy set api methods. --- src/hb-subset.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/hb-subset.h b/src/hb-subset.h index 77536650e..4b0b79303 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -132,6 +132,21 @@ hb_subset_input_unicode_set (hb_subset_input_t *input); HB_EXTERN hb_set_t * hb_subset_input_glyph_set (hb_subset_input_t *input); +HB_EXTERN hb_set_t * +hb_subset_input_nameid_set (hb_subset_input_t *input); + +HB_EXTERN hb_set_t * +hb_subset_input_namelangid_set (hb_subset_input_t *input); + +HB_EXTERN hb_set_t * +hb_subset_input_layout_features_set (hb_subset_input_t *input); + +HB_EXTERN hb_set_t * +hb_subset_input_no_subset_tables_set (hb_subset_input_t *input); + +HB_EXTERN hb_set_t * +hb_subset_input_drop_tables_set (hb_subset_input_t *input); + HB_EXTERN hb_set_t * hb_subset_input_set (hb_subset_input_t *input, hb_subset_sets_t set_type); From 50193262f0d8aa1c2d6a2a2e4b68f8d2771157b3 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 25 Aug 2021 15:10:21 -0700 Subject: [PATCH 06/12] [subset] reorder set enums. --- src/hb-subset.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hb-subset.h b/src/hb-subset.h index 4b0b79303..079db2872 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -83,14 +83,14 @@ typedef enum { /*< flags >*/ * hb_subset_sets_t: * HB_SUBSET_SETS_GLYPH_INDEX: the set of glyph indexes to retain in the subset. * HB_SUBSET_SETS_UNICODE: the set of unicode codepoints to retain in the subset. - * @HB_SUBSET_SETS_LAYOUT_FEATURE_TAG: the set of layout feature tags that will be retained - * in the subset. - * @HB_SUBSET_SETS_NAME_ID: the set of name ids that will be retained. - * @HB_SUBSET_SETS_NAME_LANG_ID: the set of name lang ids that will be retained. * @HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG: the set of table tags which specifies tables that should not be * subsetted. * @HB_SUBSET_SETS_DROP_TABLE_TAG: the set of table tags which specifies tables which will be dropped * in the subset. + * @HB_SUBSET_SETS_NAME_ID: the set of name ids that will be retained. + * @HB_SUBSET_SETS_NAME_LANG_ID: the set of name lang ids that will be retained. + * @HB_SUBSET_SETS_LAYOUT_FEATURE_TAG: the set of layout feature tags that will be retained + * in the subset. * * List of sets that can be configured on the subset input. * @@ -99,11 +99,11 @@ typedef enum { /*< flags >*/ typedef enum { HB_SUBSET_SETS_GLYPH_INDEX = 0, HB_SUBSET_SETS_UNICODE, - HB_SUBSET_SETS_LAYOUT_FEATURE_TAG, - HB_SUBSET_SETS_NAME_ID, - HB_SUBSET_SETS_NAME_LANG_ID, HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG, HB_SUBSET_SETS_DROP_TABLE_TAG, + HB_SUBSET_SETS_NAME_ID, + HB_SUBSET_SETS_NAME_LANG_ID, + HB_SUBSET_SETS_LAYOUT_FEATURE_TAG, } hb_subset_sets_t; HB_EXTERN hb_subset_input_t * From 05204d758689751350cf9f14518bfd7fc86db608 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 25 Aug 2021 16:51:26 -0700 Subject: [PATCH 07/12] [subset] implement hb_subset_input_set (...). Switch to storing the sets keyed by enum internally. --- src/hb-subset-input.cc | 85 +++++++++++++++++++++--------------- src/hb-subset-input.hh | 97 ++++++++++++++++++++++++++++++++++++------ src/hb-subset-plan.cc | 20 ++++----- 3 files changed, 144 insertions(+), 58 deletions(-) diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index ad2d6b3fc..b70c86a5b 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -45,23 +45,16 @@ hb_subset_input_create_or_fail (void) if (unlikely (!input)) return nullptr; - input->unicodes = hb_set_create (); - input->glyphs = hb_set_create (); - input->name_ids = hb_set_create (); - hb_set_add_range (input->name_ids, 0, 6); - input->name_languages = hb_set_create (); - hb_set_add (input->name_languages, 0x0409); - input->layout_features = hb_set_create (); - input->drop_tables = hb_set_create (); - input->no_subset_tables = hb_set_create (); + input->sets.init (); + input->sets.set (HB_SUBSET_SETS_GLYPH_INDEX, hb_set_create ()); + input->sets.set (HB_SUBSET_SETS_UNICODE, hb_set_create ()); + input->sets.set (HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG, hb_set_create ()); + input->sets.set (HB_SUBSET_SETS_DROP_TABLE_TAG, hb_set_create ()); + input->sets.set (HB_SUBSET_SETS_NAME_ID, hb_set_create ()); + input->sets.set (HB_SUBSET_SETS_NAME_LANG_ID, hb_set_create ()); + input->sets.set (HB_SUBSET_SETS_LAYOUT_FEATURE_TAG, hb_set_create ()); - if (unlikely (input->unicodes->in_error () - || input->glyphs->in_error () - || input->name_ids->in_error () - || input->name_languages->in_error () - || input->layout_features->in_error () - || input->drop_tables->in_error () - || input->no_subset_tables->in_error ())) + if (input->in_error ()) { hb_subset_input_destroy (input); return nullptr; @@ -69,6 +62,9 @@ hb_subset_input_create_or_fail (void) input->flags = HB_SUBSET_FLAGS_DEFAULT; + hb_set_add_range (input->name_ids (), 0, 6); + hb_set_add (input->name_languages (), 0x0409); + hb_tag_t default_drop_tables[] = { // Layout disabled by default HB_TAG ('m', 'o', 'r', 'x'), @@ -93,7 +89,7 @@ hb_subset_input_create_or_fail (void) HB_TAG ('S', 'i', 'l', 'f'), HB_TAG ('S', 'i', 'l', 'l'), }; - input->drop_tables->add_array (default_drop_tables, ARRAY_LENGTH (default_drop_tables)); + input->drop_tables ()->add_array (default_drop_tables, ARRAY_LENGTH (default_drop_tables)); hb_tag_t default_no_subset_tables[] = { HB_TAG ('a', 'v', 'a', 'r'), @@ -108,8 +104,8 @@ hb_subset_input_create_or_fail (void) HB_TAG ('c', 'v', 'a', 'r'), HB_TAG ('S', 'T', 'A', 'T'), }; - input->no_subset_tables->add_array (default_no_subset_tables, - ARRAY_LENGTH (default_no_subset_tables)); + input->no_subset_tables ()->add_array (default_no_subset_tables, + ARRAY_LENGTH (default_no_subset_tables)); //copied from _layout_features_groups in fonttools hb_tag_t default_layout_features[] = { @@ -198,7 +194,13 @@ hb_subset_input_create_or_fail (void) HB_TAG ('b', 'l', 'w', 'm'), }; - input->layout_features->add_array (default_layout_features, ARRAY_LENGTH (default_layout_features)); + input->layout_features ()->add_array (default_layout_features, ARRAY_LENGTH (default_layout_features)); + + if (input->in_error ()) + { + hb_subset_input_destroy (input); + return nullptr; + } return input; } @@ -232,13 +234,10 @@ hb_subset_input_destroy (hb_subset_input_t *input) { if (!hb_object_destroy (input)) return; - hb_set_destroy (input->unicodes); - hb_set_destroy (input->glyphs); - hb_set_destroy (input->name_ids); - hb_set_destroy (input->name_languages); - hb_set_destroy (input->drop_tables); - hb_set_destroy (input->layout_features); - hb_set_destroy (input->no_subset_tables); + for (hb_set_t* set : input->sets.values ()) + hb_set_destroy (set); + + input->sets.fini (); hb_free (input); } @@ -258,7 +257,7 @@ hb_subset_input_destroy (hb_subset_input_t *input) HB_EXTERN hb_set_t * hb_subset_input_unicode_set (hb_subset_input_t *input) { - return input->unicodes; + return input->unicodes (); } /** @@ -275,7 +274,7 @@ hb_subset_input_unicode_set (hb_subset_input_t *input) HB_EXTERN hb_set_t * hb_subset_input_glyph_set (hb_subset_input_t *input) { - return input->glyphs; + return input->glyphs (); } /** @@ -292,7 +291,7 @@ hb_subset_input_glyph_set (hb_subset_input_t *input) HB_EXTERN hb_set_t * hb_subset_input_nameid_set (hb_subset_input_t *input) { - return input->name_ids; + return input->name_ids (); } /** @@ -309,7 +308,7 @@ hb_subset_input_nameid_set (hb_subset_input_t *input) HB_EXTERN hb_set_t * hb_subset_input_namelangid_set (hb_subset_input_t *input) { - return input->name_languages; + return input->name_languages (); } @@ -327,7 +326,7 @@ hb_subset_input_namelangid_set (hb_subset_input_t *input) HB_EXTERN hb_set_t * hb_subset_input_layout_features_set (hb_subset_input_t *input) { - return input->layout_features; + return input->layout_features (); } /** @@ -344,7 +343,25 @@ hb_subset_input_layout_features_set (hb_subset_input_t *input) HB_EXTERN hb_set_t * hb_subset_input_drop_tables_set (hb_subset_input_t *input) { - return input->drop_tables; + return input->drop_tables (); +} + +/** + * hb_subset_input_set: + * @input: a #hb_subset_input_t object. + * @set_type: a #hb_subset_sets_t set type. + * + * Gets the set of the specified type. + * + * Return value: (transfer none): pointer to the #hb_set_t of the specified type. + * + * Since: REPLACEME + **/ +HB_EXTERN hb_set_t * +hb_subset_input_set (hb_subset_input_t *input, hb_subset_sets_t set_type) +{ + // TODO(garretrieger): add test for this method. + return input->sets.get (set_type); } /** @@ -361,7 +378,7 @@ hb_subset_input_drop_tables_set (hb_subset_input_t *input) HB_EXTERN hb_set_t * hb_subset_input_no_subset_tables_set (hb_subset_input_t *input) { - return input->no_subset_tables; + return input->no_subset_tables (); } diff --git a/src/hb-subset-input.hh b/src/hb-subset-input.hh index ddc35f287..82ffb6d73 100644 --- a/src/hb-subset-input.hh +++ b/src/hb-subset-input.hh @@ -31,6 +31,8 @@ #include "hb.hh" #include "hb-subset.h" +#include "hb-map.hh" +#include "hb-set.hh" #include "hb-font.hh" @@ -40,23 +42,90 @@ struct hb_subset_input_t { hb_object_header_t header; - hb_set_t *unicodes; // invert safe - hb_set_t *glyphs; // invert safe - hb_set_t *name_ids; // invert safe - hb_set_t *name_languages; // invert safe - hb_set_t *no_subset_tables; // invert safe - hb_set_t *drop_tables; // invert safe - hb_set_t *layout_features; // invert safe + hb_hashmap_t sets; unsigned flags; - /* TODO - * - * features - * lookups - * name_ids - * ... - */ + inline hb_set_t* unicodes() + { + return sets.get (HB_SUBSET_SETS_UNICODE); + } + + inline const hb_set_t* unicodes() const + { + return sets.get (HB_SUBSET_SETS_UNICODE); + } + + inline hb_set_t* glyphs () + { + return sets.get (HB_SUBSET_SETS_GLYPH_INDEX); + } + + inline const hb_set_t* glyphs () const + { + return sets.get (HB_SUBSET_SETS_GLYPH_INDEX); + } + + inline hb_set_t* name_ids () + { + return sets.get (HB_SUBSET_SETS_NAME_ID); + } + + inline const hb_set_t* name_ids () const + { + return sets.get (HB_SUBSET_SETS_NAME_ID); + } + + inline hb_set_t* name_languages () + { + return sets.get (HB_SUBSET_SETS_NAME_LANG_ID); + } + + inline const hb_set_t* name_languages () const + { + return sets.get (HB_SUBSET_SETS_NAME_LANG_ID); + } + + inline hb_set_t* no_subset_tables () + { + return sets.get (HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG); + } + + inline const hb_set_t* no_subset_tables () const + { + return sets.get (HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG); + } + + inline hb_set_t* drop_tables () + { + return sets.get (HB_SUBSET_SETS_DROP_TABLE_TAG); + } + + inline const hb_set_t* drop_tables () const + { + return sets.get (HB_SUBSET_SETS_DROP_TABLE_TAG); + } + + inline hb_set_t* layout_features () + { + return sets.get (HB_SUBSET_SETS_LAYOUT_FEATURE_TAG); + } + + inline const hb_set_t* layout_features () const + { + return sets.get (HB_SUBSET_SETS_LAYOUT_FEATURE_TAG); + } + + bool in_error () const + { + if (sets.in_error ()) return true; + for (const hb_set_t* set : sets.values ()) + { + if (unlikely (set->in_error ())) + return true; + } + return false; + } }; diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index fb23a6488..d6c7f8fa6 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -456,13 +456,13 @@ hb_subset_plan_create (hb_face_t *face, plan->successful = true; plan->flags = input->flags; plan->unicodes = hb_set_create (); - plan->name_ids = hb_set_copy (input->name_ids); + plan->name_ids = hb_set_copy (input->name_ids ()); _nameid_closure (face, plan->name_ids); - plan->name_languages = hb_set_copy (input->name_languages); - plan->layout_features = hb_set_copy (input->layout_features); - plan->glyphs_requested = hb_set_copy (input->glyphs); - plan->drop_tables = hb_set_copy (input->drop_tables); - plan->no_subset_tables = hb_set_copy (input->no_subset_tables); + plan->name_languages = hb_set_copy (input->name_languages ()); + plan->layout_features = hb_set_copy (input->layout_features ()); + plan->glyphs_requested = hb_set_copy (input->glyphs ()); + plan->drop_tables = hb_set_copy (input->drop_tables ()); + plan->no_subset_tables = hb_set_copy (input->no_subset_tables ()); plan->source = hb_face_reference (face); plan->dest = hb_face_builder_create (); @@ -490,12 +490,12 @@ hb_subset_plan_create (hb_face_t *face, return plan; } - _populate_unicodes_to_retain (input->unicodes, input->glyphs, plan); + _populate_unicodes_to_retain (input->unicodes (), input->glyphs (), plan); _populate_gids_to_retain (plan, - !input->drop_tables->has (HB_OT_TAG_GSUB), - !input->drop_tables->has (HB_OT_TAG_GPOS), - !input->drop_tables->has (HB_OT_TAG_GDEF)); + !input->drop_tables ()->has (HB_OT_TAG_GSUB), + !input->drop_tables ()->has (HB_OT_TAG_GPOS), + !input->drop_tables ()->has (HB_OT_TAG_GDEF)); _create_old_gid_to_new_gid_map (face, input->flags & HB_SUBSET_FLAGS_RETAIN_GIDS, From 7194c2a2a370a39d8e41539cb7fde9a9ffed80c3 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Fri, 27 Aug 2021 08:20:58 -0700 Subject: [PATCH 08/12] [subset] use anonymous union to hold the input sets instead of a map. --- src/hb-subset-input.cc | 16 +++--------- src/hb-subset-input.hh | 56 ++++++++++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index b70c86a5b..c2b7c0492 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -45,14 +45,8 @@ hb_subset_input_create_or_fail (void) if (unlikely (!input)) return nullptr; - input->sets.init (); - input->sets.set (HB_SUBSET_SETS_GLYPH_INDEX, hb_set_create ()); - input->sets.set (HB_SUBSET_SETS_UNICODE, hb_set_create ()); - input->sets.set (HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG, hb_set_create ()); - input->sets.set (HB_SUBSET_SETS_DROP_TABLE_TAG, hb_set_create ()); - input->sets.set (HB_SUBSET_SETS_NAME_ID, hb_set_create ()); - input->sets.set (HB_SUBSET_SETS_NAME_LANG_ID, hb_set_create ()); - input->sets.set (HB_SUBSET_SETS_LAYOUT_FEATURE_TAG, hb_set_create ()); + for (auto& set : input->sets_iter ()) + set = hb_set_create (); if (input->in_error ()) { @@ -234,11 +228,9 @@ hb_subset_input_destroy (hb_subset_input_t *input) { if (!hb_object_destroy (input)) return; - for (hb_set_t* set : input->sets.values ()) + for (hb_set_t* set : input->sets_iter ()) hb_set_destroy (set); - input->sets.fini (); - hb_free (input); } @@ -361,7 +353,7 @@ HB_EXTERN hb_set_t * hb_subset_input_set (hb_subset_input_t *input, hb_subset_sets_t set_type) { // TODO(garretrieger): add test for this method. - return input->sets.get (set_type); + return input->sets_iter () [set_type]; } /** diff --git a/src/hb-subset-input.hh b/src/hb-subset-input.hh index 82ffb6d73..0b0609128 100644 --- a/src/hb-subset-input.hh +++ b/src/hb-subset-input.hh @@ -42,86 +42,106 @@ struct hb_subset_input_t { hb_object_header_t header; - hb_hashmap_t sets; + union { + struct { + hb_set_t *glyphs; + hb_set_t *unicodes; + hb_set_t *no_subset_tables; + hb_set_t *drop_tables; + hb_set_t *name_ids; + hb_set_t *name_languages; + hb_set_t *layout_features; + } sets; + hb_set_t* set_ptrs[1]; + }; unsigned flags; + inline unsigned num_sets () const + { + return sizeof (sets) / sizeof (hb_set_t*); + } + + inline hb_array_t sets_iter () + { + return hb_array_t (set_ptrs, num_sets ()); + } + inline hb_set_t* unicodes() { - return sets.get (HB_SUBSET_SETS_UNICODE); + return sets.unicodes; } inline const hb_set_t* unicodes() const { - return sets.get (HB_SUBSET_SETS_UNICODE); + return sets.unicodes; } inline hb_set_t* glyphs () { - return sets.get (HB_SUBSET_SETS_GLYPH_INDEX); + return sets.glyphs; } inline const hb_set_t* glyphs () const { - return sets.get (HB_SUBSET_SETS_GLYPH_INDEX); + return sets.glyphs; } inline hb_set_t* name_ids () { - return sets.get (HB_SUBSET_SETS_NAME_ID); + return sets.name_ids; } inline const hb_set_t* name_ids () const { - return sets.get (HB_SUBSET_SETS_NAME_ID); + return sets.name_ids; } inline hb_set_t* name_languages () { - return sets.get (HB_SUBSET_SETS_NAME_LANG_ID); + return sets.name_languages; } inline const hb_set_t* name_languages () const { - return sets.get (HB_SUBSET_SETS_NAME_LANG_ID); + return sets.name_languages; } inline hb_set_t* no_subset_tables () { - return sets.get (HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG); + return sets.no_subset_tables; } inline const hb_set_t* no_subset_tables () const { - return sets.get (HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG); + return sets.no_subset_tables; } inline hb_set_t* drop_tables () { - return sets.get (HB_SUBSET_SETS_DROP_TABLE_TAG); + return sets.drop_tables; } inline const hb_set_t* drop_tables () const { - return sets.get (HB_SUBSET_SETS_DROP_TABLE_TAG); + return sets.drop_tables; } inline hb_set_t* layout_features () { - return sets.get (HB_SUBSET_SETS_LAYOUT_FEATURE_TAG); + return sets.layout_features; } inline const hb_set_t* layout_features () const { - return sets.get (HB_SUBSET_SETS_LAYOUT_FEATURE_TAG); + return sets.layout_features; } bool in_error () const { - if (sets.in_error ()) return true; - for (const hb_set_t* set : sets.values ()) + for (unsigned i = 0; i < num_sets (); i++) { - if (unlikely (set->in_error ())) + if (unlikely (set_ptrs[i]->in_error ())) return true; } return false; From 102666dab7ef649fca0fbd3ce043ab2b166d662c Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Fri, 27 Aug 2021 10:31:37 -0700 Subject: [PATCH 09/12] [subset] add test for hb_subset_input_set (...). --- src/hb-subset-input.cc | 1 - test/api/test-subset.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index c2b7c0492..3c5e71cdf 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -352,7 +352,6 @@ hb_subset_input_drop_tables_set (hb_subset_input_t *input) HB_EXTERN hb_set_t * hb_subset_input_set (hb_subset_input_t *input, hb_subset_sets_t set_type) { - // TODO(garretrieger): add test for this method. return input->sets_iter () [set_type]; } diff --git a/test/api/test-subset.c b/test/api/test-subset.c index 89894f5c9..41017bc2f 100644 --- a/test/api/test-subset.c +++ b/test/api/test-subset.c @@ -127,6 +127,35 @@ test_subset_set_flags (void) } +static void +test_subset_sets (void) +{ + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + hb_set_t* set = hb_set_create (); + + hb_set_add (hb_subset_input_set (input, HB_SUBSET_SETS_GLYPH_INDEX), 83); + hb_set_add (hb_subset_input_set (input, HB_SUBSET_SETS_UNICODE), 85); + + hb_set_clear (hb_subset_input_set (input, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG)); + hb_set_add (hb_subset_input_set (input, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG), 87); + + hb_set_add (set, 83); + g_assert (hb_set_is_equal (hb_subset_input_glyph_set (input), set)); + hb_set_clear (set); + + hb_set_add (set, 85); + g_assert (hb_set_is_equal (hb_subset_input_unicode_set (input), set)); + hb_set_clear (set); + + hb_set_add (set, 87); + g_assert (hb_set_is_equal (hb_subset_input_layout_features_set (input), set)); + hb_set_clear (set); + + hb_set_destroy (set); + hb_subset_input_destroy (input); +} + + static void test_subset_legacy_api (void) { @@ -185,6 +214,7 @@ main (int argc, char **argv) hb_test_add (test_subset_no_inf_loop); hb_test_add (test_subset_crash); hb_test_add (test_subset_set_flags); + hb_test_add (test_subset_sets); hb_test_add (test_subset_legacy_api); return hb_test_run(); From 57d6bf82519f39717ddb7b7574ac079e3016757f Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Fri, 27 Aug 2021 10:59:28 -0700 Subject: [PATCH 10/12] [subset] in sets union correctly size the pointer array. --- src/hb-subset-input.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hb-subset-input.hh b/src/hb-subset-input.hh index 0b0609128..3b2c42a96 100644 --- a/src/hb-subset-input.hh +++ b/src/hb-subset-input.hh @@ -52,14 +52,14 @@ struct hb_subset_input_t hb_set_t *name_languages; hb_set_t *layout_features; } sets; - hb_set_t* set_ptrs[1]; + hb_set_t* set_ptrs[sizeof (sets) / sizeof (hb_set_t*)]; }; unsigned flags; inline unsigned num_sets () const { - return sizeof (sets) / sizeof (hb_set_t*); + return sizeof (set_ptrs) / sizeof (hb_set_t*); } inline hb_array_t sets_iter () From 3844e58e14f6f528c52df06d49c771dd174730b9 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 30 Aug 2021 11:16:51 -0700 Subject: [PATCH 11/12] [subset] remove helper functions for accessing subset input sets. --- src/hb-subset-input.cc | 24 +++++++-------- src/hb-subset-input.hh | 70 ------------------------------------------ src/hb-subset-plan.cc | 20 ++++++------ 3 files changed, 22 insertions(+), 92 deletions(-) diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index 3c5e71cdf..d459bb7eb 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -56,8 +56,8 @@ hb_subset_input_create_or_fail (void) input->flags = HB_SUBSET_FLAGS_DEFAULT; - hb_set_add_range (input->name_ids (), 0, 6); - hb_set_add (input->name_languages (), 0x0409); + hb_set_add_range (input->sets.name_ids, 0, 6); + hb_set_add (input->sets.name_languages, 0x0409); hb_tag_t default_drop_tables[] = { // Layout disabled by default @@ -83,7 +83,7 @@ hb_subset_input_create_or_fail (void) HB_TAG ('S', 'i', 'l', 'f'), HB_TAG ('S', 'i', 'l', 'l'), }; - input->drop_tables ()->add_array (default_drop_tables, ARRAY_LENGTH (default_drop_tables)); + input->sets.drop_tables->add_array (default_drop_tables, ARRAY_LENGTH (default_drop_tables)); hb_tag_t default_no_subset_tables[] = { HB_TAG ('a', 'v', 'a', 'r'), @@ -98,7 +98,7 @@ hb_subset_input_create_or_fail (void) HB_TAG ('c', 'v', 'a', 'r'), HB_TAG ('S', 'T', 'A', 'T'), }; - input->no_subset_tables ()->add_array (default_no_subset_tables, + input->sets.no_subset_tables->add_array (default_no_subset_tables, ARRAY_LENGTH (default_no_subset_tables)); //copied from _layout_features_groups in fonttools @@ -188,7 +188,7 @@ hb_subset_input_create_or_fail (void) HB_TAG ('b', 'l', 'w', 'm'), }; - input->layout_features ()->add_array (default_layout_features, ARRAY_LENGTH (default_layout_features)); + input->sets.layout_features->add_array (default_layout_features, ARRAY_LENGTH (default_layout_features)); if (input->in_error ()) { @@ -249,7 +249,7 @@ hb_subset_input_destroy (hb_subset_input_t *input) HB_EXTERN hb_set_t * hb_subset_input_unicode_set (hb_subset_input_t *input) { - return input->unicodes (); + return input->sets.unicodes; } /** @@ -266,7 +266,7 @@ hb_subset_input_unicode_set (hb_subset_input_t *input) HB_EXTERN hb_set_t * hb_subset_input_glyph_set (hb_subset_input_t *input) { - return input->glyphs (); + return input->sets.glyphs; } /** @@ -283,7 +283,7 @@ hb_subset_input_glyph_set (hb_subset_input_t *input) HB_EXTERN hb_set_t * hb_subset_input_nameid_set (hb_subset_input_t *input) { - return input->name_ids (); + return input->sets.name_ids; } /** @@ -300,7 +300,7 @@ hb_subset_input_nameid_set (hb_subset_input_t *input) HB_EXTERN hb_set_t * hb_subset_input_namelangid_set (hb_subset_input_t *input) { - return input->name_languages (); + return input->sets.name_languages; } @@ -318,7 +318,7 @@ hb_subset_input_namelangid_set (hb_subset_input_t *input) HB_EXTERN hb_set_t * hb_subset_input_layout_features_set (hb_subset_input_t *input) { - return input->layout_features (); + return input->sets.layout_features; } /** @@ -335,7 +335,7 @@ hb_subset_input_layout_features_set (hb_subset_input_t *input) HB_EXTERN hb_set_t * hb_subset_input_drop_tables_set (hb_subset_input_t *input) { - return input->drop_tables (); + return input->sets.drop_tables; } /** @@ -369,7 +369,7 @@ hb_subset_input_set (hb_subset_input_t *input, hb_subset_sets_t set_type) HB_EXTERN hb_set_t * hb_subset_input_no_subset_tables_set (hb_subset_input_t *input) { - return input->no_subset_tables (); + return input->sets.no_subset_tables; } diff --git a/src/hb-subset-input.hh b/src/hb-subset-input.hh index 3b2c42a96..a3e28b056 100644 --- a/src/hb-subset-input.hh +++ b/src/hb-subset-input.hh @@ -67,76 +67,6 @@ struct hb_subset_input_t return hb_array_t (set_ptrs, num_sets ()); } - inline hb_set_t* unicodes() - { - return sets.unicodes; - } - - inline const hb_set_t* unicodes() const - { - return sets.unicodes; - } - - inline hb_set_t* glyphs () - { - return sets.glyphs; - } - - inline const hb_set_t* glyphs () const - { - return sets.glyphs; - } - - inline hb_set_t* name_ids () - { - return sets.name_ids; - } - - inline const hb_set_t* name_ids () const - { - return sets.name_ids; - } - - inline hb_set_t* name_languages () - { - return sets.name_languages; - } - - inline const hb_set_t* name_languages () const - { - return sets.name_languages; - } - - inline hb_set_t* no_subset_tables () - { - return sets.no_subset_tables; - } - - inline const hb_set_t* no_subset_tables () const - { - return sets.no_subset_tables; - } - - inline hb_set_t* drop_tables () - { - return sets.drop_tables; - } - - inline const hb_set_t* drop_tables () const - { - return sets.drop_tables; - } - - inline hb_set_t* layout_features () - { - return sets.layout_features; - } - - inline const hb_set_t* layout_features () const - { - return sets.layout_features; - } - bool in_error () const { for (unsigned i = 0; i < num_sets (); i++) diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index d6c7f8fa6..677df35fa 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -456,13 +456,13 @@ hb_subset_plan_create (hb_face_t *face, plan->successful = true; plan->flags = input->flags; plan->unicodes = hb_set_create (); - plan->name_ids = hb_set_copy (input->name_ids ()); + plan->name_ids = hb_set_copy (input->sets.name_ids); _nameid_closure (face, plan->name_ids); - plan->name_languages = hb_set_copy (input->name_languages ()); - plan->layout_features = hb_set_copy (input->layout_features ()); - plan->glyphs_requested = hb_set_copy (input->glyphs ()); - plan->drop_tables = hb_set_copy (input->drop_tables ()); - plan->no_subset_tables = hb_set_copy (input->no_subset_tables ()); + plan->name_languages = hb_set_copy (input->sets.name_languages); + plan->layout_features = hb_set_copy (input->sets.layout_features); + plan->glyphs_requested = hb_set_copy (input->sets.glyphs); + plan->drop_tables = hb_set_copy (input->sets.drop_tables); + plan->no_subset_tables = hb_set_copy (input->sets.no_subset_tables); plan->source = hb_face_reference (face); plan->dest = hb_face_builder_create (); @@ -490,12 +490,12 @@ hb_subset_plan_create (hb_face_t *face, return plan; } - _populate_unicodes_to_retain (input->unicodes (), input->glyphs (), plan); + _populate_unicodes_to_retain (input->sets.unicodes, input->sets.glyphs, plan); _populate_gids_to_retain (plan, - !input->drop_tables ()->has (HB_OT_TAG_GSUB), - !input->drop_tables ()->has (HB_OT_TAG_GPOS), - !input->drop_tables ()->has (HB_OT_TAG_GDEF)); + !input->sets.drop_tables->has (HB_OT_TAG_GSUB), + !input->sets.drop_tables->has (HB_OT_TAG_GPOS), + !input->sets.drop_tables->has (HB_OT_TAG_GDEF)); _create_old_gid_to_new_gid_map (face, input->flags & HB_SUBSET_FLAGS_RETAIN_GIDS, From de85636581f3c7c8f8140624b78efd76e3ecfd4b Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 30 Aug 2021 14:36:05 -0700 Subject: [PATCH 12/12] [subset] s/REPLACE/REPLACEME/ --- src/hb-subset.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-subset.h b/src/hb-subset.h index 079db2872..07ca4c241 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -94,7 +94,7 @@ typedef enum { /*< flags >*/ * * List of sets that can be configured on the subset input. * - * Since: REPLACE + * Since: REPLACEME **/ typedef enum { HB_SUBSET_SETS_GLYPH_INDEX = 0,