[Coverage] Rename and templatize intersected_coverage_glyphs

This commit is contained in:
Behdad Esfahbod 2022-07-21 11:39:32 -06:00
parent d0eb273791
commit 00dfbbce1c
8 changed files with 43 additions and 38 deletions

View File

@ -204,15 +204,17 @@ struct Coverage
}
}
void intersected_coverage_glyphs (const hb_set_t *glyphs, hb_set_t *intersect_glyphs) const
template <typename IteratorOut,
hb_requires (hb_is_sink_of (IteratorOut, hb_codepoint_t))>
void intersect_set (const hb_set_t &glyphs, IteratorOut &intersect_glyphs) const
{
switch (u.format)
{
case 1: return u.format1.intersected_coverage_glyphs (glyphs, intersect_glyphs);
case 2: return u.format2.intersected_coverage_glyphs (glyphs, intersect_glyphs);
case 1: return u.format1.intersect_set (glyphs, intersect_glyphs);
case 2: return u.format2.intersect_set (glyphs, intersect_glyphs);
#ifndef HB_NO_BORING_EXPANSION
case 3: return u.format3.intersected_coverage_glyphs (glyphs, intersect_glyphs);
case 4: return u.format4.intersected_coverage_glyphs (glyphs, intersect_glyphs);
case 3: return u.format3.intersect_set (glyphs, intersect_glyphs);
case 4: return u.format4.intersect_set (glyphs, intersect_glyphs);
#endif
default:return ;
}

View File

@ -86,12 +86,14 @@ struct CoverageFormat1_3
bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const
{ return glyphs->has (glyphArray[index]); }
void intersected_coverage_glyphs (const hb_set_t *glyphs, hb_set_t *intersect_glyphs) const
template <typename IteratorOut,
hb_requires (hb_is_sink_of (IteratorOut, hb_codepoint_t))>
void intersect_set (const hb_set_t &glyphs, IteratorOut &intersect_glyphs) const
{
unsigned count = glyphArray.len;
for (unsigned i = 0; i < count; i++)
if (glyphs->has (glyphArray[i]))
intersect_glyphs->add (glyphArray[i]);
if (glyphs.has (glyphArray[i]))
intersect_glyphs << glyphArray[i];
}
template <typename set_t>

View File

@ -116,7 +116,7 @@ struct CoverageFormat2_4
bool intersects (const hb_set_t *glyphs) const
{
return hb_any (+ hb_iter (rangeRecord.as_array ())
| hb_map ([glyphs] (const RangeRecord<Types> &range) { return range.intersects (glyphs); }));
| hb_map ([glyphs] (const RangeRecord<Types> &range) { return range.intersects (*glyphs); }));
}
bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const
{
@ -134,19 +134,21 @@ struct CoverageFormat2_4
if (hb_bsearch_impl (&idx, index,
arr.arrayZ, arr.length, sizeof (arr[0]),
(int (*)(const void *_key, const void *_item)) cmp))
return arr.arrayZ[idx].intersects (glyphs);
return arr.arrayZ[idx].intersects (*glyphs);
return false;
}
void intersected_coverage_glyphs (const hb_set_t *glyphs, hb_set_t *intersect_glyphs) const
template <typename IteratorOut,
hb_requires (hb_is_sink_of (IteratorOut, hb_codepoint_t))>
void intersect_set (const hb_set_t &glyphs, IteratorOut &intersect_glyphs) const
{
for (const auto& range : rangeRecord.as_array ())
{
if (!range.intersects (glyphs)) continue;
unsigned last = range.last;
for (hb_codepoint_t g = range.first - 1;
glyphs->next (&g) && g <= last;)
intersect_glyphs->add (g);
glyphs.next (&g) && g <= last;)
intersect_glyphs << g;
}
}

View File

@ -57,8 +57,8 @@ struct RangeRecord
return (last - first + 1);
}
bool intersects (const hb_set_t *glyphs) const
{ return glyphs->intersects (first, last); }
bool intersects (const hb_set_t &glyphs) const
{ return glyphs.intersects (first, last); }
template <typename set_t>
bool collect_coverage (set_t *glyphs) const

View File

@ -105,7 +105,7 @@ struct SinglePosFormat1
const hb_map_t &glyph_map = *c->plan->glyph_map;
hb_set_t intersection;
(this+coverage).intersected_coverage_glyphs (&glyphset, &intersection);
(this+coverage).intersect_set (glyphset, intersection);
auto it =
+ hb_iter (intersection)

View File

@ -136,7 +136,7 @@ struct SingleSubstFormat1_3
hb_codepoint_t mask = get_mask ();
hb_set_t intersection;
(this+coverage).intersected_coverage_glyphs (&glyphset, &intersection);
(this+coverage).intersect_set (glyphset, intersection);
auto it =
+ hb_iter (intersection)

View File

@ -1786,7 +1786,7 @@ struct ClassDefFormat2_4
for (unsigned int i = 0; i < count; i++)
{
const auto& range = rangeRecord[i];
if (range.intersects (glyphs) && range.value)
if (range.intersects (*glyphs) && range.value)
return true;
}
return false;
@ -1814,7 +1814,7 @@ struct ClassDefFormat2_4
/* TODO(iter) Rewrite as dagger. */
const auto *arr = rangeRecord.arrayZ;
for (unsigned int i = 0; i < count; i++)
if (arr[i].value == klass && arr[i].intersects (glyphs))
if (arr[i].value == klass && arr[i].intersects (*glyphs))
return true;
return false;
}
@ -1889,7 +1889,7 @@ struct ClassDefFormat2_4
intersect_classes->add (0);
for (const auto& record : rangeRecord.iter ())
if (record.intersects (glyphs))
if (record.intersects (*glyphs))
intersect_classes->add (record.value);
}

