mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Prevent paragraph from overflowing due to trailing linebreak
This commit is contained in:
parent
cdb9867e0d
commit
5594868f8b
@ -179,8 +179,6 @@ impl<'a> GridLayouter<'a> {
|
|||||||
// Sum of fractions of all fractional tracks.
|
// Sum of fractions of all fractional tracks.
|
||||||
let mut fr = Fractional::zero();
|
let mut fr = Fractional::zero();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Resolve the size of all linear columns and compute the sum of all
|
// Resolve the size of all linear columns and compute the sum of all
|
||||||
// fractional tracks.
|
// fractional tracks.
|
||||||
for (&col, rcol) in self.cols.iter().zip(&mut self.rcols) {
|
for (&col, rcol) in self.cols.iter().zip(&mut self.rcols) {
|
||||||
|
@ -218,22 +218,26 @@ impl<'a> ParLayouter<'a> {
|
|||||||
stack.constraints.max.y.set_min(stack.size.h + line.size.h);
|
stack.constraints.max.y.set_min(stack.size.h + line.size.h);
|
||||||
stack.finish_region(ctx);
|
stack.finish_region(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the line does not fit horizontally or we have a mandatory
|
// If the line does not fit horizontally or we have a mandatory
|
||||||
// line break (i.e. due to "\n"), we push the line into the
|
// line break (i.e. due to "\n"), we push the line into the
|
||||||
// stack.
|
// stack.
|
||||||
if mandatory || !stack.regions.current.w.fits(line.size.w) {
|
if mandatory || !stack.regions.current.w.fits(line.size.w) {
|
||||||
stack.push(line);
|
|
||||||
start = end;
|
start = end;
|
||||||
last = None;
|
last = None;
|
||||||
|
|
||||||
|
stack.push(line);
|
||||||
stack.constraints.min.y = Some(stack.size.h);
|
stack.constraints.min.y = Some(stack.size.h);
|
||||||
|
|
||||||
// If there is a trailing line break at the end of the
|
// If there is a trailing line break at the end of the
|
||||||
// paragraph, we want to force an empty line.
|
// paragraph, we want to force an empty line.
|
||||||
if mandatory && end == self.bidi.text.len() {
|
if mandatory && end == self.bidi.text.len() {
|
||||||
stack.push(LineLayout::new(ctx, &self, end .. end));
|
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 {
|
} else {
|
||||||
// Otherwise, the line fits both horizontally and vertically
|
// Otherwise, the line fits both horizontally and vertically
|
||||||
// and we remember it.
|
// and we remember it.
|
||||||
|
@ -173,8 +173,7 @@ impl<'a> StackLayouter<'a> {
|
|||||||
let expand = self.expand;
|
let expand = self.expand;
|
||||||
let used = self.used.to_size(self.block);
|
let used = self.used.to_size(self.block);
|
||||||
|
|
||||||
// Determine the stack's size dependening on whether the region is
|
// Determine the stack's size dependening on whether the region expands.
|
||||||
// fixed.
|
|
||||||
let size = Size::new(
|
let size = Size::new(
|
||||||
if expand.x {
|
if expand.x {
|
||||||
self.constraints.exact.x = Some(self.full.w);
|
self.constraints.exact.x = Some(self.full.w);
|
||||||
|
BIN
tests/ref/layout/grid-5.png
Normal file
BIN
tests/ref/layout/grid-5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
11
tests/typ/layout/grid-5.typ
Normal file
11
tests/typ/layout/grid-5.typ
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
---
|
||||||
|
// Test that trailing linebreak doesn't overflow the region.
|
||||||
|
#page(height: 2cm)
|
||||||
|
#grid[
|
||||||
|
Hello \
|
||||||
|
Hello \
|
||||||
|
Hello \
|
||||||
|
|
||||||
|
World
|
||||||
|
]
|
Loading…
x
Reference in New Issue
Block a user