From 6289e475d9911526b303580e6717a81d3493e23f Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 17 Jun 2024 18:56:51 +0000 Subject: [PATCH] In _fill_unicode_and_glyph_map add a second unicode -> gid lookup which is general. --- src/hb-subset-plan.cc | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index df38ab395..98ae837f4 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -638,15 +638,16 @@ _remove_invalid_gids (hb_set_t *glyphs, glyphs->del_range (num_glyphs, HB_SET_VALUE_INVALID); } -template +template static void _fill_unicode_and_glyph_map(hb_subset_plan_t *plan, I unicode_iterator, - F unicode_to_gid) + F unicode_to_gid_for_iterator, + G unicode_to_gid_general) { for (hb_codepoint_t cp : unicode_iterator) { - hb_codepoint_t gid = unicode_to_gid(cp); + hb_codepoint_t gid = unicode_to_gid_for_iterator(cp); if (!GID_ALWAYS_EXISTS && gid == HB_MAP_VALUE_INVALID) { DEBUG_MSG(SUBSET, nullptr, "Drop U+%04X; no gid", cp); @@ -658,6 +659,15 @@ _fill_unicode_and_glyph_map(hb_subset_plan_t *plan, } } +template +static void +_fill_unicode_and_glyph_map(hb_subset_plan_t *plan, + I unicode_iterator, + F unicode_to_gid_for_iterator) +{ + _fill_unicode_and_glyph_map(plan, unicode_iterator, unicode_to_gid_for_iterator, unicode_to_gid_for_iterator); +} + static void _populate_unicodes_to_retain (const hb_set_t *unicodes, const hb_set_t *glyphs, @@ -721,11 +731,15 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes, plan->codepoint_to_glyph->alloc (unicodes->get_population () + glyphs->get_population ()); auto &gid_to_unicodes = plan->accelerator->gid_to_unicodes; + for (hb_codepoint_t gid : *glyphs) { auto unicodes = gid_to_unicodes.get (gid); _fill_unicode_and_glyph_map(plan, unicodes, [&] (hb_codepoint_t cp) { return gid; + }, + [&] (hb_codepoint_t cp) { + return unicode_glyphid_map->get(cp); }); } @@ -735,6 +749,9 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes, return HB_MAP_VALUE_INVALID; return unicode_glyphid_map->get(cp); + }, + [&] (hb_codepoint_t cp) { + return unicode_glyphid_map->get(cp); }); plan->unicode_to_new_gid_list.qsort (); @@ -750,6 +767,9 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes, if (!unicodes->has (cp) && !glyphs->has (gid)) return HB_MAP_VALUE_INVALID; return gid; + }, + [&] (hb_codepoint_t cp) { + return unicode_glyphid_map->get(cp); }); } }