From 8548cc760aa2720df19fa253bab6fa2972fad680 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 12 Aug 2026 21:43:00 -0600 Subject: [PATCH] [GPOS] Clamp only accumulated cursive positions Individual mark and cursive anchors stay within four ems and cannot approach the hb_position_t limits. Convert those directly, while keeping saturation where they are combined with offsets accumulated through an attachment chain. Testing: meson test -C build --print-errorlogs Assisted-by: OpenAI Codex --- src/OT/Layout/GPOS/CursivePosFormat1.hh | 24 ++++++++++++------------ src/OT/Layout/GPOS/MarkArray.hh | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/OT/Layout/GPOS/CursivePosFormat1.hh b/src/OT/Layout/GPOS/CursivePosFormat1.hh index 52fdfbe38..56ac9fbac 100644 --- a/src/OT/Layout/GPOS/CursivePosFormat1.hh +++ b/src/OT/Layout/GPOS/CursivePosFormat1.hh @@ -184,32 +184,32 @@ struct CursivePosFormat1 /* Main-direction adjustment */ switch (c->direction) { case HB_DIRECTION_LTR: - pos[i].x_advance = hb_clamp_to ((double) roundf (exit_x) + pos[i].x_offset); + pos[i].x_advance = hb_saturate_add ((hb_position_t) roundf (exit_x), pos[i].x_offset); - d = hb_clamp_to ((double) roundf (entry_x) + pos[j].x_offset); + d = hb_saturate_add ((hb_position_t) roundf (entry_x), pos[j].x_offset); pos[j].x_advance = hb_saturate_sub (pos[j].x_advance, d); pos[j].x_offset = hb_saturate_sub (pos[j].x_offset, d); break; case HB_DIRECTION_RTL: - d = hb_clamp_to ((double) roundf (exit_x) + pos[i].x_offset); + d = hb_saturate_add ((hb_position_t) roundf (exit_x), pos[i].x_offset); pos[i].x_advance = hb_saturate_sub (pos[i].x_advance, d); pos[i].x_offset = hb_saturate_sub (pos[i].x_offset, d); - pos[j].x_advance = hb_clamp_to ((double) roundf (entry_x) + pos[j].x_offset); + pos[j].x_advance = hb_saturate_add ((hb_position_t) roundf (entry_x), pos[j].x_offset); break; case HB_DIRECTION_TTB: - pos[i].y_advance = hb_clamp_to ((double) roundf (exit_y) + pos[i].y_offset); + pos[i].y_advance = hb_saturate_add ((hb_position_t) roundf (exit_y), pos[i].y_offset); - d = hb_clamp_to ((double) roundf (entry_y) + pos[j].y_offset); + d = hb_saturate_add ((hb_position_t) roundf (entry_y), pos[j].y_offset); pos[j].y_advance = hb_saturate_sub (pos[j].y_advance, d); pos[j].y_offset = hb_saturate_sub (pos[j].y_offset, d); break; case HB_DIRECTION_BTT: - d = hb_clamp_to ((double) roundf (exit_y) + pos[i].y_offset); + d = hb_saturate_add ((hb_position_t) roundf (exit_y), pos[i].y_offset); pos[i].y_advance = hb_saturate_sub (pos[i].y_advance, d); pos[i].y_offset = hb_saturate_sub (pos[i].y_offset, d); - pos[j].y_advance = hb_clamp_to (roundf (entry_y)); + pos[j].y_advance = (hb_position_t) roundf (entry_y); break; case HB_DIRECTION_INVALID: default: @@ -226,15 +226,15 @@ struct CursivePosFormat1 * Arabic. */ unsigned int child = i; unsigned int parent = j; - hb_position_t x_offset = hb_clamp_to (roundf (entry_x - exit_x)); - hb_position_t y_offset = hb_clamp_to (roundf (entry_y - exit_y)); + hb_position_t x_offset = (hb_position_t) roundf (entry_x - exit_x); + hb_position_t y_offset = (hb_position_t) roundf (entry_y - exit_y); if (!(c->lookup_props & LookupFlag::RightToLeft)) { unsigned int k = child; child = parent; parent = k; - x_offset = hb_saturate_neg (x_offset); - y_offset = hb_saturate_neg (y_offset); + x_offset = -x_offset; + y_offset = -y_offset; } /* If child was already connected to someone else, walk through its old diff --git a/src/OT/Layout/GPOS/MarkArray.hh b/src/OT/Layout/GPOS/MarkArray.hh index 039daf6c2..470651aa6 100644 --- a/src/OT/Layout/GPOS/MarkArray.hh +++ b/src/OT/Layout/GPOS/MarkArray.hh @@ -80,8 +80,8 @@ struct MarkArray : Array16Of /* Array of MarkRecords--in Cove goto overflow; } mark.attach_type() = ATTACH_TYPE_MARK; - mark.x_offset = hb_clamp_to (roundf (base_x - mark_x)); - mark.y_offset = hb_clamp_to (roundf (base_y - mark_y)); + mark.x_offset = roundf (base_x - mark_x); + mark.y_offset = roundf (base_y - mark_y); if (HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction)) mark.y_offset = hb_saturate_add (mark.y_offset, base_offset); else