[buffer] Add ::reverse_groups()

This commit is contained in:
Behdad Esfahbod 2021-12-10 12:45:43 -07:00
parent 4cd96e73e4
commit 1b78e04c78
2 changed files with 25 additions and 24 deletions

View File

@ -395,29 +395,6 @@ hb_buffer_t::set_masks (hb_mask_t value,
info[i].mask = (info[i].mask & not_mask) | value;
}
void
hb_buffer_t::reverse_clusters ()
{
unsigned int i, start, count, last_cluster;
if (unlikely (!len))
return;
reverse ();
count = len;
start = 0;
last_cluster = info[0].cluster;
for (i = 1; i < count; i++) {
if (last_cluster != info[i].cluster) {
reverse_range (start, i);
start = i;
last_cluster = info[i].cluster;
}
}
reverse_range (start, i);
}
void
hb_buffer_t::merge_clusters_impl (unsigned int start,
unsigned int end)

View File

@ -209,7 +209,31 @@ struct hb_buffer_t
}
void reverse () { reverse_range (0, len); }
HB_INTERNAL void reverse_clusters ();
template <typename FuncType>
void reverse_groups (const FuncType& group)
{
if (unlikely (!len))
return;
reverse ();
unsigned count = len;
unsigned start = 0;
unsigned i;
for (i = 1; i < count; i++)
{
if (!group (info[i - 1], info[i]))
{
reverse_range (start, i);
start = i;
}
}
reverse_range (start, i);
}
void reverse_clusters ()
{ reverse_groups ([] (const hb_glyph_info_t& a, const hb_glyph_info_t& b) -> bool { return a.cluster == b.cluster; }); }
HB_INTERNAL void guess_segment_properties ();
HB_INTERNAL void swap_buffers ();