mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Fix bad bound in forcibly overflowing optimal paragraph layout (#4975)
This commit is contained in:
parent
ea145ff33b
commit
c145e05f01
@ -698,6 +698,12 @@ impl<'a> DerefMut for Items<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Items<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
f.debug_list().entries(&self.0).finish()
|
||||
}
|
||||
}
|
||||
|
||||
/// A reference to or a boxed item.
|
||||
pub enum ItemEntry<'a> {
|
||||
Ref(&'a Item<'a>),
|
||||
|
@ -481,9 +481,19 @@ fn linebreak_optimized_approximate(
|
||||
let Entry { end, breakpoint, unbreakable, .. } = table[idx];
|
||||
|
||||
let attempt = line(engine, p, start..end, breakpoint, Some(&pred));
|
||||
let (_, line_cost) =
|
||||
let (ratio, line_cost) =
|
||||
ratio_and_cost(p, metrics, width, &pred, &attempt, breakpoint, unbreakable);
|
||||
|
||||
// If approximation produces a valid layout without too much shrinking,
|
||||
// exact layout is guaranteed to find the same layout. If, however, the
|
||||
// line is overfull, we do not have this guarantee. Then, our bound
|
||||
// becomes useless and actively harmful (it could be lower than what
|
||||
// optimal layout produces). Thus, we immediately bail with an infinite
|
||||
// bound in this case.
|
||||
if ratio < metrics.min_ratio(false) {
|
||||
return Cost::INFINITY;
|
||||
}
|
||||
|
||||
pred = attempt;
|
||||
start = end;
|
||||
exact += line_cost;
|
||||
|
BIN
tests/ref/issue-4651-justify-bad-bound.png
Normal file
BIN
tests/ref/issue-4651-justify-bad-bound.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 207 B |
@ -167,3 +167,8 @@ int main() {
|
||||
// an underfull first line.
|
||||
#set par(hanging-indent: 2.5cm, justify: true)
|
||||
#lorem(5)
|
||||
|
||||
--- issue-4651-justify-bad-bound ---
|
||||
// Test that overflow does not lead to bad bounds in paragraph optimization.
|
||||
#set par(justify: true)
|
||||
#block(width: 0pt)[A B]
|
||||
|
Loading…
x
Reference in New Issue
Block a user