[subset] Switch building of glyph maps in subset plan to use iterators.

This commit is contained in:
Garret Rieger 2019-05-08 16:33:03 -07:00
parent 971020eca7
commit 5e3cbed048
2 changed files with 27 additions and 29 deletions

View File

@ -218,9 +218,7 @@ struct hb_pair_t
hb_pair_t (const pair_t& o) : first (o.first), second (o.second) {} hb_pair_t (const pair_t& o) : first (o.first), second (o.second) {}
hb_pair_t<T1, T2> reverse () const hb_pair_t<T1, T2> reverse () const
{ { return hb_pair_t<T1, T2> (second, first); }
return hb_pair_t<T1, T2> (second, first);
}
bool operator == (const pair_t& o) const { return first == o.first && second == o.second; } bool operator == (const pair_t& o) const { return first == o.first && second == o.second; }

View File

@ -155,34 +155,34 @@ _populate_gids_to_retain (hb_face_t *face,
static void static void
_create_old_gid_to_new_gid_map (const hb_face_t *face, _create_old_gid_to_new_gid_map (const hb_face_t *face,
bool retain_gids, bool retain_gids,
hb_set_t *all_gids_to_retain, const hb_set_t *all_gids_to_retain,
hb_map_t *glyph_map, /* OUT */ hb_map_t *glyph_map, /* OUT */
hb_map_t *reverse_glyph_map, /* OUT */ hb_map_t *reverse_glyph_map, /* OUT */
unsigned int *num_glyphs /* OUT */) unsigned int *num_glyphs /* OUT */)
{ {
hb_codepoint_t gid = HB_SET_VALUE_INVALID;
unsigned int length = 0;
for (unsigned int i = 0; all_gids_to_retain->next (&gid); i++) {
if (!retain_gids) if (!retain_gids)
{ {
glyph_map->set (gid, i); + hb_enumerate (hb_iter (all_gids_to_retain), (hb_codepoint_t) 0)
reverse_glyph_map->set (i, gid); | hb_sink (reverse_glyph_map)
} ;
else *num_glyphs = reverse_glyph_map->get_population ();
{ } else {
glyph_map->set (gid, gid); + hb_iter (all_gids_to_retain)
reverse_glyph_map->set (gid, gid); | hb_map ([=] (hb_codepoint_t _) {
} return hb_pair_t<hb_codepoint_t, hb_codepoint_t> (_, _);
++length; })
} | hb_sink (reverse_glyph_map);
if (!retain_gids || length == 0) ;
{
*num_glyphs = length; // TODO(grieger): Should we discard glyphs past the max glyph to keep?
} // *num_glyphs = + hb_iter (all_gids_to_retain) | hb_reduce (hb_max, 0);
else
{
*num_glyphs = face->get_num_glyphs (); *num_glyphs = face->get_num_glyphs ();
} }
+ reverse_glyph_map->iter ()
| hb_map (&hb_pair_t<hb_codepoint_t, hb_codepoint_t>::reverse)
| hb_sink (glyph_map)
;
} }
/** /**