diff --git a/src/hb-limits.hh b/src/hb-limits.hh index 901a6cc0d..006db23f7 100644 --- a/src/hb-limits.hh +++ b/src/hb-limits.hh @@ -259,11 +259,12 @@ hb_budget_spend (int64_t &budget, unsigned int cost, unsigned int mult = 1) #define HB_BUDGET_SUBSET_GLYF ((int64_t) 1 << 28) #endif -/* The flat floor for one pass of the subsetter over the charstrings of - * a CFF or CFF2 table, in operators and operands interpreted. Glyphs - * can share subroutines, so neither HB_CFF_MAX_OPS per glyph nor the - * table size bounds that work. Running out fails the charstring being - * interpreted, as exceeding HB_CFF_MAX_OPS does. */ +/* The flat floor for the subsetter's work on the charstrings of a CFF or + * CFF2 table, in operators and operands interpreted, shared by all passes + * of one subset over them. Glyphs can share subroutines, so neither + * HB_CFF_MAX_OPS per glyph nor the table size bounds that work. Running + * out fails the charstring being interpreted, as exceeding HB_CFF_MAX_OPS + * does. */ #ifndef HB_BUDGET_SUBSET_CFF #define HB_BUDGET_SUBSET_CFF ((int64_t) 1 << 24) #endif diff --git a/src/hb-ot-cff-common.hh b/src/hb-ot-cff-common.hh index 6c0081262..0d02e0c23 100644 --- a/src/hb-ot-cff-common.hh +++ b/src/hb-ot-cff-common.hh @@ -56,7 +56,7 @@ static inline const Type& StructAtOffsetOrNull (const void *P, int offset, hb_sa return obj; } -/* Work budget of one pass over the charstrings of the table in blob. */ +/* Charstring work budget of one subset of the table in blob. */ static inline int64_t get_subset_budget (const hb_blob_t *blob) { diff --git a/src/hb-subset-cff-common.hh b/src/hb-subset-cff-common.hh index 27dd59865..d3b875ebb 100644 --- a/src/hb-subset-cff-common.hh +++ b/src/hb-subset-cff-common.hh @@ -416,7 +416,7 @@ struct subr_flattener_t unsigned count = plan->num_output_glyphs (); if (!flat_charstrings.resize_exact (count)) return false; - int64_t budget = get_subset_budget (acc.get_blob ()); + int64_t *budget = plan->cff_budget (get_subset_budget (acc.get_blob ())); for (unsigned int i = 0; i < count; i++) { hb_codepoint_t glyph; @@ -441,7 +441,7 @@ struct subr_flattener_t plan, command_capture ? &(*command_capture)[i] : nullptr }; - if (unlikely (!interp.interpret (param, &budget))) + if (unlikely (!interp.interpret (param, budget))) return false; } return true; @@ -936,7 +936,7 @@ struct subr_subsetter_t bool coalesce = !(plan->flags & HB_SUBSET_FLAGS_NO_HINTING) && !plan->inprogress_accelerator; - int64_t budget = get_subset_budget (acc.get_blob ()); + int64_t *budget = plan->cff_budget (get_subset_budget (acc.get_blob ())); /* phase 1 & 2 */ for (auto _ : plan->new_to_old_gid_list) @@ -973,7 +973,7 @@ struct subr_subsetter_t plan->flags & HB_SUBSET_FLAGS_NO_HINTING, coalesce); - if (unlikely (!interp.interpret (param, &budget))) + if (unlikely (!interp.interpret (param, budget))) return false; /* complete parsed string esp. copy CFF1 width or CFF2 vsindex to the parsed charstring for encoding */ @@ -989,7 +989,7 @@ struct subr_subsetter_t &closures.local_closures[fd], plan->flags & HB_SUBSET_FLAGS_NO_HINTING); - drop_hints_param_t drop (&budget); + drop_hints_param_t drop (budget); if (drop_hints_in_str (parsed_charstrings[new_glyph], param, drop)) { parsed_charstrings[new_glyph].set_hint_dropped (); diff --git a/src/hb-subset-cff2.cc b/src/hb-subset-cff2.cc index a87b0e094..3e3ef1a09 100644 --- a/src/hb-subset-cff2.cc +++ b/src/hb-subset-cff2.cc @@ -1221,7 +1221,7 @@ struct cff2_subset_plan hb_vector_t round_charstrings; if (unlikely (!round_charstrings.resize (num_glyphs))) return false; hb_set_t used_fds; - int64_t budget = CFF::get_subset_budget (acc.get_blob ()); + int64_t *budget = plan->cff_budget (CFF::get_subset_budget (acc.get_blob ())); for (unsigned int i = 0; i < num_glyphs; i++) { hb_codepoint_t glyph; @@ -1239,7 +1239,7 @@ struct cff2_subset_plan cff2_usage_param_t param; param.instancing = partial_instancing ? &instancing : nullptr; param.drop_hints = drop_hints; - if (unlikely (!interp.interpret (param, &budget))) + if (unlikely (!interp.interpret (param, budget))) return false; round_charstrings.arrayZ[i] = param.has_blend && !param.has_flex1; } @@ -1271,7 +1271,6 @@ struct cff2_subset_plan return false; if (capture_commands && !charstring_commands.resize_exact (num_glyphs)) return false; - budget = CFF::get_subset_budget (acc.get_blob ()); for (unsigned int i = 0; i < num_glyphs; i++) { hb_codepoint_t glyph; @@ -1296,7 +1295,7 @@ struct cff2_subset_plan cff2_cs_rounding_t rounding; if (round_charstrings.arrayZ[i]) param.rounding = &rounding; param.instancer = partial_instancing ? &instancing : nullptr; - if (unlikely (!interp.interpret (param, &budget))) + if (unlikely (!interp.interpret (param, budget))) return false; } } diff --git a/src/hb-subset-plan-var.cc b/src/hb-subset-plan-var.cc index 1a1cd7276..d59c1808d 100644 --- a/src/hb-subset-plan-var.cc +++ b/src/hb-subset-plan-var.cc @@ -732,14 +732,14 @@ update_instance_metrics_map_from_cff2 (hb_subset_plan_t *plan) if (_vmtx.has_data () && _vmtx.var_table.get_length ()) vvar_store_cache = _vmtx.var_table->get_var_store ().create_cache (); - int64_t budget = CFF::get_subset_budget (cff2.get_blob ()); + int64_t *budget = plan->cff_budget (CFF::get_subset_budget (cff2.get_blob ())); for (auto p : *plan->glyph_map) { hb_codepoint_t old_gid = p.first; hb_codepoint_t new_gid = p.second; if (!cff2.get_extents_at (font, old_gid, &extents, hb_array (font->coords, font->num_coords), - &budget)) + budget)) continue; bool has_bounds_info = true; if (extents.x_bearing == 0 && extents.width == 0 && @@ -799,7 +799,7 @@ update_instance_metrics_map_from_cff2 (hb_subset_plan_t *plan) plan->bounds_height_vec[new_gid] = hb_saturate_neg (extents.height); } } - plan->check_success (budget > 0); + plan->check_success (*budget > 0); /* No glyph contributed bounds: do not serialize the accumulator's * inverted sentinels into head (or a downgraded CFF FontBBox). */ if (plan->head_maxp_info.xMin > plan->head_maxp_info.xMax) diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 34a8a716d..224ea2fdf 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -533,11 +533,11 @@ _populate_gids_to_retain (hb_subset_plan_t* plan, bool has_seac = false; if (cff->is_valid ()) { - int64_t budget = CFF::get_subset_budget (cff->get_blob ()); + int64_t *budget = plan->cff_budget (CFF::get_subset_budget (cff->get_blob ())); for (hb_codepoint_t gid : cur_glyphset) - if (_add_cff_seac_components (*cff, gid, &plan->_glyphset, &budget)) + if (_add_cff_seac_components (*cff, gid, &plan->_glyphset, budget)) has_seac = true; - plan->check_success (budget > 0); + plan->check_success (*budget > 0); } plan->has_seac = has_seac; } diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index 3c7356caf..b5a55a43a 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -205,6 +205,10 @@ struct hb_subset_plan_t // whether we're doing avar2 partial instancing bool has_avar2; + // see cff_budget () + mutable int64_t _cff_budget = 0; + mutable bool _cff_budget_set = false; + #define HB_SUBSET_PLAN_MEMBER(Type, Name) Type Name; #include "hb-subset-plan-member-list.hh" #undef HB_SUBSET_PLAN_MEMBER @@ -260,6 +264,18 @@ struct hb_subset_plan_t return successful; } + /* Charstring work budget shared by every CFF / CFF2 pass of this + * subset; the first caller sizes it. */ + int64_t *cff_budget (int64_t initial) const + { + if (!_cff_budget_set) + { + _cff_budget = initial; + _cff_budget_set = true; + } + return &_cff_budget; + } + /* * The set of input glyph ids which will be retained in the subset. * Does NOT include ids kept due to retain_gids. You probably want to use