View File

@ -1043,7 +1043,7 @@ static inline void intersected_coverage_glyphs (const hb_set_t *glyphs, const vo
{
Offset16To<Coverage> coverage;
coverage = value;
(data+coverage).intersected_coverage_glyphs (glyphs, intersected_glyphs);
(data+coverage).intersect_set (*glyphs, *intersected_glyphs);
}
@ -2066,9 +2066,8 @@ struct ContextFormat1_4
void closure (hb_closure_context_t *c) const
{
hb_set_t* cur_active_glyphs = &c->push_cur_active_glyphs ();
get_coverage ().intersected_coverage_glyphs (&c->previous_parent_active_glyphs (),
cur_active_glyphs);
hb_set_t& cur_active_glyphs = c->push_cur_active_glyphs ();
get_coverage ().intersect_set (c->previous_parent_active_glyphs (), cur_active_glyphs);
struct ContextClosureLookupContext lookup_context = {
{intersects_glyph, intersected_glyph},
@ -2209,7 +2208,7 @@ struct ContextFormat2_5
};
hb_set_t retained_coverage_glyphs;
(this+coverage).intersected_coverage_glyphs (glyphs, &retained_coverage_glyphs);
(this+coverage).intersect_set (*glyphs, retained_coverage_glyphs);
hb_set_t coverage_glyph_classes;
class_def.intersected_classes (&retained_coverage_glyphs, &coverage_glyph_classes);
@ -2235,8 +2234,8 @@ struct ContextFormat2_5
if (!(this+coverage).intersects (c->glyphs))
return;
hb_set_t* cur_active_glyphs = &c->push_cur_active_glyphs ();
get_coverage ().intersected_coverage_glyphs (&c->previous_parent_active_glyphs (),
hb_set_t& cur_active_glyphs = c->push_cur_active_glyphs ();
get_coverage ().intersect_set (c->previous_parent_active_glyphs (),
cur_active_glyphs);
const ClassDef &class_def = this+classDef;
@ -2381,7 +2380,7 @@ struct ContextFormat2_5
const hb_set_t* glyphset = c->plan->glyphset_gsub ();
hb_set_t retained_coverage_glyphs;
(this+coverage).intersected_coverage_glyphs (glyphset, &retained_coverage_glyphs);
(this+coverage).intersect_set (*glyphset, retained_coverage_glyphs);
hb_set_t coverage_glyph_classes;
(this+classDef).intersected_classes (&retained_coverage_glyphs, &coverage_glyph_classes);
@ -2468,8 +2467,8 @@ struct ContextFormat3
if (!(this+coverageZ[0]).intersects (c->glyphs))
return;
hb_set_t* cur_active_glyphs = &c->push_cur_active_glyphs ();
get_coverage ().intersected_coverage_glyphs (&c->previous_parent_active_glyphs (),
hb_set_t& cur_active_glyphs = c->push_cur_active_glyphs ();
get_coverage ().intersect_set (c->previous_parent_active_glyphs (),
cur_active_glyphs);
@ -3124,8 +3123,8 @@ struct ChainContextFormat1_4
void closure (hb_closure_context_t *c) const
{
hb_set_t* cur_active_glyphs = &c->push_cur_active_glyphs ();
get_coverage ().intersected_coverage_glyphs (&c->previous_parent_active_glyphs (),
hb_set_t& cur_active_glyphs = c->push_cur_active_glyphs ();
get_coverage ().intersect_set (c->previous_parent_active_glyphs (),
cur_active_glyphs);
struct ChainContextClosureLookupContext lookup_context = {
@ -3269,7 +3268,7 @@ struct ChainContextFormat2_5
};
hb_set_t retained_coverage_glyphs;
(this+coverage).intersected_coverage_glyphs (glyphs, &retained_coverage_glyphs);
(this+coverage).intersect_set (*glyphs, retained_coverage_glyphs);
hb_set_t coverage_glyph_classes;
input_class_def.intersected_classes (&retained_coverage_glyphs, &coverage_glyph_classes);
@ -3294,8 +3293,8 @@ struct ChainContextFormat2_5
if (!(this+coverage).intersects (c->glyphs))
return;
hb_set_t* cur_active_glyphs = &c->push_cur_active_glyphs ();
get_coverage ().intersected_coverage_glyphs (&c->previous_parent_active_glyphs (),
hb_set_t& cur_active_glyphs = c->push_cur_active_glyphs ();
get_coverage ().intersect_set (c->previous_parent_active_glyphs (),
cur_active_glyphs);
@ -3479,7 +3478,7 @@ struct ChainContextFormat2_5
const hb_set_t* glyphset = c->plan->glyphset_gsub ();
hb_set_t retained_coverage_glyphs;
(this+coverage).intersected_coverage_glyphs (glyphset, &retained_coverage_glyphs);
(this+coverage).intersect_set (*glyphset, retained_coverage_glyphs);
hb_set_t coverage_glyph_classes;
(this+inputClassDef).intersected_classes (&retained_coverage_glyphs, &coverage_glyph_classes);
@ -3590,8 +3589,8 @@ struct ChainContextFormat3
if (!(this+input[0]).intersects (c->glyphs))
return;
hb_set_t* cur_active_glyphs = &c->push_cur_active_glyphs ();
get_coverage ().intersected_coverage_glyphs (&c->previous_parent_active_glyphs (),
hb_set_t& cur_active_glyphs = c->push_cur_active_glyphs ();
get_coverage ().intersect_set (c->previous_parent_active_glyphs (),
cur_active_glyphs);