diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-02-27 13:34:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-27 12:34:26 +0000 |
| commit | ae31640c0a62d26b7f2a7a38579293ae48c7c7b7 (patch) | |
| tree | 55a6ba86979c441b7451ce6b0fe257478b8e1014 | |
| parent | 79615a01bd4266e6a5adb385650735768ea96d56 (diff) | |
Fix out-of-order floats (#3506)
| -rw-r--r-- | crates/typst/src/layout/flow.rs | 10 | ||||
| -rw-r--r-- | crates/typst/src/layout/place.rs | 5 | ||||
| -rw-r--r-- | tests/ref/bugs/2715-float-order.png | bin | 0 -> 12944 bytes | |||
| -rw-r--r-- | tests/typ/bugs/2715-float-order.typ | 19 |
4 files changed, 27 insertions, 7 deletions
diff --git a/crates/typst/src/layout/flow.rs b/crates/typst/src/layout/flow.rs index 003c9db7..8701d35d 100644 --- a/crates/typst/src/layout/flow.rs +++ b/crates/typst/src/layout/flow.rs @@ -312,7 +312,7 @@ impl<'a> FlowLayouter<'a> { align.x().unwrap_or_default().resolve(styles) }); let y_align = alignment.map(|align| align.y().map(|y| y.resolve(styles))); - let mut frame = placed.layout(engine, styles, self.regions)?.into_frame(); + let mut frame = placed.layout(engine, styles, self.regions.base())?.into_frame(); frame.meta(styles, false); let item = FlowItem::Placed { frame, x_align, y_align, delta, float, clearance }; self.layout_item(engine, item) @@ -427,9 +427,11 @@ impl<'a> FlowLayouter<'a> { clearance, .. } => { - // If the float doesn't fit, queue it for the next region. - if !self.regions.size.y.fits(frame.height() + clearance) - && !self.regions.in_last() + // If there is a queued float in front or if the float doesn't + // fit, queue it for the next region. + if !self.pending_floats.is_empty() + || (!self.regions.size.y.fits(frame.height() + clearance) + && !self.regions.in_last()) { self.pending_floats.push(item); return Ok(()); diff --git a/crates/typst/src/layout/place.rs b/crates/typst/src/layout/place.rs index b2906024..61b07308 100644 --- a/crates/typst/src/layout/place.rs +++ b/crates/typst/src/layout/place.rs @@ -2,7 +2,7 @@ use crate::diag::{bail, At, Hint, SourceResult}; use crate::engine::Engine; use crate::foundations::{elem, Content, Packed, Smart, StyleChain}; use crate::layout::{ - Alignment, Axes, Em, Fragment, LayoutMultiple, Length, Regions, Rel, VAlignment, + Alignment, Axes, Em, Fragment, LayoutMultiple, Length, Regions, Rel, Size, VAlignment, }; use crate::realize::{Behave, Behaviour}; @@ -93,11 +93,10 @@ impl Packed<PlaceElem> { &self, engine: &mut Engine, styles: StyleChain, - regions: Regions, + base: Size, ) -> SourceResult<Fragment> { // The pod is the base area of the region because for absolute // placement we don't really care about the already used area. - let base = regions.base(); let float = self.float(styles); let alignment = self.alignment(styles); diff --git a/tests/ref/bugs/2715-float-order.png b/tests/ref/bugs/2715-float-order.png Binary files differnew file mode 100644 index 00000000..76e6db9e --- /dev/null +++ b/tests/ref/bugs/2715-float-order.png diff --git a/tests/typ/bugs/2715-float-order.typ b/tests/typ/bugs/2715-float-order.typ new file mode 100644 index 00000000..f6ac6219 --- /dev/null +++ b/tests/typ/bugs/2715-float-order.typ @@ -0,0 +1,19 @@ +#set page(height: 170pt) +#set figure(placement: auto) + +#figure( + rect(height: 60pt), + caption: [Rectangle I], +) + +#figure( + rect(height: 50pt), + caption: [Rectangle II], +) + +#figure( + circle(), + caption: [Circle], +) + +#lorem(20) |
