[subset/cff1] Speed up plan_subset_charset

This commit is contained in:
Behdad Esfahbod 2023-06-26 14:17:44 -06:00
parent d3f90a8ca7
commit 81e2db7cbc
3 changed files with 17 additions and 5 deletions

View file

@ -55,7 +55,7 @@ struct code_pair_t
using str_buff_t = hb_vector_t<unsigned char>;
using str_buff_vec_t = hb_vector_t<str_buff_t>;
using glyph_to_sid_map_t = hb_vector_t<uint16_t>;
using glyph_to_sid_map_t = hb_vector_t<code_pair_t>;
/* CFF INDEX */
template <typename COUNT>

View file

@ -334,7 +334,7 @@ struct Charset0
{
mapping->resize (num_glyphs, false);
for (hb_codepoint_t gid = 1; gid < num_glyphs; gid++)
mapping->arrayZ[gid] = sids[gid - 1];
mapping->arrayZ[gid] = {sids[gid - 1], gid + 1};
}
hb_codepoint_t get_glyph (hb_codepoint_t sid, unsigned int num_glyphs) const
@ -440,8 +440,9 @@ struct Charset1_2 {
{
hb_codepoint_t sid = ranges[i].first;
unsigned count = ranges[i].nLeft + 1;
unsigned last = gid + count;
for (unsigned j = 0; j < count; j++)
mapping->arrayZ[gid++] = sid++;
mapping->arrayZ[gid++] = {sid++, last};
if (gid >= num_glyphs)
break;
@ -1275,7 +1276,7 @@ struct cff1
auto *mapping = (glyph_to_sid_map_t *) hb_malloc (sizeof (glyph_to_sid_map_t));
if (unlikely (!mapping)) return nullptr;
mapping = new (mapping) glyph_to_sid_map_t ();
mapping->push (0);
mapping->push (code_pair_t {0, 1});
charset->collect_glyph_to_sid_map (mapping, num_glyphs);
return mapping;
}

View file

@ -533,6 +533,7 @@ struct cff1_subset_plan
if (it->first == 0) it++;
auto _ = *it;
bool not_is_cid = !acc.is_CID ();
bool skip = !not_is_cid && glyph_to_sid_map;
if (not_is_cid)
sidmap.alloc (num_glyphs);
for (glyph = 1; glyph < num_glyphs; glyph++)
@ -548,7 +549,11 @@ struct cff1_subset_plan
/* Retain the SID for the old missing glyph ID */
old_glyph = glyph;
}
unsigned sid = glyph_to_sid_map ? glyph_to_sid_map->arrayZ[old_glyph] : acc.glyph_to_sid (old_glyph, &glyph_to_sid_cache);
unsigned sid;
if (glyph_to_sid_map)
sid = glyph_to_sid_map->arrayZ[old_glyph].code;
else
sid = acc.glyph_to_sid (old_glyph, &glyph_to_sid_cache);
if (not_is_cid)
sid = sidmap.add (sid);
@ -557,6 +562,12 @@ struct cff1_subset_plan
{
code_pair_t pair { sid, glyph };
subset_charset_ranges.push (pair);
if (skip && glyph == old_glyph)
{
glyph = hb_min (_.first - 1, glyph_to_sid_map->arrayZ[old_glyph].glyph - 1);
sid += glyph - old_glyph;
}
}
last_sid = sid;
}