summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbluebear94 <uruwi@protonmail.com>2023-09-04 05:46:17 -0400
committerGitHub <noreply@github.com>2023-09-04 11:46:17 +0200
commit499c5f24448d313b988721f212536fe170953905 (patch)
tree412b6a15cdb526709c7523143858a71fb7537a40 /crates
parentba043a8d70052a15d0c664c6dc6ca2091ec2c475 (diff)
Fix improper line wrapping in the presence of medial newlines (#2056)
Fixes #2019.
Diffstat (limited to 'crates')
-rw-r--r--crates/typst-library/src/layout/par.rs32
1 files changed, 18 insertions, 14 deletions
diff --git a/crates/typst-library/src/layout/par.rs b/crates/typst-library/src/layout/par.rs
index d3cd6cbf..5ae7db76 100644
--- a/crates/typst-library/src/layout/par.rs
+++ b/crates/typst-library/src/layout/par.rs
@@ -1,3 +1,5 @@
+use std::iter::Peekable;
+
use icu_properties::{maps::CodePointMapData, LineBreak};
use icu_provider::AsDeserializingBufferProvider;
use icu_provider_adapters::fork::ForkByKeyProvider;
@@ -933,18 +935,6 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec<L
// Layout the line.
let start = pred.line.end;
- // Fix for https://github.com/unicode-org/icu4x/issues/3811
- if i > 0 {
- if let Some(s_pred) = table.get(i + 1) {
- let next_start = s_pred.line.end;
- if !p.bidi.text[start..next_start]
- .contains(|c: char| !c.is_whitespace())
- {
- continue;
- }
- }
- }
-
let attempt = line(vt, p, start..end, mandatory, hyphen);
// Determine how much the line's spaces would need to be stretched
@@ -1103,7 +1093,7 @@ fn breakpoints<'a>(p: &'a Preparation<'a>) -> Breakpoints<'a> {
linebreaks.next();
Breakpoints {
p,
- linebreaks,
+ linebreaks: linebreaks.peekable(),
syllables: None,
offset: 0,
suffix: 0,
@@ -1117,7 +1107,7 @@ struct Breakpoints<'a> {
/// The paragraph's items.
p: &'a Preparation<'a>,
/// The inner iterator over the unicode line break opportunities.
- linebreaks: LineBreakIteratorUtf8<'a, 'a>,
+ linebreaks: Peekable<LineBreakIteratorUtf8<'a, 'a>>,
/// Iterator over syllables of the current word.
syllables: Option<hypher::Syllables<'a>>,
/// The current text offset.
@@ -1179,6 +1169,20 @@ impl Iterator for Breakpoints<'_> {
}
}
+ // Fix for https://github.com/unicode-org/icu4x/issues/3811
+ if !self.mandatory {
+ while let Some(&next) = self.linebreaks.peek() {
+ if !self.p.bidi.text[self.end..next]
+ .contains(|c: char| !c.is_whitespace())
+ {
+ self.end = next;
+ self.linebreaks.next();
+ } else {
+ break;
+ }
+ }
+ }
+
self.offset = self.end;
Some((self.end, self.mandatory, false))
}