summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwznmickey <first@wznmickey.com>2024-11-17 04:04:07 -0500
committerGitHub <noreply@github.com>2024-11-17 09:04:07 +0000
commitcce744cf780dd730f1638e17a0e106faeb38de22 (patch)
treef7700bf4a169b6ac275b0e8bce7afc4159c4f575
parent7add9b459a3ca54fca085e71f3dd4e611941c4cc (diff)
Fix unnecessary hyphenation (#5394)
-rw-r--r--crates/typst-layout/src/inline/linebreak.rs7
-rw-r--r--tests/ref/issue-5360-unnecessary-hyphenation.pngbin0 -> 1569 bytes
-rw-r--r--tests/suite/layout/inline/justify.typ5
3 files changed, 11 insertions, 1 deletions
diff --git a/crates/typst-layout/src/inline/linebreak.rs b/crates/typst-layout/src/inline/linebreak.rs
index 26621cd7..236d6892 100644
--- a/crates/typst-layout/src/inline/linebreak.rs
+++ b/crates/typst-layout/src/inline/linebreak.rs
@@ -543,7 +543,12 @@ fn raw_ratio(
) -> f64 {
// Determine how much the line's spaces would need to be stretched
// to make it the desired width.
- let delta = available_width - line_width;
+ let mut delta = available_width - line_width;
+
+ // Avoid possible floating point errors in previous calculation.
+ if delta.approx_eq(Abs::zero()) {
+ delta = Abs::zero();
+ }
// Determine how much stretch or shrink is natural.
let adjustability = if delta >= Abs::zero() { stretchability } else { shrinkability };
diff --git a/tests/ref/issue-5360-unnecessary-hyphenation.png b/tests/ref/issue-5360-unnecessary-hyphenation.png
new file mode 100644
index 00000000..90a8180a
--- /dev/null
+++ b/tests/ref/issue-5360-unnecessary-hyphenation.png
Binary files differ
diff --git a/tests/suite/layout/inline/justify.typ b/tests/suite/layout/inline/justify.typ
index 576f8519..6e0317ac 100644
--- a/tests/suite/layout/inline/justify.typ
+++ b/tests/suite/layout/inline/justify.typ
@@ -172,3 +172,8 @@ int main() {
// Test that overflow does not lead to bad bounds in paragraph optimization.
#set par(justify: true)
#block(width: 0pt)[A B]
+
+--- issue-5360-unnecessary-hyphenation ---
+// Test whether `Formal` would be in one line.
+#set par(justify: true)
+#table(columns: 1, [Formal])