From cf123e6a0dae59131b028676ed919c5a09dae919 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 21 Jul 2022 10:21:57 -0600 Subject: [PATCH] [Coverage] Add get_population () --- src/OT/Layout/Common/Coverage.hh | 13 +++++++++++++ src/OT/Layout/Common/CoverageFormat1.hh | 5 +++++ src/OT/Layout/Common/CoverageFormat2.hh | 8 ++++++++ src/OT/Layout/Common/RangeRecord.hh | 6 ++++++ 4 files changed, 32 insertions(+) diff --git a/src/OT/Layout/Common/Coverage.hh b/src/OT/Layout/Common/Coverage.hh index f525edd7d..dc4b440d1 100644 --- a/src/OT/Layout/Common/Coverage.hh +++ b/src/OT/Layout/Common/Coverage.hh @@ -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 bool serialize (hb_serialize_context_t *c, Iterator glyphs) diff --git a/src/OT/Layout/Common/CoverageFormat1.hh b/src/OT/Layout/Common/CoverageFormat1.hh index 6531791f6..4a1e234e6 100644 --- a/src/OT/Layout/Common/CoverageFormat1.hh +++ b/src/OT/Layout/Common/CoverageFormat1.hh @@ -62,6 +62,11 @@ struct CoverageFormat1_3 return i; } + unsigned get_population () const + { + return glyphArray.len; + } + template bool serialize (hb_serialize_context_t *c, Iterator glyphs) diff --git a/src/OT/Layout/Common/CoverageFormat2.hh b/src/OT/Layout/Common/CoverageFormat2.hh index 9dd11ff55..4f34d2865 100644 --- a/src/OT/Layout/Common/CoverageFormat2.hh +++ b/src/OT/Layout/Common/CoverageFormat2.hh @@ -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 bool serialize (hb_serialize_context_t *c, Iterator glyphs) diff --git a/src/OT/Layout/Common/RangeRecord.hh b/src/OT/Layout/Common/RangeRecord.hh index 931c88df5..30edf1b0b 100644 --- a/src/OT/Layout/Common/RangeRecord.hh +++ b/src/OT/Layout/Common/RangeRecord.hh @@ -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); }