summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-09-27 11:38:18 +0200
committerLaurenz <laurmaedje@gmail.com>2021-09-27 11:38:18 +0200
commit6c478face427b56e1ac799b0962f77d82b5e1534 (patch)
treecbb20cc0b4c04018a6ae3d665e4ce4dcd290ee7d /src/layout
parent19e17cc6ac05a088e6b27452b4e6f86bf858d1a3 (diff)
Fix paragraph constraints
Co-Authored-By: Martin <mhaug@live.de>
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/par.rs32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/layout/par.rs b/src/layout/par.rs
index 8166779e..847612b9 100644
--- a/src/layout/par.rs
+++ b/src/layout/par.rs
@@ -190,16 +190,22 @@ impl<'a> ParLayouter<'a> {
// line cannot be broken up further.
if !stack.regions.current.fits(line.size) {
if let Some((last_line, last_end)) = last.take() {
- // The region must not fit this line for the result to be valid.
+ // Since the new line try did not fit, no region that would
+ // fit the line will yield the same line break. Therefore,
+ // the width of the region must not fit the width of the
+ // tried line.
if !stack.regions.current.w.fits(line.size.w) {
stack.constraints.max.x.set_min(line.size.w);
}
+ // Same as above, but for height.
if !stack.regions.current.h.fits(line.size.h) {
- stack.constraints.max.y.set_min(stack.size.h + line.size.h);
+ let too_large = stack.size.h + self.line_spacing + line.size.h;
+ stack.constraints.max.y.set_min(too_large);
}
stack.push(last_line);
+
stack.constraints.min.y = Some(stack.size.h);
start = last_end;
line = LineLayout::new(ctx, &self, start .. end);
@@ -207,24 +213,18 @@ impl<'a> ParLayouter<'a> {
}
// If the line does not fit vertically, we start a new region.
- while !stack.regions.current.h.fits(line.size.h)
- && !stack.regions.in_full_last()
- {
- // Again, the line must not fit. It would if the space taken up
- // plus the line height would fit, therefore the constraint
- // below.
- stack.constraints.max.y.set_min(stack.size.h + line.size.h);
- stack.finish_region(ctx);
- }
-
- // If the line does not fit vertically, we start a new region.
while !stack.regions.current.h.fits(line.size.h) {
if stack.regions.in_full_last() {
stack.overflowing = true;
break;
}
- stack.constraints.max.y.set_min(stack.size.h + line.size.h);
+ // Again, the line must not fit. It would if the space taken up
+ // plus the line height would fit, therefore the constraint
+ // below.
+ let too_large = stack.size.h + self.line_spacing + line.size.h;
+ stack.constraints.max.y.set_min(too_large);
+
stack.finish_region(ctx);
}
@@ -236,7 +236,6 @@ impl<'a> ParLayouter<'a> {
last = None;
stack.push(line);
- stack.constraints.min.y = Some(stack.size.h);
// If there is a trailing line break at the end of the
// paragraph, we want to force an empty line.
@@ -244,9 +243,10 @@ impl<'a> ParLayouter<'a> {
let line = LineLayout::new(ctx, &self, end .. end);
if stack.regions.current.h.fits(line.size.h) {
stack.push(line);
- stack.constraints.min.y = Some(stack.size.h);
}
}
+
+ stack.constraints.min.y = Some(stack.size.h);
} else {
// Otherwise, the line fits both horizontally and vertically
// and we remember it.