Fix out-of-order floats (#3506)

This commit is contained in:
Laurenz 2024-02-27 13:34:26 +01:00 committed by GitHub
parent 79615a01bd
commit ae31640c0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 7 deletions

View File

@ -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(());

View File

@ -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);

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -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)