diff options
| author | bluebear94 <uruwi@protonmail.com> | 2023-10-03 09:02:27 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-03 15:02:27 +0200 |
| commit | ce658db2f39f8472c3525a18ed1cfead23781fbb (patch) | |
| tree | fc49d6bbc94421ac8be0baaca754c6c5ba626316 /crates | |
| parent | cf9bde3245817e068c8253070e7a94dcc05369fb (diff) | |
ShapedText::push_hyphen: Use self.base for default hyphen range (#2299)
In the unlikely chance that we hyphenate after an empty line, we
set the glyph range to self.base..self.base so that subtracting
Fixes #2283.
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/typst-library/src/text/shaping.rs | 7 |
1 files changed, 6 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, |
