diff options
| -rw-r--r-- | crates/typst-library/src/layout/par.rs | 12 | ||||
| -rw-r--r-- | tests/ref/bugs/justify-hanging-indent.png | bin | 0 -> 1864 bytes | |||
| -rw-r--r-- | tests/typ/bugs/justify-hanging-indent.typ | 6 |
3 files changed, 15 insertions, 3 deletions
diff --git a/crates/typst-library/src/layout/par.rs b/crates/typst-library/src/layout/par.rs index ee47b579..9255124e 100644 --- a/crates/typst-library/src/layout/par.rs +++ b/crates/typst-library/src/layout/par.rs @@ -1015,9 +1015,15 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec<L // The line is overfull. This is the case if // - justification is on, but we'd need to shrink too much // - justification is off and the line just doesn't fit - // Since any longer line will also be overfull, we can deactivate - // this breakpoint. - active = i + 1; + // + // If this is the earliest breakpoint in the active set + // (active == i), remove it from the active set. If there is an + // earlier one (active < i), then the logically shorter line was + // in fact longer (can happen with negative spacing) and we + // can't trim the active set just yet. + if active == i { + active += 1; + } MAX_COST } else if mandatory || eof { // This is a mandatory break and the line is not overfull, so diff --git a/tests/ref/bugs/justify-hanging-indent.png b/tests/ref/bugs/justify-hanging-indent.png Binary files differnew file mode 100644 index 00000000..015cc44e --- /dev/null +++ b/tests/ref/bugs/justify-hanging-indent.png diff --git a/tests/typ/bugs/justify-hanging-indent.typ b/tests/typ/bugs/justify-hanging-indent.typ new file mode 100644 index 00000000..511aa172 --- /dev/null +++ b/tests/typ/bugs/justify-hanging-indent.typ @@ -0,0 +1,6 @@ +// Test that combination of justification and hanging indent doesn't result in +// an underfull first line. + +--- +#set par(hanging-indent: 2.5cm, justify: true) +#lorem(5) |
