diff --git a/crates/typst/src/layout/flow.rs b/crates/typst/src/layout/flow.rs index 003c9db7d..8701d35d9 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 b29060244..61b07308d 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 { &self, engine: &mut Engine, styles: StyleChain, - regions: Regions, + base: Size, ) -> SourceResult { // 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 new file mode 100644 index 000000000..76e6db9e6 Binary files /dev/null and b/tests/ref/bugs/2715-float-order.png differ diff --git a/tests/typ/bugs/2715-float-order.typ b/tests/typ/bugs/2715-float-order.typ new file mode 100644 index 000000000..f6ac6219b --- /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)