summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/typst/src/layout/flow.rs10
-rw-r--r--crates/typst/src/layout/place.rs5
-rw-r--r--tests/ref/bugs/2715-float-order.pngbin0 -> 12944 bytes
-rw-r--r--tests/typ/bugs/2715-float-order.typ19
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
new file mode 100644
index 00000000..76e6db9e
--- /dev/null
+++ b/tests/ref/bugs/2715-float-order.png
Binary files differ
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)