summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/typst-library/src/text/shaping.rs7
-rw-r--r--tests/ref/text/shaping.pngbin3902 -> 3992 bytes
-rw-r--r--tests/typ/text/shaping.typ6
3 files changed, 12 insertions, 1 deletions
diff --git a/crates/typst-library/src/text/shaping.rs b/crates/typst-library/src/text/shaping.rs
index 2d9dae33..57501c52 100644
--- a/crates/typst-library/src/text/shaping.rs
+++ b/crates/typst-library/src/text/shaping.rs
@@ -446,7 +446,12 @@ impl<'a> ShapedText<'a> {
.glyphs
.last()
.map(|g| g.range.end..g.range.end)
- .unwrap_or_default();
+ // In the unlikely chance that we hyphenate after an
+ // empty line, ensure that the glyph range still falls
+ // after self.base so that subtracting either of the
+ // endpoints by self.base doesn’t underflow.
+ // See <https://github.com/typst/typst/issues/2283>.
+ .unwrap_or_else(|| self.base..self.base);
self.width += x_advance.at(self.size);
self.glyphs.to_mut().push(ShapedGlyph {
font,
diff --git a/tests/ref/text/shaping.png b/tests/ref/text/shaping.png
index a77dda3a..a3ee750e 100644
--- a/tests/ref/text/shaping.png
+++ b/tests/ref/text/shaping.png
Binary files differ
diff --git a/tests/typ/text/shaping.typ b/tests/typ/text/shaping.typ
index 3a8d5411..c794a105 100644
--- a/tests/typ/text/shaping.typ
+++ b/tests/typ/text/shaping.typ
@@ -26,3 +26,9 @@ ABCअपार्टमेंट
// doesn't exist in shaping output.
#set text(dir: rtl, font: "Noto Serif Hebrew")
\ ט
+
+---
+// Test that #2283 is fixed.
+#set text(font: "test", lang: "de", hyphenate: true, fallback: false)
+#set par(linebreaks: "simple")
+- ensure