From 65d3db375cb51204ac971dcd2d978684ab8a9422 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Jan 2023 12:36:54 -0700 Subject: [PATCH] [subset-plan] Simplify user_axes_location allocation --- src/OT/glyf/glyf.hh | 6 +++--- src/hb-ot-layout-common.hh | 4 ++-- src/hb-ot-os2-table.hh | 8 ++++---- src/hb-ot-post-table.hh | 4 ++-- src/hb-ot-stat-table.hh | 8 ++++---- src/hb-ot-var-fvar-table.hh | 2 +- src/hb-subset-plan.cc | 23 +++++++++++------------ src/hb-subset-plan.hh | 4 +--- src/hb-subset.cc | 2 +- 9 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/OT/glyf/glyf.hh b/src/OT/glyf/glyf.hh index 3b7670669..d219d6fd3 100644 --- a/src/OT/glyf/glyf.hh +++ b/src/OT/glyf/glyf.hh @@ -429,10 +429,10 @@ glyf::_create_font_for_instancing (const hb_subset_plan_t *plan) const if (unlikely (font == hb_font_get_empty ())) return nullptr; hb_vector_t vars; - if (unlikely (!vars.alloc (plan->user_axes_location->get_population (), true))) + if (unlikely (!vars.alloc (plan->user_axes_location.get_population (), true))) return nullptr; - for (auto _ : *plan->user_axes_location) + for (auto _ : plan->user_axes_location) { hb_variation_t var; var.tag = _.first; @@ -441,7 +441,7 @@ glyf::_create_font_for_instancing (const hb_subset_plan_t *plan) const } #ifndef HB_NO_VAR - hb_font_set_variations (font, vars.arrayZ, plan->user_axes_location->get_population ()); + hb_font_set_variations (font, vars.arrayZ, plan->user_axes_location.get_population ()); #endif return font; } diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 2c1ccea40..16d079292 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -160,7 +160,7 @@ struct hb_subset_layout_context_t : script_langsys_map = &c_->plan->gsub_langsys; feature_index_map = &c_->plan->gsub_features; feature_substitutes_map = &c_->plan->gsub_feature_substitutes_map; - feature_record_cond_idx_map = c_->plan->user_axes_location->is_empty () ? nullptr : &c_->plan->gsub_feature_record_cond_idx_map; + feature_record_cond_idx_map = c_->plan->user_axes_location.is_empty () ? nullptr : &c_->plan->gsub_feature_record_cond_idx_map; } else { @@ -168,7 +168,7 @@ struct hb_subset_layout_context_t : script_langsys_map = &c_->plan->gpos_langsys; feature_index_map = &c_->plan->gpos_features; feature_substitutes_map = &c_->plan->gpos_feature_substitutes_map; - feature_record_cond_idx_map = c_->plan->user_axes_location->is_empty () ? nullptr : &c_->plan->gpos_feature_record_cond_idx_map; + feature_record_cond_idx_map = c_->plan->user_axes_location.is_empty () ? nullptr : &c_->plan->gpos_feature_record_cond_idx_map; } } diff --git a/src/hb-ot-os2-table.hh b/src/hb-ot-os2-table.hh index d63c9e0e8..3de2fec7a 100644 --- a/src/hb-ot-os2-table.hh +++ b/src/hb-ot-os2-table.hh @@ -213,20 +213,20 @@ struct OS2 OS2 *os2_prime = c->serializer->embed (this); if (unlikely (!os2_prime)) return_trace (false); - if (c->plan->user_axes_location->has (HB_TAG ('w','g','h','t')) && + if (c->plan->user_axes_location.has (HB_TAG ('w','g','h','t')) && !c->plan->pinned_at_default) { - float weight_class = c->plan->user_axes_location->get (HB_TAG ('w','g','h','t')); + float weight_class = c->plan->user_axes_location.get (HB_TAG ('w','g','h','t')); if (!c->serializer->check_assign (os2_prime->usWeightClass, roundf (hb_clamp (weight_class, 1.0f, 1000.0f)), HB_SERIALIZE_ERROR_INT_OVERFLOW)) return_trace (false); } - if (c->plan->user_axes_location->has (HB_TAG ('w','d','t','h')) && + if (c->plan->user_axes_location.has (HB_TAG ('w','d','t','h')) && !c->plan->pinned_at_default) { - float width = c->plan->user_axes_location->get (HB_TAG ('w','d','t','h')); + float width = c->plan->user_axes_location.get (HB_TAG ('w','d','t','h')); if (!c->serializer->check_assign (os2_prime->usWidthClass, roundf (map_wdth_to_widthclass (width)), HB_SERIALIZE_ERROR_INT_OVERFLOW)) diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index 0e8947c29..a1ee14587 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -102,10 +102,10 @@ struct post if (!serialize (c->serializer, glyph_names)) return_trace (false); - if (c->plan->user_axes_location->has (HB_TAG ('s','l','n','t')) && + if (c->plan->user_axes_location.has (HB_TAG ('s','l','n','t')) && !c->plan->pinned_at_default) { - float italic_angle = c->plan->user_axes_location->get (HB_TAG ('s','l','n','t')); + float italic_angle = c->plan->user_axes_location.get (HB_TAG ('s','l','n','t')); italic_angle = hb_max (-90.f, hb_min (italic_angle, 90.f)); post_prime->italicAngle.set_float (italic_angle); } diff --git a/src/hb-ot-stat-table.hh b/src/hb-ot-stat-table.hh index 59bb2dacc..3f4399b14 100644 --- a/src/hb-ot-stat-table.hh +++ b/src/hb-ot-stat-table.hh @@ -112,7 +112,7 @@ struct AxisValueFormat1 const hb_array_t axis_records) const { TRACE_SUBSET (this); - const hb_hashmap_t* user_axes_location = c->plan->user_axes_location; + const hb_hashmap_t* user_axes_location = &c->plan->user_axes_location; if (keep_axis_value (axis_records, user_axes_location)) return_trace (c->serializer->embed (this)); @@ -171,7 +171,7 @@ struct AxisValueFormat2 const hb_array_t axis_records) const { TRACE_SUBSET (this); - const hb_hashmap_t* user_axes_location = c->plan->user_axes_location; + const hb_hashmap_t* user_axes_location = &c->plan->user_axes_location; if (keep_axis_value (axis_records, user_axes_location)) return_trace (c->serializer->embed (this)); @@ -234,7 +234,7 @@ struct AxisValueFormat3 const hb_array_t axis_records) const { TRACE_SUBSET (this); - const hb_hashmap_t* user_axes_location = c->plan->user_axes_location; + const hb_hashmap_t* user_axes_location = &c->plan->user_axes_location; if (keep_axis_value (axis_records, user_axes_location)) return_trace (c->serializer->embed (this)); @@ -313,7 +313,7 @@ struct AxisValueFormat4 const hb_array_t axis_records) const { TRACE_SUBSET (this); - const hb_hashmap_t *user_axes_location = c->plan->user_axes_location; + const hb_hashmap_t *user_axes_location = &c->plan->user_axes_location; if (!keep_axis_value (axis_records, user_axes_location)) return_trace (false); diff --git a/src/hb-ot-var-fvar-table.hh b/src/hb-ot-var-fvar-table.hh index 79f42cd06..a384dfa53 100644 --- a/src/hb-ot-var-fvar-table.hh +++ b/src/hb-ot-var-fvar-table.hh @@ -56,7 +56,7 @@ struct InstanceRecord if (unlikely (!c->serializer->embed (flags))) return_trace (false); const hb_array_t coords = get_coordinates (axis_count); - const hb_hashmap_t *axes_location = c->plan->user_axes_location; + const hb_hashmap_t *axes_location = &c->plan->user_axes_location; for (unsigned i = 0 ; i < axis_count; i++) { uint32_t *axis_tag; diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 4a229310a..a4b654a22 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -160,7 +160,7 @@ static void _collect_layout_indices (hb_subset_plan_t *plan, #ifndef HB_NO_VAR // collect feature substitutes with variations - if (!plan->user_axes_location->is_empty ()) + if (!plan->user_axes_location.is_empty ()) { hb_hashmap_t, unsigned> conditionset_map; OT::hb_collect_feature_substitutes_with_var_context_t c = @@ -294,7 +294,7 @@ _closure_glyphs_lookups_features (hb_subset_plan_t *plan, // prune features table->prune_features (lookups, - plan->user_axes_location->is_empty () ? nullptr : feature_record_cond_idx_map, + plan->user_axes_location.is_empty () ? nullptr : feature_record_cond_idx_map, feature_substitutes_map, &feature_indices); hb_map_t duplicate_feature_map; @@ -335,9 +335,9 @@ _get_hb_font_with_variations (const hb_subset_plan_t *plan) hb_font_t *font = hb_font_create (plan->source); hb_vector_t vars; - vars.alloc (plan->user_axes_location->get_population ()); + vars.alloc (plan->user_axes_location.get_population ()); - for (auto _ : *plan->user_axes_location) + for (auto _ : plan->user_axes_location) { hb_variation_t var; var.tag = _.first; @@ -346,7 +346,7 @@ _get_hb_font_with_variations (const hb_subset_plan_t *plan) } #ifndef HB_NO_VAR - hb_font_set_variations (font, vars.arrayZ, plan->user_axes_location->get_population ()); + hb_font_set_variations (font, vars.arrayZ, plan->user_axes_location.get_population ()); #endif return font; } @@ -765,7 +765,7 @@ _nameid_closure (hb_face_t *face, static void _normalize_axes_location (hb_face_t *face, hb_subset_plan_t *plan) { - if (plan->user_axes_location->is_empty ()) + if (plan->user_axes_location.is_empty ()) return; hb_array_t axes = face->table.fvar->get_axes (); @@ -784,7 +784,7 @@ _normalize_axes_location (hb_face_t *face, hb_subset_plan_t *plan) hb_tag_t axis_tag = axis.get_axis_tag (); plan->axes_old_index_tag_map.set (old_axis_idx, axis_tag); - if (!plan->user_axes_location->has (axis_tag)) + if (!plan->user_axes_location.has (axis_tag)) { axis_not_pinned = true; plan->axes_index_map.set (old_axis_idx, new_axis_idx); @@ -792,7 +792,7 @@ _normalize_axes_location (hb_face_t *face, hb_subset_plan_t *plan) } else { - int normalized_v = axis.normalize_axis_value (plan->user_axes_location->get (axis_tag)); + int normalized_v = axis.normalize_axis_value (plan->user_axes_location.get (axis_tag)); if (has_avar && old_axis_idx < face->table.avar->get_axis_count ()) { normalized_v = seg_maps->map (normalized_v); @@ -857,9 +857,8 @@ hb_subset_plan_create_or_fail (hb_face_t *face, plan->gdef_varstore_inner_maps.init (); - plan->check_success (plan->user_axes_location = hb_hashmap_create ()); - if (plan->user_axes_location && input->axes_location) - *plan->user_axes_location = *input->axes_location; + if (input->axes_location) + plan->user_axes_location = *input->axes_location; plan->all_axes_pinned = false; plan->pinned_at_default = true; @@ -922,7 +921,7 @@ hb_subset_plan_create_or_fail (hb_face_t *face, plan->glyph_map->get(plan->unicode_to_new_gid_list.arrayZ[i].second); } - _nameid_closure (face, &plan->name_ids, plan->all_axes_pinned, plan->user_axes_location); + _nameid_closure (face, &plan->name_ids, plan->all_axes_pinned, &plan->user_axes_location); if (unlikely (plan->in_error ())) { hb_subset_plan_destroy (plan); return nullptr; diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index 71bb46d2d..193024e05 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -55,8 +55,6 @@ struct hb_subset_plan_t hb_map_destroy (glyph_map); hb_map_destroy (reverse_glyph_map); - hb_hashmap_destroy (user_axes_location); - #ifdef HB_EXPERIMENTAL_API if (name_table_overrides) { @@ -156,7 +154,7 @@ struct hb_subset_plan_t hb_hashmap_t axes_location; hb_vector_t normalized_coords; //user specified axes location map - hb_hashmap_t *user_axes_location; + hb_hashmap_t user_axes_location; //retained old axis index -> new axis index mapping in fvar axis array hb_map_t axes_index_map; //axis_index->axis_tag mapping in fvar axis array diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 71536e5f6..d3dc2f62a 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -469,7 +469,7 @@ _subset_table (hb_subset_plan_t *plan, case HB_OT_TAG_VVAR: return _subset (plan, buf); #endif case HB_OT_TAG_fvar: - if (plan->user_axes_location->is_empty ()) return _passthrough (plan, tag); + if (plan->user_axes_location.is_empty ()) return _passthrough (plan, tag); return _subset (plan, buf); case HB_OT_TAG_STAT: /*TODO(qxliu): change the condition as we support more complex