From 313c772989ca838f7ba9c2119ffb953ba8a4418b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 8 Aug 2023 13:06:12 -0600 Subject: [PATCH] [arabic/stch] Also work in left-to-right direction Fixes https://github.com/harfbuzz/harfbuzz/issues/4369 --- src/hb-ot-shaper-arabic.cc | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/hb-ot-shaper-arabic.cc b/src/hb-ot-shaper-arabic.cc index 12c7da22f..1bd730be2 100644 --- a/src/hb-ot-shaper-arabic.cc +++ b/src/hb-ot-shaper-arabic.cc @@ -486,8 +486,10 @@ apply_stch (const hb_ot_shape_plan_t *plan HB_UNUSED, if (likely (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_ARABIC_HAS_STCH))) return; - /* The Arabic shaper currently always processes in RTL mode, so we should - * stretch / position the stretched pieces to the left / preceding glyphs. */ + bool rtl = buffer->props.direction == HB_DIRECTION_RTL; + + if (!rtl) + buffer->reverse (); /* We do a two pass implementation: * First pass calculates the exact number of extra glyphs we need, @@ -602,14 +604,24 @@ apply_stch (const hb_ot_shape_plan_t *plan HB_UNUSED, pos[k - 1].x_advance = 0; for (unsigned int n = 0; n < repeat; n++) { - x_offset -= width; - if (n > 0) - x_offset += extra_repeat_overlap; + if (rtl) + { + x_offset -= width; + if (n > 0) + x_offset += extra_repeat_overlap; + } pos[k - 1].x_offset = x_offset; /* Append copy. */ --j; info[j] = info[k - 1]; pos[j] = pos[k - 1]; + + if (!rtl) + { + x_offset += width; + if (n > 0) + x_offset -= extra_repeat_overlap; + } } } } @@ -626,6 +638,9 @@ apply_stch (const hb_ot_shape_plan_t *plan HB_UNUSED, buffer->len = new_len; } } + + if (!rtl) + buffer->reverse (); }