mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 23:11:04 +01:00
[subset/cff] Speed up subset_cff_fdselect
This commit is contained in:
1 parent
858a022358
commit
9cdc0b6419
2 files changed
+31
-5
No files matched your search
+27
-4
@@ -368,8 +368,11 @@ struct FDSelect0 {
|
||||
return_trace (true);
|
||||
}
|
||||
|
||||
hb_codepoint_t get_fd (hb_codepoint_t glyph) const
|
||||
{ return (hb_codepoint_t) fds[glyph]; }
|
||||
unsigned get_fd (hb_codepoint_t glyph) const
|
||||
{ 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
|
||||
{ return HBUINT8::static_size * num_glyphs; }
|
||||
@@ -427,12 +430,20 @@ struct FDSelect3_4
|
||||
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);
|
||||
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 () const { return ranges.len; }
|
||||
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;
|
||||
|
||||
@@ -480,6 +491,18 @@ struct FDSelect
|
||||
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
|
||||
{
|
||||
|
||||
@@ -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 */
|
||||
hb_set_t set;
|
||||
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);
|
||||
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 */
|
||||
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);
|
||||
|
||||
if (fd != prev_fd)
|
||||
|
||||
Reference in new issue
Block a user