mirror of
https://github.com/typst/typst
synced 2025-05-22 13:05:29 +08:00
Penalize runts (#1858)
This commit is contained in:
parent
da8367e189
commit
f56060c1b3
@ -908,6 +908,7 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec<L
|
|||||||
|
|
||||||
// Cost parameters.
|
// Cost parameters.
|
||||||
const HYPH_COST: Cost = 0.5;
|
const HYPH_COST: Cost = 0.5;
|
||||||
|
const RUNT_COST: Cost = 0.5;
|
||||||
const CONSECUTIVE_DASH_COST: Cost = 300.0;
|
const CONSECUTIVE_DASH_COST: Cost = 300.0;
|
||||||
const MAX_COST: Cost = 1_000_000.0;
|
const MAX_COST: Cost = 1_000_000.0;
|
||||||
const MIN_RATIO: f64 = -1.0;
|
const MIN_RATIO: f64 = -1.0;
|
||||||
@ -984,6 +985,11 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec<L
|
|||||||
ratio.powi(3).abs()
|
ratio.powi(3).abs()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Penalize runts.
|
||||||
|
if k == i + 1 && eof {
|
||||||
|
cost += RUNT_COST;
|
||||||
|
}
|
||||||
|
|
||||||
// Penalize hyphens.
|
// Penalize hyphens.
|
||||||
if hyphen {
|
if hyphen {
|
||||||
cost += HYPH_COST;
|
cost += HYPH_COST;
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 19 KiB |
@ -31,3 +31,12 @@ D E F #linebreak(justify: true)
|
|||||||
#set page(width: 155pt)
|
#set page(width: 155pt)
|
||||||
#set par(justify: true)
|
#set par(justify: true)
|
||||||
This text can be fitted in one line.
|
This text can be fitted in one line.
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test that runts are avoided when it's not too costly to do so.
|
||||||
|
#set page(width: 124pt)
|
||||||
|
#set par(justify: true)
|
||||||
|
#for i in range(0, 20) {
|
||||||
|
"a b c "
|
||||||
|
}
|
||||||
|
#"d"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user