diff --git a/src/graph/test-classdef-graph.cc b/src/graph/test-classdef-graph.cc index a61bbb328..d82ffc3e9 100644 --- a/src/graph/test-classdef-graph.cc +++ b/src/graph/test-classdef-graph.cc @@ -327,9 +327,47 @@ static void test_running_class_size_estimates_with_locally_consecutive_glyphs () hb_always_assert(check_add_class_def_size(estimator, map, 3, {2, 3})); } +static void +test_class_def_intersects_class () +{ + /* Range count, then first/last/class for each range. Include gaps, + * adjacent ranges, explicit class zero, and ranges starting at gid 0. */ + const unsigned cases[][7] = { + {0, 0, 0, 0, 0, 0, 0}, + {1, 0, 3, 1, 0, 0, 0}, + {1, 0, 7, 1, 0, 0, 0}, + {2, 0, 1, 1, 4, 5, 2}, + {2, 0, 1, 1, 2, 3, 2}, + {2, 0, 1, 0, 4, 5, 2}, + {2, 1, 2, 1, 4, 5, 2}, + }; + for (const auto &ranges : cases) + { + OT::HBUINT16 data[8]; + data[0] = 2; + for (unsigned i = 0; i < 7; i++) + data[i + 1] = ranges[i]; + const auto &class_def = *reinterpret_cast (data); + for (unsigned mask = 0; mask < 256; mask++) + { + hb_set_t glyphs; + for (unsigned g = 0; g < 8; g++) + if (mask & (1u << g)) glyphs.add (g); + for (unsigned klass = 0; klass < 4; klass++) + { + bool expected = false; + for (auto g : glyphs) + expected |= class_def.get_class (g) == klass; + hb_always_assert (class_def.intersects_class (&glyphs, klass) == expected); + } + } + } +} + int main (int argc, char **argv) { + test_class_def_intersects_class (); test_class_and_coverage_size_estimates (); test_running_class_and_coverage_size_estimates (); test_running_class_size_estimates_with_locally_consecutive_glyphs (); diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index a7cd03241..c13fab3bd 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -1972,21 +1972,18 @@ struct ClassDefFormat2_4 /* Match if there's any glyph that is not listed! */ hb_codepoint_t g = HB_SET_VALUE_INVALID; hb_codepoint_t last = HB_SET_VALUE_INVALID; - auto it = hb_iter (rangeRecord); - for (auto &range : it) + for (auto &range : rangeRecord) { - if (it->first == last + 1) + /* Only probe for a glyph in the gap before this range; a range + * starting right after the previous one (or at glyph 0) has none. */ + if (range.first != last + 1) { - it++; - continue; + if (!glyphs->next (&g)) + break; + if (g < range.first) + return true; } - - if (!glyphs->next (&g)) - break; - if (g < range.first) - return true; - g = range.last; - last = g; + g = last = range.last; } if (g != HB_SET_VALUE_INVALID && glyphs->next (&g)) return true;