Fix justified linebreaking without justifiables

This commit is contained in:
Laurenz 2023-10-28 18:02:16 +02:00
parent f78a8f5d48
commit c3b1e32d11
3 changed files with 9 additions and 2 deletions

View File

@ -1001,8 +1001,10 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec<L
ratio = 0.0;
}
if ratio > 1.0 {
// We should stretch the line above its stretchability. Now calculate the extra amount.
let extra_stretch = (delta - adjust) / attempt.justifiables() as f64;
// We should stretch the line above its stretchability. Now
// calculate the extra amount. Also, don't divide by zero.
let extra_stretch =
(delta - adjust) / attempt.justifiables().max(1) as f64;
// Normalize the amount by half Em size.
ratio = 1.0 + extra_stretch / (em / 2.0);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -0,0 +1,5 @@
// Test breaking a line without justifiables.
---
#set par(justify: true)
#block(width: 1cm, fill: aqua, lorem(2))