mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
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:
parent
39e101f0af
commit
c5a103867d
@ -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 |
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user