[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
This commit is contained in:
Behdad Esfahbod committed 2026-08-12 21:43:00 -06:00
1 parent dee6b6ee50
commit 8548cc760a
2 files changed
+14 -14

No files matched your search

+12 -12
View File
@@ -184,32 +184,32 @@ struct CursivePosFormat1
/* Main-direction adjustment */
switch (c->direction) {
case HB_DIRECTION_LTR:
pos[i].x_advance = hb_clamp_to<hb_position_t> ((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<hb_position_t> ((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<hb_position_t> ((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<hb_position_t> ((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<hb_position_t> ((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<hb_position_t> ((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<hb_position_t> ((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<hb_position_t> (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<hb_position_t> (roundf (entry_x - exit_x));
hb_position_t y_offset = hb_clamp_to<hb_position_t> (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
+2 -2
View File
@@ -80,8 +80,8 @@ struct MarkArray : Array16Of<MarkRecord> /* Array of MarkRecords--in Cove
goto overflow;
}
mark.attach_type() = ATTACH_TYPE_MARK;
mark.x_offset = hb_clamp_to<hb_position_t> (roundf (base_x - mark_x));
mark.y_offset = hb_clamp_to<hb_position_t> (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