summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-10-28 18:02:16 +0200
committerLaurenz <laurmaedje@gmail.com>2023-10-28 18:02:16 +0200
commitc3b1e32d11c8485194070710431b081c52a64c45 (patch)
treebbadd6b38e905a3adc13aaeb013ff717138e00b2
parentf78a8f5d4863260d05cbabe2711324489be47242 (diff)
Fix justified linebreaking without justifiables
-rw-r--r--crates/typst-library/src/layout/par.rs6
-rw-r--r--tests/ref/bugs/linebreak-no-justifiables.pngbin0 -> 1829 bytes
-rw-r--r--tests/typ/bugs/linebreak-no-justifiables.typ5
3 files changed, 9 insertions, 2 deletions
diff --git a/crates/typst-library/src/layout/par.rs b/crates/typst-library/src/layout/par.rs
index 9b5f641b..ee47b579 100644
--- a/crates/typst-library/src/layout/par.rs
+++ b/crates/typst-library/src/layout/par.rs
@@ -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);
}
diff --git a/tests/ref/bugs/linebreak-no-justifiables.png b/tests/ref/bugs/linebreak-no-justifiables.png
new file mode 100644
index 00000000..3f934592
--- /dev/null
+++ b/tests/ref/bugs/linebreak-no-justifiables.png
Binary files differ
diff --git a/tests/typ/bugs/linebreak-no-justifiables.typ b/tests/typ/bugs/linebreak-no-justifiables.typ
new file mode 100644
index 00000000..ab1b2732
--- /dev/null
+++ b/tests/typ/bugs/linebreak-no-justifiables.typ
@@ -0,0 +1,5 @@
+// Test breaking a line without justifiables.
+
+---
+#set par(justify: true)
+#block(width: 1cm, fill: aqua, lorem(2))