mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-23 07:51:10 +01:00
[GPOS] Saturate propagated attachment offsets
Deferred mark and cursive attachment propagation combines offsets with the advances between attached glyphs. Use saturating arithmetic for each position update instead of relying on signed overflow behavior. This removes the historical overflow from the function that issue #6151 moved out of Chromium's sanitizer exemption. Testing: meson test -C build --print-errorlogs Assisted-by: Codex <codex@openai.com>
This commit is contained in:
1 parent
bcce9d4f55
commit
d36a16f8ca
1 file changed
+12
-12
+12
-12
@@ -101,16 +101,16 @@ propagate_attachment_offsets (hb_glyph_position_t *pos,
|
||||
if (type & GPOS_impl::ATTACH_TYPE_CURSIVE)
|
||||
{
|
||||
if (HB_DIRECTION_IS_HORIZONTAL (direction))
|
||||
pos[i].y_offset += pos[j].y_offset;
|
||||
pos[i].y_offset = hb_saturate_add (pos[i].y_offset, pos[j].y_offset);
|
||||
else
|
||||
pos[i].x_offset += pos[j].x_offset;
|
||||
pos[i].x_offset = hb_saturate_add (pos[i].x_offset, pos[j].x_offset);
|
||||
}
|
||||
else /*if (type & GPOS_impl::ATTACH_TYPE_MARK)*/
|
||||
{
|
||||
if (HB_DIRECTION_IS_HORIZONTAL (direction))
|
||||
pos[i].x_offset += pos[j].x_offset;
|
||||
pos[i].x_offset = hb_saturate_add (pos[i].x_offset, pos[j].x_offset);
|
||||
else
|
||||
pos[i].y_offset += pos[j].y_offset;
|
||||
pos[i].y_offset = hb_saturate_add (pos[i].y_offset, pos[j].y_offset);
|
||||
|
||||
// i is the position of the mark; j is the base.
|
||||
if (j < i)
|
||||
@@ -119,13 +119,13 @@ propagate_attachment_offsets (hb_glyph_position_t *pos,
|
||||
* And currently the only way in OpenType. */
|
||||
if (HB_DIRECTION_IS_FORWARD (direction))
|
||||
for (unsigned int k = j; k < i; k++) {
|
||||
pos[i].x_offset -= pos[k].x_advance;
|
||||
pos[i].y_offset -= pos[k].y_advance;
|
||||
pos[i].x_offset = hb_saturate_sub (pos[i].x_offset, pos[k].x_advance);
|
||||
pos[i].y_offset = hb_saturate_sub (pos[i].y_offset, pos[k].y_advance);
|
||||
}
|
||||
else
|
||||
for (unsigned int k = j + 1; k < i + 1; k++) {
|
||||
pos[i].x_offset += pos[k].x_advance;
|
||||
pos[i].y_offset += pos[k].y_advance;
|
||||
pos[i].x_offset = hb_saturate_add (pos[i].x_offset, pos[k].x_advance);
|
||||
pos[i].y_offset = hb_saturate_add (pos[i].y_offset, pos[k].y_advance);
|
||||
}
|
||||
}
|
||||
else // j > i
|
||||
@@ -134,13 +134,13 @@ propagate_attachment_offsets (hb_glyph_position_t *pos,
|
||||
* to a base after it in the logical order. */
|
||||
if (HB_DIRECTION_IS_FORWARD (direction))
|
||||
for (unsigned int k = i; k < j; k++) {
|
||||
pos[i].x_offset += pos[k].x_advance;
|
||||
pos[i].y_offset += pos[k].y_advance;
|
||||
pos[i].x_offset = hb_saturate_add (pos[i].x_offset, pos[k].x_advance);
|
||||
pos[i].y_offset = hb_saturate_add (pos[i].y_offset, pos[k].y_advance);
|
||||
}
|
||||
else
|
||||
for (unsigned int k = i + 1; k < j + 1; k++) {
|
||||
pos[i].x_offset -= pos[k].x_advance;
|
||||
pos[i].y_offset -= pos[k].y_advance;
|
||||
pos[i].x_offset = hb_saturate_sub (pos[i].x_offset, pos[k].x_advance);
|
||||
pos[i].y_offset = hb_saturate_sub (pos[i].y_offset, pos[k].y_advance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user