diff --git a/src/hb-algs.hh b/src/hb-algs.hh index d63d4f30d..d85a4afe1 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -524,6 +524,18 @@ struct hb_pair_t bool operator > (const pair_t& o) const { return first > o.first || (first == o.first && second > o.second); } bool operator <= (const pair_t& o) const { return !(*this > o); } + static int cmp (const void *pa, const void *pb) + { + pair_t *a = (pair_t *) pa; + pair_t *b = (pair_t *) pb; + + if (a->first < b->first) return -1; + if (a->first > b->first) return +1; + if (a->second < b->second) return -1; + if (a->second > b->second) return +1; + return 0; + } + friend void swap (hb_pair_t& a, hb_pair_t& b) { hb_swap (a.first, b.first); diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 76666ad17..943cf082d 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -541,10 +541,15 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes, } for (hb_codepoint_t cp : *unicodes) { + /* Don't double-add entry. */ + if (plan->codepoint_to_glyph->has (cp)) + continue; + hb_codepoint_t gid = (*unicode_glyphid_map)[cp]; plan->codepoint_to_glyph->set (cp, gid); plan->unicode_to_new_gid_list.push (hb_pair (cp, gid)); } + plan->unicode_to_new_gid_list.qsort (); } else { @@ -571,7 +576,7 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes, auto &arr = plan->unicode_to_new_gid_list; if (arr.length) { - plan->unicodes->add_array (&arr.arrayZ->first, arr.length, sizeof (*arr.arrayZ)); + plan->unicodes->add_sorted_array (&arr.arrayZ->first, arr.length, sizeof (*arr.arrayZ)); plan->_glyphset_gsub->add_array (&arr.arrayZ->second, arr.length, sizeof (*arr.arrayZ)); } } diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index 1dea7aad9..0b162ee7b 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -115,7 +115,7 @@ struct hb_subset_plan_t // For each cp that we'd like to retain maps to the corresponding gid. hb_set_t *unicodes; - hb_vector_t> unicode_to_new_gid_list; + hb_sorted_vector_t> unicode_to_new_gid_list; // name_ids we would like to retain hb_set_t *name_ids;