[Coverage] Add get_population ()

This commit is contained in:
Behdad Esfahbod 2022-07-21 10:21:57 -06:00
parent 2ad3c0c770
commit cf123e6a0d
4 changed files with 32 additions and 0 deletions

View File

@ -95,6 +95,19 @@ struct Coverage
}
}
unsigned get_population () const
{
switch (u.format) {
case 1: return u.format1.get_population ();
case 2: return u.format2.get_population ();
#ifndef HB_NO_BORING_EXPANSION
case 3: return u.format3.get_population ();
case 4: return u.format4.get_population ();
#endif
default:return NOT_COVERED;
}
}
template <typename Iterator,
hb_requires (hb_is_sorted_source_of (Iterator, hb_codepoint_t))>
bool serialize (hb_serialize_context_t *c, Iterator glyphs)

View File

@ -62,6 +62,11 @@ struct CoverageFormat1_3
return i;
}
unsigned get_population () const
{
return glyphArray.len;
}
template <typename Iterator,
hb_requires (hb_is_sorted_source_of (Iterator, hb_codepoint_t))>
bool serialize (hb_serialize_context_t *c, Iterator glyphs)

View File

@ -65,6 +65,14 @@ struct CoverageFormat2_4
: NOT_COVERED;
}
unsigned get_population () const
{
unsigned ret = 0;
for (const auto &r : rangeRecord)
ret += r.get_population (); // TODO Overflow
return ret;
}
template <typename Iterator,
hb_requires (hb_is_sorted_source_of (Iterator, hb_codepoint_t))>
bool serialize (hb_serialize_context_t *c, Iterator glyphs)

View File

@ -51,6 +51,12 @@ struct RangeRecord
int cmp (hb_codepoint_t g) const
{ return g < first ? -1 : g <= last ? 0 : +1; }
unsigned get_population () const
{
if (unlikely (last < first)) return 0;
return (last - first + 1);
}
bool intersects (const hb_set_t *glyphs) const
{ return glyphs->intersects (first, last); }