[buffer] Add foreach_group()
This commit is contained in:
parent
1b78e04c78
commit
eb96e69d18
|
@ -217,10 +217,9 @@ struct hb_buffer_t
|
|||
|
||||
reverse ();
|
||||
|
||||
unsigned count = len;
|
||||
unsigned start = 0;
|
||||
unsigned i;
|
||||
for (i = 1; i < count; i++)
|
||||
for (i = 1; i < len; i++)
|
||||
{
|
||||
if (!group (info[i - 1], info[i]))
|
||||
{
|
||||
|
@ -231,8 +230,20 @@ struct hb_buffer_t
|
|||
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; }); }
|
||||
template <typename FuncType>
|
||||
unsigned group_end (unsigned start, const FuncType& group) const
|
||||
{
|
||||
while (++start < len && group (info[start - 1], info[start]))
|
||||
;
|
||||
|
||||
return start;
|
||||
}
|
||||
|
||||
static bool _cluster_group_func (const hb_glyph_info_t& a,
|
||||
const hb_glyph_info_t& b)
|
||||
{ return a.cluster == b.cluster; }
|
||||
|
||||
void reverse_clusters () { reverse_groups (_cluster_group_func); }
|
||||
|
||||
HB_INTERNAL void guess_segment_properties ();
|
||||
|
||||
|
@ -489,26 +500,15 @@ struct hb_buffer_t
|
|||
DECLARE_NULL_INSTANCE (hb_buffer_t);
|
||||
|
||||
|
||||
/* Loop over clusters. Duplicated in foreach_syllable(). */
|
||||
#define foreach_cluster(buffer, start, end) \
|
||||
#define foreach_group(buffer, start, end, group_func) \
|
||||
for (unsigned int \
|
||||
_count = buffer->len, \
|
||||
start = 0, end = _count ? _next_cluster (buffer, 0) : 0; \
|
||||
start = 0, end = _count ? buffer->group_end (0, group_func) : 0; \
|
||||
start < _count; \
|
||||
start = end, end = _next_cluster (buffer, start))
|
||||
start = end, end = buffer->group_end (start, group_func))
|
||||
|
||||
static inline unsigned int
|
||||
_next_cluster (hb_buffer_t *buffer, unsigned int start)
|
||||
{
|
||||
hb_glyph_info_t *info = buffer->info;
|
||||
unsigned int count = buffer->len;
|
||||
|
||||
unsigned int cluster = info[start].cluster;
|
||||
while (++start < count && cluster == info[start].cluster)
|
||||
;
|
||||
|
||||
return start;
|
||||
}
|
||||
#define foreach_cluster(buffer, start, end) \
|
||||
foreach_group (buffer, start, end, hb_buffer_t::_cluster_group_func)
|
||||
|
||||
|
||||
#define HB_BUFFER_XALLOCATE_VAR(b, func, var) \
|
||||
|
|
Loading…
Reference in New Issue