diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index dc2d59b39..27dbd3475 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -211,15 +211,17 @@ struct hmtxvmtx } auto it = - + hb_range (c->plan->num_output_glyphs ()) - | hb_map ([c, &_mtx, mtx_map] (unsigned _) + + hb_enumerate (c->plan->new_to_old_gid_list) + | hb_map ([c, &_mtx, mtx_map] (const hb_pair_t &_) { - hb_pair_t *v = nullptr; - if (!mtx_map->has (_, &v)) + hb_codepoint_t new_gid = _.first; + hb_codepoint_t old_gid = _.second; + if (old_gid == HB_MAP_VALUE_INVALID) + return hb_pair (0u, 0); + + hb_pair_t *v = nullptr; + if (!mtx_map->has (new_gid, &v)) { - hb_codepoint_t old_gid; - if (!c->plan->old_gid_for_new_gid (_, &old_gid)) - return hb_pair (0u, 0); int lsb = 0; if (!_mtx.get_leading_bearing_without_var_unscaled (old_gid, &lsb)) (void) _glyf_get_leading_bearing_without_var_unscaled (c->plan->source, old_gid, !T::is_horizontal, &lsb); diff --git a/src/hb-subset-plan-member-list.hh b/src/hb-subset-plan-member-list.hh index c0ccd5d0c..4794f9b5f 100644 --- a/src/hb-subset-plan-member-list.hh +++ b/src/hb-subset-plan-member-list.hh @@ -35,6 +35,8 @@ HB_SUBSET_PLAN_MEMBER (hb_set_t, unicodes) HB_SUBSET_PLAN_MEMBER (hb_sorted_vector_t E(>), unicode_to_new_gid_list) +HB_SUBSET_PLAN_MEMBER (hb_vector_t, new_to_old_gid_list) + // name_ids we would like to retain HB_SUBSET_PLAN_MEMBER (hb_set_t, name_ids) diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 94fb1be36..b6558e945 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -755,7 +755,6 @@ _populate_gids_to_retain (hb_subset_plan_t* plan, _remove_invalid_gids (&plan->_glyphset, plan->source->get_num_glyphs ()); - #ifndef HB_NO_VAR if (!drop_tables->has (HB_OT_TAG_GDEF)) _collect_layout_variation_indices (plan); @@ -783,6 +782,7 @@ _create_old_gid_to_new_gid_map (const hb_face_t *face, const hb_map_t *requested_glyph_map, hb_map_t *glyph_map, /* OUT */ hb_map_t *reverse_glyph_map, /* OUT */ + hb_vector_t *new_to_old_gid_list /* OUT */, unsigned int *num_glyphs /* OUT */) { unsigned pop = all_gids_to_retain->get_population (); @@ -863,6 +863,12 @@ _create_old_gid_to_new_gid_map (const hb_face_t *face, | hb_sink (glyph_map) ; + auto &l = *new_to_old_gid_list; + l.resize (*num_glyphs); + hb_memset (l.arrayZ, 0xff, l.length * sizeof (l[0])); + for (auto _ : *reverse_glyph_map) + l[_.first] = _.second; + return true; } @@ -1086,6 +1092,7 @@ hb_subset_plan_t::hb_subset_plan_t (hb_face_t *face, &input->glyph_map, glyph_map, reverse_glyph_map, + &new_to_old_gid_list, &_num_output_glyphs))) { return; }