From 36373ee15c209ba6d49f4a36aaece91a3cff2f55 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 25 Jun 2022 16:54:46 -0600 Subject: [PATCH] [glyf] Move add_gid_and_children to subset-plan where it belongs --- src/OT/glyf/glyf.hh | 25 ------------------------- src/hb-subset-plan.cc | 31 ++++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/OT/glyf/glyf.hh b/src/OT/glyf/glyf.hh index ab5d56b26..f51c25525 100644 --- a/src/OT/glyf/glyf.hh +++ b/src/OT/glyf/glyf.hh @@ -15,11 +15,6 @@ namespace OT { -#ifndef HB_MAX_COMPOSITE_OPERATIONS -#define HB_MAX_COMPOSITE_OPERATIONS 100000 -#endif - - /* * glyf -- TrueType Glyph Data * https://docs.microsoft.com/en-us/typography/opentype/spec/glyf @@ -453,26 +448,6 @@ struct glyf_accelerator_t return needs_padding_removal ? glyph.trim_padding () : glyph; } - unsigned - add_gid_and_children (hb_codepoint_t gid, - hb_set_t *gids_to_retain, - unsigned depth = 0, - unsigned operation_count = 0) const - { - if (unlikely (depth++ > HB_MAX_NESTING_LEVEL)) return operation_count; - if (unlikely (operation_count++ > HB_MAX_COMPOSITE_OPERATIONS)) return operation_count; - /* Check if is already visited */ - if (gids_to_retain->has (gid)) return operation_count; - - gids_to_retain->add (gid); - - for (auto item : glyph_for_gid (gid).get_composite_iterator ()) - operation_count = - add_gid_and_children (item.get_glyph_index (), gids_to_retain, depth, operation_count); - - return operation_count; - } - struct path_builder_t { hb_font_t *font; diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 8968eff4c..220f31590 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -347,6 +347,35 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes, } } +#ifndef HB_MAX_COMPOSITE_OPERATIONS +#define HB_MAX_COMPOSITE_OPERATIONS 100000 +#endif + +static unsigned +_glyf_add_gid_and_children (const OT::glyf_accelerator_t &glyf, + hb_codepoint_t gid, + hb_set_t *gids_to_retain, + unsigned depth = 0, + unsigned operation_count = 0) +{ + if (unlikely (depth++ > HB_MAX_NESTING_LEVEL)) return operation_count; + if (unlikely (operation_count++ > HB_MAX_COMPOSITE_OPERATIONS)) return operation_count; + /* Check if is already visited */ + if (gids_to_retain->has (gid)) return operation_count; + + gids_to_retain->add (gid); + + for (auto item : glyf.glyph_for_gid (gid).get_composite_iterator ()) + operation_count = + _glyf_add_gid_and_children (glyf, + item.get_glyph_index (), + gids_to_retain, + depth, + operation_count); + + return operation_count; +} + static void _populate_gids_to_retain (hb_subset_plan_t* plan, bool close_over_gsub, @@ -398,7 +427,7 @@ _populate_gids_to_retain (hb_subset_plan_t* plan, * composite glyphs. */ if (glyf.has_data ()) for (hb_codepoint_t gid : cur_glyphset) - glyf.add_gid_and_children (gid, plan->_glyphset); + _glyf_add_gid_and_children (glyf, gid, plan->_glyphset); else plan->_glyphset->union_ (cur_glyphset); #ifndef HB_NO_SUBSET_CFF