Add foreach_syllable
Use it in USE.
diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh
index 7a8e2bf..3a482ff 100644
--- a/src/hb-ot-layout-private.hh
+++ b/src/hb-ot-layout-private.hh
@@ -179,6 +179,30 @@
#define lig_props() var1.u8[2] /* GSUB/GPOS ligature tracking */
#define syllable() var1.u8[3] /* GSUB/GPOS shaping boundaries */
+
+/* loop over syllables */
+
+#define foreach_syllable(buffer, start, end) \
+ for (unsigned int \
+ _count = buffer->len, \
+ start = 0, end = _count ? _next_syllable (buffer, 0) : 0; \
+ start < _count; \
+ start = end, end = _next_syllable (buffer, start))
+
+static inline unsigned int
+_next_syllable (hb_buffer_t *buffer, unsigned int start)
+{
+ hb_glyph_info_t *info = buffer->info;
+ unsigned int count = buffer->len;
+
+ unsigned int syllable = info[start].syllable();
+ while (++start < count && syllable == info[start].syllable())
+ ;
+
+ return start;
+}
+
+
/* unicode_props */
enum {
diff --git a/src/hb-ot-shape-complex-use.cc b/src/hb-ot-shape-complex-use.cc
index b50fc71..ba4c04c 100644
--- a/src/hb-ot-shape-complex-use.cc
+++ b/src/hb-ot-shape-complex-use.cc
@@ -264,38 +264,27 @@
}
static void
-setup_syllable (const use_shape_plan_t *use_plan,
- hb_glyph_info_t *info,
- unsigned int start, unsigned int end)
-{
- unsigned int limit = info[start].use_category() == USE_R ? 1 : MIN (3u, end - start);
- for (unsigned int i = start; i < start + limit; i++)
- info[i].mask |= use_plan->rphf_mask;
-}
-
-static void
setup_syllables (const hb_ot_shape_plan_t *plan,
hb_font_t *font HB_UNUSED,
hb_buffer_t *buffer)
{
find_syllables (buffer);
- /* Setup masks for 'rphf' and 'pref'. */
+ /* Setup 'rphf' mask. */
+
const use_shape_plan_t *use_plan = (const use_shape_plan_t *) plan->data;
- if (!use_plan->rphf_mask) return;
+
+ hb_mask_t mask = use_plan->rphf_mask;
+ if (!mask) return;
hb_glyph_info_t *info = buffer->info;
- unsigned int count = buffer->len;
- if (unlikely (!count)) return;
- unsigned int last = 0;
- unsigned int last_syllable = info[0].syllable();
- for (unsigned int i = 1; i < count; i++)
- if (last_syllable != info[i].syllable()) {
- setup_syllable (use_plan, info, last, i);
- last = i;
- last_syllable = info[last].syllable();
- }
- setup_syllable (use_plan, info, last, count);
+
+ foreach_syllable (buffer, start, end)
+ {
+ unsigned int limit = info[start].use_category() == USE_R ? 1 : MIN (3u, end - start);
+ for (unsigned int i = start; i < start + limit; i++)
+ info[i].mask |= mask;
+ }
}
static void
@@ -310,55 +299,26 @@
}
static void
-record_rphf_syllable (hb_glyph_info_t *info,
- unsigned int start, unsigned int end,
- hb_mask_t mask)
-{
- /* Mark a substituted repha as USE_R. */
- for (unsigned int i = start; i < end && (info[i].mask & mask); i++)
- if (_hb_glyph_info_substituted (&info[i]))
- {
- /* Found the one. Mark it as Repha. */
- info[i].use_category() = USE_R;
- return;
- }
-}
-
-static void
record_rphf (const hb_ot_shape_plan_t *plan,
hb_font_t *font,
hb_buffer_t *buffer)
{
const use_shape_plan_t *use_plan = (const use_shape_plan_t *) plan->data;
- hb_mask_t mask = use_plan->rphf_mask;
+ hb_mask_t mask = use_plan->rphf_mask;
if (!mask) return;
hb_glyph_info_t *info = buffer->info;
- unsigned int count = buffer->len;
- if (unlikely (!count)) return;
- unsigned int last = 0;
- unsigned int last_syllable = info[0].syllable();
- for (unsigned int i = 1; i < count; i++)
- if (last_syllable != info[i].syllable()) {
- record_rphf_syllable (info, last, i, mask);
- last = i;
- last_syllable = info[last].syllable();
- }
- record_rphf_syllable (info, last, count, mask);
-}
-static void
-record_pref_syllable (hb_glyph_info_t *info,
- unsigned int start, unsigned int end)
-{
- /* Mark a substituted pref as VPre, as they behave the same way. */
- for (unsigned int i = start; i < end; i++)
- if (_hb_glyph_info_substituted (&info[i]))
- {
- /* Found the one. Mark it as Repha. */
- info[i].use_category() = USE_VPre;
- return;
- }
+ foreach_syllable (buffer, start, end)
+ {
+ /* Mark a substituted repha as USE_R. */
+ for (unsigned int i = start; i < end && (info[i].mask & mask); i++)
+ if (_hb_glyph_info_substituted (&info[i]))
+ {
+ info[i].use_category() = USE_R;
+ break;
+ }
+ }
}
static void
@@ -367,24 +327,21 @@
hb_buffer_t *buffer)
{
hb_glyph_info_t *info = buffer->info;
- unsigned int count = buffer->len;
- if (unlikely (!count)) return;
- unsigned int last = 0;
- unsigned int last_syllable = info[0].syllable();
- for (unsigned int i = 1; i < count; i++)
- if (last_syllable != info[i].syllable()) {
- record_pref_syllable (info, last, i);
- last = i;
- last_syllable = info[last].syllable();
- }
- record_pref_syllable (info, last, count);
+
+ foreach_syllable (buffer, start, end)
+ {
+ /* Mark a substituted pref as VPre, as they behave the same way. */
+ for (unsigned int i = start; i < end; i++)
+ if (_hb_glyph_info_substituted (&info[i]))
+ {
+ info[i].use_category() = USE_VPre;
+ break;
+ }
+ }
}
static void
-reorder_syllable (const hb_ot_shape_plan_t *plan,
- hb_face_t *face,
- hb_buffer_t *buffer,
- unsigned int start, unsigned int end)
+reorder_syllable (hb_buffer_t *buffer, unsigned int start, unsigned int end)
{
syllable_type_t syllable_type = (syllable_type_t) (buffer->info[start].syllable() & 0x0F);
/* Only a few syllable types need reordering. */
@@ -481,6 +438,7 @@
buffer->clear_output ();
buffer->idx = 0;
+
unsigned int last_syllable = 0;
while (buffer->idx < buffer->len)
{
@@ -519,19 +477,12 @@
insert_dotted_circles (plan, font, buffer);
hb_glyph_info_t *info = buffer->info;
- unsigned int count = buffer->len;
- if (unlikely (!count)) return;
- unsigned int last = 0;
- unsigned int last_syllable = info[0].syllable();
- for (unsigned int i = 1; i < count; i++)
- if (last_syllable != info[i].syllable()) {
- reorder_syllable (plan, font->face, buffer, last, i);
- last = i;
- last_syllable = info[last].syllable();
- }
- reorder_syllable (plan, font->face, buffer, last, count);
+
+ foreach_syllable (buffer, start, end)
+ reorder_syllable (buffer, start, end);
/* Zero syllables now... */
+ unsigned int count = buffer->len;
for (unsigned int i = 0; i < count; i++)
info[i].syllable() = 0;