[subset/hvar/retaingids] Synthesize a DeltaSetIndexMap if needed

Before we were emitting the entire VarStore rows if advMap
was Null. Instead, synthesize an advMap.

20% speed up in subset_glyphs/SourceHanSans-VF.otf/retaingids benchmark.
pull/4317/head
Behdad Esfahbod 2 years ago
parent 1f4645c6fc
commit c8f6ae1df7
  1. 32
      src/hb-ot-var-hvar-table.hh
  2. BIN
      test/api/fonts/AdobeVFPrototype.ac.retaingids.otf
  3. BIN
      test/api/fonts/SourceSansVariable-Roman.abc.ttf
  4. BIN
      test/api/fonts/SourceSansVariable-Roman.ac.retaingids.ttf
  5. BIN
      test/api/fonts/SourceSansVariable-Roman.ac.ttf

@ -45,7 +45,8 @@ struct index_map_subset_plan_t
void init (const DeltaSetIndexMap &index_map,
hb_inc_bimap_t &outer_map,
hb_vector_t<hb_set_t *> &inner_sets,
const hb_subset_plan_t *plan)
const hb_subset_plan_t *plan,
bool bypass_empty = true)
{
map_count = 0;
outer_bit_count = 0;
@ -53,11 +54,10 @@ struct index_map_subset_plan_t
max_inners.init ();
output_map.init ();
if (&index_map == &Null (DeltaSetIndexMap)) return;
if (bypass_empty && !index_map.get_map_count ()) return;
unsigned int last_val = (unsigned int)-1;
hb_codepoint_t last_gid = HB_CODEPOINT_INVALID;
hb_codepoint_t num_gid = (hb_codepoint_t) hb_min (index_map.get_map_count (), plan->num_output_glyphs ());
outer_bit_count = (index_map.get_width () * 8) - index_map.get_inner_bit_count ();
max_inners.resize (inner_sets.length);
@ -68,24 +68,17 @@ struct index_map_subset_plan_t
unsigned count = new_to_old_gid_list.length;
for (unsigned j = count; j; j--)
{
hb_codepoint_t gid = new_to_old_gid_list[j - 1].first;
if (gid >= num_gid) continue;
hb_codepoint_t old_gid = new_to_old_gid_list[j - 1].second;
hb_codepoint_t gid = new_to_old_gid_list.arrayZ[j - 1].first;
hb_codepoint_t old_gid = new_to_old_gid_list.arrayZ[j - 1].second;
unsigned int v = index_map.map (old_gid);
if (last_gid == HB_CODEPOINT_INVALID)
{
if (gid + 1 != num_gid)
{
last_gid = gid + 1;
break;
}
last_val = v;
last_gid = gid;
continue;
}
if (v != last_val || gid + 1 != last_gid)
if (v != last_val)
break;
last_gid = gid;
@ -120,8 +113,6 @@ struct index_map_subset_plan_t
const hb_vector_t<hb_inc_bimap_t> &inner_maps,
const hb_subset_plan_t *plan)
{
if (input_map == &Null (DeltaSetIndexMap)) return;
for (unsigned int i = 0; i < max_inners.length; i++)
{
if (inner_maps[i].get_population () == 0) continue;
@ -183,7 +174,7 @@ struct hvarvvar_subset_plan_t
if (unlikely (!index_map_plans.length || !inner_sets.length || !inner_maps.length)) return;
bool retain_adv_map = false;
index_map_plans[0].init (*index_maps[0], outer_map, inner_sets, plan);
index_map_plans[0].init (*index_maps[0], outer_map, inner_sets, plan, false);
if (index_maps[0] == &Null (DeltaSetIndexMap))
{
retain_adv_map = plan->flags & HB_SUBSET_FLAGS_RETAIN_GIDS;
@ -200,15 +191,10 @@ struct hvarvvar_subset_plan_t
if (retain_adv_map)
{
hb_codepoint_t next_gid = 0;
for (const auto &_ : plan->new_to_old_gid_list)
{
hb_codepoint_t gid = _.first;
inner_maps[0].skip (gid - next_gid);
inner_maps[0].add (gid);
next_gid = gid + 1;
hb_codepoint_t old_gid = _.second;
inner_maps[0].add (old_gid);
}
}
else

Loading…
Cancel
Save