mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
linebreak_optimized: Handle breakpoints separated only by spaces (#1821)
This commit is contained in:
parent
a4ad407a79
commit
b59b8bfb35
@ -929,9 +929,22 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec<L
|
|||||||
let mut best: Option<Entry> = None;
|
let mut best: Option<Entry> = None;
|
||||||
|
|
||||||
// Find the optimal predecessor.
|
// Find the optimal predecessor.
|
||||||
for (i, pred) in table.iter_mut().enumerate().skip(active) {
|
for (i, pred) in table.iter().enumerate().skip(active) {
|
||||||
// Layout the line.
|
// Layout the line.
|
||||||
let start = pred.line.end;
|
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);
|
let attempt = line(vt, p, start..end, mandatory, hyphen);
|
||||||
|
|
||||||
// Determine how much the line's spaces would need to be stretched
|
// Determine how much the line's spaces would need to be stretched
|
||||||
@ -996,7 +1009,7 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec<L
|
|||||||
}
|
}
|
||||||
|
|
||||||
// In Knuth paper, cost = (1 + 100|r|^3 + p)^2 + a,
|
// In Knuth paper, cost = (1 + 100|r|^3 + p)^2 + a,
|
||||||
// where r is the ratio, p=50 is penaty, and a=3000 is consecutive penaty.
|
// where r is the ratio, p=50 is the penalty, and a=3000 is consecutive the penalty.
|
||||||
// We divide the whole formula by 10, resulting (0.01 + |r|^3 + p)^2 + a,
|
// We divide the whole formula by 10, resulting (0.01 + |r|^3 + p)^2 + a,
|
||||||
// where p=0.5 and a=300
|
// where p=0.5 and a=300
|
||||||
cost = (0.01 + cost).powi(2);
|
cost = (0.01 + cost).powi(2);
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 27 KiB |
@ -40,3 +40,13 @@ This text can be fitted in one line.
|
|||||||
"a b c "
|
"a b c "
|
||||||
}
|
}
|
||||||
#"d"
|
#"d"
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test that justification cannot lead to a leading space
|
||||||
|
#set par(justify: true)
|
||||||
|
#set text(size: 12pt)
|
||||||
|
#set page(width: 45mm, height: auto)
|
||||||
|
|
||||||
|
lorem ipsum 1234, lorem ipsum dolor sit amet
|
||||||
|
|
||||||
|
#" leading whitespace should still be displayed"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user