From feb23892a36a7c855306db6d21521d5e8362bdf7 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Thu, 7 Jun 2018 14:32:34 -0700 Subject: [PATCH] [subset] Use gsub closure if ot layout is not being dropped. --- src/hb-ot-layout.cc | 10 ++++++++-- src/hb-subset-plan.cc | 20 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 108144388..e8d4bcae1 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -973,8 +973,14 @@ hb_ot_layout_lookups_substitute_closure (hb_face_t *face, do { glyphs_length = glyphs->get_population (); - for (hb_codepoint_t lookup_index = HB_SET_VALUE_INVALID; hb_set_next (lookups, &lookup_index);) - gsub.get_lookup (lookup_index).closure (&c, lookup_index); + if (lookups != nullptr) + { + for (hb_codepoint_t lookup_index = HB_SET_VALUE_INVALID; hb_set_next (lookups, &lookup_index);) + gsub.get_lookup (lookup_index).closure (&c, lookup_index); + } else { + for (unsigned int i = 0; i < gsub.get_lookup_count (); i++) + gsub.get_lookup (i).closure (&c, i); + } } while (glyphs_length != glyphs->get_population ()); } diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 53f83ee8c..55c4e3f61 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -53,9 +53,22 @@ _add_gid_and_children (const OT::glyf::accelerator_t &glyf, } } +static void +_gsub_closure (hb_face_t *face, hb_set_t *gids_to_retain) +{ + // TODO(grieger): This uses all lookups, instead collect + // the set of lookups that are relevant. + // See fontTools implementation. + hb_ot_layout_lookups_substitute_closure (face, + nullptr, + gids_to_retain); +} + + static void _populate_gids_to_retain (hb_face_t *face, const hb_set_t *unicodes, + bool close_over_gsub, hb_set_t *unicodes_to_retain, hb_map_t *codepoint_to_glyph, hb_vector_t *glyphs) @@ -82,10 +95,12 @@ _populate_gids_to_retain (hb_face_t *face, initial_gids_to_retain->add (gid); } + if (close_over_gsub) + // Add all glyphs needed for GSUB substitutions. + _gsub_closure (face, initial_gids_to_retain); + // Populate a full set of glyphs to retain by adding all referenced // composite glyphs. - // TODO expand with glyphs reached by G* - hb_codepoint_t gid = HB_SET_VALUE_INVALID; hb_set_t *all_gids_to_retain = hb_set_create (); while (initial_gids_to_retain->next (&gid)) @@ -141,6 +156,7 @@ hb_subset_plan_create (hb_face_t *face, _populate_gids_to_retain (face, input->unicodes, + !plan->drop_ot_layout, plan->unicodes, plan->codepoint_to_glyph, &plan->glyphs);