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.
This commit is contained in:
bluebear94 2023-10-03 09:02:27 -04:00 committed by GitHub
parent cf9bde3245
commit ce658db2f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -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 doesnt 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,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -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