From 46d4a5e67353517bb27d0ac2d944b7343a8cff3c Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Thu, 29 Jul 2021 15:07:13 -0700 Subject: [PATCH] [subset] Convert subset plan to use a flags bit set. --- src/hb-ot-glyf-table.hh | 15 +++++++++------ src/hb-ot-layout-gpos-table.hh | 6 +++--- src/hb-ot-maxp-table.hh | 2 +- src/hb-ot-name-table.hh | 6 +++++- src/hb-ot-os2-table.hh | 3 ++- src/hb-ot-post-table.hh | 5 +++-- src/hb-ot-var-gvar-table.hh | 8 ++++++-- src/hb-ot-var-hvar-table.hh | 2 +- src/hb-subset-cff-common.hh | 13 ++++++++----- src/hb-subset-cff1.cc | 4 ++-- src/hb-subset-cff2.cc | 4 ++-- src/hb-subset-plan.cc | 29 +++++++++++++++++------------ src/hb-subset-plan.hh | 13 ++----------- src/hb-subset.cc | 4 ++-- 14 files changed, 63 insertions(+), 51 deletions(-) diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index fa11a7fe9..9b8658185 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -213,13 +213,15 @@ struct glyf if (!plan->old_gid_for_new_gid (new_gid, &subset_glyph.old_gid)) return subset_glyph; - if (new_gid == 0 && !plan->notdef_outline) + if (new_gid == 0 && + !(plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE)) subset_glyph.source_glyph = Glyph (); else subset_glyph.source_glyph = glyf.glyph_for_gid (subset_glyph.old_gid, true); - if (plan->drop_hints) subset_glyph.drop_hints_bytes (); - else subset_glyph.dest_start = subset_glyph.source_glyph.get_bytes (); - + if (plan->flags & HB_SUBSET_FLAGS_NO_HINTING) + subset_glyph.drop_hints_bytes (); + else + subset_glyph.dest_start = subset_glyph.source_glyph.get_bytes (); return subset_glyph; }) | hb_sink (glyphs) @@ -1274,9 +1276,10 @@ struct glyf const_cast (_).set_glyph_index (new_gid); } - if (plan->drop_hints) Glyph (dest_glyph).drop_hints (); + if (plan->flags & HB_SUBSET_FLAGS_NO_HINTING) + Glyph (dest_glyph).drop_hints (); - if (plan->overlaps_flag) + if (plan->flags & HB_SUBSET_FLAGS_SET_OVERLAPS_FLAG) Glyph (dest_glyph).set_overlaps_flag (); return_trace (true); diff --git a/src/hb-ot-layout-gpos-table.hh b/src/hb-ot-layout-gpos-table.hh index b5981bda7..1e305518f 100644 --- a/src/hb-ot-layout-gpos-table.hh +++ b/src/hb-ot-layout-gpos-table.hh @@ -538,7 +538,7 @@ struct Anchor switch (u.format) { case 1: return_trace (bool (reinterpret_cast (u.format1.copy (c->serializer)))); case 2: - if (c->plan->drop_hints) + if (c->plan->flags & HB_SUBSET_FLAGS_NO_HINTING) { // AnchorFormat 2 just containins extra hinting information, so // if hints are being dropped convert to format 1. @@ -1373,7 +1373,7 @@ struct PairPosFormat1 out->format = format; out->valueFormat[0] = valueFormat[0]; out->valueFormat[1] = valueFormat[1]; - if (c->plan->drop_hints) + if (c->plan->flags & HB_SUBSET_FLAGS_NO_HINTING) { hb_pair_t newFormats = compute_effective_value_formats (glyphset); out->valueFormat[0] = newFormats.first; @@ -1591,7 +1591,7 @@ struct PairPosFormat2 unsigned len2 = valueFormat2.get_len (); hb_pair_t newFormats = hb_pair (valueFormat1, valueFormat2); - if (c->plan->drop_hints) + if (c->plan->flags & HB_SUBSET_FLAGS_NO_HINTING) newFormats = compute_effective_value_formats (klass1_map, klass2_map); out->valueFormat1 = newFormats.first; diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh index 929956d12..3a019ef78 100644 --- a/src/hb-ot-maxp-table.hh +++ b/src/hb-ot-maxp-table.hh @@ -107,7 +107,7 @@ struct maxp maxpV1Tail *dest_v1 = c->serializer->embed (src_v1); if (unlikely (!dest_v1)) return_trace (false); - if (c->plan->drop_hints) + if (c->plan->flags & HB_SUBSET_FLAGS_NO_HINTING) drop_hint_fields (dest_v1); } diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh index dec4d1213..c17bb4abb 100644 --- a/src/hb-ot-name-table.hh +++ b/src/hb-ot-name-table.hh @@ -249,7 +249,11 @@ struct name + nameRecordZ.as_array (count) | hb_filter (c->plan->name_ids, &NameRecord::nameID) | hb_filter (c->plan->name_languages, &NameRecord::languageID) - | hb_filter ([&] (const NameRecord& namerecord) { return c->plan->name_legacy || namerecord.isUnicode (); }) + | hb_filter ([&] (const NameRecord& namerecord) { + return + (c->plan->flags & HB_SUBSET_FLAGS_NAME_LEGACY) + || namerecord.isUnicode (); + }) ; name_prime->serialize (c->serializer, it, hb_addressof (this + stringOffset)); diff --git a/src/hb-ot-os2-table.hh b/src/hb-ot-os2-table.hh index 979b19281..f0035e2f0 100644 --- a/src/hb-ot-os2-table.hh +++ b/src/hb-ot-os2-table.hh @@ -171,7 +171,8 @@ struct OS2 TRACE_SUBSET (this); OS2 *os2_prime = c->serializer->embed (this); if (unlikely (!os2_prime)) return_trace (false); - if (!c->plan->prune_unicode_ranges) return_trace (true); + if (c->plan->flags & HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES) + return_trace (true); /* when --gids option is not used, no need to do collect_mapping that is * iterating all codepoints in each subtable, which is not efficient */ diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index 1184682df..39de67170 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -98,10 +98,11 @@ struct post post *post_prime = c->serializer->start_embed (); if (unlikely (!post_prime)) return_trace (false); - if (!serialize (c->serializer, c->plan->glyph_names)) + bool glyph_names = c->plan->flags & HB_SUBSET_FLAGS_GLYPH_NAMES; + if (!serialize (c->serializer, glyph_names)) return_trace (false); - if (c->plan->glyph_names && version.major == 2) + if (glyph_names && version.major == 2) return_trace (v2X.subset (c)); return_trace (true); diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index 516766161..49b5532d4 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -419,7 +419,9 @@ struct gvar out->glyphCount = num_glyphs; unsigned int subset_data_size = 0; - for (hb_codepoint_t gid = c->plan->notdef_outline ? 0 : 1; gid < num_glyphs; gid++) + for (hb_codepoint_t gid = (c->plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE) ? 0 : 1; + gid < num_glyphs; + gid++) { hb_codepoint_t old_gid; if (!c->plan->old_gid_for_new_gid (gid, &old_gid)) continue; @@ -449,7 +451,9 @@ struct gvar out->dataZ = subset_data - (char *) out; unsigned int glyph_offset = 0; - for (hb_codepoint_t gid = c->plan->notdef_outline ? 0 : 1; gid < num_glyphs; gid++) + for (hb_codepoint_t gid = (c->plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE) ? 0 : 1; + gid < num_glyphs; + gid++) { hb_codepoint_t old_gid; hb_bytes_t var_data_bytes = c->plan->old_gid_for_new_gid (gid, &old_gid) diff --git a/src/hb-ot-var-hvar-table.hh b/src/hb-ot-var-hvar-table.hh index 928fcc719..72217e7f2 100644 --- a/src/hb-ot-var-hvar-table.hh +++ b/src/hb-ot-var-hvar-table.hh @@ -272,7 +272,7 @@ struct hvarvvar_subset_plan_t index_map_plans[0].init (*index_maps[0], outer_map, inner_sets, plan); if (index_maps[0] == &Null (DeltaSetIndexMap)) { - retain_adv_map = plan->retain_gids; + retain_adv_map = plan->flags & HB_SUBSET_FLAGS_RETAIN_GIDS; outer_map.add (0); for (hb_codepoint_t gid = 0; gid < plan->num_output_glyphs (); gid++) { diff --git a/src/hb-subset-cff-common.hh b/src/hb-subset-cff-common.hh index 422b20b8d..7fd96ca86 100644 --- a/src/hb-subset-cff-common.hh +++ b/src/hb-subset-cff-common.hh @@ -259,7 +259,10 @@ struct subr_flattener_t return false; cs_interpreter_t interp; interp.env.init (str, acc, fd); - flatten_param_t param = { flat_charstrings[i], plan->drop_hints }; + flatten_param_t param = { + flat_charstrings[i], + (bool) (plan->flags & HB_SUBSET_FLAGS_NO_HINTING) + }; if (unlikely (!interp.interpret (param))) return false; } @@ -636,7 +639,7 @@ struct subr_subsetter_t param.init (&parsed_charstrings[i], &parsed_global_subrs, &parsed_local_subrs[fd], closures.global_closure, closures.local_closures[fd], - plan->drop_hints); + plan->flags & HB_SUBSET_FLAGS_NO_HINTING); if (unlikely (!interp.interpret (param))) return false; @@ -645,7 +648,7 @@ struct subr_subsetter_t SUBSETTER::complete_parsed_str (interp.env, param, parsed_charstrings[i]); } - if (plan->drop_hints) + if (plan->flags & HB_SUBSET_FLAGS_NO_HINTING) { /* mark hint ops and arguments for drop */ for (unsigned int i = 0; i < plan->num_output_glyphs (); i++) @@ -660,7 +663,7 @@ struct subr_subsetter_t param.init (&parsed_charstrings[i], &parsed_global_subrs, &parsed_local_subrs[fd], closures.global_closure, closures.local_closures[fd], - plan->drop_hints); + plan->flags & HB_SUBSET_FLAGS_NO_HINTING); drop_hints_param_t drop; if (drop_hints_in_str (parsed_charstrings[i], param, drop)) @@ -685,7 +688,7 @@ struct subr_subsetter_t param.init (&parsed_charstrings[i], &parsed_global_subrs, &parsed_local_subrs[fd], closures.global_closure, closures.local_closures[fd], - plan->drop_hints); + plan->flags & HB_SUBSET_FLAGS_NO_HINTING); collect_subr_refs_in_str (parsed_charstrings[i], param); } } diff --git a/src/hb-subset-cff1.cc b/src/hb-subset-cff1.cc index 1d492c615..b4e24122c 100644 --- a/src/hb-subset-cff1.cc +++ b/src/hb-subset-cff1.cc @@ -543,8 +543,8 @@ struct cff_subset_plan { num_glyphs = plan->num_output_glyphs (); orig_fdcount = acc.fdCount; - drop_hints = plan->drop_hints; - desubroutinize = plan->desubroutinize; + drop_hints = plan->flags & HB_SUBSET_FLAGS_NO_HINTING; + desubroutinize = plan->flags & HB_SUBSET_FLAGS_DESUBROUTINIZE; /* check whether the subset renumbers any glyph IDs */ gid_renum = false; diff --git a/src/hb-subset-cff2.cc b/src/hb-subset-cff2.cc index 1082be4ae..896ae6401 100644 --- a/src/hb-subset-cff2.cc +++ b/src/hb-subset-cff2.cc @@ -262,8 +262,8 @@ struct cff2_subset_plan { { orig_fdcount = acc.fdArray->count; - drop_hints = plan->drop_hints; - desubroutinize = plan->desubroutinize; + drop_hints = plan->flags & HB_SUBSET_FLAGS_NO_HINTING; + desubroutinize = plan->flags & HB_SUBSET_FLAGS_DESUBROUTINIZE; if (desubroutinize) { diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 5a3404416..aab78c5f0 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -296,10 +296,24 @@ _populate_gids_to_retain (hb_subset_plan_t* plan, #ifndef HB_NO_SUBSET_LAYOUT if (close_over_gsub) // closure all glyphs/lookups/features needed for GSUB substitutions. - _closure_glyphs_lookups_features (plan->source, plan->_glyphset_gsub, plan->layout_features, plan->retain_all_layout_features, plan->gsub_lookups, plan->gsub_features, plan->gsub_langsys); + _closure_glyphs_lookups_features ( + plan->source, + plan->_glyphset_gsub, + plan->layout_features, + plan->flags & HB_SUBSET_FLAGS_RETAIN_ALL_FEATURES, + plan->gsub_lookups, + plan->gsub_features, + plan->gsub_langsys); if (close_over_gpos) - _closure_glyphs_lookups_features (plan->source, plan->_glyphset_gsub, plan->layout_features, plan->retain_all_layout_features, plan->gpos_lookups, plan->gpos_features, plan->gpos_langsys); + _closure_glyphs_lookups_features ( + plan->source, + plan->_glyphset_gsub, + plan->layout_features, + plan->flags & HB_SUBSET_FLAGS_RETAIN_ALL_FEATURES, + plan->gpos_lookups, + plan->gpos_features, + plan->gpos_langsys); #endif _remove_invalid_gids (plan->_glyphset_gsub, plan->source->get_num_glyphs ()); @@ -423,16 +437,7 @@ hb_subset_plan_create (hb_face_t *face, return const_cast (&Null (hb_subset_plan_t)); plan->successful = true; - plan->drop_hints = input->flags & HB_SUBSET_FLAGS_NO_HINTING; - plan->desubroutinize = input->flags & HB_SUBSET_FLAGS_DESUBROUTINIZE; - plan->retain_gids = input->flags & HB_SUBSET_FLAGS_RETAIN_GIDS; - plan->name_legacy = input->flags & HB_SUBSET_FLAGS_NAME_LEGACY; - plan->overlaps_flag = input->flags & HB_SUBSET_FLAGS_SET_OVERLAPS_FLAG; - plan->notdef_outline = input->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE; - plan->glyph_names = input->flags & HB_SUBSET_FLAGS_GLYPH_NAMES; - plan->prune_unicode_ranges = !(input->flags & HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES); - plan->retain_all_layout_features = input->flags & HB_SUBSET_FLAGS_RETAIN_ALL_FEATURES; - plan->passthrough_unrecognized = input->flags & HB_SUBSET_FLAGS_PASSTHROUGH_UNRECOGNIZED; + plan->flags = input->flags; plan->unicodes = hb_set_create (); plan->name_ids = hb_set_copy (input->name_ids); _nameid_closure (face, plan->name_ids); diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index 9252e706a..d4d0bdc82 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -39,17 +39,8 @@ struct hb_subset_plan_t { hb_object_header_t header; - bool successful : 1; - bool drop_hints : 1; - bool desubroutinize : 1; - bool retain_gids : 1; - bool name_legacy : 1; - bool overlaps_flag : 1; - bool notdef_outline : 1; - bool glyph_names : 1; - bool prune_unicode_ranges : 1; - bool retain_all_layout_features : 1; - bool passthrough_unrecognized : 1; + bool successful; + hb_subset_flags_t flags; // For each cp that we'd like to retain maps to the corresponding gid. hb_set_t *unicodes; diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 66bb5daba..fdc584e42 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -246,7 +246,7 @@ _should_drop_table (hb_subset_plan_t *plan, hb_tag_t tag) case HB_TAG ('p','r','e','p'): /* hint table, fallthrough */ case HB_TAG ('h','d','m','x'): /* hint table, fallthrough */ case HB_TAG ('V','D','M','X'): /* hint table, fallthrough */ - return plan->drop_hints; + return plan->flags & HB_SUBSET_FLAGS_NO_HINTING; #ifdef HB_NO_SUBSET_LAYOUT // Drop Layout Tables if requested. @@ -322,7 +322,7 @@ _subset_table (hb_subset_plan_t *plan, hb_tag_t tag) #endif default: - if (plan->passthrough_unrecognized) + if (plan->flags & HB_SUBSET_FLAGS_PASSTHROUGH_UNRECOGNIZED) return _passthrough (plan, tag); // Drop table