Count image height in float content
VerticalItem::Image was missing from Float::content_height, so image floats reported zero content height and could overlap following text. Include the image height and add a regression test. Test count is 1074.
This commit is contained in:
1 parent
c2310d85ac
commit
16dd2e1f62
5 files changed
+33
-7
No files matched your search
@@ -1110,6 +1110,7 @@ impl Float {
|
||||
VerticalItem::Halign(halign) => halign.height,
|
||||
VerticalItem::Paragraph(paragraph) => paragraph.height,
|
||||
VerticalItem::Math { height, depth, .. } => height + depth,
|
||||
VerticalItem::Image { height, .. } => *height,
|
||||
_ => 0,
|
||||
})
|
||||
.sum()
|
||||
@@ -7909,6 +7910,31 @@ mod tests {
|
||||
assert_eq!(float.height, 30);
|
||||
assert_eq!(float.content_height(), 30);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_height_covers_image_content() {
|
||||
let image = crate::render::RasterImage {
|
||||
width: 1,
|
||||
height: 1,
|
||||
rgb: vec![0, 0, 0],
|
||||
};
|
||||
let unit = Unit::float_with_content(
|
||||
1,
|
||||
FloatPlacement::Top,
|
||||
100,
|
||||
5,
|
||||
vec![VerticalItem::Image {
|
||||
width: 100,
|
||||
height: 30,
|
||||
image,
|
||||
}],
|
||||
);
|
||||
let VerticalItem::Float(float) = &unit.items[0] else {
|
||||
panic!("expected float");
|
||||
};
|
||||
assert_eq!(float.height, 30);
|
||||
assert_eq!(float.content_height(), 30);
|
||||
}
|
||||
#[test]
|
||||
fn float_carries_vertical_content() {
|
||||
let unit = Unit::float_with_content(
|
||||
|
||||
Reference in new issue
Block a user