diff options
| author | Peng Guanwen <pg999w@outlook.com> | 2023-09-19 23:05:32 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-19 17:05:32 +0200 |
| commit | 50f354e9890d00f8b2089cd221db4133757b3b41 (patch) | |
| tree | e833a8f6398f8302beda47db1b5d6ae1cda6eb44 | |
| parent | 7a46a85d3e25dd7eeee6abc9068302ba8d01fa65 (diff) | |
Correct the consecutive hyphen cost (#2190)
This just fixes a mistake previously made. `0.3` is the correct number that is proportional to the parameters in Knuth's paper. The previously choosed value `300` is due to my calculation mistake and is too large that essentially prevent any consecutive hyphens.
| -rw-r--r-- | crates/typst-library/src/layout/par.rs | 4 | ||||
| -rw-r--r-- | tests/ref/layout/page-binding.png | bin | 17255 -> 16919 bytes |
2 files changed, 2 insertions, 2 deletions
diff --git a/crates/typst-library/src/layout/par.rs b/crates/typst-library/src/layout/par.rs index e28e661c..01ccf127 100644 --- a/crates/typst-library/src/layout/par.rs +++ b/crates/typst-library/src/layout/par.rs @@ -903,7 +903,7 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec<L // Cost parameters. const HYPH_COST: Cost = 0.5; const RUNT_COST: Cost = 0.5; - const CONSECUTIVE_DASH_COST: Cost = 300.0; + const CONSECUTIVE_DASH_COST: Cost = 0.3; const MAX_COST: Cost = 1_000_000.0; const MIN_RATIO: f64 = -1.0; @@ -993,7 +993,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, // 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, - // where p=0.5 and a=300 + // where p=0.5 and a=0.3 cost = (0.01 + cost).powi(2); // Penalize two consecutive dashes (not necessarily hyphens) extra. diff --git a/tests/ref/layout/page-binding.png b/tests/ref/layout/page-binding.png Binary files differindex 59d73fa4..5b6d0657 100644 --- a/tests/ref/layout/page-binding.png +++ b/tests/ref/layout/page-binding.png |
