[subset-plan] Sort unicode_to_new_gid_list when needed

This commit is contained in:
Behdad Esfahbod 2022-12-02 16:25:26 -07:00
parent 1a40da4ad1
commit ff419789ef
3 changed files with 19 additions and 2 deletions

View File

@ -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 first > o.first || (first == o.first && second > o.second); }
bool operator <= (const pair_t& o) const { return !(*this > o); } 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) friend void swap (hb_pair_t& a, hb_pair_t& b)
{ {
hb_swap (a.first, b.first); hb_swap (a.first, b.first);

View File

@ -541,10 +541,15 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes,
} }
for (hb_codepoint_t cp : *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]; hb_codepoint_t gid = (*unicode_glyphid_map)[cp];
plan->codepoint_to_glyph->set (cp, gid); plan->codepoint_to_glyph->set (cp, gid);
plan->unicode_to_new_gid_list.push (hb_pair (cp, gid)); plan->unicode_to_new_gid_list.push (hb_pair (cp, gid));
} }
plan->unicode_to_new_gid_list.qsort ();
} }
else else
{ {
@ -571,7 +576,7 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes,
auto &arr = plan->unicode_to_new_gid_list; auto &arr = plan->unicode_to_new_gid_list;
if (arr.length) 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)); plan->_glyphset_gsub->add_array (&arr.arrayZ->second, arr.length, sizeof (*arr.arrayZ));
} }
} }

View File

@ -115,7 +115,7 @@ struct hb_subset_plan_t
// For each cp that we'd like to retain maps to the corresponding gid. // For each cp that we'd like to retain maps to the corresponding gid.
hb_set_t *unicodes; hb_set_t *unicodes;
hb_vector_t<hb_pair_t<hb_codepoint_t, hb_codepoint_t>> unicode_to_new_gid_list; hb_sorted_vector_t<hb_pair_t<hb_codepoint_t, hb_codepoint_t>> unicode_to_new_gid_list;
// name_ids we would like to retain // name_ids we would like to retain
hb_set_t *name_ids; hb_set_t *name_ids;