[subset-plan] Simplify user_axes_location allocation

This commit is contained in:
Behdad Esfahbod 2023-01-11 12:36:54 -07:00
parent 60418fcb95
commit 65d3db375c
9 changed files with 29 additions and 32 deletions

View File

@ -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<hb_variation_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;
}

View File

@ -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;
}
}

View File

@ -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))

View File

@ -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);
}

View File

@ -112,7 +112,7 @@ struct AxisValueFormat1
const hb_array_t<const StatAxisRecord> axis_records) const
{
TRACE_SUBSET (this);
const hb_hashmap_t<hb_tag_t, float>* user_axes_location = c->plan->user_axes_location;
const hb_hashmap_t<hb_tag_t, float>* 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<const StatAxisRecord> axis_records) const
{
TRACE_SUBSET (this);
const hb_hashmap_t<hb_tag_t, float>* user_axes_location = c->plan->user_axes_location;
const hb_hashmap_t<hb_tag_t, float>* 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<const StatAxisRecord> axis_records) const
{
TRACE_SUBSET (this);
const hb_hashmap_t<hb_tag_t, float>* user_axes_location = c->plan->user_axes_location;
const hb_hashmap_t<hb_tag_t, float>* 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<const StatAxisRecord> axis_records) const
{
TRACE_SUBSET (this);
const hb_hashmap_t<hb_tag_t, float> *user_axes_location = c->plan->user_axes_location;
const hb_hashmap_t<hb_tag_t, float> *user_axes_location = &c->plan->user_axes_location;
if (!keep_axis_value (axis_records, user_axes_location))
return_trace (false);

View File

@ -56,7 +56,7 @@ struct InstanceRecord
if (unlikely (!c->serializer->embed (flags))) return_trace (false);
const hb_array_t<const F16DOT16> coords = get_coordinates (axis_count);
const hb_hashmap_t<hb_tag_t, float> *axes_location = c->plan->user_axes_location;
const hb_hashmap_t<hb_tag_t, float> *axes_location = &c->plan->user_axes_location;
for (unsigned i = 0 ; i < axis_count; i++)
{
uint32_t *axis_tag;

View File

@ -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<hb::shared_ptr<hb_map_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<hb_variation_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<const OT::AxisRecord> 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<hb_tag_t, float> ());
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;

View File

@ -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<hb_tag_t, int> axes_location;
hb_vector_t<int> normalized_coords;
//user specified axes location map
hb_hashmap_t<hb_tag_t, float> *user_axes_location;
hb_hashmap_t<hb_tag_t, float> 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

View File

@ -469,7 +469,7 @@ _subset_table (hb_subset_plan_t *plan,
case HB_OT_TAG_VVAR: return _subset<const OT::VVAR> (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<const OT::fvar> (plan, buf);
case HB_OT_TAG_STAT:
/*TODO(qxliu): change the condition as we support more complex