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,