Match XeTeX margin boundaries and Web2c glue rounding

This commit is contained in:
gloamxun committed 2026-11-29 03:21:19 +08:00
1 parent 52db77885d
commit 9da75c82f5
5 files changed
+150 -19

No files matched your search

@@ -599,12 +599,12 @@ impl GlueSetting {
return 0;
}
*cumulative += f.amount as i128;
let n = *cumulative * self.numerator as i128 * self.sign as i128;
let d = self.denominator as i128;
// web2c rounds signed cumulative glue away from zero at half a sp.
// TeX's vet_glue clamps the cumulative adjustment before shipping it.
let now = (n.signum() * d.signum() * ((n.abs() + d.abs() / 2) / d.abs()))
.clamp(-1_000_000_000, 1_000_000_000) as i64;
// Web2c first stores the floating-point ratio when it packs the box.
// Multiply by that rounded ratio before applying vet_glue and round.
let ratio = self.numerator as f64 / self.denominator as f64;
let amount = (ratio * *cumulative as f64 * f64::from(self.sign))
.clamp(-1_000_000_000.0, 1_000_000_000.0);
let now = (amount + 0.5_f64.copysign(amount)) as i64;
let result = now - *previous;
*previous = now;
result