[subset/cff] Speed up subset_cff_fdselect

pull/4264/head
Behdad Esfahbod 1 year ago
parent 858a022358
commit 9cdc0b6419
  1. 31
      src/hb-ot-cff-common.hh
  2. 5
      src/hb-subset-cff-common.cc

@ -368,8 +368,11 @@ struct FDSelect0 {
return_trace (true); return_trace (true);
} }
hb_codepoint_t get_fd (hb_codepoint_t glyph) const unsigned get_fd (hb_codepoint_t glyph) const
{ return (hb_codepoint_t) fds[glyph]; } { return fds[glyph]; }
hb_pair_t<unsigned, hb_codepoint_t> get_fd_range (hb_codepoint_t glyph) const
{ return {fds[glyph], glyph + 1}; }
unsigned int get_size (unsigned int num_glyphs) const unsigned int get_size (unsigned int num_glyphs) const
{ return HBUINT8::static_size * num_glyphs; } { return HBUINT8::static_size * num_glyphs; }
@ -427,12 +430,20 @@ struct FDSelect3_4
return +1; return +1;
} }
hb_codepoint_t get_fd (hb_codepoint_t glyph) const unsigned get_fd (hb_codepoint_t glyph) const
{ {
auto *range = hb_bsearch (glyph, &ranges[0], nRanges () - 1, sizeof (ranges[0]), _cmp_range); auto *range = hb_bsearch (glyph, &ranges[0], nRanges () - 1, sizeof (ranges[0]), _cmp_range);
return range ? range->fd : ranges[nRanges () - 1].fd; return range ? range->fd : ranges[nRanges () - 1].fd;
} }
hb_pair_t<unsigned, hb_codepoint_t> get_fd_range (hb_codepoint_t glyph) const
{
auto *range = hb_bsearch (glyph, &ranges[0], nRanges () - 1, sizeof (ranges[0]), _cmp_range);
unsigned fd = range ? range->fd : ranges[nRanges () - 1].fd;
hb_codepoint_t end = range ? range[1].first : 0;
return {fd, end};
}
GID_TYPE &nRanges () { return ranges.len; } GID_TYPE &nRanges () { return ranges.len; }
GID_TYPE nRanges () const { return ranges.len; } GID_TYPE nRanges () const { return ranges.len; }
GID_TYPE &sentinel () { return StructAfter<GID_TYPE> (ranges[nRanges () - 1]); } GID_TYPE &sentinel () { return StructAfter<GID_TYPE> (ranges[nRanges () - 1]); }
@ -469,7 +480,7 @@ struct FDSelect
} }
} }
hb_codepoint_t get_fd (hb_codepoint_t glyph) const unsigned get_fd (hb_codepoint_t glyph) const
{ {
if (this == &Null (FDSelect)) return 0; if (this == &Null (FDSelect)) return 0;
@ -480,6 +491,18 @@ struct FDSelect
default:return 0; default:return 0;
} }
} }
/* Returns pair of fd and one after last glyph in range. */
hb_pair_t<unsigned, hb_codepoint_t> get_fd_range (hb_codepoint_t glyph) const
{
if (this == &Null (FDSelect)) return {0, 0};
switch (format)
{
case 0: return u.format0.get_fd_range (glyph);
case 3: return u.format3.get_fd_range (glyph);
default:return {0, 0};
}
}
bool sanitize (hb_sanitize_context_t *c, unsigned int fdcount) const bool sanitize (hb_sanitize_context_t *c, unsigned int fdcount) const
{ {

@ -68,6 +68,7 @@ hb_plan_subset_cff_fdselect (const hb_subset_plan_t *plan,
/* use hb_set to determine the subset of font dicts */ /* use hb_set to determine the subset of font dicts */
hb_set_t set; hb_set_t set;
hb_codepoint_t prev_fd = CFF_UNDEF_CODE; hb_codepoint_t prev_fd = CFF_UNDEF_CODE;
hb_pair_t<unsigned, hb_codepoint_t> last_range {0, 0};
auto it = hb_iter (plan->new_to_old_gid_list); auto it = hb_iter (plan->new_to_old_gid_list);
for (hb_codepoint_t gid = 0; gid < subset_num_glyphs; gid++) for (hb_codepoint_t gid = 0; gid < subset_num_glyphs; gid++)
{ {
@ -82,7 +83,9 @@ hb_plan_subset_cff_fdselect (const hb_subset_plan_t *plan,
/* fonttools retains FDSelect & font dicts for missing glyphs. do the same */ /* fonttools retains FDSelect & font dicts for missing glyphs. do the same */
old_glyph = gid; old_glyph = gid;
} }
unsigned fd = src.get_fd (old_glyph); if (old_glyph >= last_range.second)
last_range = src.get_fd_range (old_glyph);
unsigned fd = last_range.first;
set.add (fd); set.add (fd);
if (fd != prev_fd) if (fd != prev_fd)

Loading…
Cancel
Save