layout::par::finalize: Bound allotted width when fitting to width (#1828)

Sometimes, optimized line breaking outputs lines that are wider
than the allotted width so that spacing between words can be
narrowed to fit. However, the width calculation for the fit-to-width
case does not account for this, causing the resulting width to exceed
the width of the region. This commit takes the minimum of the
calculated width with the width of the region. Fixes #1825.
This commit is contained in:
bluebear94 2023-08-02 18:45:40 -04:00 committed by GitHub
parent 39e101f0af
commit c5a103867d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

View File

@ -1344,7 +1344,9 @@ fn finalize(
let width = if !region.x.is_finite()
|| (!expand && lines.iter().all(|line| line.fr().is_zero()))
{
p.hang + lines.iter().map(|line| line.width).max().unwrap_or_default()
region
.x
.min(p.hang + lines.iter().map(|line| line.width).max().unwrap_or_default())
} else {
region.x
};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 242 KiB

View File

@ -53,3 +53,11 @@
---
// Error: 15-21 expected length, color, dictionary, stroke, none, or auto, found array
#rect(stroke: (1, 2))
---
#set page(width: 17.8cm)
#lorem(100)
#rect(lorem(100))
#set par(justify: true)
#lorem(100)
#rect(lorem(100))